| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/base/tracing.h" | 5 #include "chrome/test/base/tracing.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 using namespace base::debug; | 31 using namespace base::debug; |
| 32 | 32 |
| 33 TraceResultBuffer::SimpleOutput output; | 33 TraceResultBuffer::SimpleOutput output; |
| 34 trace_buffer_.SetOutputCallback(output.GetCallback()); | 34 trace_buffer_.SetOutputCallback(output.GetCallback()); |
| 35 | 35 |
| 36 trace_buffer_.Start(); | 36 trace_buffer_.Start(); |
| 37 if (!content::TraceController::GetInstance()->EndTracingAsync(this)) | 37 if (!content::TraceController::GetInstance()->EndTracingAsync(this)) |
| 38 return false; | 38 return false; |
| 39 // Wait for OnEndTracingComplete() to quit the message loop. | 39 // Wait for OnEndTracingComplete() to quit the message loop. |
| 40 // OnTraceDataCollected may be called multiple times while blocking here. | 40 // OnTraceDataCollected may be called multiple times while blocking here. |
| 41 ui_test_utils::RunMessageLoop(); | 41 message_loop_runner_ = new ui_test_utils::MessageLoopRunner; |
| 42 message_loop_runner_->Run(); |
| 42 trace_buffer_.Finish(); | 43 trace_buffer_.Finish(); |
| 43 trace_buffer_.SetOutputCallback(TraceResultBuffer::OutputCallback()); | 44 trace_buffer_.SetOutputCallback(TraceResultBuffer::OutputCallback()); |
| 44 | 45 |
| 45 *json_trace_output = output.json_output; | 46 *json_trace_output = output.json_output; |
| 46 return true; | 47 return true; |
| 47 } | 48 } |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 friend struct DefaultSingletonTraits<InProcessTraceController>; | 51 friend struct DefaultSingletonTraits<InProcessTraceController>; |
| 51 | 52 |
| 52 // TraceSubscriber | 53 // TraceSubscriber |
| 53 virtual void OnEndTracingComplete() OVERRIDE { | 54 virtual void OnEndTracingComplete() OVERRIDE { |
| 54 MessageLoopForUI::current()->Quit(); | 55 message_loop_runner_->Quit(); |
| 55 } | 56 } |
| 56 | 57 |
| 57 // TraceSubscriber | 58 // TraceSubscriber |
| 58 virtual void OnTraceDataCollected( | 59 virtual void OnTraceDataCollected( |
| 59 const scoped_refptr<base::RefCountedString>& trace_fragment) OVERRIDE { | 60 const scoped_refptr<base::RefCountedString>& trace_fragment) OVERRIDE { |
| 60 trace_buffer_.AddFragment(trace_fragment->data()); | 61 trace_buffer_.AddFragment(trace_fragment->data()); |
| 61 } | 62 } |
| 62 | 63 |
| 63 // For collecting trace data asynchronously. | 64 // For collecting trace data asynchronously. |
| 64 base::debug::TraceResultBuffer trace_buffer_; | 65 base::debug::TraceResultBuffer trace_buffer_; |
| 65 | 66 |
| 67 scoped_refptr<ui_test_utils::MessageLoopRunner> message_loop_runner_; |
| 68 |
| 66 DISALLOW_COPY_AND_ASSIGN(InProcessTraceController); | 69 DISALLOW_COPY_AND_ASSIGN(InProcessTraceController); |
| 67 }; | 70 }; |
| 68 | 71 |
| 69 } // namespace | 72 } // namespace |
| 70 | 73 |
| 71 namespace tracing { | 74 namespace tracing { |
| 72 | 75 |
| 73 bool BeginTracing(const std::string& categories) { | 76 bool BeginTracing(const std::string& categories) { |
| 74 return InProcessTraceController::GetInstance()->BeginTracing(categories); | 77 return InProcessTraceController::GetInstance()->BeginTracing(categories); |
| 75 } | 78 } |
| 76 | 79 |
| 77 bool EndTracing(std::string* json_trace_output) { | 80 bool EndTracing(std::string* json_trace_output) { |
| 78 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); | 81 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); |
| 79 } | 82 } |
| 80 | 83 |
| 81 } // namespace tracing | 84 } // namespace tracing |
| 82 | 85 |
| OLD | NEW |