Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 #include "content/browser/tracing/background_tracing_manager.h" | |
| 5 | |
| 6 #include "base/memory/ref_counted_memory.h" | |
| 7 #include "base/memory/singleton.h" | |
| 8 #include "content/browser/tracing/background_tracing_endpoint.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/tracing_controller.h" | |
| 11 | |
| 12 BackgroundTracingManager::BackgroundTracingManager() : weak_ptr_factory_(this) { | |
|
oystein (OOO til 10th of July)
2015/04/21 17:31:44
is_recording_ isn't being initialized looks like?
| |
| 13 active_scenario_ = NULL; | |
| 14 is_gathering_ = false; | |
| 15 } | |
| 16 | |
| 17 BackgroundTracingManager::~BackgroundTracingManager() { | |
| 18 } | |
| 19 | |
| 20 void BackgroundTracingManager::SetActiveScenario( | |
| 21 scoped_refptr<BackgroundTracingScenario> scenario) { | |
| 22 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 23 CHECK(!active_scenario_); | |
| 24 active_scenario_ = scenario; | |
| 25 | |
| 26 EnableRecording(); | |
| 27 } | |
| 28 | |
| 29 void BackgroundTracingManager::EnableRecording() { | |
| 30 is_recording_ = true; | |
| 31 content::TracingController::GetInstance()->EnableRecording( | |
| 32 active_scenario_->GetCategoryFilter(), | |
| 33 base::trace_event::TraceOptions(base::trace_event::RECORD_CONTINUOUSLY), | |
| 34 content::TracingController::EnableRecordingDoneCallback()); | |
| 35 } | |
| 36 | |
| 37 void BackgroundTracingManager::OnFinalizeComplete() { | |
| 38 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | |
| 39 content::BrowserThread::PostTask( | |
| 40 content::BrowserThread::UI, FROM_HERE, | |
| 41 base::Bind(&BackgroundTracingManager::OnFinalizeComplete, | |
| 42 weak_ptr_factory_.GetWeakPtr())); | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 47 | |
| 48 is_gathering_ = false; | |
| 49 | |
| 50 EnableRecording(); | |
| 51 } | |
| 52 | |
| 53 void BackgroundTracingManager::BeginFinalizingBackgroundTracing() { | |
| 54 active_scenario_->GetEndpoint()->SetDoneCallback( | |
| 55 base::Bind(&BackgroundTracingManager::OnFinalizeComplete, | |
| 56 weak_ptr_factory_.GetWeakPtr())); | |
| 57 content::TracingController::GetInstance()->DisableRecording( | |
| 58 content::TracingController::CreateCompressedStringSink( | |
| 59 active_scenario_->GetEndpoint())); | |
| 60 } | |
| 61 | |
| 62 void BackgroundTracingManager::TryFinalizingBackgroundTracing( | |
| 63 StartedFinalizingCallback callback) { | |
| 64 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | |
| 65 content::BrowserThread::PostTask( | |
| 66 content::BrowserThread::UI, FROM_HERE, | |
| 67 base::Bind(&BackgroundTracingManager::TryFinalizingBackgroundTracing, | |
| 68 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 if (!active_scenario_ || is_gathering_) { | |
| 73 if (!callback.is_null()) | |
| 74 callback.Run(false); | |
| 75 return; | |
| 76 } | |
| 77 | |
| 78 is_gathering_ = true; | |
| 79 | |
| 80 BeginFinalizingBackgroundTracing(); | |
| 81 | |
| 82 if (!callback.is_null()) | |
| 83 callback.Run(true); | |
| 84 } | |
| 85 | |
| 86 BackgroundTracingManager* BackgroundTracingManager::GetInstance() { | |
| 87 return Singleton<BackgroundTracingManager>::get(); | |
| 88 } | |
| OLD | NEW |