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" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 | 181 |
182 if (!can_enable_recording()) | 182 if (!can_enable_recording()) |
183 return false; | 183 return false; |
184 is_recording_ = true; | 184 is_recording_ = true; |
185 | 185 |
186 #if defined(OS_ANDROID) | 186 #if defined(OS_ANDROID) |
187 if (pending_get_categories_done_callback_.is_null()) | 187 if (pending_get_categories_done_callback_.is_null()) |
188 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 188 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
189 #endif | 189 #endif |
190 | 190 |
191 options_ = options; | |
191 int trace_options = (options & RECORD_CONTINUOUSLY) ? | 192 int trace_options = (options & RECORD_CONTINUOUSLY) ? |
192 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL; | 193 TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL; |
193 if (options & ENABLE_SAMPLING) { | 194 if (options & ENABLE_SAMPLING) { |
194 trace_options |= TraceLog::ENABLE_SAMPLING; | 195 trace_options |= TraceLog::ENABLE_SAMPLING; |
195 } | 196 } |
196 // TODO(haraken): How to handle ENABLE_SYSTRACE? | 197 // TODO(haraken): How to handle ENABLE_SYSTRACE? |
197 | 198 |
198 base::Closure on_enable_recording_done_callback = | 199 base::Closure on_enable_recording_done_callback = |
199 base::Bind(&TracingControllerImpl::OnEnableRecordingDone, | 200 base::Bind(&TracingControllerImpl::OnEnableRecordingDone, |
200 base::Unretained(this), | 201 base::Unretained(this), |
(...skipping 26 matching lines...) Expand all Loading... | |
227 } | 228 } |
228 | 229 |
229 bool TracingControllerImpl::DisableRecording( | 230 bool TracingControllerImpl::DisableRecording( |
230 const base::FilePath& result_file_path, | 231 const base::FilePath& result_file_path, |
231 const TracingFileResultCallback& callback) { | 232 const TracingFileResultCallback& callback) { |
232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
233 | 234 |
234 if (!can_disable_recording()) | 235 if (!can_disable_recording()) |
235 return false; | 236 return false; |
236 | 237 |
238 options_ = TracingController::Options(); | |
237 // Disable local trace early to avoid traces during end-tracing process from | 239 // Disable local trace early to avoid traces during end-tracing process from |
238 // interfering with the process. | 240 // interfering with the process. |
239 base::Closure on_disable_recording_done_callback = | 241 base::Closure on_disable_recording_done_callback = |
240 base::Bind(&TracingControllerImpl::OnDisableRecordingDone, | 242 base::Bind(&TracingControllerImpl::OnDisableRecordingDone, |
241 base::Unretained(this), | 243 base::Unretained(this), |
242 result_file_path, callback); | 244 result_file_path, callback); |
243 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 245 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
244 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread, | 246 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread, |
245 base::Unretained(this), | 247 base::Unretained(this), |
246 on_disable_recording_done_callback)); | 248 on_disable_recording_done_callback)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
292 | 294 |
293 if (!can_enable_monitoring()) | 295 if (!can_enable_monitoring()) |
294 return false; | 296 return false; |
295 OnMonitoringStateChanged(true); | 297 OnMonitoringStateChanged(true); |
296 | 298 |
297 #if defined(OS_ANDROID) | 299 #if defined(OS_ANDROID) |
298 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); | 300 TraceLog::GetInstance()->AddClockSyncMetadataEvent(); |
299 #endif | 301 #endif |
300 | 302 |
303 options_ = options; | |
301 int trace_options = 0; | 304 int trace_options = 0; |
302 if (options & ENABLE_SAMPLING) | 305 if (options & ENABLE_SAMPLING) |
303 trace_options |= TraceLog::ENABLE_SAMPLING; | 306 trace_options |= TraceLog::ENABLE_SAMPLING; |
304 | 307 |
305 base::Closure on_enable_monitoring_done_callback = | 308 base::Closure on_enable_monitoring_done_callback = |
306 base::Bind(&TracingControllerImpl::OnEnableMonitoringDone, | 309 base::Bind(&TracingControllerImpl::OnEnableMonitoringDone, |
307 base::Unretained(this), | 310 base::Unretained(this), |
308 category_filter, trace_options, callback); | 311 category_filter, trace_options, callback); |
309 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 312 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
310 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, | 313 base::Bind(&TracingControllerImpl::SetEnabledOnFileThread, |
(...skipping 22 matching lines...) Expand all Loading... | |
333 callback.Run(); | 336 callback.Run(); |
334 } | 337 } |
335 | 338 |
336 bool TracingControllerImpl::DisableMonitoring( | 339 bool TracingControllerImpl::DisableMonitoring( |
337 const DisableMonitoringDoneCallback& callback) { | 340 const DisableMonitoringDoneCallback& callback) { |
338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
339 | 342 |
340 if (!can_disable_monitoring()) | 343 if (!can_disable_monitoring()) |
341 return false; | 344 return false; |
342 | 345 |
346 options_ = TracingController::Options(); | |
343 base::Closure on_disable_monitoring_done_callback = | 347 base::Closure on_disable_monitoring_done_callback = |
344 base::Bind(&TracingControllerImpl::OnDisableMonitoringDone, | 348 base::Bind(&TracingControllerImpl::OnDisableMonitoringDone, |
345 base::Unretained(this), callback); | 349 base::Unretained(this), callback); |
346 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 350 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
347 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread, | 351 base::Bind(&TracingControllerImpl::SetDisabledOnFileThread, |
348 base::Unretained(this), | 352 base::Unretained(this), |
349 on_disable_monitoring_done_callback)); | 353 on_disable_monitoring_done_callback)); |
350 return true; | 354 return true; |
351 } | 355 } |
352 | 356 |
(...skipping 10 matching lines...) Expand all Loading... | |
363 } | 367 } |
364 | 368 |
365 if (!callback.is_null()) | 369 if (!callback.is_null()) |
366 callback.Run(); | 370 callback.Run(); |
367 } | 371 } |
368 | 372 |
369 void TracingControllerImpl::GetMonitoringStatus( | 373 void TracingControllerImpl::GetMonitoringStatus( |
370 bool* out_enabled, | 374 bool* out_enabled, |
371 std::string* out_category_filter, | 375 std::string* out_category_filter, |
372 TracingController::Options* out_options) { | 376 TracingController::Options* out_options) { |
373 NOTIMPLEMENTED(); | 377 *out_enabled = is_monitoring_; |
378 *out_category_filter = | |
379 TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString(); | |
380 *out_options = options_; | |
374 } | 381 } |
375 | 382 |
376 bool TracingControllerImpl::CaptureMonitoringSnapshot( | 383 bool TracingControllerImpl::CaptureMonitoringSnapshot( |
377 const base::FilePath& result_file_path, | 384 const base::FilePath& result_file_path, |
378 const TracingFileResultCallback& callback) { | 385 const TracingFileResultCallback& callback) { |
379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
380 | 387 |
381 if (!can_disable_monitoring()) | 388 if (!can_disable_monitoring()) |
382 return false; | 389 return false; |
383 | 390 |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
780 } | 787 } |
781 | 788 |
782 if (!watch_event_callback_.is_null()) | 789 if (!watch_event_callback_.is_null()) |
783 watch_event_callback_.Run(); | 790 watch_event_callback_.Run(); |
784 } | 791 } |
785 | 792 |
786 void TracingControllerImpl::RegisterTracingUI(TracingUI* tracing_ui) | 793 void TracingControllerImpl::RegisterTracingUI(TracingUI* tracing_ui) |
787 { | 794 { |
788 DCHECK(tracing_uis_.find(tracing_ui) == tracing_uis_.end()); | 795 DCHECK(tracing_uis_.find(tracing_ui) == tracing_uis_.end()); |
789 tracing_uis_.insert(tracing_ui); | 796 tracing_uis_.insert(tracing_ui); |
790 tracing_ui->OnMonitoringStateChanged(is_monitoring_); | |
haraken
2014/01/16 02:32:14
I expected that this will fire window.onMonitoring
| |
791 } | 797 } |
792 | 798 |
793 void TracingControllerImpl::UnregisterTracingUI(TracingUI* tracing_ui) | 799 void TracingControllerImpl::UnregisterTracingUI(TracingUI* tracing_ui) |
794 { | 800 { |
795 std::set<TracingUI*>::iterator it = tracing_uis_.find(tracing_ui); | 801 std::set<TracingUI*>::iterator it = tracing_uis_.find(tracing_ui); |
796 DCHECK(it != tracing_uis_.end()); | 802 DCHECK(it != tracing_uis_.end()); |
797 tracing_uis_.erase(it); | 803 tracing_uis_.erase(it); |
798 } | 804 } |
799 | 805 |
800 void TracingControllerImpl::OnMonitoringStateChanged(bool is_monitoring) | 806 void TracingControllerImpl::OnMonitoringStateChanged(bool is_monitoring) |
801 { | 807 { |
802 if (is_monitoring_ == is_monitoring) | 808 if (is_monitoring_ == is_monitoring) |
803 return; | 809 return; |
804 | 810 |
805 is_monitoring_ = is_monitoring; | 811 is_monitoring_ = is_monitoring; |
806 #if !defined(OS_ANDROID) | 812 #if !defined(OS_ANDROID) |
807 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); | 813 for (std::set<TracingUI*>::iterator it = tracing_uis_.begin(); |
808 it != tracing_uis_.end(); it++) { | 814 it != tracing_uis_.end(); it++) { |
809 (*it)->OnMonitoringStateChanged(is_monitoring); | 815 (*it)->OnMonitoringStateChanged(is_monitoring); |
810 } | 816 } |
811 #endif | 817 #endif |
812 } | 818 } |
813 | 819 |
814 } // namespace content | 820 } // namespace content |
OLD | NEW |