OLD | NEW |
---|---|
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 "content/public/browser/background_tracing_preemptive_config.h" | 8 #include "content/public/browser/background_tracing_preemptive_config.h" |
9 #include "content/public/browser/background_tracing_reactive_config.h" | 9 #include "content/public/browser/background_tracing_reactive_config.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) | 86 BackgroundTracingPreemptiveConfig::MONITOR_AND_DUMP_WHEN_TRIGGER_NAMED) |
87 return false; | 87 return false; |
88 } | 88 } |
89 | 89 |
90 return true; | 90 return true; |
91 } | 91 } |
92 | 92 |
93 bool BackgroundTracingManagerImpl::SetActiveScenario( | 93 bool BackgroundTracingManagerImpl::SetActiveScenario( |
94 scoped_ptr<BackgroundTracingConfig> config, | 94 scoped_ptr<BackgroundTracingConfig> config, |
95 const BackgroundTracingManager::ReceiveCallback& receive_callback, | 95 const BackgroundTracingManager::ReceiveCallback& receive_callback, |
96 bool requires_anonymized_data) { | 96 const base::Closure& enabled_callback, |
97 DataFiltering data_filtering) { | |
97 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 98 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
98 if (is_tracing_) | 99 if (is_tracing_) |
99 return false; | 100 return false; |
100 | 101 |
101 if (!IsSupportedConfig(config.get())) | 102 if (!IsSupportedConfig(config.get())) |
102 return false; | 103 return false; |
103 | 104 |
104 // No point in tracing if there's nowhere to send it. | 105 // No point in tracing if there's nowhere to send it. |
105 if (config && receive_callback.is_null()) | 106 if (config && receive_callback.is_null()) |
106 return false; | 107 return false; |
107 | 108 |
108 config_ = config.Pass(); | 109 config_ = config.Pass(); |
109 receive_callback_ = receive_callback; | 110 receive_callback_ = receive_callback; |
110 requires_anonymized_data_ = requires_anonymized_data; | 111 requires_anonymized_data_ = (data_filtering == ANONYMIZE_DATA); |
111 | 112 |
112 EnableRecordingIfConfigNeedsIt(); | 113 EnableRecordingIfConfigNeedsIt(enabled_callback); |
113 | 114 |
114 return true; | 115 return true; |
115 } | 116 } |
116 | 117 |
117 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt() { | 118 void BackgroundTracingManagerImpl::EnableRecordingIfConfigNeedsIt( |
119 const base::Closure& enabled_callback) { | |
118 if (!config_) | 120 if (!config_) |
119 return; | 121 return; |
120 | 122 |
121 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { | 123 if (config_->mode == BackgroundTracingConfig::PREEMPTIVE_TRACING_MODE) { |
122 EnableRecording(GetCategoryFilterForCategoryPreset( | 124 EnableRecording(GetCategoryFilterForCategoryPreset( |
123 static_cast<BackgroundTracingPreemptiveConfig*>(config_.get()) | 125 static_cast<BackgroundTracingPreemptiveConfig*>( |
124 ->category_preset)); | 126 config_.get())->category_preset), |
127 enabled_callback); | |
125 } else { | 128 } else { |
126 // TODO(simonhatch): Implement reactive tracing path. | 129 // TODO(simonhatch): Implement reactive tracing path. |
127 NOTREACHED(); | 130 NOTREACHED(); |
128 } | 131 } |
129 } | 132 } |
130 | 133 |
131 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( | 134 bool BackgroundTracingManagerImpl::IsAbleToTriggerTracing( |
132 TriggerHandle handle) const { | 135 TriggerHandle handle) const { |
133 if (!config_) | 136 if (!config_) |
134 return false; | 137 return false; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 trigger_handles_.begin(); | 224 trigger_handles_.begin(); |
222 it != trigger_handles_.end(); ++it) | 225 it != trigger_handles_.end(); ++it) |
223 trigger_names->push_back(it->second); | 226 trigger_names->push_back(it->second); |
224 } | 227 } |
225 | 228 |
226 void BackgroundTracingManagerImpl::InvalidateTriggerHandlesForTesting() { | 229 void BackgroundTracingManagerImpl::InvalidateTriggerHandlesForTesting() { |
227 trigger_handles_.clear(); | 230 trigger_handles_.clear(); |
228 } | 231 } |
229 | 232 |
230 void BackgroundTracingManagerImpl::EnableRecording( | 233 void BackgroundTracingManagerImpl::EnableRecording( |
231 base::trace_event::CategoryFilter category_filter) { | 234 base::trace_event::CategoryFilter category_filter, |
235 const base::Closure& enabled_callback) { | |
236 base::trace_event::TraceOptions trace_options( | |
237 base::trace_event::RECORD_CONTINUOUSLY); | |
238 trace_options.enable_argument_filter = requires_anonymized_data_; | |
232 is_tracing_ = TracingController::GetInstance()->EnableRecording( | 239 is_tracing_ = TracingController::GetInstance()->EnableRecording( |
233 category_filter, | 240 category_filter, trace_options, enabled_callback); |
234 base::trace_event::TraceOptions(base::trace_event::RECORD_CONTINUOUSLY), | |
235 TracingController::EnableRecordingDoneCallback()); | |
dsinclair
2015/06/01 18:50:05
Where does this callback get set, I'm not seeing i
oystein (OOO til 10th of July)
2015/06/01 20:46:20
It's the same one from the other review comments t
| |
236 } | 241 } |
237 | 242 |
238 void BackgroundTracingManagerImpl::OnFinalizeStarted( | 243 void BackgroundTracingManagerImpl::OnFinalizeStarted( |
239 scoped_refptr<base::RefCountedString> file_contents) { | 244 scoped_refptr<base::RefCountedString> file_contents) { |
240 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 245 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
241 | 246 |
242 if (!receive_callback_.is_null()) | 247 if (!receive_callback_.is_null()) |
243 receive_callback_.Run( | 248 receive_callback_.Run( |
244 file_contents.get(), | 249 file_contents, |
245 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete, | 250 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete, |
246 base::Unretained(this))); | 251 base::Unretained(this))); |
247 } | 252 } |
248 | 253 |
249 void BackgroundTracingManagerImpl::OnFinalizeComplete() { | 254 void BackgroundTracingManagerImpl::OnFinalizeComplete() { |
250 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 255 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
251 BrowserThread::PostTask( | 256 BrowserThread::PostTask( |
252 BrowserThread::UI, FROM_HERE, | 257 BrowserThread::UI, FROM_HERE, |
253 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete, | 258 base::Bind(&BackgroundTracingManagerImpl::OnFinalizeComplete, |
254 base::Unretained(this))); | 259 base::Unretained(this))); |
255 return; | 260 return; |
256 } | 261 } |
257 | 262 |
258 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 263 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
259 | 264 |
260 is_gathering_ = false; | 265 is_gathering_ = false; |
261 | 266 |
262 if (!idle_callback_.is_null()) | 267 if (!idle_callback_.is_null()) |
263 idle_callback_.Run(); | 268 idle_callback_.Run(); |
264 | 269 |
265 // Now that a trace has completed, we may need to enable recording again. | 270 // Now that a trace has completed, we may need to enable recording again. |
266 EnableRecordingIfConfigNeedsIt(); | 271 EnableRecordingIfConfigNeedsIt(base::Closure()); |
267 } | 272 } |
268 | 273 |
269 void BackgroundTracingManagerImpl::BeginFinalizing( | 274 void BackgroundTracingManagerImpl::BeginFinalizing( |
270 StartedFinalizingCallback callback) { | 275 StartedFinalizingCallback callback) { |
271 is_gathering_ = true; | 276 is_gathering_ = true; |
272 is_tracing_ = false; | 277 is_tracing_ = false; |
273 | 278 |
274 content::TracingController::GetInstance()->DisableRecording( | 279 content::TracingController::GetInstance()->DisableRecording( |
275 content::TracingController::CreateCompressedStringSink( | 280 content::TracingController::CreateCompressedStringSink( |
276 data_endpoint_wrapper_)); | 281 data_endpoint_wrapper_)); |
(...skipping 12 matching lines...) Expand all Loading... | |
289 "disabled-by-default-toplevel.flow," | 294 "disabled-by-default-toplevel.flow," |
290 "disabled-by-default-ipc.flow"); | 295 "disabled-by-default-ipc.flow"); |
291 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP: | 296 case BackgroundTracingConfig::CategoryPreset::BENCHMARK_DEEP: |
292 return base::trace_event::CategoryFilter( | 297 return base::trace_event::CategoryFilter( |
293 "*,disabled-by-default-blink.debug.layout"); | 298 "*,disabled-by-default-blink.debug.layout"); |
294 } | 299 } |
295 NOTREACHED(); | 300 NOTREACHED(); |
296 return base::trace_event::CategoryFilter(); | 301 return base::trace_event::CategoryFilter(); |
297 } | 302 } |
298 | 303 |
299 BackgroundTracingConfig* BackgroundTracingConfig::FromDict( | 304 BackgroundTracingConfig* BackgroundTracingConfig::FromDict( |
dsinclair
2015/06/01 18:50:05
Why the ownership change?
oystein (OOO til 10th of July)
2015/06/01 20:46:20
I think simonhatch@ already changed this to return
| |
300 const base::DictionaryValue* dict) { | 305 const base::DictionaryValue* dict) { |
301 // TODO(simonhatch): Implement this. | 306 // TODO(simonhatch): Implement this. |
302 CHECK(false); | 307 CHECK(false); |
303 return NULL; | 308 return NULL; |
304 } | 309 } |
305 | 310 |
306 void BackgroundTracingConfig::IntoDict(const BackgroundTracingConfig* config, | 311 void BackgroundTracingConfig::IntoDict(const BackgroundTracingConfig* config, |
307 base::DictionaryValue* dict) { | 312 base::DictionaryValue* dict) { |
308 // TODO(simonhatch): Implement this. | 313 // TODO(simonhatch): Implement this. |
309 CHECK(false); | 314 CHECK(false); |
310 } | 315 } |
311 | 316 |
312 } // namspace content | 317 } // namspace content |
OLD | NEW |