1 : // Copyright 2012 Google Inc.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 : //
15 : // This file declares the TraceFileWriter class, which is the default
16 : // implementation for the buffer consumer used by the call trace service.
17 :
18 : #ifndef SYZYGY_TRACE_SERVICE_TRACE_FILE_WRITER_FACTORY_H_
19 : #define SYZYGY_TRACE_SERVICE_TRACE_FILE_WRITER_FACTORY_H_
20 :
21 : #include <set>
22 :
23 : #include "base/file_path.h"
24 : #include "base/synchronization/lock.h"
25 : #include "base/win/scoped_handle.h"
26 : #include "syzygy/trace/service/buffer_consumer.h"
27 :
28 m : class MessageLoop;
29 :
30 m : namespace trace {
31 m : namespace service {
32 :
33 m : class TraceFileWriter;
34 :
35 : // This class creates manages buffer consumer instances for a call trace
36 : // service instance.
37 m : class TraceFileWriterFactory : public BufferConsumerFactory {
38 m : public:
39 : // construct a TraceFileWriterFactory instance.
40 : // @param message_loop The message loop on which TraceFileWriter instances
41 : // created by this factory will consume buffers. The factory instance
42 : // does NOT take ownership of the message_loop. The message_loop must
43 : // outlive the factory instance.
44 m : explicit TraceFileWriterFactory(MessageLoop* message_loop);
45 :
46 : // @name BufferConsumerFactory implementation.
47 : // @{
48 m : virtual bool CreateConsumer(scoped_refptr<BufferConsumer>* consumer) OVERRIDE;
49 : // @}
50 :
51 : // Sets the trace file directory to which all subsequently created trace
52 : // file writers will output trace files.
53 m : bool SetTraceFileDirectory(const FilePath& path);
54 :
55 : // Get the message loop the trace file writers should use for IO.
56 m : MessageLoop* message_loop() { return message_loop_; }
57 :
58 m : protected:
59 : // The message loop the trace file writers should use for IO.
60 m : MessageLoop* const message_loop_;
61 :
62 : // The directory into which trace file writers will write.
63 m : FilePath trace_file_directory_;
64 :
65 : // The set of currently active buffer consumer objects. Protected by lock_.
66 m : std::set<scoped_refptr<BufferConsumer>> active_consumers_;
67 :
68 : // Used to protect access to the set of active consumers.
69 m : base::Lock lock_;
70 :
71 m : private:
72 m : DISALLOW_COPY_AND_ASSIGN(TraceFileWriterFactory);
73 m : };
74 :
75 m : } // namespace service
76 m : } // namespace trace
77 :
78 : #endif // SYZYGY_TRACE_SERVICE_TRACE_FILE_WRITER_FACTORY_H_
|