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> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 17 matching lines...) Expand all Loading... | |
28 #include "chrome/browser/platform_util.h" | 28 #include "chrome/browser/platform_util.h" |
29 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 30 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
31 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/common/chrome_version_info.h" | 32 #include "chrome/common/chrome_version_info.h" |
33 #include "chrome/common/jstemplate_builder.h" | 33 #include "chrome/common/jstemplate_builder.h" |
34 #include "chrome/common/net/url_request_context_getter.h" | 34 #include "chrome/common/net/url_request_context_getter.h" |
35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
36 #include "content/browser/browser_thread.h" | 36 #include "content/browser/browser_thread.h" |
37 #include "content/browser/gpu_process_host.h" | 37 #include "content/browser/gpu_process_host.h" |
38 #include "content/browser/renderer_host/render_view_host.h" | |
38 #include "content/browser/tab_contents/tab_contents.h" | 39 #include "content/browser/tab_contents/tab_contents.h" |
39 #include "grit/browser_resources.h" | 40 #include "grit/browser_resources.h" |
40 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
41 #include "net/base/escape.h" | 42 #include "net/base/escape.h" |
42 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
43 #include "ui/base/resource/resource_bundle.h" | 44 #include "ui/base/resource/resource_bundle.h" |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 class GpuHTMLSource : public ChromeURLDataManager::DataSource { | 48 class GpuHTMLSource : public ChromeURLDataManager::DataSource { |
(...skipping 20 matching lines...) Expand all Loading... | |
68 public base::SupportsWeakPtr<GpuMessageHandler> { | 69 public base::SupportsWeakPtr<GpuMessageHandler> { |
69 public: | 70 public: |
70 GpuMessageHandler(); | 71 GpuMessageHandler(); |
71 virtual ~GpuMessageHandler(); | 72 virtual ~GpuMessageHandler(); |
72 | 73 |
73 // WebUIMessageHandler implementation. | 74 // WebUIMessageHandler implementation. |
74 virtual WebUIMessageHandler* Attach(WebUI* web_ui); | 75 virtual WebUIMessageHandler* Attach(WebUI* web_ui); |
75 virtual void RegisterMessages(); | 76 virtual void RegisterMessages(); |
76 | 77 |
77 // Mesages | 78 // Mesages |
79 void OnBeginTracing(const ListValue* list); | |
80 void OnBeginToEndTracing(const ListValue* list); | |
Ken Russell (switch to Gerrit)
2011/03/14 23:57:35
The name "OnBeginToEndTracing" is a little hard to
nduca
2011/03/15 01:21:40
Done.
| |
78 void OnBrowserBridgeInitialized(const ListValue* list); | 81 void OnBrowserBridgeInitialized(const ListValue* list); |
79 void OnCallAsync(const ListValue* list); | 82 void OnCallAsync(const ListValue* list); |
80 | 83 |
81 // Submessages dispatched from OnCallAsync | 84 // Submessages dispatched from OnCallAsync |
82 Value* OnRequestClientInfo(const ListValue* list); | 85 Value* OnRequestClientInfo(const ListValue* list); |
83 Value* OnRequestLogMessages(const ListValue* list); | 86 Value* OnRequestLogMessages(const ListValue* list); |
84 | 87 |
88 // Callbacks. | |
89 void OnTraceDataCollected(const std::string& json_events); | |
85 void OnGpuInfoUpdate(); | 90 void OnGpuInfoUpdate(); |
86 | 91 |
87 // Executes the javascript function |function_name| in the renderer, passing | 92 // Executes the javascript function |function_name| in the renderer, passing |
88 // it the argument |value|. | 93 // it the argument |value|. |
89 void CallJavascriptFunction(const std::wstring& function_name, | 94 void CallJavascriptFunction(const std::wstring& function_name, |
90 const Value* value); | 95 const Value* value); |
91 | 96 |
92 private: | 97 private: |
93 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); | 98 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); |
94 | 99 |
95 // Cache the Singleton for efficiency. | 100 // Cache the Singleton for efficiency. |
96 GpuDataManager* gpu_data_manager_; | 101 GpuDataManager* gpu_data_manager_; |
97 | 102 |
103 void OnEndTracingComplete(); | |
104 | |
98 Callback0::Type* gpu_info_update_callback_; | 105 Callback0::Type* gpu_info_update_callback_; |
106 | |
107 bool traceEnabled_; | |
greggman
2011/03/15 00:19:50
trace_enabled_? (style guide)
| |
99 }; | 108 }; |
100 | 109 |
101 //////////////////////////////////////////////////////////////////////////////// | 110 //////////////////////////////////////////////////////////////////////////////// |
102 // | 111 // |
103 // GpuHTMLSource | 112 // GpuHTMLSource |
104 // | 113 // |
105 //////////////////////////////////////////////////////////////////////////////// | 114 //////////////////////////////////////////////////////////////////////////////// |
106 | 115 |
107 GpuHTMLSource::GpuHTMLSource() | 116 GpuHTMLSource::GpuHTMLSource() |
108 : DataSource(chrome::kChromeUIGpuInternalsHost, MessageLoop::current()) { | 117 : DataSource(chrome::kChromeUIGpuInternalsHost, MessageLoop::current()) { |
(...skipping 25 matching lines...) Expand all Loading... | |
134 std::string GpuHTMLSource::GetMimeType(const std::string&) const { | 143 std::string GpuHTMLSource::GetMimeType(const std::string&) const { |
135 return "text/html"; | 144 return "text/html"; |
136 } | 145 } |
137 | 146 |
138 //////////////////////////////////////////////////////////////////////////////// | 147 //////////////////////////////////////////////////////////////////////////////// |
139 // | 148 // |
140 // GpuMessageHandler | 149 // GpuMessageHandler |
141 // | 150 // |
142 //////////////////////////////////////////////////////////////////////////////// | 151 //////////////////////////////////////////////////////////////////////////////// |
143 | 152 |
144 GpuMessageHandler::GpuMessageHandler() : gpu_info_update_callback_(NULL) { | 153 GpuMessageHandler::GpuMessageHandler() |
154 : gpu_info_update_callback_(NULL) | |
155 , traceEnabled_(false) { | |
145 gpu_data_manager_ = GpuDataManager::GetInstance(); | 156 gpu_data_manager_ = GpuDataManager::GetInstance(); |
146 DCHECK(gpu_data_manager_); | 157 DCHECK(gpu_data_manager_); |
147 } | 158 } |
148 | 159 |
149 GpuMessageHandler::~GpuMessageHandler() { | 160 GpuMessageHandler::~GpuMessageHandler() { |
150 if (gpu_info_update_callback_) { | 161 if (gpu_info_update_callback_) { |
151 gpu_data_manager_->RemoveGpuInfoUpdateCallback(gpu_info_update_callback_); | 162 gpu_data_manager_->RemoveGpuInfoUpdateCallback(gpu_info_update_callback_); |
152 delete gpu_info_update_callback_; | 163 delete gpu_info_update_callback_; |
153 } | 164 } |
165 | |
166 if (traceEnabled_) | |
167 OnBeginToEndTracing(NULL); | |
154 } | 168 } |
155 | 169 |
156 WebUIMessageHandler* GpuMessageHandler::Attach(WebUI* web_ui) { | 170 WebUIMessageHandler* GpuMessageHandler::Attach(WebUI* web_ui) { |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
158 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); | 172 WebUIMessageHandler* result = WebUIMessageHandler::Attach(web_ui); |
159 return result; | 173 return result; |
160 } | 174 } |
161 | 175 |
162 /* BrowserBridge.callAsync prepends a requestID to these messages. */ | 176 /* BrowserBridge.callAsync prepends a requestID to these messages. */ |
163 void GpuMessageHandler::RegisterMessages() { | 177 void GpuMessageHandler::RegisterMessages() { |
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
165 | 179 |
166 web_ui_->RegisterMessageCallback( | 180 web_ui_->RegisterMessageCallback( |
181 "beginTracing", | |
182 NewCallback(this, &GpuMessageHandler::OnBeginTracing)); | |
183 web_ui_->RegisterMessageCallback( | |
184 "beginToEndTracing", | |
185 NewCallback(this, &GpuMessageHandler::OnBeginToEndTracing)); | |
186 web_ui_->RegisterMessageCallback( | |
167 "browserBridgeInitialized", | 187 "browserBridgeInitialized", |
168 NewCallback(this, &GpuMessageHandler::OnBrowserBridgeInitialized)); | 188 NewCallback(this, &GpuMessageHandler::OnBrowserBridgeInitialized)); |
169 web_ui_->RegisterMessageCallback( | 189 web_ui_->RegisterMessageCallback( |
170 "callAsync", | 190 "callAsync", |
171 NewCallback(this, &GpuMessageHandler::OnCallAsync)); | 191 NewCallback(this, &GpuMessageHandler::OnCallAsync)); |
172 } | 192 } |
173 | 193 |
174 void GpuMessageHandler::OnCallAsync(const ListValue* args) { | 194 void GpuMessageHandler::OnCallAsync(const ListValue* args) { |
175 DCHECK_GE(args->GetSize(), static_cast<size_t>(2)); | 195 DCHECK_GE(args->GetSize(), static_cast<size_t>(2)); |
176 // unpack args into requestId, submessage and submessageArgs | 196 // unpack args into requestId, submessage and submessageArgs |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 gpu_info_val->Set("blacklistingReasons", blacklisting_reasons); | 392 gpu_info_val->Set("blacklistingReasons", blacklisting_reasons); |
373 | 393 |
374 | 394 |
375 // Send GPU Info to javascript. | 395 // Send GPU Info to javascript. |
376 web_ui_->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", | 396 web_ui_->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", |
377 *gpu_info_val); | 397 *gpu_info_val); |
378 | 398 |
379 delete gpu_info_val; | 399 delete gpu_info_val; |
380 } | 400 } |
381 | 401 |
402 void GpuMessageHandler::OnBeginTracing(const ListValue* args) { | |
403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
404 | |
405 traceEnabled_ = true; | |
406 // TODO(jbates): TracingController::BeginTracing() | |
407 } | |
408 | |
409 void GpuMessageHandler::OnBeginToEndTracing(const ListValue* list) { | |
410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
411 DCHECK(traceEnabled_); | |
412 | |
413 // TODO(jbates): TracingController::BeginToEndTracing(new | |
414 // Callback(this, GpuMessageHandler::OnEndTracingComplete)) | |
415 } | |
416 | |
417 void GpuMessageHandler::OnEndTracingComplete() { | |
418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
419 traceEnabled_ = false; | |
420 web_ui_->CallJavascriptFunction("tracingController.onEndTracingComplete"); | |
421 } | |
422 | |
423 void GpuMessageHandler::OnTraceDataCollected(const std::string& json_events) { | |
424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
425 std::wstring javascript; | |
426 javascript += L"tracingController.onTraceDataCollected("; | |
427 javascript += UTF8ToWide(json_events); | |
428 javascript += L");"; | |
429 | |
430 web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), | |
431 WideToUTF16Hack(javascript)); | |
432 } | |
433 | |
382 } // namespace | 434 } // namespace |
383 | 435 |
384 | 436 |
385 //////////////////////////////////////////////////////////////////////////////// | 437 //////////////////////////////////////////////////////////////////////////////// |
386 // | 438 // |
387 // GpuInternalsUI | 439 // GpuInternalsUI |
388 // | 440 // |
389 //////////////////////////////////////////////////////////////////////////////// | 441 //////////////////////////////////////////////////////////////////////////////// |
390 | 442 |
391 GpuInternalsUI::GpuInternalsUI(TabContents* contents) : WebUI(contents) { | 443 GpuInternalsUI::GpuInternalsUI(TabContents* contents) : WebUI(contents) { |
392 AddMessageHandler((new GpuMessageHandler())->Attach(this)); | 444 AddMessageHandler((new GpuMessageHandler())->Attach(this)); |
393 | 445 |
394 GpuHTMLSource* html_source = new GpuHTMLSource(); | 446 GpuHTMLSource* html_source = new GpuHTMLSource(); |
395 | 447 |
396 // Set up the chrome://gpu/ source. | 448 // Set up the chrome://gpu/ source. |
397 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); | 449 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); |
398 } | 450 } |
399 | |
OLD | NEW |