Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1050)

Side by Side Diff: chrome/browser/ui/webui/crashes_ui.cc

Issue 2268783002: Manual crash uploads for mac and win (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: policy restrictions + show crashes when crash uploads disabled Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted_memory.h" 12 #include "base/memory/ref_counted_memory.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/sys_info.h" 14 #include "base/sys_info.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "chrome/browser/crash_upload_list/crash_upload_list.h" 17 #include "chrome/browser/crash_upload_list/crash_upload_list.h"
18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
19 #include "chrome/browser/metrics/metrics_reporting_state.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
21 #include "chrome/grit/chromium_strings.h" 22 #include "chrome/grit/chromium_strings.h"
22 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
23 #include "components/crash/core/browser/crashes_ui_util.h" 24 #include "components/crash/core/browser/crashes_ui_util.h"
24 #include "components/version_info/version_info.h" 25 #include "components/version_info/version_info.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_ui.h" 27 #include "content/public/browser/web_ui.h"
27 #include "content/public/browser/web_ui_data_source.h" 28 #include "content/public/browser/web_ui_data_source.h"
28 #include "content/public/browser/web_ui_message_handler.h" 29 #include "content/public/browser/web_ui_message_handler.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 void HandleRequestCrashes(const base::ListValue* args); 86 void HandleRequestCrashes(const base::ListValue* args);
86 87
87 #if defined(OS_CHROMEOS) 88 #if defined(OS_CHROMEOS)
88 // Asynchronously triggers crash uploading. Called from JS. 89 // Asynchronously triggers crash uploading. Called from JS.
89 void HandleRequestUploads(const base::ListValue* args); 90 void HandleRequestUploads(const base::ListValue* args);
90 #endif 91 #endif
91 92
92 // Sends the recent crashes list JS. 93 // Sends the recent crashes list JS.
93 void UpdateUI(); 94 void UpdateUI();
94 95
96 #if defined(OS_WIN) || defined(OS_MACOSX)
97 // Asynchronously requests a user triggered upload. Called from JS.
98 void HandleRequestSingleCrashUpload(const base::ListValue* args);
99 #endif
100
95 scoped_refptr<CrashUploadList> upload_list_; 101 scoped_refptr<CrashUploadList> upload_list_;
96 bool list_available_; 102 bool list_available_;
97 bool first_load_; 103 bool first_load_;
98 104
99 DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler); 105 DISALLOW_COPY_AND_ASSIGN(CrashesDOMHandler);
100 }; 106 };
101 107
102 CrashesDOMHandler::CrashesDOMHandler() 108 CrashesDOMHandler::CrashesDOMHandler()
103 : list_available_(false), first_load_(true) { 109 : list_available_(false), first_load_(true) {
104 upload_list_ = CreateCrashUploadList(this); 110 upload_list_ = CreateCrashUploadList(this);
105 } 111 }
106 112
107 CrashesDOMHandler::~CrashesDOMHandler() { 113 CrashesDOMHandler::~CrashesDOMHandler() {
108 upload_list_->ClearDelegate(); 114 upload_list_->ClearDelegate();
109 } 115 }
110 116
111 void CrashesDOMHandler::RegisterMessages() { 117 void CrashesDOMHandler::RegisterMessages() {
112 upload_list_->LoadUploadListAsynchronously(); 118 upload_list_->LoadUploadListAsynchronously();
113 web_ui()->RegisterMessageCallback( 119 web_ui()->RegisterMessageCallback(
114 crash::kCrashesUIRequestCrashList, 120 crash::kCrashesUIRequestCrashList,
115 base::Bind(&CrashesDOMHandler::HandleRequestCrashes, 121 base::Bind(&CrashesDOMHandler::HandleRequestCrashes,
116 base::Unretained(this))); 122 base::Unretained(this)));
117 123
118 #if defined(OS_CHROMEOS) 124 #if defined(OS_CHROMEOS)
119 web_ui()->RegisterMessageCallback( 125 web_ui()->RegisterMessageCallback(
120 crash::kCrashesUIRequestCrashUpload, 126 crash::kCrashesUIRequestCrashUpload,
121 base::Bind(&CrashesDOMHandler::HandleRequestUploads, 127 base::Bind(&CrashesDOMHandler::HandleRequestUploads,
122 base::Unretained(this))); 128 base::Unretained(this)));
123 #endif 129 #endif
130
131 #if defined(OS_WIN) || defined(OS_MACOSX)
132 web_ui()->RegisterMessageCallback(
133 crash::kCrashesUIRequestSingleCrashUpload,
134 base::Bind(&CrashesDOMHandler::HandleRequestSingleCrashUpload,
135 base::Unretained(this)));
136 #endif
124 } 137 }
125 138
126 void CrashesDOMHandler::HandleRequestCrashes(const base::ListValue* args) { 139 void CrashesDOMHandler::HandleRequestCrashes(const base::ListValue* args) {
127 if (first_load_) { 140 if (first_load_) {
128 first_load_ = false; 141 first_load_ = false;
129 if (list_available_) 142 if (list_available_)
130 UpdateUI(); 143 UpdateUI();
131 } else { 144 } else {
132 list_available_ = false; 145 list_available_ = false;
133 upload_list_->LoadUploadListAsynchronously(); 146 upload_list_->LoadUploadListAsynchronously();
(...skipping 19 matching lines...) Expand all
153 void CrashesDOMHandler::UpdateUI() { 166 void CrashesDOMHandler::UpdateUI() {
154 bool crash_reporting_enabled = 167 bool crash_reporting_enabled =
155 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled(); 168 ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled();
156 169
157 bool system_crash_reporter = false; 170 bool system_crash_reporter = false;
158 #if defined(OS_CHROMEOS) 171 #if defined(OS_CHROMEOS)
159 // Chrome OS has a system crash reporter. 172 // Chrome OS has a system crash reporter.
160 system_crash_reporter = true; 173 system_crash_reporter = true;
161 #endif 174 #endif
162 175
176 bool support_manual_uploads = false;
Mark Mentovai 2016/08/25 20:25:11 Put “const bool support_manual_uploads = …” in bot
gayane -on leave until 09-2017 2016/08/26 00:12:54 Done.
163 base::ListValue crash_list; 177 base::ListValue crash_list;
178 #if defined(OS_WIN) || defined(OS_MACOSX)
179 // Maunal uploads currently are supported only for Windows and Mac platforms.
180 // Allow manual uploads only if crash uploads are not disabled by policy.
Mark Mentovai 2016/08/25 20:25:11 s/Windows and Mac/Crashpad-using/
gayane -on leave until 09-2017 2016/08/26 00:12:55 Done.
181 support_manual_uploads =
182 crash_reporting_enabled || IsMetricsReportingPolicyManaged();
Mark Mentovai 2016/08/25 20:25:11 We want to support manual uploads if the user has
gayane -on leave until 09-2017 2016/08/26 00:12:55 Thanks. There was a logic problem here. Now manual
183 // Show crash reports regardless of |crash_reporting_enabled| so that users
184 // can manually uploads those reports.
185 crash::UploadListToValue(upload_list_.get(), &crash_list);
186 #else
187 // Don't show crash reports list if crash reporting is disbled for platforms
188 // where manual uploads are not supported.
164 if (crash_reporting_enabled) 189 if (crash_reporting_enabled)
165 crash::UploadListToValue(upload_list_.get(), &crash_list); 190 crash::UploadListToValue(upload_list_.get(), &crash_list);
191 #endif
166 192
167 base::FundamentalValue enabled(crash_reporting_enabled); 193 base::FundamentalValue enabled(crash_reporting_enabled);
168 base::FundamentalValue dynamic_backend(system_crash_reporter); 194 base::FundamentalValue dynamic_backend(system_crash_reporter);
195 base::FundamentalValue manual_uploads(support_manual_uploads);
169 base::StringValue version(version_info::GetVersionNumber()); 196 base::StringValue version(version_info::GetVersionNumber());
170 base::StringValue os_string(base::SysInfo::OperatingSystemName() + " " + 197 base::StringValue os_string(base::SysInfo::OperatingSystemName() + " " +
171 base::SysInfo::OperatingSystemVersion()); 198 base::SysInfo::OperatingSystemVersion());
172 199
173 std::vector<const base::Value*> args; 200 std::vector<const base::Value*> args;
174 args.push_back(&enabled); 201 args.push_back(&enabled);
175 args.push_back(&dynamic_backend); 202 args.push_back(&dynamic_backend);
203 args.push_back(&manual_uploads);
176 args.push_back(&crash_list); 204 args.push_back(&crash_list);
177 args.push_back(&version); 205 args.push_back(&version);
178 args.push_back(&os_string); 206 args.push_back(&os_string);
179 web_ui()->CallJavascriptFunctionUnsafe(crash::kCrashesUIUpdateCrashList, 207 web_ui()->CallJavascriptFunctionUnsafe(crash::kCrashesUIUpdateCrashList,
180 args); 208 args);
181 } 209 }
182 210
211 #if defined(OS_WIN) || defined(OS_MACOSX)
212 void CrashesDOMHandler::HandleRequestSingleCrashUpload(
Mark Mentovai 2016/08/25 20:25:11 I think it’s a good idea to check that policy says
gayane -on leave until 09-2017 2016/08/26 00:12:55 Done.
213 const base::ListValue* args) {
214 std::string local_id;
215 if (!args || !args->GetString(0, &local_id))
216 return;
217 upload_list_->RequestSingleCrashUploadAsync(local_id);
218 }
219 #endif
220
183 } // namespace 221 } // namespace
184 222
185 /////////////////////////////////////////////////////////////////////////////// 223 ///////////////////////////////////////////////////////////////////////////////
186 // 224 //
187 // CrashesUI 225 // CrashesUI
188 // 226 //
189 /////////////////////////////////////////////////////////////////////////////// 227 ///////////////////////////////////////////////////////////////////////////////
190 228
191 CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) { 229 CrashesUI::CrashesUI(content::WebUI* web_ui) : WebUIController(web_ui) {
192 web_ui->AddMessageHandler(new CrashesDOMHandler()); 230 web_ui->AddMessageHandler(new CrashesDOMHandler());
193 231
194 // Set up the chrome://crashes/ source. 232 // Set up the chrome://crashes/ source.
195 Profile* profile = Profile::FromWebUI(web_ui); 233 Profile* profile = Profile::FromWebUI(web_ui);
196 content::WebUIDataSource::Add(profile, CreateCrashesUIHTMLSource()); 234 content::WebUIDataSource::Add(profile, CreateCrashesUIHTMLSource());
197 } 235 }
198 236
199 // static 237 // static
200 base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes( 238 base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes(
201 ui::ScaleFactor scale_factor) { 239 ui::ScaleFactor scale_factor) {
202 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 240 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
203 IDR_CRASH_SAD_FAVICON, scale_factor); 241 IDR_CRASH_SAD_FAVICON, scale_factor);
204 } 242 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698