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/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/browser/gpu_blacklist.h" |
| 19 #include "chrome/browser/gpu_util.h" |
18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/chrome_select_file_policy.h" | 21 #include "chrome/browser/ui/chrome_select_file_policy.h" |
20 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
21 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 23 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
22 #include "chrome/common/chrome_version_info.h" | 24 #include "chrome/common/chrome_version_info.h" |
23 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
24 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/gpu_data_manager.h" | 27 #include "content/public/browser/gpu_data_manager.h" |
26 #include "content/public/browser/gpu_data_manager_observer.h" | 28 #include "content/public/browser/gpu_data_manager_observer.h" |
27 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 return source; | 63 return source; |
62 } | 64 } |
63 | 65 |
64 // This class receives javascript messages from the renderer. | 66 // This class receives javascript messages from the renderer. |
65 // Note that the WebUI infrastructure runs on the UI thread, therefore all of | 67 // Note that the WebUI infrastructure runs on the UI thread, therefore all of |
66 // this class's methods are expected to run on the UI thread. | 68 // this class's methods are expected to run on the UI thread. |
67 class TracingMessageHandler | 69 class TracingMessageHandler |
68 : public WebUIMessageHandler, | 70 : public WebUIMessageHandler, |
69 public ui::SelectFileDialog::Listener, | 71 public ui::SelectFileDialog::Listener, |
70 public base::SupportsWeakPtr<TracingMessageHandler>, | 72 public base::SupportsWeakPtr<TracingMessageHandler>, |
71 public content::TraceSubscriber { | 73 public content::TraceSubscriber, |
| 74 public content::GpuDataManagerObserver { |
72 public: | 75 public: |
73 TracingMessageHandler(); | 76 TracingMessageHandler(); |
74 virtual ~TracingMessageHandler(); | 77 virtual ~TracingMessageHandler(); |
75 | 78 |
76 // WebUIMessageHandler implementation. | 79 // WebUIMessageHandler implementation. |
77 virtual void RegisterMessages(); | 80 virtual void RegisterMessages(); |
78 | 81 |
79 // SelectFileDialog::Listener implementation | 82 // SelectFileDialog::Listener implementation |
80 virtual void FileSelected(const FilePath& path, int index, void* params); | 83 virtual void FileSelected(const FilePath& path, int index, void* params); |
81 virtual void FileSelectionCanceled(void* params); | 84 virtual void FileSelectionCanceled(void* params); |
82 | 85 |
83 // TraceSubscriber implementation. | 86 // TraceSubscriber implementation. |
84 virtual void OnEndTracingComplete(); | 87 virtual void OnEndTracingComplete(); |
85 virtual void OnTraceDataCollected( | 88 virtual void OnTraceDataCollected( |
86 const scoped_refptr<base::RefCountedString>& trace_fragment); | 89 const scoped_refptr<base::RefCountedString>& trace_fragment); |
87 virtual void OnTraceBufferPercentFullReply(float percent_full); | 90 virtual void OnTraceBufferPercentFullReply(float percent_full); |
88 | 91 |
| 92 // GpuDataManagerObserver implementation. |
| 93 virtual void OnGpuInfoUpdate() OVERRIDE; |
| 94 virtual void OnVideoMemoryUsageStatsUpdate( |
| 95 const content::GPUVideoMemoryUsageStats& video_memory) OVERRIDE {} |
| 96 |
89 // Messages. | 97 // Messages. |
90 void OnTracingControllerInitialized(const ListValue* list); | 98 void OnTracingControllerInitialized(const ListValue* list); |
91 void OnBeginTracing(const ListValue* list); | 99 void OnBeginTracing(const ListValue* list); |
92 void OnEndTracingAsync(const ListValue* list); | 100 void OnEndTracingAsync(const ListValue* list); |
93 void OnBeginRequestBufferPercentFull(const ListValue* list); | 101 void OnBeginRequestBufferPercentFull(const ListValue* list); |
94 void OnLoadTraceFile(const ListValue* list); | 102 void OnLoadTraceFile(const ListValue* list); |
95 void OnSaveTraceFile(const ListValue* list); | 103 void OnSaveTraceFile(const ListValue* list); |
96 | 104 |
97 // Callbacks. | 105 // Callbacks. |
98 void LoadTraceFileComplete(string16* file_contents); | 106 void LoadTraceFileComplete(string16* file_contents); |
99 void SaveTraceFileComplete(); | 107 void SaveTraceFileComplete(); |
100 | 108 |
101 private: | 109 private: |
102 // The file dialog to select a file for loading or saving traces. | 110 // The file dialog to select a file for loading or saving traces. |
103 scoped_refptr<ui::SelectFileDialog> select_trace_file_dialog_; | 111 scoped_refptr<ui::SelectFileDialog> select_trace_file_dialog_; |
104 | 112 |
105 // The type of the file dialog as the same one is used for loading or saving | 113 // The type of the file dialog as the same one is used for loading or saving |
106 // traces. | 114 // traces. |
107 ui::SelectFileDialog::Type select_trace_file_dialog_type_; | 115 ui::SelectFileDialog::Type select_trace_file_dialog_type_; |
108 | 116 |
109 // The trace data that is to be written to the file on saving. | 117 // The trace data that is to be written to the file on saving. |
110 scoped_ptr<std::string> trace_data_to_save_; | 118 scoped_ptr<std::string> trace_data_to_save_; |
111 | 119 |
112 // True while tracing is active. | 120 // True while tracing is active. |
113 bool trace_enabled_; | 121 bool trace_enabled_; |
114 | 122 |
115 // True while system tracing is active. | 123 // True while system tracing is active. |
116 bool system_trace_in_progress_; | 124 bool system_trace_in_progress_; |
117 | 125 |
| 126 // True if observing the GpuDataManager (re-attaching as observer would |
| 127 // DCHECK). |
| 128 bool observing_; |
| 129 |
118 void OnEndSystemTracingAck( | 130 void OnEndSystemTracingAck( |
119 const scoped_refptr<base::RefCountedString>& events_str_ptr); | 131 const scoped_refptr<base::RefCountedString>& events_str_ptr); |
120 | 132 |
121 DISALLOW_COPY_AND_ASSIGN(TracingMessageHandler); | 133 DISALLOW_COPY_AND_ASSIGN(TracingMessageHandler); |
122 }; | 134 }; |
123 | 135 |
124 // A proxy passed to the Read and Write tasks used when loading or saving trace | 136 // A proxy passed to the Read and Write tasks used when loading or saving trace |
125 // data. | 137 // data. |
126 class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> { | 138 class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> { |
127 public: | 139 public: |
(...skipping 22 matching lines...) Expand all Loading... |
150 | 162 |
151 //////////////////////////////////////////////////////////////////////////////// | 163 //////////////////////////////////////////////////////////////////////////////// |
152 // | 164 // |
153 // TracingMessageHandler | 165 // TracingMessageHandler |
154 // | 166 // |
155 //////////////////////////////////////////////////////////////////////////////// | 167 //////////////////////////////////////////////////////////////////////////////// |
156 | 168 |
157 TracingMessageHandler::TracingMessageHandler() | 169 TracingMessageHandler::TracingMessageHandler() |
158 : select_trace_file_dialog_type_(ui::SelectFileDialog::SELECT_NONE), | 170 : select_trace_file_dialog_type_(ui::SelectFileDialog::SELECT_NONE), |
159 trace_enabled_(false), | 171 trace_enabled_(false), |
160 system_trace_in_progress_(false) { | 172 system_trace_in_progress_(false), |
| 173 observing_(false) { |
161 } | 174 } |
162 | 175 |
163 TracingMessageHandler::~TracingMessageHandler() { | 176 TracingMessageHandler::~TracingMessageHandler() { |
| 177 GpuDataManager::GetInstance()->RemoveObserver(this); |
| 178 |
164 if (select_trace_file_dialog_) | 179 if (select_trace_file_dialog_) |
165 select_trace_file_dialog_->ListenerDestroyed(); | 180 select_trace_file_dialog_->ListenerDestroyed(); |
166 | 181 |
167 // If we are the current subscriber, this will result in ending tracing. | 182 // If we are the current subscriber, this will result in ending tracing. |
168 TraceController::GetInstance()->CancelSubscriber(this); | 183 TraceController::GetInstance()->CancelSubscriber(this); |
169 | 184 |
170 // Shutdown any system tracing too. | 185 // Shutdown any system tracing too. |
171 if (system_trace_in_progress_) { | 186 if (system_trace_in_progress_) { |
172 #if defined(OS_CHROMEOS) | 187 #if defined(OS_CHROMEOS) |
173 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> | 188 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()-> |
(...skipping 23 matching lines...) Expand all Loading... |
197 base::Unretained(this))); | 212 base::Unretained(this))); |
198 web_ui()->RegisterMessageCallback("saveTraceFile", | 213 web_ui()->RegisterMessageCallback("saveTraceFile", |
199 base::Bind(&TracingMessageHandler::OnSaveTraceFile, | 214 base::Bind(&TracingMessageHandler::OnSaveTraceFile, |
200 base::Unretained(this))); | 215 base::Unretained(this))); |
201 } | 216 } |
202 | 217 |
203 void TracingMessageHandler::OnTracingControllerInitialized( | 218 void TracingMessageHandler::OnTracingControllerInitialized( |
204 const ListValue* args) { | 219 const ListValue* args) { |
205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
206 | 221 |
| 222 // Watch for changes in GPUInfo |
| 223 if (!observing_) |
| 224 GpuDataManager::GetInstance()->AddObserver(this); |
| 225 observing_ = true; |
| 226 |
| 227 // Tell GpuDataManager it should have full GpuInfo. If the |
| 228 // Gpu process has not run yet, this will trigger its launch. |
| 229 GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded(); |
| 230 |
| 231 // Run callback immediately in case the info is ready and no update in the |
| 232 // future. |
| 233 OnGpuInfoUpdate(); |
| 234 |
207 // Send the client info to the tracingController | 235 // Send the client info to the tracingController |
208 { | 236 { |
209 scoped_ptr<DictionaryValue> dict(new DictionaryValue()); | 237 scoped_ptr<DictionaryValue> dict(new DictionaryValue()); |
210 chrome::VersionInfo version_info; | 238 chrome::VersionInfo version_info; |
211 | 239 |
212 if (!version_info.is_valid()) { | 240 if (!version_info.is_valid()) { |
213 DLOG(ERROR) << "Unable to create chrome::VersionInfo"; | 241 DLOG(ERROR) << "Unable to create chrome::VersionInfo"; |
214 } else { | 242 } else { |
215 // We have everything we need to send the right values. | 243 // We have everything we need to send the right values. |
216 dict->SetString("version", version_info.Version()); | 244 dict->SetString("version", version_info.Version()); |
217 dict->SetString("cl", version_info.LastChange()); | 245 dict->SetString("cl", version_info.LastChange()); |
218 dict->SetString("version_mod", | 246 dict->SetString("version_mod", |
219 chrome::VersionInfo::GetVersionStringModifier()); | 247 chrome::VersionInfo::GetVersionStringModifier()); |
220 dict->SetString("official", | 248 dict->SetString("official", |
221 l10n_util::GetStringUTF16( | 249 l10n_util::GetStringUTF16( |
222 version_info.IsOfficialBuild() ? | 250 version_info.IsOfficialBuild() ? |
223 IDS_ABOUT_VERSION_OFFICIAL : | 251 IDS_ABOUT_VERSION_OFFICIAL : |
224 IDS_ABOUT_VERSION_UNOFFICIAL)); | 252 IDS_ABOUT_VERSION_UNOFFICIAL)); |
225 | 253 |
226 dict->SetString("command_line", | 254 dict->SetString("command_line", |
227 CommandLine::ForCurrentProcess()->GetCommandLineString()); | 255 CommandLine::ForCurrentProcess()->GetCommandLineString()); |
228 } | 256 } |
229 | 257 |
230 dict->SetString("blacklist_version", | 258 dict->SetString("blacklist_version", |
231 GpuDataManager::GetInstance()->GetBlacklistVersion()); | 259 GpuBlacklist::GetInstance()->GetVersion()); |
232 web_ui()->CallJavascriptFunction("tracingController.onClientInfoUpdate", | 260 web_ui()->CallJavascriptFunction("tracingController.onClientInfoUpdate", |
233 *dict); | 261 *dict); |
234 } | 262 } |
235 } | 263 } |
236 | 264 |
237 void TracingMessageHandler::OnBeginRequestBufferPercentFull( | 265 void TracingMessageHandler::OnBeginRequestBufferPercentFull( |
238 const ListValue* list) { | 266 const ListValue* list) { |
239 TraceController::GetInstance()->GetTraceBufferPercentFullAsync(this); | 267 TraceController::GetInstance()->GetTraceBufferPercentFullAsync(this); |
240 } | 268 } |
241 | 269 |
| 270 void TracingMessageHandler::OnGpuInfoUpdate() { |
| 271 // Get GPU Info. |
| 272 scoped_ptr<base::DictionaryValue> gpu_info_val( |
| 273 gpu_util::GpuInfoAsDictionaryValue()); |
| 274 |
| 275 // Add in blacklisting features |
| 276 Value* feature_status = gpu_util::GetFeatureStatus(); |
| 277 if (feature_status) |
| 278 gpu_info_val->Set("featureStatus", feature_status); |
| 279 |
| 280 // Send GPU Info to javascript. |
| 281 web_ui()->CallJavascriptFunction("tracingController.onGpuInfoUpdate", |
| 282 *(gpu_info_val.get())); |
| 283 } |
| 284 |
242 // A callback used for asynchronously reading a file to a string. Calls the | 285 // A callback used for asynchronously reading a file to a string. Calls the |
243 // TaskProxy callback when reading is complete. | 286 // TaskProxy callback when reading is complete. |
244 void ReadTraceFileCallback(TaskProxy* proxy, const FilePath& path) { | 287 void ReadTraceFileCallback(TaskProxy* proxy, const FilePath& path) { |
245 std::string file_contents; | 288 std::string file_contents; |
246 if (!file_util::ReadFileToString(path, &file_contents)) | 289 if (!file_util::ReadFileToString(path, &file_contents)) |
247 return; | 290 return; |
248 | 291 |
249 // We need to escape the file contents, because it will go into a javascript | 292 // We need to escape the file contents, because it will go into a javascript |
250 // quoted string in TracingMessageHandler::LoadTraceFileComplete. We need to | 293 // quoted string in TracingMessageHandler::LoadTraceFileComplete. We need to |
251 // escape control characters (to have well-formed javascript statements), as | 294 // escape control characters (to have well-formed javascript statements), as |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 // | 548 // |
506 //////////////////////////////////////////////////////////////////////////////// | 549 //////////////////////////////////////////////////////////////////////////////// |
507 | 550 |
508 TracingUI::TracingUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 551 TracingUI::TracingUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
509 web_ui->AddMessageHandler(new TracingMessageHandler()); | 552 web_ui->AddMessageHandler(new TracingMessageHandler()); |
510 | 553 |
511 // Set up the chrome://tracing/ source. | 554 // Set up the chrome://tracing/ source. |
512 Profile* profile = Profile::FromWebUI(web_ui); | 555 Profile* profile = Profile::FromWebUI(web_ui); |
513 ChromeURLDataManager::AddDataSource(profile, CreateTracingHTMLSource()); | 556 ChromeURLDataManager::AddDataSource(profile, CreateTracingHTMLSource()); |
514 } | 557 } |
OLD | NEW |