Index: content/browser/tracing/background_tracing_manager.cc |
diff --git a/content/browser/tracing/background_tracing_manager.cc b/content/browser/tracing/background_tracing_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b40ba2c70a66142e6e9e21b7a24715283dc02122 |
--- /dev/null |
+++ b/content/browser/tracing/background_tracing_manager.cc |
@@ -0,0 +1,88 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/tracing/background_tracing_manager.h" |
+ |
+#include "base/memory/ref_counted_memory.h" |
+#include "base/memory/singleton.h" |
+#include "content/browser/tracing/background_tracing_endpoint.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/tracing_controller.h" |
+ |
+BackgroundTracingManager::BackgroundTracingManager() |
+ : is_gathering_(false), is_recording_(false), weak_ptr_factory_(this) { |
+} |
+ |
+BackgroundTracingManager::~BackgroundTracingManager() { |
+} |
+ |
+void BackgroundTracingManager::SetActiveScenario( |
+ scoped_refptr<BackgroundTracingScenario> scenario) { |
+ CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
+ CHECK(!active_scenario_); |
+ active_scenario_ = scenario; |
+ |
+ EnableRecording(); |
+} |
+ |
+void BackgroundTracingManager::EnableRecording() { |
+ is_recording_ = true; |
dsinclair
2015/05/01 15:46:14
I don't see this getting reset to false anywhere?
|
+ content::TracingController::GetInstance()->EnableRecording( |
+ active_scenario_->GetCategoryFilter(), |
+ base::trace_event::TraceOptions(base::trace_event::RECORD_CONTINUOUSLY), |
dsinclair
2015/05/01 15:46:14
Do we always want to set RECORD_CONTINUOUSLY? Won'
|
+ content::TracingController::EnableRecordingDoneCallback()); |
+} |
+ |
+void BackgroundTracingManager::OnFinalizeComplete() { |
+ if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(&BackgroundTracingManager::OnFinalizeComplete, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ return; |
+ } |
+ |
+ CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
+ |
+ is_gathering_ = false; |
+ |
+ EnableRecording(); |
+} |
+ |
+void BackgroundTracingManager::BeginFinalizingBackgroundTracing() { |
+ active_scenario_->GetEndpoint()->SetDoneCallback( |
+ base::Bind(&BackgroundTracingManager::OnFinalizeComplete, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ content::TracingController::GetInstance()->DisableRecording( |
+ content::TracingController::CreateCompressedStringSink( |
+ active_scenario_->GetEndpoint())); |
+} |
+ |
+void BackgroundTracingManager::TryFinalizingBackgroundTracing( |
dsinclair
2015/05/01 15:46:14
I'm a little confused by the terminology is the fl
|
+ StartedFinalizingCallback callback) { |
+ if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::UI, FROM_HERE, |
+ base::Bind(&BackgroundTracingManager::TryFinalizingBackgroundTracing, |
+ weak_ptr_factory_.GetWeakPtr(), callback)); |
+ return; |
+ } |
+ |
+ if (!active_scenario_ || is_gathering_) { |
+ if (!callback.is_null()) |
+ callback.Run(false); |
+ return; |
+ } |
+ |
+ is_gathering_ = true; |
+ |
+ BeginFinalizingBackgroundTracing(); |
+ |
+ if (!callback.is_null()) |
+ callback.Run(true); |
+} |
+ |
+BackgroundTracingManager* BackgroundTracingManager::GetInstance() { |
+ return Singleton<BackgroundTracingManager>::get(); |
+} |