Chromium Code Reviews| Index: chrome/test/base/tracing.cc |
| diff --git a/chrome/test/base/tracing.cc b/chrome/test/base/tracing.cc |
| index 7e609ec6d515255ed68ae2b7bb40ac5343b3393b..a94ad1e6bd27d5489a5b51b5659f51e6001c0932 100644 |
| --- a/chrome/test/base/tracing.cc |
| +++ b/chrome/test/base/tracing.cc |
| @@ -19,7 +19,9 @@ class InProcessTraceController : public content::TraceSubscriber { |
| return Singleton<InProcessTraceController>::get(); |
| } |
| - InProcessTraceController() {} |
| + InProcessTraceController() |
| + : is_waiting_on_watch_(false) |
| + , got_watch_notification_(false) {} |
| virtual ~InProcessTraceController() {} |
| bool BeginTracing(const std::string& categories) { |
| @@ -27,6 +29,32 @@ class InProcessTraceController : public content::TraceSubscriber { |
| this, categories); |
| } |
| + bool BeginTracingWithWatch(const std::string& categories, |
| + const char* category_name, |
| + const char* event_name, |
| + int num_occurrences) { |
| + return BeginTracing(categories) && |
| + content::TraceController::GetInstance()->SetWatchEvent( |
| + this, category_name, event_name, num_occurrences); |
| + } |
| + |
| + bool WaitForWatchEvent(base::TimeDelta timeout) { |
| + if (got_watch_notification_) |
| + return true; |
| + |
| + if (timeout != base::TimeDelta()) { |
| + timer_.Start(FROM_HERE, timeout, this, |
| + &InProcessTraceController::Timeout); |
| + } |
| + |
| + is_waiting_on_watch_ = true; |
|
ccameron
2012/08/21 01:06:34
Race: we will use is_waiting_on_watch to see if it
jbates
2012/08/23 22:45:28
As discussed, the missing detail is that these met
|
| + message_loop_runner_ = new content::MessageLoopRunner; |
| + message_loop_runner_->Run(); |
| + is_waiting_on_watch_ = false; |
| + |
| + return got_watch_notification_; |
| + } |
| + |
| bool EndTracing(std::string* json_trace_output) { |
| using namespace base::debug; |
| @@ -44,28 +72,50 @@ class InProcessTraceController : public content::TraceSubscriber { |
| trace_buffer_.SetOutputCallback(TraceResultBuffer::OutputCallback()); |
| *json_trace_output = output.json_output; |
| + |
| + // Watch notifications can occur during this method's message loop run, but |
| + // not after, so clear them here. |
| + got_watch_notification_ = false; |
| return true; |
| } |
| private: |
| friend struct DefaultSingletonTraits<InProcessTraceController>; |
| - // TraceSubscriber |
| + // TraceSubscriber implementation |
| virtual void OnEndTracingComplete() OVERRIDE { |
| message_loop_runner_->Quit(); |
| } |
| - // TraceSubscriber |
| + // TraceSubscriber implementation |
| virtual void OnTraceDataCollected( |
| const scoped_refptr<base::RefCountedString>& trace_fragment) OVERRIDE { |
| trace_buffer_.AddFragment(trace_fragment->data()); |
| } |
| + // TraceSubscriber implementation |
| + virtual void OnEventWatchNotification() { |
| + got_watch_notification_ = true; |
| + timer_.Stop(); |
| + if (is_waiting_on_watch_) |
|
ccameron
2012/08/21 01:06:34
Race: is_waiting_in_watch_ can be true while messa
|
| + message_loop_runner_->Quit(); |
| + } |
| + |
| + void Timeout() { |
| + DCHECK(is_waiting_on_watch_); |
| + message_loop_runner_->Quit(); |
| + } |
| + |
| // For collecting trace data asynchronously. |
| base::debug::TraceResultBuffer trace_buffer_; |
| scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| + base::OneShotTimer<InProcessTraceController> timer_; |
| + |
| + bool is_waiting_on_watch_; |
| + bool got_watch_notification_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(InProcessTraceController); |
| }; |
| @@ -77,6 +127,18 @@ bool BeginTracing(const std::string& categories) { |
| return InProcessTraceController::GetInstance()->BeginTracing(categories); |
| } |
| +bool BeginTracingWithWatch(const std::string& categories, |
| + const char* category_name, |
| + const char* event_name, |
| + int num_occurrences) { |
| + return InProcessTraceController::GetInstance()->BeginTracingWithWatch( |
| + categories, category_name, event_name, num_occurrences); |
| +} |
| + |
| +bool WaitForWatchEvent(base::TimeDelta timeout) { |
| + return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); |
| +} |
| + |
| bool EndTracing(std::string* json_trace_output) { |
| return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); |
| } |