OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ |
6 #define CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include <memory> |
| 9 |
9 #include "base/trace_event/trace_event_impl.h" | 10 #include "base/trace_event/trace_event_impl.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 class BackgroundTracingConfig; | 15 class BackgroundTracingConfig; |
15 struct BackgroundTracingUploadConfig; | 16 struct BackgroundTracingUploadConfig; |
16 | 17 |
17 // BackgroundTracingManager is used on the browser process to trigger the | 18 // BackgroundTracingManager is used on the browser process to trigger the |
18 // collection of trace data and upload the results. Only the browser UI thread | 19 // collection of trace data and upload the results. Only the browser UI thread |
19 // is allowed to interact with the BackgroundTracingManager. All callbacks are | 20 // is allowed to interact with the BackgroundTracingManager. All callbacks are |
20 // called on the UI thread. | 21 // called on the UI thread. |
21 class BackgroundTracingManager { | 22 class BackgroundTracingManager { |
22 public: | 23 public: |
23 CONTENT_EXPORT static BackgroundTracingManager* GetInstance(); | 24 CONTENT_EXPORT static BackgroundTracingManager* GetInstance(); |
24 | 25 |
25 // ReceiveCallback will will be called on the UI thread every time the | 26 // ReceiveCallback will will be called on the UI thread every time the |
26 // BackgroundTracingManager finalizes a trace. The first parameter of | 27 // BackgroundTracingManager finalizes a trace. The first parameter of |
27 // this callback is the trace data. The second is metadata that was | 28 // this callback is the trace data. The second is metadata that was |
28 // generated and embedded into the trace. The third is a callback to | 29 // generated and embedded into the trace. The third is a callback to |
29 // notify the BackgroundTracingManager that you've finished processing | 30 // notify the BackgroundTracingManager that you've finished processing |
30 // the trace data. | 31 // the trace data. |
31 // | 32 // |
32 // Example: | 33 // Example: |
33 // | 34 // |
34 // void Upload(const scoped_refptr<base::RefCountedString>& data, | 35 // void Upload(const scoped_refptr<base::RefCountedString>& data, |
35 // scoped_ptr<base::DictionaryValue>, | 36 // std::unique_ptr<base::DictionaryValue>, |
36 // base::Closure done_callback) { | 37 // base::Closure done_callback) { |
37 // BrowserThread::PostTaskAndReply( | 38 // BrowserThread::PostTaskAndReply( |
38 // BrowserThread::FILE, | 39 // BrowserThread::FILE, |
39 // FROM_HERE, | 40 // FROM_HERE, |
40 // base::Bind(&DoUploadOnFileThread, data), | 41 // base::Bind(&DoUploadOnFileThread, data), |
41 // done_callback | 42 // done_callback |
42 // ); | 43 // ); |
43 // } | 44 // } |
44 // | 45 // |
45 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&, | 46 typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&, |
46 scoped_ptr<const base::DictionaryValue>, | 47 std::unique_ptr<const base::DictionaryValue>, |
47 base::Closure)> ReceiveCallback; | 48 base::Closure)> |
| 49 ReceiveCallback; |
48 | 50 |
49 // Set the triggering rules for when to start recording. | 51 // Set the triggering rules for when to start recording. |
50 // | 52 // |
51 // In preemptive mode, recording begins immediately and any calls to | 53 // In preemptive mode, recording begins immediately and any calls to |
52 // TriggerNamedEvent() will potentially trigger the trace to finalize and get | 54 // TriggerNamedEvent() will potentially trigger the trace to finalize and get |
53 // uploaded to the specified upload_sink. Once the trace has been uploaded, | 55 // uploaded to the specified upload_sink. Once the trace has been uploaded, |
54 // tracing will be enabled again. | 56 // tracing will be enabled again. |
55 // | 57 // |
56 // In reactive mode, recording begins when TriggerNamedEvent() is called, and | 58 // In reactive mode, recording begins when TriggerNamedEvent() is called, and |
57 // continues until either the next call to TriggerNamedEvent, or a timeout | 59 // continues until either the next call to TriggerNamedEvent, or a timeout |
58 // occurs. Tracing will not be re-enabled after the trace is finalized and | 60 // occurs. Tracing will not be re-enabled after the trace is finalized and |
59 // uploaded to the upload_sink. | 61 // uploaded to the upload_sink. |
60 // | 62 // |
61 // Calls to SetActiveScenario() with a config will fail if tracing is | 63 // Calls to SetActiveScenario() with a config will fail if tracing is |
62 // currently on. Use WhenIdle to register a callback to get notified when | 64 // currently on. Use WhenIdle to register a callback to get notified when |
63 // the manager is idle and a config can be set again. | 65 // the manager is idle and a config can be set again. |
64 enum DataFiltering { | 66 enum DataFiltering { |
65 NO_DATA_FILTERING, | 67 NO_DATA_FILTERING, |
66 ANONYMIZE_DATA, | 68 ANONYMIZE_DATA, |
67 }; | 69 }; |
68 virtual bool SetActiveScenario(scoped_ptr<BackgroundTracingConfig> config, | 70 virtual bool SetActiveScenario( |
69 const ReceiveCallback& receive_callback, | 71 std::unique_ptr<BackgroundTracingConfig> config, |
70 DataFiltering data_filtering) = 0; | 72 const ReceiveCallback& receive_callback, |
| 73 DataFiltering data_filtering) = 0; |
71 | 74 |
72 // Notifies the caller when the manager is idle (not recording or uploading), | 75 // Notifies the caller when the manager is idle (not recording or uploading), |
73 // so that a call to SetActiveScenario() is likely to succeed. | 76 // so that a call to SetActiveScenario() is likely to succeed. |
74 typedef base::Callback<void()> IdleCallback; | 77 typedef base::Callback<void()> IdleCallback; |
75 virtual void WhenIdle(IdleCallback idle_callback) = 0; | 78 virtual void WhenIdle(IdleCallback idle_callback) = 0; |
76 | 79 |
77 typedef base::Callback<void(bool)> StartedFinalizingCallback; | 80 typedef base::Callback<void(bool)> StartedFinalizingCallback; |
78 typedef int TriggerHandle; | 81 typedef int TriggerHandle; |
79 | 82 |
80 // Notifies that a manual trigger event has occurred, and we may need to | 83 // Notifies that a manual trigger event has occurred, and we may need to |
(...skipping 14 matching lines...) Expand all Loading... |
95 const base::Closure& callback) = 0; | 98 const base::Closure& callback) = 0; |
96 virtual void FireTimerForTesting() = 0; | 99 virtual void FireTimerForTesting() = 0; |
97 | 100 |
98 protected: | 101 protected: |
99 virtual ~BackgroundTracingManager() {} | 102 virtual ~BackgroundTracingManager() {} |
100 }; | 103 }; |
101 | 104 |
102 } // namespace content | 105 } // namespace content |
103 | 106 |
104 #endif // CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ | 107 #endif // CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ |
OLD | NEW |