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

Side by Side Diff: chrome/browser/shell_integration.cc

Issue 1770943005: Removed AttemptResult enum in favor of using DefaultWebClientState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dont_record_async_duration
Patch Set: Merge + simplified Created 4 years, 9 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/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // DefaultWebClientWorker 141 // DefaultWebClientWorker
142 // 142 //
143 143
144 DefaultWebClientWorker::DefaultWebClientWorker( 144 DefaultWebClientWorker::DefaultWebClientWorker(
145 const DefaultWebClientWorkerCallback& callback) 145 const DefaultWebClientWorkerCallback& callback)
146 : callback_(callback) {} 146 : callback_(callback) {}
147 147
148 void DefaultWebClientWorker::StartCheckIsDefault() { 148 void DefaultWebClientWorker::StartCheckIsDefault() {
149 BrowserThread::PostTask( 149 BrowserThread::PostTask(
150 BrowserThread::FILE, FROM_HERE, 150 BrowserThread::FILE, FROM_HERE,
151 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this)); 151 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, false));
152 } 152 }
153 153
154 void DefaultWebClientWorker::StartSetAsDefault() { 154 void DefaultWebClientWorker::StartSetAsDefault() {
155 BrowserThread::PostTask( 155 BrowserThread::PostTask(
156 BrowserThread::FILE, FROM_HERE, 156 BrowserThread::FILE, FROM_HERE,
157 base::Bind(&DefaultWebClientWorker::SetAsDefault, this)); 157 base::Bind(&DefaultWebClientWorker::SetAsDefault, this));
158 } 158 }
159 159
160 /////////////////////////////////////////////////////////////////////////////// 160 ///////////////////////////////////////////////////////////////////////////////
161 // DefaultWebClientWorker, private: 161 // DefaultWebClientWorker, private:
162 162
163 DefaultWebClientWorker::~DefaultWebClientWorker() {} 163 DefaultWebClientWorker::~DefaultWebClientWorker() {}
164 164
165 void DefaultWebClientWorker::OnCheckIsDefaultComplete( 165 void DefaultWebClientWorker::OnCheckIsDefaultComplete(
166 DefaultWebClientState state) { 166 DefaultWebClientState state,
167 bool is_following_set_as_default) {
167 DCHECK_CURRENTLY_ON(BrowserThread::UI); 168 DCHECK_CURRENTLY_ON(BrowserThread::UI);
168 UpdateUI(state); 169 UpdateUI(state);
169 170
170 if (check_default_should_report_success_) { 171 if (is_following_set_as_default)
171 check_default_should_report_success_ = false; 172 ReportSetDefaultResult(state);
172
173 ReportAttemptResult(state == DefaultWebClientState::IS_DEFAULT
174 ? AttemptResult::SUCCESS
175 : AttemptResult::NO_ERRORS_NOT_DEFAULT);
176 }
177 } 173 }
178 174
179 void DefaultWebClientWorker::OnSetAsDefaultAttemptComplete( 175 void DefaultWebClientWorker::ReportSetDefaultResult(
180 AttemptResult result) { 176 DefaultWebClientState state) {
181 DCHECK_CURRENTLY_ON(BrowserThread::UI);
182
183 // Report failures here. Successes are reported in
184 // OnCheckIsDefaultComplete() after checking that the change is verified.
185 check_default_should_report_success_ = result == AttemptResult::SUCCESS;
186 if (!check_default_should_report_success_)
187 ReportAttemptResult(result);
188
189 // Start the default browser check. The default state will be reported to
190 // the caller via the |callback_|.
191 StartCheckIsDefault();
192 }
193
194 void DefaultWebClientWorker::ReportAttemptResult(AttemptResult result) {
195 base::LinearHistogram::FactoryGet( 177 base::LinearHistogram::FactoryGet(
196 base::StringPrintf("%s.SetDefaultResult", GetHistogramPrefix()), 1, 178 base::StringPrintf("%s.SetDefaultResult2", GetHistogramPrefix()), 1,
197 AttemptResult::NUM_ATTEMPT_RESULT_TYPES, 179 DefaultWebClientState::NUM_DEFAULT_STATES,
198 AttemptResult::NUM_ATTEMPT_RESULT_TYPES + 1, 180 DefaultWebClientState::NUM_DEFAULT_STATES + 1,
199 base::HistogramBase::kUmaTargetedHistogramFlag) 181 base::HistogramBase::kUmaTargetedHistogramFlag)
200 ->Add(result); 182 ->Add(state);
201 } 183 }
202 184
203 void DefaultWebClientWorker::UpdateUI(DefaultWebClientState state) { 185 void DefaultWebClientWorker::UpdateUI(DefaultWebClientState state) {
204 if (!callback_.is_null()) { 186 if (!callback_.is_null()) {
205 switch (state) { 187 switch (state) {
206 case NOT_DEFAULT: 188 case NOT_DEFAULT:
207 callback_.Run(NOT_DEFAULT); 189 callback_.Run(NOT_DEFAULT);
208 break; 190 break;
209 case IS_DEFAULT: 191 case IS_DEFAULT:
210 callback_.Run(IS_DEFAULT); 192 callback_.Run(IS_DEFAULT);
(...skipping 14 matching lines...) Expand all
225 207
226 DefaultBrowserWorker::DefaultBrowserWorker( 208 DefaultBrowserWorker::DefaultBrowserWorker(
227 const DefaultWebClientWorkerCallback& callback) 209 const DefaultWebClientWorkerCallback& callback)
228 : DefaultWebClientWorker(callback) {} 210 : DefaultWebClientWorker(callback) {}
229 211
230 DefaultBrowserWorker::~DefaultBrowserWorker() {} 212 DefaultBrowserWorker::~DefaultBrowserWorker() {}
231 213
232 /////////////////////////////////////////////////////////////////////////////// 214 ///////////////////////////////////////////////////////////////////////////////
233 // DefaultBrowserWorker, private: 215 // DefaultBrowserWorker, private:
234 216
235 void DefaultBrowserWorker::CheckIsDefault() { 217 void DefaultBrowserWorker::CheckIsDefault(bool is_following_set_as_default) {
236 DefaultWebClientState state = GetDefaultBrowser(); 218 DefaultWebClientState state = GetDefaultBrowser();
237 BrowserThread::PostTask( 219 BrowserThread::PostTask(
238 BrowserThread::UI, FROM_HERE, 220 BrowserThread::UI, FROM_HERE,
239 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state)); 221 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state,
222 is_following_set_as_default));
240 } 223 }
241 224
242 void DefaultBrowserWorker::SetAsDefault() { 225 void DefaultBrowserWorker::SetAsDefault() {
243 AttemptResult result = AttemptResult::FAILURE;
244 switch (CanSetAsDefaultBrowser()) { 226 switch (CanSetAsDefaultBrowser()) {
245 case SET_DEFAULT_NOT_ALLOWED: 227 case SET_DEFAULT_NOT_ALLOWED:
246 NOTREACHED(); 228 NOTREACHED();
247 break; 229 break;
248 case SET_DEFAULT_UNATTENDED: 230 case SET_DEFAULT_UNATTENDED:
249 if (SetAsDefaultBrowser()) 231 SetAsDefaultBrowser();
250 result = AttemptResult::SUCCESS;
251 break; 232 break;
252 case SET_DEFAULT_INTERACTIVE: 233 case SET_DEFAULT_INTERACTIVE:
253 if (interactive_permitted_ && SetAsDefaultBrowserInteractive()) 234 if (interactive_permitted_)
254 result = AttemptResult::SUCCESS; 235 SetAsDefaultBrowserInteractive();
255 break; 236 break;
256 } 237 }
257 BrowserThread::PostTask( 238 CheckIsDefault(true);
258 BrowserThread::UI, FROM_HERE,
259 base::Bind(&DefaultBrowserWorker::OnSetAsDefaultAttemptComplete, this,
260 result));
261 } 239 }
262 240
263 const char* DefaultBrowserWorker::GetHistogramPrefix() { 241 const char* DefaultBrowserWorker::GetHistogramPrefix() {
264 return "DefaultBrowser"; 242 return "DefaultBrowser";
265 } 243 }
266 244
267 /////////////////////////////////////////////////////////////////////////////// 245 ///////////////////////////////////////////////////////////////////////////////
268 // DefaultProtocolClientWorker 246 // DefaultProtocolClientWorker
269 // 247 //
270 248
271 DefaultProtocolClientWorker::DefaultProtocolClientWorker( 249 DefaultProtocolClientWorker::DefaultProtocolClientWorker(
272 const DefaultWebClientWorkerCallback& callback, 250 const DefaultWebClientWorkerCallback& callback,
273 const std::string& protocol) 251 const std::string& protocol)
274 : DefaultWebClientWorker(callback), protocol_(protocol) {} 252 : DefaultWebClientWorker(callback), protocol_(protocol) {}
275 253
276 /////////////////////////////////////////////////////////////////////////////// 254 ///////////////////////////////////////////////////////////////////////////////
277 // DefaultProtocolClientWorker, private: 255 // DefaultProtocolClientWorker, private:
278 256
279 DefaultProtocolClientWorker::~DefaultProtocolClientWorker() {} 257 DefaultProtocolClientWorker::~DefaultProtocolClientWorker() {}
280 258
281 void DefaultProtocolClientWorker::CheckIsDefault() { 259 void DefaultProtocolClientWorker::CheckIsDefault(
260 bool is_following_set_as_default) {
282 DefaultWebClientState state = IsDefaultProtocolClient(protocol_); 261 DefaultWebClientState state = IsDefaultProtocolClient(protocol_);
283 BrowserThread::PostTask( 262 BrowserThread::PostTask(
284 BrowserThread::UI, FROM_HERE, 263 BrowserThread::UI, FROM_HERE,
285 base::Bind(&DefaultProtocolClientWorker::OnCheckIsDefaultComplete, this, 264 base::Bind(&DefaultProtocolClientWorker::OnCheckIsDefaultComplete, this,
286 state)); 265 state, is_following_set_as_default));
287 } 266 }
288 267
289 void DefaultProtocolClientWorker::SetAsDefault() { 268 void DefaultProtocolClientWorker::SetAsDefault() {
290 AttemptResult result = AttemptResult::FAILURE;
291 switch (CanSetAsDefaultProtocolClient()) { 269 switch (CanSetAsDefaultProtocolClient()) {
292 case SET_DEFAULT_NOT_ALLOWED: 270 case SET_DEFAULT_NOT_ALLOWED:
293 // Not allowed, do nothing. 271 // Not allowed, do nothing.
294 break; 272 break;
295 case SET_DEFAULT_UNATTENDED: 273 case SET_DEFAULT_UNATTENDED:
296 if (SetAsDefaultProtocolClient(protocol_)) 274 SetAsDefaultProtocolClient(protocol_);
297 result = AttemptResult::SUCCESS;
298 break; 275 break;
299 case SET_DEFAULT_INTERACTIVE: 276 case SET_DEFAULT_INTERACTIVE:
300 if (interactive_permitted_ && 277 if (interactive_permitted_) {
301 SetAsDefaultProtocolClientInteractive(protocol_)) { 278 SetAsDefaultProtocolClientInteractive(protocol_);
302 result = AttemptResult::SUCCESS;
303 } 279 }
304 break; 280 break;
305 } 281 }
306 BrowserThread::PostTask( 282 CheckIsDefault(true);
307 BrowserThread::UI, FROM_HERE,
308 base::Bind(&DefaultProtocolClientWorker::OnSetAsDefaultAttemptComplete,
309 this, result));
310 } 283 }
311 284
312 const char* DefaultProtocolClientWorker::GetHistogramPrefix() { 285 const char* DefaultProtocolClientWorker::GetHistogramPrefix() {
313 return "DefaultProtocolClient"; 286 return "DefaultProtocolClient";
314 } 287 }
315 288
316 } // namespace shell_integration 289 } // namespace shell_integration
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698