Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: content/browser/tracing/background_tracing_manager.cc

Issue 1089253003: Re-land first pass BackgroundTracingManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "content/browser/tracing/background_tracing_manager.h"
6
7 #include "base/memory/ref_counted_memory.h"
8 #include "base/memory/singleton.h"
9 #include "content/browser/tracing/background_tracing_endpoint.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/tracing_controller.h"
12
13 BackgroundTracingManager::BackgroundTracingManager()
14 : is_gathering_(false), is_recording_(false), weak_ptr_factory_(this) {
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;
dsinclair 2015/05/01 15:46:14 I don't see this getting reset to false anywhere?
31 content::TracingController::GetInstance()->EnableRecording(
32 active_scenario_->GetCategoryFilter(),
33 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'
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(
dsinclair 2015/05/01 15:46:14 I'm a little confused by the terminology is the fl
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698