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/crashes_ui.h" | 5 #include "chrome/browser/ui/webui/crashes_ui.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 void HandleRequestCrashes(const base::ListValue* args); | 85 void HandleRequestCrashes(const base::ListValue* args); |
86 | 86 |
87 #if defined(OS_CHROMEOS) | 87 #if defined(OS_CHROMEOS) |
88 // Asynchronously triggers crash uploading. Called from JS. | 88 // Asynchronously triggers crash uploading. Called from JS. |
89 void HandleRequestUploads(const base::ListValue* args); | 89 void HandleRequestUploads(const base::ListValue* args); |
90 #endif | 90 #endif |
91 | 91 |
92 // Sends the recent crashes list JS. | 92 // Sends the recent crashes list JS. |
93 void UpdateUI(); | 93 void UpdateUI(); |
94 | 94 |
| 95 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 96 // Asynchronously requests a user triggered upload. Called from JS. |
| 97 void HandleRequestSingleCrashUpload(const base::ListValue* args); |
| 98 #endif |
| 99 |
95 scoped_refptr<CrashUploadList> upload_list_; | 100 scoped_refptr<CrashUploadList> upload_list_; |
96 bool list_available_; | 101 bool list_available_; |
97 bool first_load_; | 102 bool first_load_; |
98 | 103 |
99 DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler); | 104 DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler); |
100 }; | 105 }; |
101 | 106 |
102 CrashesDOMHandler::CrashesDOMHandler() | 107 CrashesDOMHandler::CrashesDOMHandler() |
103 : list_available_(false), first_load_(true) { | 108 : list_available_(false), first_load_(true) { |
104 upload_list_ = CreateCrashUploadList(this); | 109 upload_list_ = CreateCrashUploadList(this); |
105 } | 110 } |
106 | 111 |
107 CrashesDOMHandler::~CrashesDOMHandler() { | 112 CrashesDOMHandler::~CrashesDOMHandler() { |
108 upload_list_->ClearDelegate(); | 113 upload_list_->ClearDelegate(); |
109 } | 114 } |
110 | 115 |
111 void CrashesDOMHandler::RegisterMessages() { | 116 void CrashesDOMHandler::RegisterMessages() { |
112 upload_list_->LoadUploadListAsynchronously(); | 117 upload_list_->LoadUploadListAsynchronously(); |
113 web_ui()->RegisterMessageCallback( | 118 web_ui()->RegisterMessageCallback( |
114 crash::kCrashesUIRequestCrashList, | 119 crash::kCrashesUIRequestCrashList, |
115 base::Bind(&CrashesDOMHandler::HandleRequestCrashes, | 120 base::Bind(&CrashesDOMHandler::HandleRequestCrashes, |
116 base::Unretained(this))); | 121 base::Unretained(this))); |
117 | 122 |
118 #if defined(OS_CHROMEOS) | 123 #if defined(OS_CHROMEOS) |
119 web_ui()->RegisterMessageCallback( | 124 web_ui()->RegisterMessageCallback( |
120 crash::kCrashesUIRequestCrashUpload, | 125 crash::kCrashesUIRequestCrashUpload, |
121 base::Bind(&CrashesDOMHandler::HandleRequestUploads, | 126 base::Bind(&CrashesDOMHandler::HandleRequestUploads, |
122 base::Unretained(this))); | 127 base::Unretained(this))); |
123 #endif | 128 #endif |
| 129 |
| 130 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 131 web_ui()->RegisterMessageCallback( |
| 132 crash::kCrashesUIRequestSingleCrashUpload, |
| 133 base::Bind(&CrashesDOMHandler::HandleRequestSingleCrashUpload, |
| 134 base::Unretained(this))); |
| 135 #endif |
124 } | 136 } |
125 | 137 |
126 void CrashesDOMHandler::HandleRequestCrashes(const base::ListValue* args) { | 138 void CrashesDOMHandler::HandleRequestCrashes(const base::ListValue* args) { |
127 if (first_load_) { | 139 if (first_load_) { |
128 first_load_ = false; | 140 first_load_ = false; |
129 if (list_available_) | 141 if (list_available_) |
130 UpdateUI(); | 142 UpdateUI(); |
131 } else { | 143 } else { |
132 list_available_ = false; | 144 list_available_ = false; |
133 upload_list_->LoadUploadListAsynchronously(); | 145 upload_list_->LoadUploadListAsynchronously(); |
(...skipping 19 matching lines...) Expand all Loading... |
153 void CrashesDOMHandler::UpdateUI() { | 165 void CrashesDOMHandler::UpdateUI() { |
154 bool crash_reporting_enabled = | 166 bool crash_reporting_enabled = |
155 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); | 167 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); |
156 | 168 |
157 bool system_crash_reporter = false; | 169 bool system_crash_reporter = false; |
158 #if defined(OS_CHROMEOS) | 170 #if defined(OS_CHROMEOS) |
159 // Chrome OS has a system crash reporter. | 171 // Chrome OS has a system crash reporter. |
160 system_crash_reporter = true; | 172 system_crash_reporter = true; |
161 #endif | 173 #endif |
162 | 174 |
| 175 bool support_manual_uploads = false; |
| 176 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 177 // Maunal uploads are supported only for Windows and Mac platforms. |
| 178 support_manual_uploads = true; |
| 179 #endif |
| 180 |
163 base::ListValue crash_list; | 181 base::ListValue crash_list; |
164 if (crash_reporting_enabled) | 182 if (crash_reporting_enabled) |
165 crash::UploadListToValue(upload_list_.get(), &crash_list); | 183 crash::UploadListToValue(upload_list_.get(), &crash_list); |
166 | 184 |
167 base::FundamentalValue enabled(crash_reporting_enabled); | 185 base::FundamentalValue enabled(crash_reporting_enabled); |
168 base::FundamentalValue dynamic_backend(system_crash_reporter); | 186 base::FundamentalValue dynamic_backend(system_crash_reporter); |
| 187 base::FundamentalValue manual_uploads(support_manual_uploads); |
169 base::StringValue version(version_info::GetVersionNumber()); | 188 base::StringValue version(version_info::GetVersionNumber()); |
170 base::StringValue os_string(base::SysInfo::OperatingSystemName() + " " + | 189 base::StringValue os_string(base::SysInfo::OperatingSystemName() + " " + |
171 base::SysInfo::OperatingSystemVersion()); | 190 base::SysInfo::OperatingSystemVersion()); |
172 | 191 |
173 std::vector<const base::Value*> args; | 192 std::vector<const base::Value*> args; |
174 args.push_back(&enabled); | 193 args.push_back(&enabled); |
175 args.push_back(&dynamic_backend); | 194 args.push_back(&dynamic_backend); |
| 195 args.push_back(&manual_uploads); |
176 args.push_back(&crash_list); | 196 args.push_back(&crash_list); |
177 args.push_back(&version); | 197 args.push_back(&version); |
178 args.push_back(&os_string); | 198 args.push_back(&os_string); |
179 web_ui()->CallJavascriptFunctionUnsafe(crash::kCrashesUIUpdateCrashList, | 199 web_ui()->CallJavascriptFunctionUnsafe(crash::kCrashesUIUpdateCrashList, |
180 args); | 200 args); |
181 } | 201 } |
182 | 202 |
| 203 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 204 void CrashesDOMHandler::HandleRequestSingleCrashUpload( |
| 205 const base::ListValue* args) { |
| 206 std::string local_id; |
| 207 if (!args || !args->GetString(0, &local_id)) |
| 208 return; |
| 209 upload_list_->RequestSingleCrashUploadAsync(local_id); |
| 210 } |
| 211 #endif |
| 212 |
183 } // namespace | 213 } // namespace |
184 | 214 |
185 /////////////////////////////////////////////////////////////////////////////// | 215 /////////////////////////////////////////////////////////////////////////////// |
186 // | 216 // |
187 // CrashesUI | 217 // CrashesUI |
188 // | 218 // |
189 /////////////////////////////////////////////////////////////////////////////// | 219 /////////////////////////////////////////////////////////////////////////////// |
190 | 220 |
191 CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 221 CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
192 web_ui->AddMessageHandler(new CrashesDOMHandler()); | 222 web_ui->AddMessageHandler(new CrashesDOMHandler()); |
193 | 223 |
194 // Set up the chrome://crashes/ source. | 224 // Set up the chrome://crashes/ source. |
195 Profile* profile = Profile::FromWebUI(web_ui); | 225 Profile* profile = Profile::FromWebUI(web_ui); |
196 content::WebUIDataSource::Add(profile, CreateCrashesUIHTMLSource()); | 226 content::WebUIDataSource::Add(profile, CreateCrashesUIHTMLSource()); |
197 } | 227 } |
198 | 228 |
199 // static | 229 // static |
200 base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes( | 230 base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes( |
201 ui::ScaleFactor scale_factor) { | 231 ui::ScaleFactor scale_factor) { |
202 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( | 232 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( |
203 IDR_CRASH_SAD_FAVICON, scale_factor); | 233 IDR_CRASH_SAD_FAVICON, scale_factor); |
204 } | 234 } |
OLD | NEW |