OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tracing_controller_impl.h" | 5 #include "content/browser/tracing/tracing_controller_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "content/browser/tracing/trace_message_filter.h" | 12 #include "content/browser/tracing/trace_message_filter.h" |
13 #include "content/browser/tracing/tracing_ui.h" | |
13 #include "content/common/child_process_messages.h" | 14 #include "content/common/child_process_messages.h" |
14 #include "content/public/browser/browser_message_filter.h" | 15 #include "content/public/browser/browser_message_filter.h" |
15 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
16 | 17 |
17 using base::debug::TraceLog; | 18 using base::debug::TraceLog; |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 } | 285 } |
285 | 286 |
286 bool TracingControllerImpl::EnableMonitoring( | 287 bool TracingControllerImpl::EnableMonitoring( |
287 const std::string& category_filter, | 288 const std::string& category_filter, |
288 TracingController::Options options, | 289 TracingController::Options options, |
289 const EnableMonitoringDoneCallback& callback) { | 290 const EnableMonitoringDoneCallback& callback) { |
290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
291 | 292 |
292 if (!can_enable_monitoring()) | 293 if (!can_enable_monitoring()) |
293 return false; | 294 return false; |
294 is_monitoring_ = true; | 295 OnMonitoringStateChanged(true); |
295 | 296 |
296 #if defined(OS_ANDROID) | 297 #if defined(OS_ANDROID) |
297 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 298 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
298 #endif | 299 #endif |
299 | 300 |
300 int trace_options = 0; | 301 int trace_options = 0; |
301 if (options & ENABLE_SAMPLING) | 302 if (options & ENABLE_SAMPLING) |
302 trace_options |= TraceLog::ENABLE_SAMPLING; | 303 trace_options |= TraceLog::ENABLE_SAMPLING; |
303 | 304 |
304 base::Closure on_enable_monitoring_done_callback = | 305 base::Closure on_enable_monitoring_done_callback = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread, | 347 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread, |
347 base::Unretained(this), | 348 base::Unretained(this), |
348 on_disable_monitoring_done_callback)); | 349 on_disable_monitoring_done_callback)); |
349 return true; | 350 return true; |
350 } | 351 } |
351 | 352 |
352 void TracingControllerImpl::OnDisableMonitoringDone( | 353 void TracingControllerImpl::OnDisableMonitoringDone( |
353 const DisableMonitoringDoneCallback& callback) { | 354 const DisableMonitoringDoneCallback& callback) { |
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
355 | 356 |
356 is_monitoring_ = false; | 357 OnMonitoringStateChanged(false); |
357 | 358 |
358 // Notify all child processes. | 359 // Notify all child processes. |
359 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); | 360 for (TraceMessageFilterSet::iterator it = trace_message_filters_.begin(); |
360 it != trace_message_filters_.end(); ++it) { | 361 it != trace_message_filters_.end(); ++it) { |
361 it->get()->SendDisableMonitoring(); | 362 it->get()->SendDisableMonitoring(); |
362 } | 363 } |
363 | 364 |
364 if (!callback.is_null()) | 365 if (!callback.is_null()) |
365 callback.Run(); | 366 callback.Run(); |
366 } | 367 } |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 786 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
786 base::Bind(&TracingControllerImpl::OnWatchEventMatched, | 787 base::Bind(&TracingControllerImpl::OnWatchEventMatched, |
787 base::Unretained(this))); | 788 base::Unretained(this))); |
788 return; | 789 return; |
789 } | 790 } |
790 | 791 |
791 if (!watch_event_callback_.is_null()) | 792 if (!watch_event_callback_.is_null()) |
792 watch_event_callback_.Run(); | 793 watch_event_callback_.Run(); |
793 } | 794 } |
794 | 795 |
796 void TracingControllerImpl::RegisterTracingUI(TracingUI* tracing_ui) | |
797 { | |
798 DCHECK(tracing_uis_.find(tracing_ui) == tracing_uis_.end()); | |
799 tracing_uis_.insert(tracing_ui); | |
800 tracing_ui->OnMonitoringStateChanged(is_monitoring_); | |
801 } | |
802 | |
803 void TracingControllerImpl::UnregisterTracingUI(TracingUI* tracing_ui) | |
804 { | |
805 std::set<TracingUI*>::iterator it = tracing_uis_.find(tracing_ui); | |
806 DCHECK(it != tracing_uis_.end()); | |
807 tracing_uis_.erase(it); | |
808 } | |
809 | |
810 void TracingControllerImpl::OnMonitoringStateChanged(bool is_monitoring) | |
811 { | |
dsinclair
2014/01/08 15:57:27
Should we add a:
if (is_monitoring == is_monitori
| |
812 is_monitoring_ = is_monitoring; | |
813 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); | |
814 it != tracing_uis_.end(); it++) { | |
815 (*it)->OnMonitoringStateChanged(is_monitoring); | |
816 } | |
817 } | |
818 | |
795 } // namespace content | 819 } // namespace content |
OLD | NEW |