Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: chrome/test/base/tracing.cc

Issue 10479018: Add base::RunLoop and update ui_test_utils to use it to reduce flakiness (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: phajdan feedback Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/base/testing_profile.cc ('k') | chrome/test/base/ui_test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « chrome/test/base/testing_profile.cc ('k') | chrome/test/base/ui_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698