1 : // Copyright 2012 Google Inc. All Rights Reserved.
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/files/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 : // Forward declaration.
29 m : namespace base { class MessageLoop; }
30 :
31 m : namespace trace {
32 m : namespace service {
33 :
34 m : class TraceFileWriter;
35 :
36 : // This class creates manages buffer consumer instances for a call trace
37 : // service instance.
38 m : class TraceFileWriterFactory : public BufferConsumerFactory {
39 m : public:
40 : // construct a TraceFileWriterFactory instance.
41 : // @param message_loop The message loop on which TraceFileWriter instances
42 : // created by this factory will consume buffers. The factory instance
43 : // does NOT take ownership of the message_loop. The message_loop must
44 : // outlive the factory instance.
45 m : explicit TraceFileWriterFactory(base::MessageLoop* message_loop);
46 :
47 : // @name BufferConsumerFactory implementation.
48 : // @{
49 m : virtual bool CreateConsumer(scoped_refptr<BufferConsumer>* consumer) OVERRIDE;
50 : // @}
51 :
52 : // Sets the trace file directory to which all subsequently created trace
53 : // file writers will output trace files.
54 m : bool SetTraceFileDirectory(const base::FilePath& path);
55 :
56 : // Get the message loop the trace file writers should use for IO.
57 m : base::MessageLoop* message_loop() { return message_loop_; }
58 :
59 m : protected:
60 : // The message loop the trace file writers should use for IO.
61 m : base::MessageLoop* const message_loop_;
62 :
63 : // The directory into which trace file writers will write.
64 m : base::FilePath trace_file_directory_;
65 :
66 : // The set of currently active buffer consumer objects. Protected by lock_.
67 m : std::set<scoped_refptr<BufferConsumer>> active_consumers_;
68 :
69 : // Used to protect access to the set of active consumers.
70 m : base::Lock lock_;
71 :
72 m : private:
73 m : DISALLOW_COPY_AND_ASSIGN(TraceFileWriterFactory);
74 m : };
75 :
76 m : } // namespace service
77 m : } // namespace trace
78 :
79 : #endif // SYZYGY_TRACE_SERVICE_TRACE_FILE_WRITER_FACTORY_H_
|