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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/i18n/time_formatting.h" |
12 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
13 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
14 #include "base/sys_info.h" | 15 #include "base/sys_info.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/crash_upload_list.h" |
16 #include "chrome/browser/gpu_blacklist.h" | 18 #include "chrome/browser/gpu_blacklist.h" |
17 #include "chrome/browser/gpu_util.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/webui/chrome_web_ui_data_source.h" | 21 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 22 #include "chrome/browser/ui/webui/crashes_ui.h" |
20 #include "chrome/common/chrome_version_info.h" | 23 #include "chrome/common/chrome_version_info.h" |
21 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
22 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/gpu_data_manager.h" | 26 #include "content/public/browser/gpu_data_manager.h" |
24 #include "content/public/browser/gpu_data_manager_observer.h" | 27 #include "content/public/browser/gpu_data_manager_observer.h" |
25 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
27 #include "content/public/browser/web_ui_message_handler.h" | 30 #include "content/public/browser/web_ui_message_handler.h" |
28 #include "grit/browser_resources.h" | 31 #include "grit/browser_resources.h" |
29 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
(...skipping 16 matching lines...) Expand all Loading... |
46 source->set_default_resource(IDR_GPU_INTERNALS_HTML); | 49 source->set_default_resource(IDR_GPU_INTERNALS_HTML); |
47 return source; | 50 return source; |
48 } | 51 } |
49 | 52 |
50 // This class receives javascript messages from the renderer. | 53 // This class receives javascript messages from the renderer. |
51 // Note that the WebUI infrastructure runs on the UI thread, therefore all of | 54 // Note that the WebUI infrastructure runs on the UI thread, therefore all of |
52 // this class's methods are expected to run on the UI thread. | 55 // this class's methods are expected to run on the UI thread. |
53 class GpuMessageHandler | 56 class GpuMessageHandler |
54 : public WebUIMessageHandler, | 57 : public WebUIMessageHandler, |
55 public base::SupportsWeakPtr<GpuMessageHandler>, | 58 public base::SupportsWeakPtr<GpuMessageHandler>, |
56 public content::GpuDataManagerObserver { | 59 public content::GpuDataManagerObserver, |
| 60 public CrashUploadList::Delegate { |
57 public: | 61 public: |
58 GpuMessageHandler(); | 62 GpuMessageHandler(); |
59 virtual ~GpuMessageHandler(); | 63 virtual ~GpuMessageHandler(); |
60 | 64 |
61 // WebUIMessageHandler implementation. | 65 // WebUIMessageHandler implementation. |
62 virtual void RegisterMessages() OVERRIDE; | 66 virtual void RegisterMessages() OVERRIDE; |
63 | 67 |
64 // GpuDataManagerObserver implementation. | 68 // GpuDataManagerObserver implementation. |
65 virtual void OnGpuInfoUpdate() OVERRIDE; | 69 virtual void OnGpuInfoUpdate() OVERRIDE; |
66 | 70 |
| 71 // CrashUploadList::Delegate implemenation. |
| 72 virtual void OnCrashListAvailable() OVERRIDE; |
| 73 |
67 // Messages | 74 // Messages |
68 void OnBrowserBridgeInitialized(const ListValue* list); | 75 void OnBrowserBridgeInitialized(const ListValue* list); |
69 void OnCallAsync(const ListValue* list); | 76 void OnCallAsync(const ListValue* list); |
70 | 77 |
71 // Submessages dispatched from OnCallAsync | 78 // Submessages dispatched from OnCallAsync |
72 Value* OnRequestClientInfo(const ListValue* list); | 79 Value* OnRequestClientInfo(const ListValue* list); |
73 Value* OnRequestLogMessages(const ListValue* list); | 80 Value* OnRequestLogMessages(const ListValue* list); |
| 81 Value* OnRequestCrashList(const ListValue* list); |
74 | 82 |
75 // Executes the javascript function |function_name| in the renderer, passing | 83 // Executes the javascript function |function_name| in the renderer, passing |
76 // it the argument |value|. | 84 // it the argument |value|. |
77 void CallJavascriptFunction(const std::wstring& function_name, | 85 void CallJavascriptFunction(const std::wstring& function_name, |
78 const Value* value); | 86 const Value* value); |
79 | 87 |
80 private: | 88 private: |
| 89 scoped_refptr<CrashUploadList> crash_list_; |
| 90 bool crash_list_available_; |
| 91 |
81 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); | 92 DISALLOW_COPY_AND_ASSIGN(GpuMessageHandler); |
82 }; | 93 }; |
83 | 94 |
84 //////////////////////////////////////////////////////////////////////////////// | 95 //////////////////////////////////////////////////////////////////////////////// |
85 // | 96 // |
86 // GpuMessageHandler | 97 // GpuMessageHandler |
87 // | 98 // |
88 //////////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////////// |
89 | 100 |
90 GpuMessageHandler::GpuMessageHandler() { | 101 GpuMessageHandler::GpuMessageHandler() |
| 102 : crash_list_available_(false) { |
| 103 crash_list_ = CrashUploadList::Create(this); |
91 } | 104 } |
92 | 105 |
93 GpuMessageHandler::~GpuMessageHandler() { | 106 GpuMessageHandler::~GpuMessageHandler() { |
94 GpuDataManager::GetInstance()->RemoveObserver(this); | 107 GpuDataManager::GetInstance()->RemoveObserver(this); |
| 108 crash_list_->ClearDelegate(); |
95 } | 109 } |
96 | 110 |
97 /* BrowserBridge.callAsync prepends a requestID to these messages. */ | 111 /* BrowserBridge.callAsync prepends a requestID to these messages. */ |
98 void GpuMessageHandler::RegisterMessages() { | 112 void GpuMessageHandler::RegisterMessages() { |
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
100 | 114 |
| 115 crash_list_->LoadCrashListAsynchronously(); |
| 116 |
101 web_ui()->RegisterMessageCallback("browserBridgeInitialized", | 117 web_ui()->RegisterMessageCallback("browserBridgeInitialized", |
102 base::Bind(&GpuMessageHandler::OnBrowserBridgeInitialized, | 118 base::Bind(&GpuMessageHandler::OnBrowserBridgeInitialized, |
103 base::Unretained(this))); | 119 base::Unretained(this))); |
104 web_ui()->RegisterMessageCallback("callAsync", | 120 web_ui()->RegisterMessageCallback("callAsync", |
105 base::Bind(&GpuMessageHandler::OnCallAsync, | 121 base::Bind(&GpuMessageHandler::OnCallAsync, |
106 base::Unretained(this))); | 122 base::Unretained(this))); |
107 } | 123 } |
108 | 124 |
109 void GpuMessageHandler::OnCallAsync(const ListValue* args) { | 125 void GpuMessageHandler::OnCallAsync(const ListValue* args) { |
110 DCHECK_GE(args->GetSize(), static_cast<size_t>(2)); | 126 DCHECK_GE(args->GetSize(), static_cast<size_t>(2)); |
(...skipping 16 matching lines...) Expand all Loading... |
127 Value* argCopy = arg->DeepCopy(); | 143 Value* argCopy = arg->DeepCopy(); |
128 submessageArgs->Append(argCopy); | 144 submessageArgs->Append(argCopy); |
129 } | 145 } |
130 | 146 |
131 // call the submessage handler | 147 // call the submessage handler |
132 Value* ret = NULL; | 148 Value* ret = NULL; |
133 if (submessage == "requestClientInfo") { | 149 if (submessage == "requestClientInfo") { |
134 ret = OnRequestClientInfo(submessageArgs); | 150 ret = OnRequestClientInfo(submessageArgs); |
135 } else if (submessage == "requestLogMessages") { | 151 } else if (submessage == "requestLogMessages") { |
136 ret = OnRequestLogMessages(submessageArgs); | 152 ret = OnRequestLogMessages(submessageArgs); |
| 153 } else if (submessage == "requestCrashList") { |
| 154 ret = OnRequestCrashList(submessageArgs); |
137 } else { // unrecognized submessage | 155 } else { // unrecognized submessage |
138 NOTREACHED(); | 156 NOTREACHED(); |
139 delete submessageArgs; | 157 delete submessageArgs; |
140 return; | 158 return; |
141 } | 159 } |
142 delete submessageArgs; | 160 delete submessageArgs; |
143 | 161 |
144 // call BrowserBridge.onCallAsyncReply with result | 162 // call BrowserBridge.onCallAsyncReply with result |
145 if (ret) { | 163 if (ret) { |
146 web_ui()->CallJavascriptFunction("browserBridge.onCallAsyncReply", | 164 web_ui()->CallJavascriptFunction("browserBridge.onCallAsyncReply", |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 225 |
208 return dict; | 226 return dict; |
209 } | 227 } |
210 | 228 |
211 Value* GpuMessageHandler::OnRequestLogMessages(const ListValue*) { | 229 Value* GpuMessageHandler::OnRequestLogMessages(const ListValue*) { |
212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
213 | 231 |
214 return GpuDataManager::GetInstance()->GetLogMessages().DeepCopy(); | 232 return GpuDataManager::GetInstance()->GetLogMessages().DeepCopy(); |
215 } | 233 } |
216 | 234 |
| 235 Value* GpuMessageHandler::OnRequestCrashList(const ListValue*) { |
| 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 237 |
| 238 if (!CrashesUI::CrashReportingEnabled()) { |
| 239 // We need to return an empty list instead of NULL. |
| 240 return new ListValue; |
| 241 } |
| 242 if (!crash_list_available_) { |
| 243 // If we are still obtaining crash list, then return null so another |
| 244 // request will be scheduled. |
| 245 return NULL; |
| 246 } |
| 247 |
| 248 ListValue* list_value = new ListValue; |
| 249 std::vector<CrashUploadList::CrashInfo> crashes; |
| 250 crash_list_->GetUploadedCrashes(50, &crashes); |
| 251 for (std::vector<CrashUploadList::CrashInfo>::iterator i = crashes.begin(); |
| 252 i != crashes.end(); ++i) { |
| 253 DictionaryValue* crash = new DictionaryValue(); |
| 254 crash->SetString("id", i->crash_id); |
| 255 crash->SetString("time", |
| 256 base::TimeFormatFriendlyDateAndTime(i->crash_time)); |
| 257 list_value->Append(crash); |
| 258 } |
| 259 return list_value; |
| 260 } |
| 261 |
217 void GpuMessageHandler::OnGpuInfoUpdate() { | 262 void GpuMessageHandler::OnGpuInfoUpdate() { |
218 // Get GPU Info. | 263 // Get GPU Info. |
219 scoped_ptr<base::DictionaryValue> gpu_info_val( | 264 scoped_ptr<base::DictionaryValue> gpu_info_val( |
220 gpu_util::GpuInfoAsDictionaryValue()); | 265 gpu_util::GpuInfoAsDictionaryValue()); |
221 | 266 |
222 // Add in blacklisting features | 267 // Add in blacklisting features |
223 Value* feature_status = gpu_util::GetFeatureStatus(); | 268 Value* feature_status = gpu_util::GetFeatureStatus(); |
224 if (feature_status) | 269 if (feature_status) |
225 gpu_info_val->Set("featureStatus", feature_status); | 270 gpu_info_val->Set("featureStatus", feature_status); |
226 | 271 |
227 // Send GPU Info to javascript. | 272 // Send GPU Info to javascript. |
228 web_ui()->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", | 273 web_ui()->CallJavascriptFunction("browserBridge.onGpuInfoUpdate", |
229 *(gpu_info_val.get())); | 274 *(gpu_info_val.get())); |
230 } | 275 } |
231 | 276 |
| 277 void GpuMessageHandler::OnCrashListAvailable() { |
| 278 crash_list_available_ = true; |
| 279 } |
| 280 |
232 } // namespace | 281 } // namespace |
233 | 282 |
234 | 283 |
235 //////////////////////////////////////////////////////////////////////////////// | 284 //////////////////////////////////////////////////////////////////////////////// |
236 // | 285 // |
237 // GpuInternalsUI | 286 // GpuInternalsUI |
238 // | 287 // |
239 //////////////////////////////////////////////////////////////////////////////// | 288 //////////////////////////////////////////////////////////////////////////////// |
240 | 289 |
241 GpuInternalsUI::GpuInternalsUI(content::WebUI* web_ui) | 290 GpuInternalsUI::GpuInternalsUI(content::WebUI* web_ui) |
242 : WebUIController(web_ui) { | 291 : WebUIController(web_ui) { |
243 web_ui->AddMessageHandler(new GpuMessageHandler()); | 292 web_ui->AddMessageHandler(new GpuMessageHandler()); |
244 | 293 |
245 // Set up the chrome://gpu-internals/ source. | 294 // Set up the chrome://gpu-internals/ source. |
246 Profile* profile = Profile::FromWebUI(web_ui); | 295 Profile* profile = Profile::FromWebUI(web_ui); |
247 profile->GetChromeURLDataManager()->AddDataSource(CreateGpuHTMLSource()); | 296 profile->GetChromeURLDataManager()->AddDataSource(CreateGpuHTMLSource()); |
248 } | 297 } |
OLD | NEW |