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/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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/gpu_blacklist.h" | 17 #include "chrome/browser/gpu_blacklist.h" |
18 #include "chrome/browser/gpu_util.h" | 18 #include "chrome/browser/gpu_util.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/chrome_select_file_policy.h" | 20 #include "chrome/browser/ui/chrome_select_file_policy.h" |
21 #include "chrome/browser/ui/select_file_dialog.h" | |
22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 21 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 22 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
24 #include "chrome/common/chrome_version_info.h" | 23 #include "chrome/common/chrome_version_info.h" |
25 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
26 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/gpu_data_manager.h" | 26 #include "content/public/browser/gpu_data_manager.h" |
28 #include "content/public/browser/gpu_data_manager_observer.h" | 27 #include "content/public/browser/gpu_data_manager_observer.h" |
29 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
30 #include "content/public/browser/trace_controller.h" | 29 #include "content/public/browser/trace_controller.h" |
31 #include "content/public/browser/trace_subscriber.h" | 30 #include "content/public/browser/trace_subscriber.h" |
32 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
33 #include "content/public/browser/web_contents_view.h" | 32 #include "content/public/browser/web_contents_view.h" |
34 #include "content/public/browser/web_ui.h" | 33 #include "content/public/browser/web_ui.h" |
35 #include "content/public/browser/web_ui_message_handler.h" | 34 #include "content/public/browser/web_ui_message_handler.h" |
36 #include "grit/browser_resources.h" | 35 #include "grit/browser_resources.h" |
37 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
38 #include "ipc/ipc_channel.h" | 37 #include "ipc/ipc_channel.h" |
| 38 #include "ui/base/dialogs/select_file_dialog.h" |
39 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
40 | 40 |
41 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
42 #include "chromeos/dbus/dbus_thread_manager.h" | 42 #include "chromeos/dbus/dbus_thread_manager.h" |
43 #include "chromeos/dbus/debug_daemon_client.h" | 43 #include "chromeos/dbus/debug_daemon_client.h" |
44 #endif | 44 #endif |
45 | 45 |
46 using content::BrowserThread; | 46 using content::BrowserThread; |
47 using content::GpuDataManager; | 47 using content::GpuDataManager; |
48 using content::TraceController; | 48 using content::TraceController; |
(...skipping 11 matching lines...) Expand all Loading... |
60 source->add_resource_path("tracing.js", IDR_TRACING_JS); | 60 source->add_resource_path("tracing.js", IDR_TRACING_JS); |
61 source->AddLocalizedString("tracingTitle", IDS_TRACING_TITLE); | 61 source->AddLocalizedString("tracingTitle", IDS_TRACING_TITLE); |
62 return source; | 62 return source; |
63 } | 63 } |
64 | 64 |
65 // This class receives javascript messages from the renderer. | 65 // This class receives javascript messages from the renderer. |
66 // Note that the WebUI infrastructure runs on the UI thread, therefore all of | 66 // Note that the WebUI infrastructure runs on the UI thread, therefore all of |
67 // this class's methods are expected to run on the UI thread. | 67 // this class's methods are expected to run on the UI thread. |
68 class TracingMessageHandler | 68 class TracingMessageHandler |
69 : public WebUIMessageHandler, | 69 : public WebUIMessageHandler, |
70 public SelectFileDialog::Listener, | 70 public ui::SelectFileDialog::Listener, |
71 public base::SupportsWeakPtr<TracingMessageHandler>, | 71 public base::SupportsWeakPtr<TracingMessageHandler>, |
72 public content::TraceSubscriber, | 72 public content::TraceSubscriber, |
73 public content::GpuDataManagerObserver { | 73 public content::GpuDataManagerObserver { |
74 public: | 74 public: |
75 TracingMessageHandler(); | 75 TracingMessageHandler(); |
76 virtual ~TracingMessageHandler(); | 76 virtual ~TracingMessageHandler(); |
77 | 77 |
78 // WebUIMessageHandler implementation. | 78 // WebUIMessageHandler implementation. |
79 virtual void RegisterMessages(); | 79 virtual void RegisterMessages(); |
80 | 80 |
(...skipping 17 matching lines...) Expand all Loading... |
98 void OnBeginRequestBufferPercentFull(const ListValue* list); | 98 void OnBeginRequestBufferPercentFull(const ListValue* list); |
99 void OnLoadTraceFile(const ListValue* list); | 99 void OnLoadTraceFile(const ListValue* list); |
100 void OnSaveTraceFile(const ListValue* list); | 100 void OnSaveTraceFile(const ListValue* list); |
101 | 101 |
102 // Callbacks. | 102 // Callbacks. |
103 void LoadTraceFileComplete(string16* file_contents); | 103 void LoadTraceFileComplete(string16* file_contents); |
104 void SaveTraceFileComplete(); | 104 void SaveTraceFileComplete(); |
105 | 105 |
106 private: | 106 private: |
107 // The file dialog to select a file for loading or saving traces. | 107 // The file dialog to select a file for loading or saving traces. |
108 scoped_refptr<SelectFileDialog> select_trace_file_dialog_; | 108 scoped_refptr<ui::SelectFileDialog> select_trace_file_dialog_; |
109 | 109 |
110 // The type of the file dialog as the same one is used for loading or saving | 110 // The type of the file dialog as the same one is used for loading or saving |
111 // traces. | 111 // traces. |
112 SelectFileDialog::Type select_trace_file_dialog_type_; | 112 ui::SelectFileDialog::Type select_trace_file_dialog_type_; |
113 | 113 |
114 // The trace data that is to be written to the file on saving. | 114 // The trace data that is to be written to the file on saving. |
115 scoped_ptr<std::string> trace_data_to_save_; | 115 scoped_ptr<std::string> trace_data_to_save_; |
116 | 116 |
117 // True while tracing is active. | 117 // True while tracing is active. |
118 bool trace_enabled_; | 118 bool trace_enabled_; |
119 | 119 |
120 // True while system tracing is active. | 120 // True while system tracing is active. |
121 bool system_trace_in_progress_; | 121 bool system_trace_in_progress_; |
122 | 122 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 DISALLOW_COPY_AND_ASSIGN(TaskProxy); | 157 DISALLOW_COPY_AND_ASSIGN(TaskProxy); |
158 }; | 158 }; |
159 | 159 |
160 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
161 // | 161 // |
162 // TracingMessageHandler | 162 // TracingMessageHandler |
163 // | 163 // |
164 //////////////////////////////////////////////////////////////////////////////// | 164 //////////////////////////////////////////////////////////////////////////////// |
165 | 165 |
166 TracingMessageHandler::TracingMessageHandler() | 166 TracingMessageHandler::TracingMessageHandler() |
167 : select_trace_file_dialog_type_(SelectFileDialog::SELECT_NONE), | 167 : select_trace_file_dialog_type_(ui::SelectFileDialog::SELECT_NONE), |
168 trace_enabled_(false), | 168 trace_enabled_(false), |
169 system_trace_in_progress_(false), | 169 system_trace_in_progress_(false), |
170 observing_(false) { | 170 observing_(false) { |
171 } | 171 } |
172 | 172 |
173 TracingMessageHandler::~TracingMessageHandler() { | 173 TracingMessageHandler::~TracingMessageHandler() { |
174 GpuDataManager::GetInstance()->RemoveObserver(this); | 174 GpuDataManager::GetInstance()->RemoveObserver(this); |
175 | 175 |
176 if (select_trace_file_dialog_) | 176 if (select_trace_file_dialog_) |
177 select_trace_file_dialog_->ListenerDestroyed(); | 177 select_trace_file_dialog_->ListenerDestroyed(); |
178 | 178 |
179 // If we are the current subscriber, this will result in ending tracing. | 179 // If we are the current subscriber, this will result in ending tracing. |
180 TraceController::GetInstance()->CancelSubscriber(this); | 180 TraceController::GetInstance()->CancelSubscriber(this); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 if (!file_util::WriteFile(path, contents->c_str(), contents->size())) | 324 if (!file_util::WriteFile(path, contents->c_str(), contents->size())) |
325 return; | 325 return; |
326 | 326 |
327 BrowserThread::PostTask( | 327 BrowserThread::PostTask( |
328 BrowserThread::UI, FROM_HERE, | 328 BrowserThread::UI, FROM_HERE, |
329 base::Bind(&TaskProxy::SaveTraceFileCompleteProxy, proxy)); | 329 base::Bind(&TaskProxy::SaveTraceFileCompleteProxy, proxy)); |
330 } | 330 } |
331 | 331 |
332 void TracingMessageHandler::FileSelected( | 332 void TracingMessageHandler::FileSelected( |
333 const FilePath& path, int index, void* params) { | 333 const FilePath& path, int index, void* params) { |
334 if (select_trace_file_dialog_type_ == SelectFileDialog::SELECT_OPEN_FILE) { | 334 if (select_trace_file_dialog_type_ == |
| 335 ui::SelectFileDialog::SELECT_OPEN_FILE) { |
335 BrowserThread::PostTask( | 336 BrowserThread::PostTask( |
336 BrowserThread::FILE, FROM_HERE, | 337 BrowserThread::FILE, FROM_HERE, |
337 base::Bind(&ReadTraceFileCallback, | 338 base::Bind(&ReadTraceFileCallback, |
338 make_scoped_refptr(new TaskProxy(AsWeakPtr())), path)); | 339 make_scoped_refptr(new TaskProxy(AsWeakPtr())), path)); |
339 } else { | 340 } else { |
340 BrowserThread::PostTask( | 341 BrowserThread::PostTask( |
341 BrowserThread::FILE, FROM_HERE, | 342 BrowserThread::FILE, FROM_HERE, |
342 base::Bind(&WriteTraceFileCallback, | 343 base::Bind(&WriteTraceFileCallback, |
343 make_scoped_refptr(new TaskProxy(AsWeakPtr())), path, | 344 make_scoped_refptr(new TaskProxy(AsWeakPtr())), path, |
344 trace_data_to_save_.release())); | 345 trace_data_to_save_.release())); |
345 } | 346 } |
346 | 347 |
347 select_trace_file_dialog_.release(); | 348 select_trace_file_dialog_.release(); |
348 } | 349 } |
349 | 350 |
350 void TracingMessageHandler::FileSelectionCanceled(void* params) { | 351 void TracingMessageHandler::FileSelectionCanceled(void* params) { |
351 select_trace_file_dialog_.release(); | 352 select_trace_file_dialog_.release(); |
352 if (select_trace_file_dialog_type_ == SelectFileDialog::SELECT_OPEN_FILE) { | 353 if (select_trace_file_dialog_type_ == |
| 354 ui::SelectFileDialog::SELECT_OPEN_FILE) { |
353 web_ui()->CallJavascriptFunction( | 355 web_ui()->CallJavascriptFunction( |
354 "tracingController.onLoadTraceFileCanceled"); | 356 "tracingController.onLoadTraceFileCanceled"); |
355 } else { | 357 } else { |
356 web_ui()->CallJavascriptFunction( | 358 web_ui()->CallJavascriptFunction( |
357 "tracingController.onSaveTraceFileCanceled"); | 359 "tracingController.onSaveTraceFileCanceled"); |
358 } | 360 } |
359 } | 361 } |
360 | 362 |
361 void TracingMessageHandler::OnLoadTraceFile(const ListValue* list) { | 363 void TracingMessageHandler::OnLoadTraceFile(const ListValue* list) { |
362 // Only allow a single dialog at a time. | 364 // Only allow a single dialog at a time. |
363 if (select_trace_file_dialog_.get()) | 365 if (select_trace_file_dialog_.get()) |
364 return; | 366 return; |
365 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; | 367 select_trace_file_dialog_type_ = ui::SelectFileDialog::SELECT_OPEN_FILE; |
366 select_trace_file_dialog_ = SelectFileDialog::Create( | 368 select_trace_file_dialog_ = ui::SelectFileDialog::Create( |
367 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | 369 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); |
368 select_trace_file_dialog_->SelectFile( | 370 select_trace_file_dialog_->SelectFile( |
369 SelectFileDialog::SELECT_OPEN_FILE, | 371 ui::SelectFileDialog::SELECT_OPEN_FILE, |
370 string16(), | 372 string16(), |
371 FilePath(), | 373 FilePath(), |
372 NULL, 0, FILE_PATH_LITERAL(""), | 374 NULL, 0, FILE_PATH_LITERAL(""), |
373 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); | 375 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); |
374 } | 376 } |
375 | 377 |
376 void TracingMessageHandler::LoadTraceFileComplete(string16* contents) { | 378 void TracingMessageHandler::LoadTraceFileComplete(string16* contents) { |
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
378 | 380 |
379 // We need to pass contents to tracingController.onLoadTraceFileComplete, but | 381 // We need to pass contents to tracingController.onLoadTraceFileComplete, but |
(...skipping 24 matching lines...) Expand all Loading... |
404 if (select_trace_file_dialog_.get()) | 406 if (select_trace_file_dialog_.get()) |
405 return; | 407 return; |
406 | 408 |
407 DCHECK(list->GetSize() == 1); | 409 DCHECK(list->GetSize() == 1); |
408 | 410 |
409 std::string* trace_data = new std::string(); | 411 std::string* trace_data = new std::string(); |
410 bool ok = list->GetString(0, trace_data); | 412 bool ok = list->GetString(0, trace_data); |
411 DCHECK(ok); | 413 DCHECK(ok); |
412 trace_data_to_save_.reset(trace_data); | 414 trace_data_to_save_.reset(trace_data); |
413 | 415 |
414 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE; | 416 select_trace_file_dialog_type_ = ui::SelectFileDialog::SELECT_SAVEAS_FILE; |
415 select_trace_file_dialog_ = SelectFileDialog::Create( | 417 select_trace_file_dialog_ = ui::SelectFileDialog::Create( |
416 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | 418 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); |
417 select_trace_file_dialog_->SelectFile( | 419 select_trace_file_dialog_->SelectFile( |
418 SelectFileDialog::SELECT_SAVEAS_FILE, | 420 ui::SelectFileDialog::SELECT_SAVEAS_FILE, |
419 string16(), | 421 string16(), |
420 FilePath(), | 422 FilePath(), |
421 NULL, 0, FILE_PATH_LITERAL(""), | 423 NULL, 0, FILE_PATH_LITERAL(""), |
422 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); | 424 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(), NULL); |
423 } | 425 } |
424 | 426 |
425 void TracingMessageHandler::SaveTraceFileComplete() { | 427 void TracingMessageHandler::SaveTraceFileComplete() { |
426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
427 web_ui()->CallJavascriptFunction("tracingController.onSaveTraceFileComplete"); | 429 web_ui()->CallJavascriptFunction("tracingController.onSaveTraceFileComplete"); |
428 } | 430 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 // | 536 // |
535 //////////////////////////////////////////////////////////////////////////////// | 537 //////////////////////////////////////////////////////////////////////////////// |
536 | 538 |
537 TracingUI::TracingUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 539 TracingUI::TracingUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
538 web_ui->AddMessageHandler(new TracingMessageHandler()); | 540 web_ui->AddMessageHandler(new TracingMessageHandler()); |
539 | 541 |
540 // Set up the chrome://tracing/ source. | 542 // Set up the chrome://tracing/ source. |
541 Profile* profile = Profile::FromWebUI(web_ui); | 543 Profile* profile = Profile::FromWebUI(web_ui); |
542 ChromeURLDataManager::AddDataSource(profile, CreateTracingHTMLSource()); | 544 ChromeURLDataManager::AddDataSource(profile, CreateTracingHTMLSource()); |
543 } | 545 } |
OLD | NEW |