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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 InProcessTraceController() | 27 InProcessTraceController() |
28 : is_waiting_on_watch_(false), | 28 : is_waiting_on_watch_(false), |
29 watch_notification_count_(0) {} | 29 watch_notification_count_(0) {} |
30 virtual ~InProcessTraceController() {} | 30 virtual ~InProcessTraceController() {} |
31 | 31 |
32 bool BeginTracing(const std::string& category_patterns) { | 32 bool BeginTracing(const std::string& category_patterns) { |
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
34 return content::TracingController::GetInstance()->EnableRecording( | 34 return content::TracingController::GetInstance()->EnableRecording( |
35 category_patterns, content::TracingController::DEFAULT_OPTIONS, | 35 category_patterns, content::TracingController::DEFAULT_OPTIONS, |
36 content::TracingController::EnableRecordingDoneCallback()); | 36 content::TracingController::EnableRecordingDoneCallback()); |
37 return true; | |
38 } | 37 } |
39 | 38 |
40 bool BeginTracingWithWatch(const std::string& category_patterns, | 39 bool BeginTracingWithWatch(const std::string& category_patterns, |
41 const std::string& category_name, | 40 const std::string& category_name, |
42 const std::string& event_name, | 41 const std::string& event_name, |
43 int num_occurrences) { | 42 int num_occurrences) { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
45 DCHECK(num_occurrences > 0); | 44 DCHECK(num_occurrences > 0); |
46 watch_notification_count_ = num_occurrences; | 45 watch_notification_count_ = num_occurrences; |
47 return content::TracingController::GetInstance()->SetWatchEvent( | 46 if (!content::TracingController::GetInstance()->SetWatchEvent( |
48 category_name, event_name, | 47 category_name, event_name, |
49 base::Bind(&InProcessTraceController::OnWatchEventMatched, | 48 base::Bind(&InProcessTraceController::OnWatchEventMatched, |
50 base::Unretained(this))) && | 49 base::Unretained(this)))) { |
sky
2014/01/06 18:14:24
How do you know unretained is safe here and on 55?
haraken
2014/01/07 02:04:43
InProcessTraceController is a Singleton, so I thin
| |
51 BeginTracing(category_patterns); | 50 return false; |
51 } | |
52 if (!content::TracingController::GetInstance()->EnableRecording( | |
53 category_patterns, content::TracingController::DEFAULT_OPTIONS, | |
54 base::Bind(&InProcessTraceController::OnEnableTracingComplete, | |
55 base::Unretained(this)))) { | |
56 return false; | |
57 } | |
58 | |
59 message_loop_runner_ = new content::MessageLoopRunner; | |
60 message_loop_runner_->Run(); | |
61 return true; | |
52 } | 62 } |
53 | 63 |
54 bool WaitForWatchEvent(base::TimeDelta timeout) { | 64 bool WaitForWatchEvent(base::TimeDelta timeout) { |
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
56 if (watch_notification_count_ == 0) | 66 if (watch_notification_count_ == 0) |
57 return true; | 67 return true; |
58 | 68 |
59 if (timeout != base::TimeDelta()) { | 69 if (timeout != base::TimeDelta()) { |
60 timer_.Start(FROM_HERE, timeout, this, | 70 timer_.Start(FROM_HERE, timeout, this, |
61 &InProcessTraceController::Timeout); | 71 &InProcessTraceController::Timeout); |
(...skipping 24 matching lines...) Expand all Loading... | |
86 | 96 |
87 // Watch notifications can occur during this method's message loop run, but | 97 // Watch notifications can occur during this method's message loop run, but |
88 // not after, so clear them here. | 98 // not after, so clear them here. |
89 watch_notification_count_ = 0; | 99 watch_notification_count_ = 0; |
90 return true; | 100 return true; |
91 } | 101 } |
92 | 102 |
93 private: | 103 private: |
94 friend struct DefaultSingletonTraits<InProcessTraceController>; | 104 friend struct DefaultSingletonTraits<InProcessTraceController>; |
95 | 105 |
106 void OnEnableTracingComplete() { | |
107 message_loop_runner_->Quit(); | |
108 } | |
109 | |
96 void OnEndTracingComplete() { | 110 void OnEndTracingComplete() { |
97 message_loop_runner_->Quit(); | 111 message_loop_runner_->Quit(); |
98 } | 112 } |
99 | 113 |
100 void OnTraceDataCollected(std::string* json_trace_output, | 114 void OnTraceDataCollected(std::string* json_trace_output, |
101 const base::FilePath& path) { | 115 const base::FilePath& path) { |
102 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 116 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
103 base::Bind(&InProcessTraceController::ReadTraceData, | 117 base::Bind(&InProcessTraceController::ReadTraceData, |
104 base::Unretained(this), | 118 base::Unretained(this), |
105 base::Unretained(json_trace_output), | 119 base::Unretained(json_trace_output), |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 bool WaitForWatchEvent(base::TimeDelta timeout) { | 185 bool WaitForWatchEvent(base::TimeDelta timeout) { |
172 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); | 186 return InProcessTraceController::GetInstance()->WaitForWatchEvent(timeout); |
173 } | 187 } |
174 | 188 |
175 bool EndTracing(std::string* json_trace_output) { | 189 bool EndTracing(std::string* json_trace_output) { |
176 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); | 190 return InProcessTraceController::GetInstance()->EndTracing(json_trace_output); |
177 } | 191 } |
178 | 192 |
179 } // namespace tracing | 193 } // namespace tracing |
180 | 194 |
OLD | NEW |