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 <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/callback_old.h" | |
12 #include "base/command_line.h" | 11 #include "base/command_line.h" |
13 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
14 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
15 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
16 #include "base/values.h" | 15 #include "base/values.h" |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 17 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
19 #include "chrome/common/chrome_version_info.h" | 18 #include "chrome/common/chrome_version_info.h" |
20 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
21 #include "content/browser/browser_thread.h" | 20 #include "content/browser/browser_thread.h" |
(...skipping 15 matching lines...) Expand all Loading... |
37 source->add_resource_path("gpu_internals.js", IDR_GPU_INTERNALS_JS); | 36 source->add_resource_path("gpu_internals.js", IDR_GPU_INTERNALS_JS); |
38 source->set_default_resource(IDR_GPU_INTERNALS_HTML); | 37 source->set_default_resource(IDR_GPU_INTERNALS_HTML); |
39 return source; | 38 return source; |
40 } | 39 } |
41 | 40 |
42 // This class receives javascript messages from the renderer. | 41 // This class receives javascript messages from the renderer. |
43 // Note that the WebUI infrastructure runs on the UI thread, therefore all of | 42 // Note that the WebUI infrastructure runs on the UI thread, therefore all of |
44 // this class's methods are expected to run on the UI thread. | 43 // this class's methods are expected to run on the UI thread. |
45 class GpuMessageHandler | 44 class GpuMessageHandler |
46 : public WebUIMessageHandler, | 45 : public WebUIMessageHandler, |
47 public base::SupportsWeakPtr<GpuMessageHandler> { | 46 public base::SupportsWeakPtr<GpuMessageHandler>, |
| 47 public GpuDataManager::Observer { |
48 public: | 48 public: |
49 GpuMessageHandler(); | 49 GpuMessageHandler(); |
50 virtual ~GpuMessageHandler(); | 50 virtual ~GpuMessageHandler(); |
51 | 51 |
52 // WebUIMessageHandler implementation. | 52 // WebUIMessageHandler implementation. |
53 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; | 53 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; |
54 virtual void RegisterMessages() OVERRIDE; | 54 virtual void RegisterMessages() OVERRIDE; |
55 | 55 |
| 56 // GpuDataManager::Observer implementation. |
| 57 virtual void OnGpuInfoUpdate() OVERRIDE; |
| 58 |
56 // Messages | 59 // Messages |
57 void OnBrowserBridgeInitialized(const ListValue* list); | 60 void OnBrowserBridgeInitialized(const ListValue* list); |
58 void OnCallAsync(const ListValue* list); | 61 void OnCallAsync(const ListValue* list); |
59 | 62 |
60 // Submessages dispatched from OnCallAsync | 63 // Submessages dispatched from OnCallAsync |
61 Value* OnRequestClientInfo(const ListValue* list); | 64 Value* OnRequestClientInfo(const ListValue* list); |
62 Value* OnRequestLogMessages(const ListValue* list); | 65 Value* OnRequestLogMessages(const ListValue* list); |
63 | 66 |
64 // Callbacks. | |
65 void OnGpuInfoUpdate(); | |
66 | |
67 // Executes the javascript function |function_name| in the renderer, passing | 67 // Executes the javascript function |function_name| in the renderer, passing |
68 // it the argument |value|. | 68 // it the argument |value|. |
69 void CallJavascriptFunction(const std::wstring& function_name, | 69 void CallJavascriptFunction(const std::wstring& function_name, |
70 const Value* value); | 70 const Value* value); |
71 | 71 |
72 private: | 72 private: |
73 // Cache the Singleton for efficiency. | 73 // Cache the Singleton for efficiency. |
74 GpuDataManager* gpu_data_manager_; | 74 GpuDataManager* gpu_data_manager_; |
75 | 75 |
76 Callback0::Type* gpu_info_update_callback_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); | 76 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); |
79 }; | 77 }; |
80 | 78 |
81 //////////////////////////////////////////////////////////////////////////////// | 79 //////////////////////////////////////////////////////////////////////////////// |
82 // | 80 // |
83 // GpuMessageHandler | 81 // GpuMessageHandler |
84 // | 82 // |
85 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
86 | 84 |
87 GpuMessageHandler::GpuMessageHandler() | 85 GpuMessageHandler::GpuMessageHandler() { |
88 : gpu_info_update_callback_(NULL) { | |
89 gpu_data_manager_ = GpuDataManager::GetInstance(); | 86 gpu_data_manager_ = GpuDataManager::GetInstance(); |
90 DCHECK(gpu_data_manager_); | 87 DCHECK(gpu_data_manager_); |
91 } | 88 } |
92 | 89 |
93 GpuMessageHandler::~GpuMessageHandler() { | 90 GpuMessageHandler::~GpuMessageHandler() { |
94 if (gpu_info_update_callback_) { | 91 gpu_data_manager_->RemoveObserver(this); |
95 gpu_data_manager_->RemoveGpuInfoUpdateCallback(gpu_info_update_callback_); | |
96 delete gpu_info_update_callback_; | |
97 } | |
98 } | 92 } |
99 | 93 |
100 WebUIMessageHandler* GpuMessageHandler::Attach(WebUI* web_ui) { | 94 WebUIMessageHandler* GpuMessageHandler::Attach(WebUI* web_ui) { |
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
102 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); | 96 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); |
103 return result; | 97 return result; |
104 } | 98 } |
105 | 99 |
106 /* BrowserBridge.callAsync prepends a requestID to these messages. */ | 100 /* BrowserBridge.callAsync prepends a requestID to these messages. */ |
107 void GpuMessageHandler::RegisterMessages() { | 101 void GpuMessageHandler::RegisterMessages() { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 delete ret; | 152 delete ret; |
159 } else { | 153 } else { |
160 web_ui_->CallJavascriptFunction("browserBridge.onCallAsyncReply", | 154 web_ui_->CallJavascriptFunction("browserBridge.onCallAsyncReply", |
161 *requestId); | 155 *requestId); |
162 } | 156 } |
163 } | 157 } |
164 | 158 |
165 void GpuMessageHandler::OnBrowserBridgeInitialized(const ListValue* args) { | 159 void GpuMessageHandler::OnBrowserBridgeInitialized(const ListValue* args) { |
166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
167 | 161 |
168 DCHECK(!gpu_info_update_callback_); | |
169 | |
170 // Watch for changes in GPUInfo | 162 // Watch for changes in GPUInfo |
171 gpu_info_update_callback_ = | 163 gpu_data_manager_->AddObserver(this); |
172 NewCallback(this, &GpuMessageHandler::OnGpuInfoUpdate); | |
173 gpu_data_manager_->AddGpuInfoUpdateCallback(gpu_info_update_callback_); | |
174 | 164 |
175 // Tell GpuDataManager it should have full GpuInfo. If the | 165 // Tell GpuDataManager it should have full GpuInfo. If the |
176 // Gpu process has not run yet, this will trigger its launch. | 166 // Gpu process has not run yet, this will trigger its launch. |
177 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); | 167 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); |
178 | 168 |
179 // Run callback immediately in case the info is ready and no update in the | 169 // Run callback immediately in case the info is ready and no update in the |
180 // future. | 170 // future. |
181 OnGpuInfoUpdate(); | 171 OnGpuInfoUpdate(); |
182 } | 172 } |
183 | 173 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 // | 236 // |
247 //////////////////////////////////////////////////////////////////////////////// | 237 //////////////////////////////////////////////////////////////////////////////// |
248 | 238 |
249 GpuInternalsUI::GpuInternalsUI(TabContents* contents) : ChromeWebUI(contents) { | 239 GpuInternalsUI::GpuInternalsUI(TabContents* contents) : ChromeWebUI(contents) { |
250 AddMessageHandler((new GpuMessageHandler())->Attach(this)); | 240 AddMessageHandler((new GpuMessageHandler())->Attach(this)); |
251 | 241 |
252 // Set up the chrome://gpu-internals/ source. | 242 // Set up the chrome://gpu-internals/ source. |
253 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 243 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
254 profile->GetChromeURLDataManager()->AddDataSource(CreateGpuHTMLSource()); | 244 profile->GetChromeURLDataManager()->AddDataSource(CreateGpuHTMLSource()); |
255 } | 245 } |
OLD | NEW |