| 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/gpu_internals_ui.h" | 5 #include "chrome/browser/ui/webui/gpu_internals_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 #include <string> | |
| 9 #include <utility> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 13 #include "base/file_util.h" | 8 #include "base/string_number_conversions.h" |
| 14 #include "base/memory/singleton.h" | |
| 15 #include "base/message_loop.h" | |
| 16 #include "base/path_service.h" | |
| 17 #include "base/scoped_ptr.h" | |
| 18 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 19 #include "base/string_number_conversions.h" | |
| 20 #include "base/string_piece.h" | |
| 21 #include "base/utf_string_conversions.h" | |
| 22 #include "base/values.h" | 10 #include "base/values.h" |
| 23 #include "chrome/browser/browser_process.h" | |
| 24 #include "chrome/browser/io_thread.h" | |
| 25 #include "chrome/browser/net/chrome_net_log.h" | |
| 26 #include "chrome/browser/net/connection_tester.h" | |
| 27 #include "chrome/browser/net/passive_log_collector.h" | |
| 28 #include "chrome/browser/net/url_fixer_upper.h" | |
| 29 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/ui/shell_dialogs.h" | |
| 31 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
| 32 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 12 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 33 #include "chrome/common/chrome_paths.h" | |
| 34 #include "chrome/common/chrome_version_info.h" | 13 #include "chrome/common/chrome_version_info.h" |
| 35 #include "chrome/common/jstemplate_builder.h" | |
| 36 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 37 #include "content/browser/browser_thread.h" | 15 #include "content/browser/browser_thread.h" |
| 38 #include "content/browser/gpu/gpu_data_manager.h" | 16 #include "content/browser/gpu/gpu_data_manager.h" |
| 39 #include "content/browser/gpu/gpu_process_host.h" | |
| 40 #include "content/browser/renderer_host/render_view_host.h" | |
| 41 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
| 42 #include "content/browser/tab_contents/tab_contents_view.h" | 18 #include "content/browser/webui/web_ui.h" |
| 43 #include "content/browser/trace_controller.h" | |
| 44 #include "grit/browser_resources.h" | 19 #include "grit/browser_resources.h" |
| 45 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 46 #include "net/base/escape.h" | |
| 47 #include "net/url_request/url_request_context_getter.h" | |
| 48 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 49 #include "ui/base/resource/resource_bundle.h" | |
| 50 | 22 |
| 51 namespace { | 23 namespace { |
| 52 | 24 |
| 53 ChromeWebUIDataSource* CreateGpuHTMLSource() { | 25 ChromeWebUIDataSource* CreateGpuHTMLSource() { |
| 54 ChromeWebUIDataSource* source = | 26 ChromeWebUIDataSource* source = |
| 55 new ChromeWebUIDataSource(chrome::kChromeUIGpuInternalsHost); | 27 new ChromeWebUIDataSource(chrome::kChromeUIGpuInternalsHost); |
| 56 | 28 |
| 57 source->set_json_path("strings.js"); | 29 source->set_json_path("strings.js"); |
| 58 source->add_resource_path("gpu_internals.js", IDR_GPU_INTERNALS_JS); | 30 source->add_resource_path("gpu_internals.js", IDR_GPU_INTERNALS_JS); |
| 59 source->set_default_resource(IDR_GPU_INTERNALS_HTML); | 31 source->set_default_resource(IDR_GPU_INTERNALS_HTML); |
| 60 return source; | 32 return source; |
| 61 } | 33 } |
| 62 | 34 |
| 63 // This class receives javascript messages from the renderer. | 35 // This class receives javascript messages from the renderer. |
| 64 // Note that the WebUI infrastructure runs on the UI thread, therefore all of | 36 // Note that the WebUI infrastructure runs on the UI thread, therefore all of |
| 65 // this class's methods are expected to run on the UI thread. | 37 // this class's methods are expected to run on the UI thread. |
| 66 class GpuMessageHandler | 38 class GpuMessageHandler |
| 67 : public WebUIMessageHandler, | 39 : public WebUIMessageHandler, |
| 68 public SelectFileDialog::Listener, | 40 public base::SupportsWeakPtr<GpuMessageHandler> { |
| 69 public base::SupportsWeakPtr<GpuMessageHandler>, | |
| 70 public TraceSubscriber { | |
| 71 public: | 41 public: |
| 72 GpuMessageHandler(); | 42 GpuMessageHandler(); |
| 73 virtual ~GpuMessageHandler(); | 43 virtual ~GpuMessageHandler(); |
| 74 | 44 |
| 75 // WebUIMessageHandler implementation. | 45 // WebUIMessageHandler implementation. |
| 76 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; | 46 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; |
| 77 virtual void RegisterMessages() OVERRIDE; | 47 virtual void RegisterMessages() OVERRIDE; |
| 78 | 48 |
| 79 // Messages | 49 // Messages |
| 80 void OnBeginTracing(const ListValue* list); | |
| 81 void OnEndTracingAsync(const ListValue* list); | |
| 82 void OnBrowserBridgeInitialized(const ListValue* list); | 50 void OnBrowserBridgeInitialized(const ListValue* list); |
| 83 void OnCallAsync(const ListValue* list); | 51 void OnCallAsync(const ListValue* list); |
| 84 void OnBeginRequestBufferPercentFull(const ListValue* list); | |
| 85 void OnLoadTraceFile(const ListValue* list); | |
| 86 void OnSaveTraceFile(const ListValue* list); | |
| 87 | 52 |
| 88 // Submessages dispatched from OnCallAsync | 53 // Submessages dispatched from OnCallAsync |
| 89 Value* OnRequestClientInfo(const ListValue* list); | 54 Value* OnRequestClientInfo(const ListValue* list); |
| 90 Value* OnRequestLogMessages(const ListValue* list); | 55 Value* OnRequestLogMessages(const ListValue* list); |
| 91 | 56 |
| 92 // SelectFileDialog::Listener implementation | |
| 93 virtual void FileSelected(const FilePath& path, | |
| 94 int index, | |
| 95 void* params) OVERRIDE; | |
| 96 virtual void FileSelectionCanceled(void* params) OVERRIDE; | |
| 97 | |
| 98 // Callbacks. | 57 // Callbacks. |
| 99 void OnGpuInfoUpdate(); | 58 void OnGpuInfoUpdate(); |
| 100 void LoadTraceFileComplete(std::string* file_contents); | |
| 101 void SaveTraceFileComplete(); | |
| 102 | |
| 103 // TraceSubscriber implementation. | |
| 104 virtual void OnEndTracingComplete() OVERRIDE; | |
| 105 virtual void OnTraceDataCollected(const std::string& json_events) OVERRIDE; | |
| 106 virtual void OnTraceBufferPercentFullReply(float percent_full) OVERRIDE; | |
| 107 | 59 |
| 108 // Executes the javascript function |function_name| in the renderer, passing | 60 // Executes the javascript function |function_name| in the renderer, passing |
| 109 // it the argument |value|. | 61 // it the argument |value|. |
| 110 void CallJavascriptFunction(const std::wstring& function_name, | 62 void CallJavascriptFunction(const std::wstring& function_name, |
| 111 const Value* value); | 63 const Value* value); |
| 112 | 64 |
| 113 private: | 65 private: |
| 114 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); | 66 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); |
| 115 | 67 |
| 116 // Cache the Singleton for efficiency. | 68 // Cache the Singleton for efficiency. |
| 117 GpuDataManager* gpu_data_manager_; | 69 GpuDataManager* gpu_data_manager_; |
| 118 | 70 |
| 119 Callback0::Type* gpu_info_update_callback_; | 71 Callback0::Type* gpu_info_update_callback_; |
| 120 | |
| 121 scoped_refptr<SelectFileDialog> select_trace_file_dialog_; | |
| 122 SelectFileDialog::Type select_trace_file_dialog_type_; | |
| 123 scoped_ptr<std::string> trace_data_to_save_; | |
| 124 | |
| 125 bool trace_enabled_; | |
| 126 }; | |
| 127 | |
| 128 class TaskProxy : public base::RefCountedThreadSafe<TaskProxy> { | |
| 129 public: | |
| 130 explicit TaskProxy(const base::WeakPtr<GpuMessageHandler>& handler) | |
| 131 : handler_(handler) {} | |
| 132 void LoadTraceFileCompleteProxy(std::string* file_contents) { | |
| 133 if (handler_) | |
| 134 handler_->LoadTraceFileComplete(file_contents); | |
| 135 delete file_contents; | |
| 136 } | |
| 137 | |
| 138 void SaveTraceFileCompleteProxy() { | |
| 139 if (handler_) | |
| 140 handler_->SaveTraceFileComplete(); | |
| 141 } | |
| 142 | |
| 143 private: | |
| 144 base::WeakPtr<GpuMessageHandler> handler_; | |
| 145 friend class base::RefCountedThreadSafe<TaskProxy>; | |
| 146 DISALLOW_COPY_AND_ASSIGN(TaskProxy); | |
| 147 }; | 72 }; |
| 148 | 73 |
| 149 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
| 150 // | 75 // |
| 151 // GpuMessageHandler | 76 // GpuMessageHandler |
| 152 // | 77 // |
| 153 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// |
| 154 | 79 |
| 155 GpuMessageHandler::GpuMessageHandler() | 80 GpuMessageHandler::GpuMessageHandler() |
| 156 : gpu_info_update_callback_(NULL), | 81 : gpu_info_update_callback_(NULL) { |
| 157 select_trace_file_dialog_type_(SelectFileDialog::SELECT_NONE), | |
| 158 trace_enabled_(false) { | |
| 159 gpu_data_manager_ = GpuDataManager::GetInstance(); | 82 gpu_data_manager_ = GpuDataManager::GetInstance(); |
| 160 DCHECK(gpu_data_manager_); | 83 DCHECK(gpu_data_manager_); |
| 161 } | 84 } |
| 162 | 85 |
| 163 GpuMessageHandler::~GpuMessageHandler() { | 86 GpuMessageHandler::~GpuMessageHandler() { |
| 164 if (gpu_info_update_callback_) { | 87 if (gpu_info_update_callback_) { |
| 165 gpu_data_manager_->RemoveGpuInfoUpdateCallback(gpu_info_update_callback_); | 88 gpu_data_manager_->RemoveGpuInfoUpdateCallback(gpu_info_update_callback_); |
| 166 delete gpu_info_update_callback_; | 89 delete gpu_info_update_callback_; |
| 167 } | 90 } |
| 168 | |
| 169 if (select_trace_file_dialog_) | |
| 170 select_trace_file_dialog_->ListenerDestroyed(); | |
| 171 | |
| 172 // If we are the current subscriber, this will result in ending tracing. | |
| 173 TraceController::GetInstance()->CancelSubscriber(this); | |
| 174 } | 91 } |
| 175 | 92 |
| 176 WebUIMessageHandler* GpuMessageHandler::Attach(WebUI* web_ui) { | 93 WebUIMessageHandler* GpuMessageHandler::Attach(WebUI* web_ui) { |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 178 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); | 95 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); |
| 179 return result; | 96 return result; |
| 180 } | 97 } |
| 181 | 98 |
| 182 /* BrowserBridge.callAsync prepends a requestID to these messages. */ | 99 /* BrowserBridge.callAsync prepends a requestID to these messages. */ |
| 183 void GpuMessageHandler::RegisterMessages() { | 100 void GpuMessageHandler::RegisterMessages() { |
| 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 185 | 102 |
| 186 web_ui_->RegisterMessageCallback( | 103 web_ui_->RegisterMessageCallback( |
| 187 "beginTracing", | |
| 188 NewCallback(this, &GpuMessageHandler::OnBeginTracing)); | |
| 189 web_ui_->RegisterMessageCallback( | |
| 190 "endTracingAsync", | |
| 191 NewCallback(this, &GpuMessageHandler::OnEndTracingAsync)); | |
| 192 web_ui_->RegisterMessageCallback( | |
| 193 "browserBridgeInitialized", | 104 "browserBridgeInitialized", |
| 194 NewCallback(this, &GpuMessageHandler::OnBrowserBridgeInitialized)); | 105 NewCallback(this, &GpuMessageHandler::OnBrowserBridgeInitialized)); |
| 195 web_ui_->RegisterMessageCallback( | 106 web_ui_->RegisterMessageCallback( |
| 196 "callAsync", | 107 "callAsync", |
| 197 NewCallback(this, &GpuMessageHandler::OnCallAsync)); | 108 NewCallback(this, &GpuMessageHandler::OnCallAsync)); |
| 198 web_ui_->RegisterMessageCallback( | |
| 199 "beginRequestBufferPercentFull", | |
| 200 NewCallback(this, &GpuMessageHandler::OnBeginRequestBufferPercentFull)); | |
| 201 web_ui_->RegisterMessageCallback( | |
| 202 "loadTraceFile", | |
| 203 NewCallback(this, &GpuMessageHandler::OnLoadTraceFile)); | |
| 204 web_ui_->RegisterMessageCallback( | |
| 205 "saveTraceFile", | |
| 206 NewCallback(this, &GpuMessageHandler::OnSaveTraceFile)); | |
| 207 } | 109 } |
| 208 | 110 |
| 209 void GpuMessageHandler::OnCallAsync(const ListValue* args) { | 111 void GpuMessageHandler::OnCallAsync(const ListValue* args) { |
| 210 DCHECK_GE(args->GetSize(), static_cast<size_t>(2)); | 112 DCHECK_GE(args->GetSize(), static_cast<size_t>(2)); |
| 211 // unpack args into requestId, submessage and submessageArgs | 113 // unpack args into requestId, submessage and submessageArgs |
| 212 bool ok; | 114 bool ok; |
| 213 Value* requestId; | 115 Value* requestId; |
| 214 ok = args->Get(0, &requestId); | 116 ok = args->Get(0, &requestId); |
| 215 DCHECK(ok); | 117 DCHECK(ok); |
| 216 | 118 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 246 web_ui_->CallJavascriptFunction("browserBridge.onCallAsyncReply", | 148 web_ui_->CallJavascriptFunction("browserBridge.onCallAsyncReply", |
| 247 *requestId, | 149 *requestId, |
| 248 *ret); | 150 *ret); |
| 249 delete ret; | 151 delete ret; |
| 250 } else { | 152 } else { |
| 251 web_ui_->CallJavascriptFunction("browserBridge.onCallAsyncReply", | 153 web_ui_->CallJavascriptFunction("browserBridge.onCallAsyncReply", |
| 252 *requestId); | 154 *requestId); |
| 253 } | 155 } |
| 254 } | 156 } |
| 255 | 157 |
| 256 void GpuMessageHandler::OnBeginRequestBufferPercentFull(const ListValue* list) { | |
| 257 TraceController::GetInstance()->GetTraceBufferPercentFullAsync(this); | |
| 258 } | |
| 259 | |
| 260 class ReadTraceFileTask : public Task { | |
| 261 public: | |
| 262 ReadTraceFileTask(TaskProxy* proxy, const FilePath& path) | |
| 263 : proxy_(proxy) | |
| 264 , path_(path) {} | |
| 265 | |
| 266 virtual void Run() { | |
| 267 std::string* file_contents = new std::string(); | |
| 268 if (!file_util::ReadFileToString(path_, file_contents)) { | |
| 269 delete file_contents; | |
| 270 return; | |
| 271 } | |
| 272 BrowserThread::PostTask( | |
| 273 BrowserThread::UI, FROM_HERE, | |
| 274 NewRunnableMethod(proxy_.get(), | |
| 275 &TaskProxy::LoadTraceFileCompleteProxy, | |
| 276 file_contents)); | |
| 277 } | |
| 278 | |
| 279 private: | |
| 280 scoped_refptr<TaskProxy> proxy_; | |
| 281 | |
| 282 // Path of the file to open. | |
| 283 const FilePath path_; | |
| 284 }; | |
| 285 | |
| 286 class WriteTraceFileTask : public Task { | |
| 287 public: | |
| 288 WriteTraceFileTask(TaskProxy* proxy, | |
| 289 const FilePath& path, | |
| 290 std::string* contents) | |
| 291 : proxy_(proxy) | |
| 292 , path_(path) | |
| 293 , contents_(contents) {} | |
| 294 | |
| 295 virtual void Run() { | |
| 296 if (!file_util::WriteFile(path_, contents_->c_str(), contents_->size())) | |
| 297 return; | |
| 298 BrowserThread::PostTask( | |
| 299 BrowserThread::UI, FROM_HERE, | |
| 300 NewRunnableMethod(proxy_.get(), | |
| 301 &TaskProxy::SaveTraceFileCompleteProxy)); | |
| 302 } | |
| 303 | |
| 304 private: | |
| 305 scoped_refptr<TaskProxy> proxy_; | |
| 306 | |
| 307 // Path of the file to save. | |
| 308 const FilePath path_; | |
| 309 | |
| 310 // What to save | |
| 311 scoped_ptr<std::string> contents_; | |
| 312 }; | |
| 313 | |
| 314 void GpuMessageHandler::FileSelected( | |
| 315 const FilePath& path, int index, void* params) { | |
| 316 if (select_trace_file_dialog_type_ == SelectFileDialog::SELECT_OPEN_FILE) | |
| 317 BrowserThread::PostTask( | |
| 318 BrowserThread::FILE, FROM_HERE, | |
| 319 new ReadTraceFileTask(new TaskProxy(AsWeakPtr()), path)); | |
| 320 else | |
| 321 BrowserThread::PostTask( | |
| 322 BrowserThread::FILE, FROM_HERE, | |
| 323 new WriteTraceFileTask(new TaskProxy(AsWeakPtr()), path, | |
| 324 trace_data_to_save_.release())); | |
| 325 select_trace_file_dialog_.release(); | |
| 326 } | |
| 327 | |
| 328 void GpuMessageHandler::FileSelectionCanceled(void* params) { | |
| 329 select_trace_file_dialog_.release(); | |
| 330 if (select_trace_file_dialog_type_ == SelectFileDialog::SELECT_OPEN_FILE) | |
| 331 web_ui_->CallJavascriptFunction("tracingController.onLoadTraceFileCanceled")
; | |
| 332 else | |
| 333 web_ui_->CallJavascriptFunction("tracingController.onSaveTraceFileCanceled")
; | |
| 334 } | |
| 335 | |
| 336 void GpuMessageHandler::OnLoadTraceFile(const ListValue* list) { | |
| 337 // Only allow a single dialog at a time. | |
| 338 if (select_trace_file_dialog_.get()) | |
| 339 return; | |
| 340 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_OPEN_FILE; | |
| 341 select_trace_file_dialog_ = SelectFileDialog::Create(this); | |
| 342 select_trace_file_dialog_->SelectFile( | |
| 343 SelectFileDialog::SELECT_OPEN_FILE, | |
| 344 string16(), | |
| 345 FilePath(), | |
| 346 NULL, 0, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), | |
| 347 web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); | |
| 348 } | |
| 349 | |
| 350 void GpuMessageHandler::LoadTraceFileComplete(std::string* file_contents) { | |
| 351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 352 std::wstring javascript; | |
| 353 javascript += L"tracingController.onLoadTraceFileComplete("; | |
| 354 javascript += UTF8ToWide(*file_contents); | |
| 355 javascript += L");"; | |
| 356 | |
| 357 web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), | |
| 358 WideToUTF16Hack(javascript)); | |
| 359 } | |
| 360 | |
| 361 void GpuMessageHandler::OnSaveTraceFile(const ListValue* list) { | |
| 362 // Only allow a single dialog at a time. | |
| 363 if (select_trace_file_dialog_.get()) | |
| 364 return; | |
| 365 | |
| 366 DCHECK(list->GetSize() == 1); | |
| 367 | |
| 368 std::string* trace_data = new std::string(); | |
| 369 bool ok = list->GetString(0, trace_data); | |
| 370 DCHECK(ok); | |
| 371 trace_data_to_save_.reset(trace_data); | |
| 372 | |
| 373 select_trace_file_dialog_type_ = SelectFileDialog::SELECT_SAVEAS_FILE; | |
| 374 select_trace_file_dialog_ = SelectFileDialog::Create(this); | |
| 375 select_trace_file_dialog_->SelectFile( | |
| 376 SelectFileDialog::SELECT_SAVEAS_FILE, | |
| 377 string16(), | |
| 378 FilePath(), | |
| 379 NULL, 0, FILE_PATH_LITERAL(""), web_ui_->tab_contents(), | |
| 380 web_ui_->tab_contents()->view()->GetTopLevelNativeWindow(), NULL); | |
| 381 } | |
| 382 | |
| 383 void GpuMessageHandler::SaveTraceFileComplete() { | |
| 384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 385 std::wstring javascript; | |
| 386 web_ui_->CallJavascriptFunction("tracingController.onSaveTraceFileComplete"); | |
| 387 } | |
| 388 | |
| 389 void GpuMessageHandler::OnBrowserBridgeInitialized(const ListValue* args) { | 158 void GpuMessageHandler::OnBrowserBridgeInitialized(const ListValue* args) { |
| 390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 391 | 160 |
| 392 DCHECK(!gpu_info_update_callback_); | 161 DCHECK(!gpu_info_update_callback_); |
| 393 | 162 |
| 394 // Watch for changes in GPUInfo | 163 // Watch for changes in GPUInfo |
| 395 gpu_info_update_callback_ = | 164 gpu_info_update_callback_ = |
| 396 NewCallback(this, &GpuMessageHandler::OnGpuInfoUpdate); | 165 NewCallback(this, &GpuMessageHandler::OnGpuInfoUpdate); |
| 397 gpu_data_manager_->AddGpuInfoUpdateCallback(gpu_info_update_callback_); | 166 gpu_data_manager_->AddGpuInfoUpdateCallback(gpu_info_update_callback_); |
| 398 | 167 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 429 dict->SetString("command_line", | 198 dict->SetString("command_line", |
| 430 CommandLine::ForCurrentProcess()->GetCommandLineString()); | 199 CommandLine::ForCurrentProcess()->GetCommandLineString()); |
| 431 } | 200 } |
| 432 | 201 |
| 433 dict->SetString("blacklist_version", | 202 dict->SetString("blacklist_version", |
| 434 GpuDataManager::GetInstance()->GetBlacklistVersion()); | 203 GpuDataManager::GetInstance()->GetBlacklistVersion()); |
| 435 | 204 |
| 436 return dict; | 205 return dict; |
| 437 } | 206 } |
| 438 | 207 |
| 439 DictionaryValue* NewDescriptionValuePair(const std::string& desc, | |
| 440 const std::string& value) { | |
| 441 DictionaryValue* dict = new DictionaryValue(); | |
| 442 dict->SetString("description", desc); | |
| 443 dict->SetString("value", value); | |
| 444 return dict; | |
| 445 } | |
| 446 | |
| 447 DictionaryValue* NewDescriptionValuePair(const std::string& desc, | |
| 448 Value* value) { | |
| 449 DictionaryValue* dict = new DictionaryValue(); | |
| 450 dict->SetString("description", desc); | |
| 451 dict->Set("value", value); | |
| 452 return dict; | |
| 453 } | |
| 454 | |
| 455 #if defined(OS_WIN) | |
| 456 // Output DxDiagNode tree as nested array of {description,value} pairs | |
| 457 ListValue* DxDiagNodeToList(const DxDiagNode& node) { | |
| 458 ListValue* list = new ListValue(); | |
| 459 for (std::map<std::string, std::string>::const_iterator it = | |
| 460 node.values.begin(); | |
| 461 it != node.values.end(); | |
| 462 ++it) { | |
| 463 list->Append(NewDescriptionValuePair(it->first, it->second)); | |
| 464 } | |
| 465 | |
| 466 for (std::map<std::string, DxDiagNode>::const_iterator it = | |
| 467 node.children.begin(); | |
| 468 it != node.children.end(); | |
| 469 ++it) { | |
| 470 ListValue* sublist = DxDiagNodeToList(it->second); | |
| 471 list->Append(NewDescriptionValuePair(it->first, sublist)); | |
| 472 } | |
| 473 return list; | |
| 474 } | |
| 475 | |
| 476 #endif // OS_WIN | |
| 477 | |
| 478 DictionaryValue* GpuInfoToDict(const GPUInfo& gpu_info) { | |
| 479 ListValue* basic_info = new ListValue(); | |
| 480 basic_info->Append(NewDescriptionValuePair("Initialization time", | |
| 481 base::Int64ToString(gpu_info.initialization_time.InMilliseconds()))); | |
| 482 basic_info->Append(NewDescriptionValuePair("Vendor Id", | |
| 483 base::StringPrintf("0x%04x", gpu_info.vendor_id))); | |
| 484 basic_info->Append(NewDescriptionValuePair("Device Id", | |
| 485 base::StringPrintf("0x%04x", gpu_info.device_id))); | |
| 486 basic_info->Append(NewDescriptionValuePair("Driver vendor", | |
| 487 gpu_info.driver_vendor)); | |
| 488 basic_info->Append(NewDescriptionValuePair("Driver version", | |
| 489 gpu_info.driver_version)); | |
| 490 basic_info->Append(NewDescriptionValuePair("Driver date", | |
| 491 gpu_info.driver_date)); | |
| 492 basic_info->Append(NewDescriptionValuePair("Pixel shader version", | |
| 493 gpu_info.pixel_shader_version)); | |
| 494 basic_info->Append(NewDescriptionValuePair("Vertex shader version", | |
| 495 gpu_info.vertex_shader_version)); | |
| 496 basic_info->Append(NewDescriptionValuePair("GL version", | |
| 497 gpu_info.gl_version)); | |
| 498 basic_info->Append(NewDescriptionValuePair("GL_VENDOR", | |
| 499 gpu_info.gl_vendor)); | |
| 500 basic_info->Append(NewDescriptionValuePair("GL_RENDERER", | |
| 501 gpu_info.gl_renderer)); | |
| 502 basic_info->Append(NewDescriptionValuePair("GL_VERSION", | |
| 503 gpu_info.gl_version_string)); | |
| 504 basic_info->Append(NewDescriptionValuePair("GL_EXTENSIONS", | |
| 505 gpu_info.gl_extensions)); | |
| 506 | |
| 507 DictionaryValue* info = new DictionaryValue(); | |
| 508 info->Set("basic_info", basic_info); | |
| 509 | |
| 510 #if defined(OS_WIN) | |
| 511 Value* dx_info; | |
| 512 if (gpu_info.dx_diagnostics.children.size()) | |
| 513 dx_info = DxDiagNodeToList(gpu_info.dx_diagnostics); | |
| 514 else | |
| 515 dx_info = Value::CreateNullValue(); | |
| 516 info->Set("diagnostics", dx_info); | |
| 517 #endif | |
| 518 | |
| 519 return info; | |
| 520 } | |
| 521 | |
| 522 Value* GpuMessageHandler::OnRequestLogMessages(const ListValue*) { | 208 Value* GpuMessageHandler::OnRequestLogMessages(const ListValue*) { |
| 523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 524 | 210 |
| 525 return gpu_data_manager_->log_messages().DeepCopy(); | 211 return gpu_data_manager_->log_messages().DeepCopy(); |
| 526 } | 212 } |
| 527 | 213 |
| 528 void GpuMessageHandler::OnGpuInfoUpdate() { | 214 void GpuMessageHandler::OnGpuInfoUpdate() { |
| 529 const GPUInfo& gpu_info = gpu_data_manager_->gpu_info(); | |
| 530 | |
| 531 // Get GPU Info. | 215 // Get GPU Info. |
| 532 DictionaryValue* gpu_info_val = GpuInfoToDict(gpu_info); | 216 scoped_ptr<base::DictionaryValue> gpu_info_val( |
| 217 gpu_data_manager_->GpuInfoAsDictionaryValue()); |
| 533 | 218 |
| 534 // Add in blacklisting features | 219 // Add in blacklisting features |
| 535 Value* feature_status = gpu_data_manager_->GetFeatureStatus(); | 220 Value* feature_status = gpu_data_manager_->GetFeatureStatus(); |
| 536 if (feature_status) | 221 if (feature_status) |
| 537 gpu_info_val->Set("featureStatus", feature_status); | 222 gpu_info_val->Set("featureStatus", feature_status); |
| 538 | 223 |
| 539 // Send GPU Info to javascript. | 224 // Send GPU Info to javascript. |
| 540 web_ui_->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", | 225 web_ui_->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", |
| 541 *gpu_info_val); | 226 *(gpu_info_val.get())); |
| 542 | |
| 543 delete gpu_info_val; | |
| 544 } | |
| 545 | |
| 546 void GpuMessageHandler::OnBeginTracing(const ListValue* args) { | |
| 547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 548 trace_enabled_ = true; | |
| 549 // TODO(jbates) This may fail, but that's OK for current use cases. | |
| 550 // Ex: Multiple about:gpu traces can not trace simultaneously. | |
| 551 // TODO(nduca) send feedback to javascript about whether or not BeginTracing | |
| 552 // was successful. | |
| 553 TraceController::GetInstance()->BeginTracing(this); | |
| 554 } | |
| 555 | |
| 556 void GpuMessageHandler::OnEndTracingAsync(const ListValue* list) { | |
| 557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 558 | |
| 559 // TODO(nduca): fix javascript code to make sure trace_enabled_ is always true | |
| 560 // here. triggered a false condition by just clicking stop | |
| 561 // trace a few times when it was going slow, and maybe switching | |
| 562 // between tabs. | |
| 563 if (trace_enabled_ && | |
| 564 !TraceController::GetInstance()->EndTracingAsync(this)) { | |
| 565 // Set to false now, since it turns out we never were the trace subscriber. | |
| 566 OnEndTracingComplete(); | |
| 567 } | |
| 568 } | |
| 569 | |
| 570 void GpuMessageHandler::OnEndTracingComplete() { | |
| 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 572 trace_enabled_ = false; | |
| 573 web_ui_->CallJavascriptFunction("tracingController.onEndTracingComplete"); | |
| 574 } | |
| 575 | |
| 576 void GpuMessageHandler::OnTraceDataCollected(const std::string& json_events) { | |
| 577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 578 std::wstring javascript; | |
| 579 javascript += L"tracingController.onTraceDataCollected("; | |
| 580 javascript += UTF8ToWide(json_events); | |
| 581 javascript += L");"; | |
| 582 | |
| 583 web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), | |
| 584 WideToUTF16Hack(javascript)); | |
| 585 } | |
| 586 | |
| 587 void GpuMessageHandler::OnTraceBufferPercentFullReply(float percent_full) { | |
| 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 589 web_ui_->CallJavascriptFunction( | |
| 590 "tracingController.onRequestBufferPercentFullComplete", | |
| 591 *scoped_ptr<Value>(Value::CreateDoubleValue(percent_full))); | |
| 592 } | 227 } |
| 593 | 228 |
| 594 } // namespace | 229 } // namespace |
| 595 | 230 |
| 596 | 231 |
| 597 //////////////////////////////////////////////////////////////////////////////// | 232 //////////////////////////////////////////////////////////////////////////////// |
| 598 // | 233 // |
| 599 // GpuInternalsUI | 234 // GpuInternalsUI |
| 600 // | 235 // |
| 601 //////////////////////////////////////////////////////////////////////////////// | 236 //////////////////////////////////////////////////////////////////////////////// |
| 602 | 237 |
| 603 GpuInternalsUI::GpuInternalsUI(TabContents* contents) : ChromeWebUI(contents) { | 238 GpuInternalsUI::GpuInternalsUI(TabContents* contents) : ChromeWebUI(contents) { |
| 604 AddMessageHandler((new GpuMessageHandler())->Attach(this)); | 239 AddMessageHandler((new GpuMessageHandler())->Attach(this)); |
| 605 | 240 |
| 606 // Set up the chrome://gpu-internals/ source. | 241 // Set up the chrome://gpu-internals/ source. |
| 607 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 242 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
| 608 profile->GetChromeURLDataManager()->AddDataSource(CreateGpuHTMLSource()); | 243 profile->GetChromeURLDataManager()->AddDataSource(CreateGpuHTMLSource()); |
| 609 } | 244 } |
| OLD | NEW |