summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhusky@chromium.org <husky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-24 04:17:06 +0000
committerhusky@chromium.org <husky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-24 04:17:06 +0000
commitb77226e27cab2828e1638a978864442dd336a73e (patch)
tree190bad928416e69b85b5a930dac33954b9c2fb8a
parentb07cdbcc2fd4044902f1542df9501b49c5f94786 (diff)
downloadchromium_src-b77226e27cab2828e1638a978864442dd336a73e.zip
chromium_src-b77226e27cab2828e1638a978864442dd336a73e.tar.gz
chromium_src-b77226e27cab2828e1638a978864442dd336a73e.tar.bz2
Use SequencedWorkerPool for disk operations in TraceSubscriberStdio.
This class was hitting a ThreadRestrictions assert because it called OpenFile on the UI thread. To reduce unnecessary copying, I've changed the OnTraceDataCollected argument from std::string to RefCountedString. Second attempt (originally committed in 123140, reverted in 123146). Added DISALLOW_COPY_AND_ASSIGN to fix Windows compilation error. BUG=None TEST=content_unittests Review URL: http://codereview.chromium.org/9443020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123433 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/debug/trace_event_impl.cc2
-rw-r--r--base/debug/trace_event_impl.h5
-rw-r--r--base/debug/trace_event_unittest.cc6
-rw-r--r--base/test/trace_event_analyzer_unittest.cc8
-rw-r--r--chrome/browser/automation/automation_provider.cc4
-rw-r--r--chrome/browser/automation/automation_provider.h3
-rw-r--r--chrome/browser/ui/webui/tracing_ui.cc7
-rw-r--r--chrome/test/base/tracing.cc8
-rw-r--r--content/browser/trace_controller.cc12
-rw-r--r--content/browser/trace_controller.h9
-rw-r--r--content/browser/trace_message_filter.cc7
-rw-r--r--content/browser/trace_subscriber_stdio.cc116
-rw-r--r--content/browser/trace_subscriber_stdio.h29
-rw-r--r--content/browser/trace_subscriber_stdio_unittest.cc50
-rw-r--r--content/common/child_trace_message_filter.cc7
-rw-r--r--content/common/child_trace_message_filter.h5
16 files changed, 147 insertions, 131 deletions
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index 1f23c36..fbe315e 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -564,7 +564,7 @@ void TraceLog::Flush() {
TraceEvent::AppendEventsAsJSON(previous_logged_events,
i,
kTraceEventBatchSize,
- &(json_events_str_ptr->data));
+ &(json_events_str_ptr->data()));
output_callback_copy.Run(json_events_str_ptr);
}
}
diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h
index 1806f893..04aea18 100644
--- a/base/debug/trace_event_impl.h
+++ b/base/debug/trace_event_impl.h
@@ -42,8 +42,6 @@ struct StaticMemorySingletonTraits;
namespace base {
-class RefCountedString;
-
namespace debug {
const int kTraceMaxNumArgs = 2;
@@ -221,8 +219,7 @@ class BASE_EXPORT TraceLog {
// silently dropped. The callback must be thread safe. The string format is
// undefined. Use TraceResultBuffer to convert one or more trace strings to
// JSON.
- typedef RefCountedData<std::string> RefCountedString;
- typedef base::Callback<void(const scoped_refptr<RefCountedString>&)>
+ typedef base::Callback<void(const scoped_refptr<base::RefCountedString>&)>
OutputCallback;
void SetOutputCallback(const OutputCallback& cb);
diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc
index 9afd68b..befd4e8 100644
--- a/base/debug/trace_event_unittest.cc
+++ b/base/debug/trace_event_unittest.cc
@@ -42,7 +42,7 @@ class TraceEventTestFixture : public testing::Test {
// up multiple times when testing AtExit. Use ManualTestSetUp for this.
void ManualTestSetUp();
void OnTraceDataCollected(
- const scoped_refptr<TraceLog::RefCountedString>& events_str);
+ const scoped_refptr<base::RefCountedString>& events_str);
DictionaryValue* FindMatchingTraceEntry(const JsonKeyValue* key_values);
DictionaryValue* FindNamePhase(const char* name, const char* phase);
DictionaryValue* FindNamePhaseKeyValue(const char* name,
@@ -91,11 +91,11 @@ void TraceEventTestFixture::ManualTestSetUp() {
}
void TraceEventTestFixture::OnTraceDataCollected(
- const scoped_refptr<TraceLog::RefCountedString>& events_str) {
+ const scoped_refptr<base::RefCountedString>& events_str) {
AutoLock lock(lock_);
json_output_.json_output.clear();
trace_buffer_.Start();
- trace_buffer_.AddFragment(events_str->data);
+ trace_buffer_.AddFragment(events_str->data());
trace_buffer_.Finish();
scoped_ptr<Value> root;
diff --git a/base/test/trace_event_analyzer_unittest.cc b/base/test/trace_event_analyzer_unittest.cc
index ccce3f3..8ff611f 100644
--- a/base/test/trace_event_analyzer_unittest.cc
+++ b/base/test/trace_event_analyzer_unittest.cc
@@ -15,8 +15,7 @@ class TraceEventAnalyzerTest : public testing::Test {
public:
void ManualSetUp();
void OnTraceDataCollected(
- const scoped_refptr<base::debug::TraceLog::RefCountedString>&
- json_events_str);
+ const scoped_refptr<base::RefCountedString>& json_events_str);
void BeginTracing();
void EndTracing();
@@ -36,9 +35,8 @@ void TraceEventAnalyzerTest::ManualSetUp() {
}
void TraceEventAnalyzerTest::OnTraceDataCollected(
- const scoped_refptr<base::debug::TraceLog::RefCountedString>&
- json_events_str) {
- buffer_.AddFragment(json_events_str->data);
+ const scoped_refptr<base::RefCountedString>& json_events_str) {
+ buffer_.AddFragment(json_events_str->data());
}
void TraceEventAnalyzerTest::BeginTracing() {
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index b4a32cf..38b1b0b 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -406,8 +406,8 @@ void AutomationProvider::OnEndTracingComplete() {
}
void AutomationProvider::OnTraceDataCollected(
- const std::string& trace_fragment) {
- tracing_data_.trace_output.push_back(trace_fragment);
+ const scoped_refptr<base::RefCountedString>& trace_fragment) {
+ tracing_data_.trace_output.push_back(trace_fragment->data());
}
bool AutomationProvider::OnMessageReceived(const IPC::Message& message) {
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index b0026ea..3a61cda 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -246,7 +246,8 @@ class AutomationProvider
// TraceSubscriber:
virtual void OnEndTracingComplete() OVERRIDE;
- virtual void OnTraceDataCollected(const std::string& trace_fragment) OVERRIDE;
+ virtual void OnTraceDataCollected(
+ const scoped_refptr<base::RefCountedString>& trace_fragment) OVERRIDE;
void OnUnhandledMessage(const IPC::Message& message);
diff --git a/chrome/browser/ui/webui/tracing_ui.cc b/chrome/browser/ui/webui/tracing_ui.cc
index 3a1c492..9f5bc5f 100644
--- a/chrome/browser/ui/webui/tracing_ui.cc
+++ b/chrome/browser/ui/webui/tracing_ui.cc
@@ -73,7 +73,8 @@ class TracingMessageHandler
// TraceSubscriber implementation.
virtual void OnEndTracingComplete();
- virtual void OnTraceDataCollected(const std::string& trace_fragment);
+ virtual void OnTraceDataCollected(
+ const scoped_refptr<base::RefCountedString>& trace_fragment);
virtual void OnTraceBufferPercentFullReply(float percent_full);
// GpuDataManagerObserver implementation.
@@ -379,7 +380,7 @@ void TracingMessageHandler::OnEndTracingComplete() {
}
void TracingMessageHandler::OnTraceDataCollected(
- const std::string& trace_fragment) {
+ const scoped_refptr<base::RefCountedString>& trace_fragment) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
base::debug::TraceResultBuffer::SimpleOutput output;
@@ -387,7 +388,7 @@ void TracingMessageHandler::OnTraceDataCollected(
trace_buffer.SetOutputCallback(output.GetCallback());
output.Append("tracingController.onTraceDataCollected(");
trace_buffer.Start();
- trace_buffer.AddFragment(trace_fragment);
+ trace_buffer.AddFragment(trace_fragment->data());
trace_buffer.Finish();
output.Append(");");
diff --git a/chrome/test/base/tracing.cc b/chrome/test/base/tracing.cc
index 7d6542d..365e714 100644
--- a/chrome/test/base/tracing.cc
+++ b/chrome/test/base/tracing.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -52,9 +52,9 @@ class InProcessTraceController : public TraceSubscriber {
}
// TraceSubscriber
- virtual void OnTraceDataCollected(const std::string& trace_fragment)
- OVERRIDE {
- trace_buffer_.AddFragment(trace_fragment);
+ virtual void OnTraceDataCollected(
+ const scoped_refptr<base::RefCountedString>& trace_fragment) OVERRIDE {
+ trace_buffer_.AddFragment(trace_fragment->data());
}
// For collecting trace data asynchronously.
diff --git a/content/browser/trace_controller.cc b/content/browser/trace_controller.cc
index c7e570d..41770cd 100644
--- a/content/browser/trace_controller.cc
+++ b/content/browser/trace_controller.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -20,7 +20,7 @@ using content::BrowserThread;
namespace {
-class AutoStopTraceSubscriberStdio : public TraceSubscriberStdio {
+class AutoStopTraceSubscriberStdio : public content::TraceSubscriberStdio {
public:
AutoStopTraceSubscriberStdio(const FilePath& file_path)
: TraceSubscriberStdio(file_path) {}
@@ -86,10 +86,6 @@ void TraceController::InitStartupTracing(const CommandLine& command_line) {
scoped_ptr<AutoStopTraceSubscriberStdio> subscriber(
new AutoStopTraceSubscriberStdio(trace_file));
DCHECK(can_begin_tracing(subscriber.get()));
- if (!subscriber->IsValid()) {
- TraceLog::GetInstance()->SetDisabled();
- return;
- }
std::string delay_str = command_line.GetSwitchValueASCII(
switches::kTraceStartupDuration);
@@ -314,7 +310,7 @@ void TraceController::OnEndTracingAck(
}
void TraceController::OnTraceDataCollected(
- const scoped_refptr<TraceLog::RefCountedString>& events_str_ptr) {
+ const scoped_refptr<base::RefCountedString>& events_str_ptr) {
// OnTraceDataCollected may be called from any browser thread, either by the
// local event trace system or from child processes via TraceMessageFilter.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
@@ -326,7 +322,7 @@ void TraceController::OnTraceDataCollected(
// Drop trace events if we are just getting categories.
if (subscriber_ && !is_get_categories_)
- subscriber_->OnTraceDataCollected(events_str_ptr->data);
+ subscriber_->OnTraceDataCollected(events_str_ptr);
}
void TraceController::OnTraceBufferFull() {
diff --git a/content/browser/trace_controller.h b/content/browser/trace_controller.h
index 1677056..b0b05cc 100644
--- a/content/browser/trace_controller.h
+++ b/content/browser/trace_controller.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,6 +10,7 @@
#include <vector>
#include "base/debug/trace_event.h"
+#include "base/memory/ref_counted_memory.h"
#include "base/memory/singleton.h"
#include "content/common/content_export.h"
@@ -26,7 +27,8 @@ class CONTENT_EXPORT TraceSubscriber {
// Called 0 or more times between TraceController::BeginTracing and
// OnEndTracingComplete. Use base::debug::TraceResultBuffer to convert one or
// more trace fragments to JSON.
- virtual void OnTraceDataCollected(const std::string& trace_fragment) = 0;
+ virtual void OnTraceDataCollected(
+ const scoped_refptr<base::RefCountedString>& trace_fragment) = 0;
// Called once after TraceController::GetKnownCategoriesAsync.
virtual void OnKnownCategoriesCollected(
const std::set<std::string>& known_categories);
@@ -154,8 +156,7 @@ class CONTENT_EXPORT TraceController {
void OnTracingBegan(TraceSubscriber* subscriber);
void OnEndTracingAck(const std::vector<std::string>& known_categories);
void OnTraceDataCollected(
- const scoped_refptr<base::debug::TraceLog::RefCountedString>&
- events_str_ptr);
+ const scoped_refptr<base::RefCountedString>& events_str_ptr);
void OnTraceBufferFull();
void OnTraceBufferPercentFullReply(float percent_full);
diff --git a/content/browser/trace_message_filter.cc b/content/browser/trace_message_filter.cc
index 98d43db..292f02d 100644
--- a/content/browser/trace_message_filter.cc
+++ b/content/browser/trace_message_filter.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -96,8 +96,9 @@ void TraceMessageFilter::OnEndTracingAck(
}
void TraceMessageFilter::OnTraceDataCollected(const std::string& data) {
- TraceController::GetInstance()->OnTraceDataCollected(
- make_scoped_refptr(new base::debug::TraceLog::RefCountedString(data)));
+ scoped_refptr<base::RefCountedString> data_ptr(new base::RefCountedString());
+ data_ptr->data() = data;
+ TraceController::GetInstance()->OnTraceDataCollected(data_ptr);
}
void TraceMessageFilter::OnTraceBufferFull() {
diff --git a/content/browser/trace_subscriber_stdio.cc b/content/browser/trace_subscriber_stdio.cc
index 0ecd51e..028404c 100644
--- a/content/browser/trace_subscriber_stdio.cc
+++ b/content/browser/trace_subscriber_stdio.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,60 +6,94 @@
#include "base/bind.h"
#include "base/logging.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "content/public/browser/browser_thread.h"
-TraceSubscriberStdio::TraceSubscriberStdio() : file_(0) {
-}
+namespace content {
-TraceSubscriberStdio::TraceSubscriberStdio(const FilePath& path) : file_(0) {
- OpenFile(path);
-}
+// All method calls on this class are done on a SequencedWorkerPool thread.
+class TraceSubscriberStdioImpl
+ : public base::RefCountedThreadSafe<TraceSubscriberStdioImpl> {
+ public:
+ explicit TraceSubscriberStdioImpl(const FilePath& path)
+ : path_(path),
+ file_(0) {}
-TraceSubscriberStdio::~TraceSubscriberStdio() {
- CloseFile();
-}
+ ~TraceSubscriberStdioImpl() {
+ CloseFile();
+ }
+
+ void OnStart() {
+ DCHECK(!file_);
+ file_ = file_util::OpenFile(path_, "w+");
+ if (IsValid()) {
+ LOG(INFO) << "Logging performance trace to file: " << path_.value();
+ trace_buffer_.SetOutputCallback(
+ base::Bind(&TraceSubscriberStdioImpl::Write, this));
+ trace_buffer_.Start();
+ } else {
+ LOG(ERROR) << "Failed to open performance trace file: " << path_.value();
+ }
+ }
-bool TraceSubscriberStdio::OpenFile(const FilePath& path) {
- LOG(INFO) << "Logging performance trace to file: " << path.value();
- CloseFile();
- file_ = file_util::OpenFile(path, "w+");
- if (IsValid()) {
- trace_buffer_.SetOutputCallback(base::Bind(&TraceSubscriberStdio::Write,
- base::Unretained(this)));
- trace_buffer_.Start();
- return true;
- } else {
- LOG(ERROR) << "Failed to open performance trace file: " << path.value();
- return false;
+ void OnData(const scoped_refptr<base::RefCountedString>& data_ptr) {
+ trace_buffer_.AddFragment(data_ptr->data());
+ }
+
+ void OnEnd() {
+ trace_buffer_.Finish();
+ CloseFile();
+ }
+
+ private:
+ bool IsValid() {
+ return file_ && (0 == ferror(file_));
+ }
+
+ void CloseFile() {
+ if (file_) {
+ fclose(file_);
+ file_ = 0;
+ }
}
-}
-void TraceSubscriberStdio::CloseFile() {
- if (file_) {
- fclose(file_);
- file_ = 0;
+ void Write(const std::string& output_str) {
+ if (IsValid()) {
+ size_t written = fwrite(output_str.data(), 1, output_str.size(), file_);
+ if (written != output_str.size()) {
+ LOG(ERROR) << "Error " << ferror(file_) << " in fwrite() to trace file";
+ CloseFile();
+ }
+ }
}
+
+ FilePath path_;
+ FILE* file_;
+ base::debug::TraceResultBuffer trace_buffer_;
+};
+
+TraceSubscriberStdio::TraceSubscriberStdio(const FilePath& path)
+ : impl_(new TraceSubscriberStdioImpl(path)) {
+ BrowserThread::PostBlockingPoolSequencedTask(
+ __FILE__, FROM_HERE,
+ base::Bind(&TraceSubscriberStdioImpl::OnStart, impl_.get()));
}
-bool TraceSubscriberStdio::IsValid() {
- return file_ && (0 == ferror(file_));
+TraceSubscriberStdio::~TraceSubscriberStdio() {
}
void TraceSubscriberStdio::OnEndTracingComplete() {
- trace_buffer_.Finish();
- CloseFile();
+ BrowserThread::PostBlockingPoolSequencedTask(
+ __FILE__, FROM_HERE,
+ base::Bind(&TraceSubscriberStdioImpl::OnEnd, impl_.get()));
}
void TraceSubscriberStdio::OnTraceDataCollected(
- const std::string& trace_fragment) {
- trace_buffer_.AddFragment(trace_fragment);
+ const scoped_refptr<base::RefCountedString>& data_ptr) {
+ BrowserThread::PostBlockingPoolSequencedTask(
+ __FILE__, FROM_HERE,
+ base::Bind(&TraceSubscriberStdioImpl::OnData, impl_.get(), data_ptr));
}
-void TraceSubscriberStdio::Write(const std::string& output_str) {
- if (IsValid()) {
- size_t written = fwrite(output_str.data(), 1, output_str.size(), file_);
- if (written != output_str.size()) {
- LOG(ERROR) << "Error " << ferror(file_) << " when writing to trace file";
- CloseFile();
- }
- }
-}
+} // namespace content
+
diff --git a/content/browser/trace_subscriber_stdio.h b/content/browser/trace_subscriber_stdio.h
index b9742e2..c7014f7 100644
--- a/content/browser/trace_subscriber_stdio.h
+++ b/content/browser/trace_subscriber_stdio.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -12,32 +12,27 @@
#include "content/browser/trace_controller.h"
#include "content/common/content_export.h"
+namespace content {
+
+class TraceSubscriberStdioImpl;
+
// Stdio implementation of TraceSubscriber. Use this to write traces to a file.
class CONTENT_EXPORT TraceSubscriberStdio : public TraceSubscriber {
public:
- TraceSubscriberStdio();
// Creates or overwrites the specified file. Check IsValid() for success.
explicit TraceSubscriberStdio(const FilePath& path);
-
- // Creates or overwrites the specified file. Returns true on success.
- bool OpenFile(const FilePath& path);
- // Finishes json output and closes file.
- void CloseFile();
-
- // Returns TRUE if we're currently writing data to a file.
- bool IsValid();
+ virtual ~TraceSubscriberStdio();
// Implementation of TraceSubscriber
virtual void OnEndTracingComplete() OVERRIDE;
- virtual void OnTraceDataCollected(const std::string& trace_fragment) OVERRIDE;
-
- virtual ~TraceSubscriberStdio();
+ virtual void OnTraceDataCollected(
+ const scoped_refptr<base::RefCountedString>& data_ptr) OVERRIDE;
private:
- void Write(const std::string& output_str);
-
- FILE* file_;
- base::debug::TraceResultBuffer trace_buffer_;
+ scoped_refptr<TraceSubscriberStdioImpl> impl_;
+ DISALLOW_COPY_AND_ASSIGN(TraceSubscriberStdio);
};
+} // namespace content
+
#endif // CONTENT_BROWSER_TRACE_SUBSCRIBER_STDIO_H_
diff --git a/content/browser/trace_subscriber_stdio_unittest.cc b/content/browser/trace_subscriber_stdio_unittest.cc
index 92f360f..6c8531c 100644
--- a/content/browser/trace_subscriber_stdio_unittest.cc
+++ b/content/browser/trace_subscriber_stdio_unittest.cc
@@ -1,40 +1,34 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/trace_subscriber_stdio.h"
+#include "base/message_loop.h"
#include "base/scoped_temp_dir.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "content/public/browser/browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace {
+TEST(TraceSubscriberStdioTest, CanWriteDataToFile) {
+ ScopedTempDir trace_dir;
+ ASSERT_TRUE(trace_dir.CreateUniqueTempDir());
+ FilePath trace_file(trace_dir.path().AppendASCII("trace.txt"));
+ {
+ content::TraceSubscriberStdio subscriber(trace_file);
-class TraceSubscriberStdioTest : public testing::Test {
- public:
- virtual void SetUp() {
- ASSERT_TRUE(trace_dir_.CreateUniqueTempDir());
- trace_file_ = trace_dir_.path().AppendASCII("trace.txt");
- }
-
- std::string ReadTraceFile() {
- std::string result;
- EXPECT_TRUE(file_util::ReadFileToString(trace_file_, &result));
- return result;
- }
-
- ScopedTempDir trace_dir_;
- FilePath trace_file_;
-};
+ std::string foo("foo");
+ subscriber.OnTraceDataCollected(
+ make_scoped_refptr(base::RefCountedString::TakeString(&foo)));
-} // namespace
+ std::string bar("bar");
+ subscriber.OnTraceDataCollected(
+ make_scoped_refptr(base::RefCountedString::TakeString(&bar)));
-TEST_F(TraceSubscriberStdioTest, CanWriteDataToFile) {
- TraceSubscriberStdio subscriber(trace_file_);
- subscriber.OnTraceDataCollected("[foo]");
- subscriber.OnTraceDataCollected("[bar]");
- EXPECT_TRUE(subscriber.IsValid());
-
- subscriber.OnEndTracingComplete();
- EXPECT_FALSE(subscriber.IsValid());
+ subscriber.OnEndTracingComplete();
+ }
+ content::BrowserThread::GetBlockingPool()->FlushForTesting();
+ std::string result;
+ EXPECT_TRUE(file_util::ReadFileToString(trace_file, &result));
+ EXPECT_EQ("[foo,bar]", result);
}
-
diff --git a/content/common/child_trace_message_filter.cc b/content/common/child_trace_message_filter.cc
index ca280bc..cac19ea 100644
--- a/content/common/child_trace_message_filter.cc
+++ b/content/common/child_trace_message_filter.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -72,8 +72,7 @@ void ChildTraceMessageFilter::OnGetTraceBufferPercentFull() {
}
void ChildTraceMessageFilter::OnTraceDataCollected(
- const scoped_refptr<base::debug::TraceLog::RefCountedString>&
- events_str_ptr) {
+ const scoped_refptr<base::RefCountedString>& events_str_ptr) {
if (MessageLoop::current() != ChildProcess::current()->io_message_loop()) {
ChildProcess::current()->io_message_loop()->PostTask(FROM_HERE,
base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this,
@@ -82,7 +81,7 @@ void ChildTraceMessageFilter::OnTraceDataCollected(
}
channel_->Send(new ChildProcessHostMsg_TraceDataCollected(
- events_str_ptr->data));
+ events_str_ptr->data()));
}
void ChildTraceMessageFilter::OnTraceBufferFull() {
diff --git a/content/common/child_trace_message_filter.h b/content/common/child_trace_message_filter.h
index 19d3467..51f7bd3 100644
--- a/content/common/child_trace_message_filter.h
+++ b/content/common/child_trace_message_filter.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -31,8 +31,7 @@ class ChildTraceMessageFilter : public IPC::ChannelProxy::MessageFilter {
// Callback from trace subsystem.
void OnTraceDataCollected(
- const scoped_refptr<base::debug::TraceLog::RefCountedString>&
- events_str_ptr);
+ const scoped_refptr<base::RefCountedString>& events_str_ptr);
void OnTraceBufferFull();
IPC::Channel* channel_;