| Index: chrome/test/base/tracing.cc
|
| diff --git a/chrome/test/base/tracing.cc b/chrome/test/base/tracing.cc
|
| index 7060b9b6c958a9c6db44b890b2ac7d37739c2792..ac3ebe944e320cb57550ab7ead2ce92247df0893 100644
|
| --- a/chrome/test/base/tracing.cc
|
| +++ b/chrome/test/base/tracing.cc
|
| @@ -4,19 +4,20 @@
|
|
|
| #include "chrome/test/base/tracing.h"
|
|
|
| -#include "base/debug/trace_event.h"
|
| +#include "base/file_util.h"
|
| +#include "base/files/file_path.h"
|
| #include "base/memory/singleton.h"
|
| #include "base/message_loop/message_loop.h"
|
| +#include "base/timer/timer.h"
|
| #include "content/public/browser/browser_thread.h"
|
| -#include "content/public/browser/trace_controller.h"
|
| -#include "content/public/browser/trace_subscriber.h"
|
| +#include "content/public/browser/tracing_controller.h"
|
| #include "content/public/test/test_utils.h"
|
|
|
| namespace {
|
|
|
| using content::BrowserThread;
|
|
|
| -class InProcessTraceController : public content::TraceSubscriber {
|
| +class InProcessTraceController {
|
| public:
|
| static InProcessTraceController* GetInstance() {
|
| return Singleton<InProcessTraceController>::get();
|
| @@ -29,8 +30,10 @@ class InProcessTraceController : public content::TraceSubscriber {
|
|
|
| bool BeginTracing(const std::string& category_patterns) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - return content::TraceController::GetInstance()->BeginTracing(
|
| - this, category_patterns, base::debug::TraceLog::RECORD_UNTIL_FULL);
|
| + return content::TracingController::GetInstance()->EnableRecording(
|
| + category_patterns, content::TracingController::DEFAULT_OPTIONS,
|
| + content::TracingController::EnableRecordingDoneCallback());
|
| + return true;
|
| }
|
|
|
| bool BeginTracingWithWatch(const std::string& category_patterns,
|
| @@ -41,8 +44,10 @@ class InProcessTraceController : public content::TraceSubscriber {
|
| DCHECK(num_occurrences > 0);
|
| watch_notification_count_ = num_occurrences;
|
| return BeginTracing(category_patterns) &&
|
| - content::TraceController::GetInstance()->SetWatchEvent(
|
| - this, category_name, event_name);
|
| + content::TracingController::GetInstance()->SetWatchEvent(
|
| + category_name, event_name,
|
| + base::Bind(&InProcessTraceController::OnWatchEventMatched,
|
| + base::Unretained(this)));
|
| }
|
|
|
| bool WaitForWatchEvent(base::TimeDelta timeout) {
|
| @@ -67,20 +72,16 @@ class InProcessTraceController : public content::TraceSubscriber {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| using namespace base::debug;
|
|
|
| - TraceResultBuffer::SimpleOutput output;
|
| - trace_buffer_.SetOutputCallback(output.GetCallback());
|
| -
|
| - trace_buffer_.Start();
|
| - if (!content::TraceController::GetInstance()->EndTracingAsync(this))
|
| + if (!content::TracingController::GetInstance()->DisableRecording(
|
| + base::FilePath(),
|
| + base::Bind(&InProcessTraceController::OnTraceDataCollected,
|
| + base::Unretained(this),
|
| + base::Unretained(json_trace_output))))
|
| return false;
|
| - // Wait for OnEndTracingComplete() to quit the message loop.
|
| - // OnTraceDataCollected may be called multiple times while blocking here.
|
| +
|
| + // Wait for OnTraceDataCollected() to quit the message loop.
|
| message_loop_runner_ = new content::MessageLoopRunner;
|
| message_loop_runner_->Run();
|
| - trace_buffer_.Finish();
|
| - 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.
|
| @@ -91,19 +92,16 @@ class InProcessTraceController : public content::TraceSubscriber {
|
| private:
|
| friend struct DefaultSingletonTraits<InProcessTraceController>;
|
|
|
| - // TraceSubscriber implementation
|
| - virtual void OnEndTracingComplete() OVERRIDE {
|
| - message_loop_runner_->Quit();
|
| - }
|
| -
|
| - // TraceSubscriber implementation
|
| - virtual void OnTraceDataCollected(
|
| - const scoped_refptr<base::RefCountedString>& trace_fragment) OVERRIDE {
|
| - trace_buffer_.AddFragment(trace_fragment->data());
|
| + void OnTraceDataCollected(std::string* json_trace_output,
|
| + const base::FilePath& path) {
|
| + bool old_io_allowed = base::ThreadRestrictions::SetIOAllowed(true);
|
| + bool ok = base::ReadFileToString(path, json_trace_output);
|
| + DCHECK(ok);
|
| + base::DeleteFile(path, false);
|
| + base::ThreadRestrictions::SetIOAllowed(old_io_allowed);
|
| }
|
|
|
| - // TraceSubscriber implementation
|
| - virtual void OnEventWatchNotification() OVERRIDE {
|
| + void OnWatchEventMatched() {
|
| if (watch_notification_count_ == 0)
|
| return;
|
| if (--watch_notification_count_ == 0) {
|
| @@ -118,9 +116,6 @@ class InProcessTraceController : public content::TraceSubscriber {
|
| 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_;
|
|
|