| 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/gpu_internals_ui.h" | 5 #include "chrome/browser/ui/webui/gpu_internals_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" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 // Executes the javascript function |function_name| in the renderer, passing | 84 // Executes the javascript function |function_name| in the renderer, passing |
| 85 // it the argument |value|. | 85 // it the argument |value|. |
| 86 void CallJavascriptFunction(const std::wstring& function_name, | 86 void CallJavascriptFunction(const std::wstring& function_name, |
| 87 const Value* value); | 87 const Value* value); |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 scoped_refptr<CrashUploadList> crash_list_; | 90 scoped_refptr<CrashUploadList> crash_list_; |
| 91 bool crash_list_available_; | 91 bool crash_list_available_; |
| 92 | 92 |
| 93 // True if observing the GpuDataManager (re-attaching as observer would |
| 94 // DCHECK). |
| 95 bool observing_; |
| 96 |
| 93 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); | 97 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); |
| 94 }; | 98 }; |
| 95 | 99 |
| 96 //////////////////////////////////////////////////////////////////////////////// | 100 //////////////////////////////////////////////////////////////////////////////// |
| 97 // | 101 // |
| 98 // GpuMessageHandler | 102 // GpuMessageHandler |
| 99 // | 103 // |
| 100 //////////////////////////////////////////////////////////////////////////////// | 104 //////////////////////////////////////////////////////////////////////////////// |
| 101 | 105 |
| 102 GpuMessageHandler::GpuMessageHandler() | 106 GpuMessageHandler::GpuMessageHandler() |
| 103 : crash_list_available_(false) { | 107 : crash_list_available_(false), |
| 108 observing_(false) { |
| 104 crash_list_ = CrashUploadList::Create(this); | 109 crash_list_ = CrashUploadList::Create(this); |
| 105 } | 110 } |
| 106 | 111 |
| 107 GpuMessageHandler::~GpuMessageHandler() { | 112 GpuMessageHandler::~GpuMessageHandler() { |
| 108 GpuDataManager::GetInstance()->RemoveObserver(this); | 113 GpuDataManager::GetInstance()->RemoveObserver(this); |
| 109 crash_list_->ClearDelegate(); | 114 crash_list_->ClearDelegate(); |
| 110 } | 115 } |
| 111 | 116 |
| 112 /* BrowserBridge.callAsync prepends a requestID to these messages. */ | 117 /* BrowserBridge.callAsync prepends a requestID to these messages. */ |
| 113 void GpuMessageHandler::RegisterMessages() { | 118 void GpuMessageHandler::RegisterMessages() { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } else { | 174 } else { |
| 170 web_ui()->CallJavascriptFunction("browserBridge.onCallAsyncReply", | 175 web_ui()->CallJavascriptFunction("browserBridge.onCallAsyncReply", |
| 171 *requestId); | 176 *requestId); |
| 172 } | 177 } |
| 173 } | 178 } |
| 174 | 179 |
| 175 void GpuMessageHandler::OnBrowserBridgeInitialized(const ListValue* args) { | 180 void GpuMessageHandler::OnBrowserBridgeInitialized(const ListValue* args) { |
| 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 177 | 182 |
| 178 // Watch for changes in GPUInfo | 183 // Watch for changes in GPUInfo |
| 179 GpuDataManager::GetInstance()->AddObserver(this); | 184 if (!observing_) |
| 185 GpuDataManager::GetInstance()->AddObserver(this); |
| 186 observing_ = true; |
| 180 | 187 |
| 181 // Tell GpuDataManager it should have full GpuInfo. If the | 188 // Tell GpuDataManager it should have full GpuInfo. If the |
| 182 // Gpu process has not run yet, this will trigger its launch. | 189 // Gpu process has not run yet, this will trigger its launch. |
| 183 GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded(); | 190 GpuDataManager::GetInstance()->RequestCompleteGpuInfoIfNeeded(); |
| 184 | 191 |
| 185 // Run callback immediately in case the info is ready and no update in the | 192 // Run callback immediately in case the info is ready and no update in the |
| 186 // future. | 193 // future. |
| 187 OnGpuInfoUpdate(); | 194 OnGpuInfoUpdate(); |
| 188 } | 195 } |
| 189 | 196 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 //////////////////////////////////////////////////////////////////////////////// | 296 //////////////////////////////////////////////////////////////////////////////// |
| 290 | 297 |
| 291 GpuInternalsUI::GpuInternalsUI(content::WebUI* web_ui) | 298 GpuInternalsUI::GpuInternalsUI(content::WebUI* web_ui) |
| 292 : WebUIController(web_ui) { | 299 : WebUIController(web_ui) { |
| 293 web_ui->AddMessageHandler(new GpuMessageHandler()); | 300 web_ui->AddMessageHandler(new GpuMessageHandler()); |
| 294 | 301 |
| 295 // Set up the chrome://gpu-internals/ source. | 302 // Set up the chrome://gpu-internals/ source. |
| 296 Profile* profile = Profile::FromWebUI(web_ui); | 303 Profile* profile = Profile::FromWebUI(web_ui); |
| 297 ChromeURLDataManager::AddDataSource(profile, CreateGpuHTMLSource()); | 304 ChromeURLDataManager::AddDataSource(profile, CreateGpuHTMLSource()); |
| 298 } | 305 } |
| OLD | NEW |