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

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

Issue 1164023002: Slow Reports: Set a minimum time in between reports, and check for OTR sessions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 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
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 #include "content/browser/tracing/background_tracing_manager_impl.h" 5 #include "content/browser/tracing/background_tracing_manager_impl.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "content/public/browser/background_tracing_preemptive_config.h" 9 #include "content/public/browser/background_tracing_preemptive_config.h"
10 #include "content/public/browser/background_tracing_reactive_config.h" 10 #include "content/public/browser/background_tracing_reactive_config.h"
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/content_browser_client.h"
13 #include "content/public/browser/tracing_delegate.h"
14 #include "content/public/common/content_client.h"
12 15
13 namespace content { 16 namespace content {
14 17
15 namespace { 18 namespace {
16 19
17 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller = 20 base::LazyInstance<BackgroundTracingManagerImpl>::Leaky g_controller =
18 LAZY_INSTANCE_INITIALIZER; 21 LAZY_INSTANCE_INITIALIZER;
19 22
20 } // namespace 23 } // namespace
21 24
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 70
68 BackgroundTracingManager* BackgroundTracingManager::GetInstance() { 71 BackgroundTracingManager* BackgroundTracingManager::GetInstance() {
69 return BackgroundTracingManagerImpl::GetInstance(); 72 return BackgroundTracingManagerImpl::GetInstance();
70 } 73 }
71 74
72 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() { 75 BackgroundTracingManagerImpl* BackgroundTracingManagerImpl::GetInstance() {
73 return g_controller.Pointer(); 76 return g_controller.Pointer();
74 } 77 }
75 78
76 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl() 79 BackgroundTracingManagerImpl::BackgroundTracingManagerImpl()
77 : is_gathering_(false), 80 : delegate_(GetContentClient()->browser()->GetTracingDelegate()),
81 is_gathering_(false),
78 is_tracing_(false), 82 is_tracing_(false),
79 requires_anonymized_data_(true), 83 requires_anonymized_data_(true),
80 trigger_handle_ids_(0) { 84 trigger_handle_ids_(0) {
81 data_endpoint_wrapper_ = new TraceDataEndpointWrapper( 85 data_endpoint_wrapper_ = new TraceDataEndpointWrapper(
82 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeStarted, 86 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeStarted,
83 base::Unretained(this))); 87 base::Unretained(this)));
84 } 88 }
85 89
86 BackgroundTracingManagerImpl::~BackgroundTracingManagerImpl() { 90 BackgroundTracingManagerImpl::~BackgroundTracingManagerImpl() {
87 NOTREACHED(); 91 NOTREACHED();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 132 }
129 133
130 bool BackgroundTracingManagerImpl::SetActiveScenario( 134 bool BackgroundTracingManagerImpl::SetActiveScenario(
131 scoped_ptr<BackgroundTracingConfig> config, 135 scoped_ptr<BackgroundTracingConfig> config,
132 const BackgroundTracingManager::ReceiveCallback& receive_callback, 136 const BackgroundTracingManager::ReceiveCallback& receive_callback,
133 bool requires_anonymized_data) { 137 bool requires_anonymized_data) {
134 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 138 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
135 if (is_tracing_) 139 if (is_tracing_)
136 return false; 140 return false;
137 141
142 DCHECK(delegate_);
143 DCHECK(config);
144 // TODO(oysteine): Retry when time_until_allowed has elapsed.
145 if (!delegate_->IsAllowedToBeginBackgroundScenario(
146 *config.get(), requires_anonymized_data)) {
147 return false;
148 }
149
138 if (!IsSupportedConfig(config.get())) 150 if (!IsSupportedConfig(config.get()))
139 return false; 151 return false;
140 152
141 // No point in tracing if there's nowhere to send it. 153 // No point in tracing if there's nowhere to send it.
142 if (config && receive_callback.is_null()) 154 if (config && receive_callback.is_null())
143 return false; 155 return false;
144 156
145 config_ = config.Pass(); 157 config_ = config.Pass();
146 receive_callback_ = receive_callback; 158 receive_callback_ = receive_callback;
147 requires_anonymized_data_ = requires_anonymized_data; 159 requires_anonymized_data_ = requires_anonymized_data;
148 160
149 EnableRecordingIfConfigNeedsIt(); 161 EnableRecordingIfConfigNeedsIt();
150 162
151 return true; 163 return true;
152 } 164 }
153 165
154 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { 166 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() {
155 if (!config_) 167 if (!config_)
156 return; 168 return;
157 169
170 DCHECK(config_);
171 // TODO(oysteine): Retry later.
172 if (!delegate_->IsAllowedToBeginBackgroundScenario(
173 *config_.get(), requires_anonymized_data_)) {
174 return;
175 }
176
158 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { 177 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) {
159 EnableRecording(GetCategoryFilterStringForCategoryPreset( 178 EnableRecording(GetCategoryFilterStringForCategoryPreset(
160 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get()) 179 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get())
161 ->category_preset), 180 ->category_preset),
162 base::trace_event::RECORD_CONTINUOUSLY); 181 base::trace_event::RECORD_CONTINUOUSLY);
163 } 182 }
164 // There is nothing to do in case of reactive tracing. 183 // There is nothing to do in case of reactive tracing.
165 } 184 }
166 185
167 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( 186 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing(
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 356
338 // Now that a trace has completed, we may need to enable recording again. 357 // Now that a trace has completed, we may need to enable recording again.
339 EnableRecordingIfConfigNeedsIt(); 358 EnableRecordingIfConfigNeedsIt();
340 } 359 }
341 360
342 void BackgroundTracingManagerImpl::BeginFinalizing( 361 void BackgroundTracingManagerImpl::BeginFinalizing(
343 StartedFinalizingCallback callback) { 362 StartedFinalizingCallback callback) {
344 is_gathering_ = true; 363 is_gathering_ = true;
345 is_tracing_ = false; 364 is_tracing_ = false;
346 365
347 content::TracingController::GetInstance()->DisableRecording( 366 DCHECK(delegate_);
348 content::TracingController::CreateCompressedStringSink( 367 bool is_allowed_finalization = delegate_->IsAllowedToEndBackgroundScenario(
349 data_endpoint_wrapper_)); 368 *config_.get(), requires_anonymized_data_);
369
370 scoped_refptr<TracingControllerImpl::TraceDataSink> trace_data_sink;
371 if (is_allowed_finalization) {
372 trace_data_sink = content::TracingController::CreateCompressedStringSink(
373 data_endpoint_wrapper_);
374 }
375
376 content::TracingController::GetInstance()->DisableRecording(trace_data_sink);
350 377
351 if (!callback.is_null()) 378 if (!callback.is_null())
352 callback.Run(true); 379 callback.Run(is_allowed_finalization);
353 } 380 }
354 381
355 std::string 382 std::string
356 BackgroundTracingManagerImpl::GetCategoryFilterStringForCategoryPreset( 383 BackgroundTracingManagerImpl::GetCategoryFilterStringForCategoryPreset(
357 BackgroundTracingConfig::CategoryPreset preset) const { 384 BackgroundTracingConfig::CategoryPreset preset) const {
358 switch (preset) { 385 switch (preset) {
359 case BackgroundTracingConfig::CategoryPreset::BENCHMARK: 386 case BackgroundTracingConfig::CategoryPreset::BENCHMARK:
360 return "benchmark," 387 return "benchmark,"
361 "disabled-by-default-toplevel.flow," 388 "disabled-by-default-toplevel.flow,"
362 "disabled-by-default-ipc.flow"; 389 "disabled-by-default-ipc.flow";
363 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP: 390 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP:
364 return "*,disabled-by-default-blink.debug.layout"; 391 return "*,disabled-by-default-blink.debug.layout";
365 } 392 }
366 NOTREACHED(); 393 NOTREACHED();
367 return ""; 394 return "";
368 } 395 }
369 396
370 } // namspace content 397 } // namspace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698