| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ | |
| 6 #define CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ | |
| 7 | |
| 8 #include "base/trace_event/trace_event_impl.h" | |
| 9 #include "base/values.h" | |
| 10 #include "content/common/content_export.h" | |
| 11 | |
| 12 namespace content { | |
| 13 struct BackgroundTracingConfig; | |
| 14 struct BackgroundTracingUploadConfig; | |
| 15 | |
| 16 // BackgroundTracingManager is used on the browser process to trigger the | |
| 17 // collection of trace data and upload the results. Only the browser UI thread | |
| 18 // is allowed to interact with the BackgroundTracingManager. All callbacks are | |
| 19 // called on the UI thread. | |
| 20 class BackgroundTracingManager { | |
| 21 public: | |
| 22 CONTENT_EXPORT static BackgroundTracingManager* GetInstance(); | |
| 23 | |
| 24 // ReceiveCallback will will be called on the UI thread every time the | |
| 25 // BackgroundTracingManager finalizes a trace. The first parameter of | |
| 26 // this callback is the trace data. The second is a callback to | |
| 27 // notify the BackgroundTracingManager that you've finished processing | |
| 28 // the trace data. | |
| 29 // | |
| 30 // Example: | |
| 31 // | |
| 32 // void Upload(const base::RefCountedString* data, | |
| 33 // base::Closure done_callback) { | |
| 34 // BrowserThread::PostTaskAndReply( | |
| 35 // BrowserThread::FILE, | |
| 36 // FROM_HERE, | |
| 37 // base::Bind(&DoUploadOnFileThread, data), | |
| 38 // done_callback | |
| 39 // ); | |
| 40 // } | |
| 41 // | |
| 42 typedef base::Callback<void(const base::RefCountedString*, base::Closure)> | |
| 43 ReceiveCallback; | |
| 44 | |
| 45 // Set the triggering rules for when to start recording. | |
| 46 // | |
| 47 // In preemptive mode, recording begins immediately and any calls to | |
| 48 // TriggerNamedEvent() will potentially trigger the trace to finalize and get | |
| 49 // uploaded to the specified upload_sink. Once the trace has been uploaded, | |
| 50 // tracing will be enabled again. | |
| 51 // | |
| 52 // In reactive mode, recording begins when TriggerNamedEvent() is called, and | |
| 53 // continues until either the next call to TriggerNamedEvent, or a timeout | |
| 54 // occurs. Tracing will not be re-enabled after the trace is finalized and | |
| 55 // uploaded to the upload_sink. | |
| 56 // | |
| 57 // Calls to SetActiveScenario() with a config will fail if tracing is | |
| 58 // currently on. Use WhenIdle to register a callback to get notified when | |
| 59 // the manager is idle and a config can be set again. | |
| 60 virtual bool SetActiveScenario(scoped_ptr<BackgroundTracingConfig> config, | |
| 61 const ReceiveCallback& receive_callback, | |
| 62 bool requires_anonymized_data) = 0; | |
| 63 | |
| 64 // Notifies the caller when the manager is idle (not recording or uploading), | |
| 65 // so that a call to SetActiveScenario() is likely to succeed. | |
| 66 typedef base::Callback<void()> IdleCallback; | |
| 67 virtual void WhenIdle(IdleCallback idle_callback) = 0; | |
| 68 | |
| 69 typedef base::Callback<void(bool)> StartedFinalizingCallback; | |
| 70 typedef int TriggerHandle; | |
| 71 | |
| 72 // Notifies that a manual trigger event has occurred, and we may need to | |
| 73 // either begin recording or finalize the trace, depending on the config. | |
| 74 // If the trigger specified isn't active in the config, this will do nothing. | |
| 75 virtual void TriggerNamedEvent( | |
| 76 TriggerHandle trigger_handle, | |
| 77 StartedFinalizingCallback started_callback) = 0; | |
| 78 | |
| 79 // Registers a manual trigger handle, and returns a TriggerHandle which can | |
| 80 // be passed to DidTriggerHappen(). | |
| 81 virtual TriggerHandle RegisterTriggerType(const char* trigger_name) = 0; | |
| 82 | |
| 83 // Returns a list of all registered triggers. | |
| 84 virtual void GetTriggerNameList(std::vector<std::string>* trigger_names) = 0; | |
| 85 | |
| 86 virtual void InvalidateTriggerHandlesForTesting() = 0; | |
| 87 | |
| 88 protected: | |
| 89 virtual ~BackgroundTracingManager() {} | |
| 90 }; | |
| 91 | |
| 92 } // namespace content | |
| 93 | |
| 94 #endif // CONTENT_PUBLIC_BROWSER_BACKGROUND_TRACING_MANAGER_H_ | |
| OLD | NEW |