OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/ui/webui/tracing_ui.h" | 5 #include "chrome/browser/ui/webui/tracing_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // SelectFileDialog::Listener implementation | 57 // SelectFileDialog::Listener implementation |
58 virtual void FileSelected(const FilePath& path, int index, void* params); | 58 virtual void FileSelected(const FilePath& path, int index, void* params); |
59 virtual void FileSelectionCanceled(void* params); | 59 virtual void FileSelectionCanceled(void* params); |
60 | 60 |
61 // TraceSubscriber implementation. | 61 // TraceSubscriber implementation. |
62 virtual void OnEndTracingComplete(); | 62 virtual void OnEndTracingComplete(); |
63 virtual void OnTraceDataCollected(const std::string& json_events); | 63 virtual void OnTraceDataCollected(const std::string& json_events); |
64 virtual void OnTraceBufferPercentFullReply(float percent_full); | 64 virtual void OnTraceBufferPercentFullReply(float percent_full); |
65 | 65 |
66 // Messages. | 66 // Messages. |
67 void OnBrowserBridgeInitialized(const ListValue* list); | 67 void OnTracingControllerInitialized(const ListValue* list); |
68 void OnCallAsync(const ListValue* list); | |
69 void OnBeginTracing(const ListValue* list); | 68 void OnBeginTracing(const ListValue* list); |
70 void OnEndTracingAsync(const ListValue* list); | 69 void OnEndTracingAsync(const ListValue* list); |
71 void OnBeginRequestBufferPercentFull(const ListValue* list); | 70 void OnBeginRequestBufferPercentFull(const ListValue* list); |
72 void OnLoadTraceFile(const ListValue* list); | 71 void OnLoadTraceFile(const ListValue* list); |
73 void OnSaveTraceFile(const ListValue* list); | 72 void OnSaveTraceFile(const ListValue* list); |
74 | 73 |
75 // Submessages dispatched from OnCallAsync. | |
76 Value* OnRequestClientInfo(const ListValue* list); | |
77 Value* OnRequestLogMessages(const ListValue* list); | |
78 | |
79 // Callbacks. | 74 // Callbacks. |
80 void OnGpuInfoUpdate(); | 75 void OnGpuInfoUpdate(); |
81 | 76 |
82 // Callbacks. | 77 // Callbacks. |
83 void LoadTraceFileComplete(std::string* file_contents); | 78 void LoadTraceFileComplete(std::string* file_contents); |
84 void SaveTraceFileComplete(); | 79 void SaveTraceFileComplete(); |
85 | 80 |
86 // Executes the javascript function |function_name| in the renderer, passing | 81 // Executes the javascript function |function_name| in the renderer, passing |
87 // it the argument |value|. | 82 // it the argument |value|. |
88 void CallJavascriptFunction(const std::wstring& function_name, | 83 void CallJavascriptFunction(const std::wstring& function_name, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 WebUIMessageHandler* TracingMessageHandler::Attach(WebUI* web_ui) { | 162 WebUIMessageHandler* TracingMessageHandler::Attach(WebUI* web_ui) { |
168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
169 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); | 164 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); |
170 return result; | 165 return result; |
171 } | 166 } |
172 | 167 |
173 void TracingMessageHandler::RegisterMessages() { | 168 void TracingMessageHandler::RegisterMessages() { |
174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
175 | 170 |
176 web_ui_->RegisterMessageCallback( | 171 web_ui_->RegisterMessageCallback( |
177 "browserBridgeInitialized", | 172 "tracingControllerInitialized", |
178 NewCallback(this, &TracingMessageHandler::OnBrowserBridgeInitialized)); | 173 NewCallback(this, |
179 web_ui_->RegisterMessageCallback( | 174 &TracingMessageHandler::OnTracingControllerInitialized)); |
180 "callAsync", | |
181 NewCallback(this, &TracingMessageHandler::OnCallAsync)); | |
182 web_ui_->RegisterMessageCallback( | 175 web_ui_->RegisterMessageCallback( |
183 "beginTracing", | 176 "beginTracing", |
184 NewCallback(this, &TracingMessageHandler::OnBeginTracing)); | 177 NewCallback(this, &TracingMessageHandler::OnBeginTracing)); |
185 web_ui_->RegisterMessageCallback( | 178 web_ui_->RegisterMessageCallback( |
186 "endTracingAsync", | 179 "endTracingAsync", |
187 NewCallback(this, &TracingMessageHandler::OnEndTracingAsync)); | 180 NewCallback(this, &TracingMessageHandler::OnEndTracingAsync)); |
188 web_ui_->RegisterMessageCallback( | 181 web_ui_->RegisterMessageCallback( |
189 "beginRequestBufferPercentFull", | 182 "beginRequestBufferPercentFull", |
190 NewCallback(this, | 183 NewCallback(this, |
191 &TracingMessageHandler::OnBeginRequestBufferPercentFull)); | 184 &TracingMessageHandler::OnBeginRequestBufferPercentFull)); |
192 web_ui_->RegisterMessageCallback( | 185 web_ui_->RegisterMessageCallback( |
193 "loadTraceFile", | 186 "loadTraceFile", |
194 NewCallback(this, &TracingMessageHandler::OnLoadTraceFile)); | 187 NewCallback(this, &TracingMessageHandler::OnLoadTraceFile)); |
195 web_ui_->RegisterMessageCallback( | 188 web_ui_->RegisterMessageCallback( |
196 "saveTraceFile", | 189 "saveTraceFile", |
197 NewCallback(this, &TracingMessageHandler::OnSaveTraceFile)); | 190 NewCallback(this, &TracingMessageHandler::OnSaveTraceFile)); |
198 } | 191 } |
199 | 192 |
200 void TracingMessageHandler::OnCallAsync(const ListValue* args) { | 193 void TracingMessageHandler::OnTracingControllerInitialized( |
201 DCHECK_GE(args->GetSize(), static_cast<size_t>(2)); | 194 const ListValue* args) { |
202 // unpack args into requestId, submessage and submessageArgs | |
203 bool ok; | |
204 Value* requestId; | |
205 ok = args->Get(0, &requestId); | |
206 DCHECK(ok); | |
207 | |
208 std::string submessage; | |
209 ok = args->GetString(1, &submessage); | |
210 DCHECK(ok); | |
211 | |
212 ListValue* submessageArgs = new ListValue(); | |
213 for (size_t i = 2; i < args->GetSize(); ++i) { | |
214 Value* arg; | |
215 ok = args->Get(i, &arg); | |
216 DCHECK(ok); | |
217 | |
218 Value* argCopy = arg->DeepCopy(); | |
219 submessageArgs->Append(argCopy); | |
220 } | |
221 | |
222 // call the submessage handler | |
223 Value* ret = NULL; | |
224 if (submessage == "requestClientInfo") { | |
225 ret = OnRequestClientInfo(submessageArgs); | |
226 } else if (submessage == "requestLogMessages") { | |
227 ret = OnRequestLogMessages(submessageArgs); | |
228 } else { // unrecognized submessage | |
229 NOTREACHED(); | |
230 delete submessageArgs; | |
231 return; | |
232 } | |
233 delete submessageArgs; | |
234 | |
235 // call BrowserBridge.onCallAsyncReply with result | |
236 if (ret) { | |
237 web_ui_->CallJavascriptFunction("browserBridge.onCallAsyncReply", | |
238 *requestId, | |
239 *ret); | |
240 delete ret; | |
241 } else { | |
242 web_ui_->CallJavascriptFunction("browserBridge.onCallAsyncReply", | |
243 *requestId); | |
244 } | |
245 } | |
246 | |
247 void TracingMessageHandler::OnBrowserBridgeInitialized(const ListValue* args) { | |
248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
249 | 196 |
250 DCHECK(!gpu_info_update_callback_); | 197 DCHECK(!gpu_info_update_callback_); |
251 | 198 |
252 // Watch for changes in GPUInfo | 199 // Watch for changes in GPUInfo |
253 gpu_info_update_callback_ = | 200 gpu_info_update_callback_ = |
254 NewCallback(this, &TracingMessageHandler::OnGpuInfoUpdate); | 201 NewCallback(this, &TracingMessageHandler::OnGpuInfoUpdate); |
255 gpu_data_manager_->AddGpuInfoUpdateCallback(gpu_info_update_callback_); | 202 gpu_data_manager_->AddGpuInfoUpdateCallback(gpu_info_update_callback_); |
256 | 203 |
257 // Tell GpuDataManager it should have full GpuInfo. If the | 204 // Tell GpuDataManager it should have full GpuInfo. If the |
258 // Gpu process has not run yet, this will trigger its launch. | 205 // Gpu process has not run yet, this will trigger its launch. |
259 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); | 206 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); |
260 | 207 |
261 // Run callback immediately in case the info is ready and no update in the | 208 // Run callback immediately in case the info is ready and no update in the |
262 // future. | 209 // future. |
263 OnGpuInfoUpdate(); | 210 OnGpuInfoUpdate(); |
264 } | |
265 | 211 |
266 Value* TracingMessageHandler::OnRequestClientInfo(const ListValue* list) { | 212 // Send the client info to the tracingController |
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 213 { |
| 214 scoped_ptr<DictionaryValue> dict(new DictionaryValue()); |
| 215 chrome::VersionInfo version_info; |
268 | 216 |
269 DictionaryValue* dict = new DictionaryValue(); | 217 if (!version_info.is_valid()) { |
| 218 DLOG(ERROR) << "Unable to create chrome::VersionInfo"; |
| 219 } else { |
| 220 // We have everything we need to send the right values. |
| 221 dict->SetString("version", version_info.Version()); |
| 222 dict->SetString("cl", version_info.LastChange()); |
| 223 dict->SetString("version_mod", |
| 224 chrome::VersionInfo::GetVersionStringModifier()); |
| 225 dict->SetString("official", |
| 226 l10n_util::GetStringUTF16( |
| 227 version_info.IsOfficialBuild() ? |
| 228 IDS_ABOUT_VERSION_OFFICIAL : |
| 229 IDS_ABOUT_VERSION_UNOFFICIAL)); |
270 | 230 |
271 chrome::VersionInfo version_info; | 231 dict->SetString("command_line", |
| 232 CommandLine::ForCurrentProcess()->GetCommandLineString()); |
| 233 } |
272 | 234 |
273 if (!version_info.is_valid()) { | 235 dict->SetString("blacklist_version", |
274 DLOG(ERROR) << "Unable to create chrome::VersionInfo"; | 236 GpuDataManager::GetInstance()->GetBlacklistVersion()); |
275 } else { | 237 web_ui_->CallJavascriptFunction("tracingController.onClientInfoUpdate", |
276 // We have everything we need to send the right values. | 238 *dict); |
277 dict->SetString("version", version_info.Version()); | |
278 dict->SetString("cl", version_info.LastChange()); | |
279 dict->SetString("version_mod", | |
280 chrome::VersionInfo::GetVersionStringModifier()); | |
281 dict->SetString("official", | |
282 l10n_util::GetStringUTF16( | |
283 version_info.IsOfficialBuild() ? | |
284 IDS_ABOUT_VERSION_OFFICIAL : | |
285 IDS_ABOUT_VERSION_UNOFFICIAL)); | |
286 | |
287 dict->SetString("command_line", | |
288 CommandLine::ForCurrentProcess()->GetCommandLineString()); | |
289 } | 239 } |
290 | |
291 dict->SetString("blacklist_version", | |
292 GpuDataManager::GetInstance()->GetBlacklistVersion()); | |
293 | |
294 return dict; | |
295 } | |
296 | |
297 Value* TracingMessageHandler::OnRequestLogMessages(const ListValue*) { | |
298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
299 | |
300 return gpu_data_manager_->log_messages().DeepCopy(); | |
301 } | 240 } |
302 | 241 |
303 void TracingMessageHandler::OnBeginRequestBufferPercentFull( | 242 void TracingMessageHandler::OnBeginRequestBufferPercentFull( |
304 const ListValue* list) { | 243 const ListValue* list) { |
305 TraceController::GetInstance()->GetTraceBufferPercentFullAsync(this); | 244 TraceController::GetInstance()->GetTraceBufferPercentFullAsync(this); |
306 } | 245 } |
307 | 246 |
308 void TracingMessageHandler::OnGpuInfoUpdate() { | 247 void TracingMessageHandler::OnGpuInfoUpdate() { |
309 // Get GPU Info. | 248 // Get GPU Info. |
310 scoped_ptr<base::DictionaryValue> gpu_info_val( | 249 scoped_ptr<base::DictionaryValue> gpu_info_val( |
311 gpu_data_manager_->GpuInfoAsDictionaryValue()); | 250 gpu_data_manager_->GpuInfoAsDictionaryValue()); |
312 | 251 |
313 // Add in blacklisting features | 252 // Add in blacklisting features |
314 Value* feature_status = gpu_data_manager_->GetFeatureStatus(); | 253 Value* feature_status = gpu_data_manager_->GetFeatureStatus(); |
315 if (feature_status) | 254 if (feature_status) |
316 gpu_info_val->Set("featureStatus", feature_status); | 255 gpu_info_val->Set("featureStatus", feature_status); |
317 | 256 |
318 // Send GPU Info to javascript. | 257 // Send GPU Info to javascript. |
319 web_ui_->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", | 258 web_ui_->CallJavascriptFunction("tracingController.onGpuInfoUpdate", |
320 *(gpu_info_val.get())); | 259 *(gpu_info_val.get())); |
321 } | 260 } |
322 | 261 |
323 // A task used for asynchronously reading a file to a string. Calls the | 262 // A task used for asynchronously reading a file to a string. Calls the |
324 // TaskProxy callback when reading is complete. | 263 // TaskProxy callback when reading is complete. |
325 class ReadTraceFileTask : public Task { | 264 class ReadTraceFileTask : public Task { |
326 public: | 265 public: |
327 ReadTraceFileTask(TaskProxy* proxy, const FilePath& path) | 266 ReadTraceFileTask(TaskProxy* proxy, const FilePath& path) |
328 : proxy_(proxy), | 267 : proxy_(proxy), |
329 path_(path) {} | 268 path_(path) {} |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 // | 455 // |
517 //////////////////////////////////////////////////////////////////////////////// | 456 //////////////////////////////////////////////////////////////////////////////// |
518 | 457 |
519 TracingUI::TracingUI(TabContents* contents) : ChromeWebUI(contents) { | 458 TracingUI::TracingUI(TabContents* contents) : ChromeWebUI(contents) { |
520 AddMessageHandler((new TracingMessageHandler())->Attach(this)); | 459 AddMessageHandler((new TracingMessageHandler())->Attach(this)); |
521 | 460 |
522 // Set up the chrome://tracing/ source. | 461 // Set up the chrome://tracing/ source. |
523 Profile::FromBrowserContext(contents->browser_context())-> | 462 Profile::FromBrowserContext(contents->browser_context())-> |
524 GetChromeURLDataManager()->AddDataSource(CreateTracingHTMLSource()); | 463 GetChromeURLDataManager()->AddDataSource(CreateTracingHTMLSource()); |
525 } | 464 } |
OLD | NEW |