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

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: Rebase 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
« no previous file with comments | « chrome/browser/shell_integration.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 10 #include "base/metrics/histogram.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 #endif // !defined(OS_WIN) 138 #endif // !defined(OS_WIN)
139 139
140 /////////////////////////////////////////////////////////////////////////////// 140 ///////////////////////////////////////////////////////////////////////////////
141 // DefaultWebClientWorker 141 // DefaultWebClientWorker
142 // 142 //
143 143
144 void DefaultWebClientWorker::StartCheckIsDefault() { 144 void DefaultWebClientWorker::StartCheckIsDefault() {
145 BrowserThread::PostTask( 145 BrowserThread::PostTask(
146 BrowserThread::FILE, FROM_HERE, 146 BrowserThread::FILE, FROM_HERE,
147 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this)); 147 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this, false));
148 } 148 }
149 149
150 void DefaultWebClientWorker::StartSetAsDefault() { 150 void DefaultWebClientWorker::StartSetAsDefault() {
151 BrowserThread::PostTask( 151 BrowserThread::PostTask(
152 BrowserThread::FILE, FROM_HERE, 152 BrowserThread::FILE, FROM_HERE,
153 base::Bind(&DefaultWebClientWorker::SetAsDefault, this)); 153 base::Bind(&DefaultWebClientWorker::SetAsDefault, this));
154 } 154 }
155 155
156 /////////////////////////////////////////////////////////////////////////////// 156 ///////////////////////////////////////////////////////////////////////////////
157 // DefaultWebClientWorker, protected: 157 // DefaultWebClientWorker, protected:
158 158
159 DefaultWebClientWorker::DefaultWebClientWorker( 159 DefaultWebClientWorker::DefaultWebClientWorker(
160 const DefaultWebClientWorkerCallback& callback, 160 const DefaultWebClientWorkerCallback& callback,
161 const char* worker_name) 161 const char* worker_name)
162 : callback_(callback), worker_name_(worker_name) {} 162 : callback_(callback), worker_name_(worker_name) {}
163 163
164 DefaultWebClientWorker::~DefaultWebClientWorker() = default; 164 DefaultWebClientWorker::~DefaultWebClientWorker() = default;
165 165
166 void DefaultWebClientWorker::OnCheckIsDefaultComplete( 166 void DefaultWebClientWorker::OnCheckIsDefaultComplete(
167 DefaultWebClientState state) { 167 DefaultWebClientState state,
168 bool is_following_set_as_default) {
168 DCHECK_CURRENTLY_ON(BrowserThread::UI); 169 DCHECK_CURRENTLY_ON(BrowserThread::UI);
169 UpdateUI(state); 170 UpdateUI(state);
170 171
171 if (check_default_should_report_success_) { 172 if (is_following_set_as_default)
172 check_default_should_report_success_ = false; 173 ReportSetDefaultResult(state);
173
174 ReportAttemptResult(state == DefaultWebClientState::IS_DEFAULT
175 ? AttemptResult::SUCCESS
176 : AttemptResult::NO_ERRORS_NOT_DEFAULT);
177 }
178 }
179
180 void DefaultWebClientWorker::OnSetAsDefaultAttemptComplete(
181 AttemptResult result) {
182 DCHECK_CURRENTLY_ON(BrowserThread::UI);
183
184 // Report failures here. Successes are reported in
185 // OnCheckIsDefaultComplete() after checking that the change is verified.
186 check_default_should_report_success_ = result == AttemptResult::SUCCESS;
187 if (!check_default_should_report_success_)
188 ReportAttemptResult(result);
189
190 // Start the default browser check. The default state will be reported to
191 // the caller via the |callback_|.
192 StartCheckIsDefault();
193 } 174 }
194 175
195 /////////////////////////////////////////////////////////////////////////////// 176 ///////////////////////////////////////////////////////////////////////////////
196 // DefaultWebClientWorker, private: 177 // DefaultWebClientWorker, private:
197 178
198 void DefaultWebClientWorker::CheckIsDefault() { 179 void DefaultWebClientWorker::CheckIsDefault(bool is_following_set_as_default) {
199 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 180 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
200 DefaultWebClientState state = CheckIsDefaultImpl(); 181 DefaultWebClientState state = CheckIsDefaultImpl();
201 BrowserThread::PostTask( 182 BrowserThread::PostTask(
202 BrowserThread::UI, FROM_HERE, 183 BrowserThread::UI, FROM_HERE,
203 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state)); 184 base::Bind(&DefaultBrowserWorker::OnCheckIsDefaultComplete, this, state,
185 is_following_set_as_default));
204 } 186 }
205 187
206 void DefaultWebClientWorker::SetAsDefault() { 188 void DefaultWebClientWorker::SetAsDefault() {
207 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 189 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
208 AttemptResult result = SetAsDefaultImpl(); 190 SetAsDefaultImpl();
209 BrowserThread::PostTask( 191 CheckIsDefault(true);
210 BrowserThread::UI, FROM_HERE,
211 base::Bind(&DefaultBrowserWorker::OnSetAsDefaultAttemptComplete, this,
212 result));
213 } 192 }
214 193
215 void DefaultWebClientWorker::ReportAttemptResult(AttemptResult result) { 194 void DefaultWebClientWorker::ReportSetDefaultResult(
195 DefaultWebClientState state) {
216 base::LinearHistogram::FactoryGet( 196 base::LinearHistogram::FactoryGet(
217 base::StringPrintf("%s.SetDefaultResult", worker_name_), 1, 197 base::StringPrintf("%s.SetDefaultResult2", worker_name_), 1,
218 AttemptResult::NUM_ATTEMPT_RESULT_TYPES, 198 DefaultWebClientState::NUM_DEFAULT_STATES,
219 AttemptResult::NUM_ATTEMPT_RESULT_TYPES + 1, 199 DefaultWebClientState::NUM_DEFAULT_STATES + 1,
220 base::HistogramBase::kUmaTargetedHistogramFlag) 200 base::HistogramBase::kUmaTargetedHistogramFlag)
221 ->Add(result); 201 ->Add(state);
222 } 202 }
223 203
224 void DefaultWebClientWorker::UpdateUI(DefaultWebClientState state) { 204 void DefaultWebClientWorker::UpdateUI(DefaultWebClientState state) {
225 if (!callback_.is_null()) { 205 if (!callback_.is_null()) {
226 switch (state) { 206 switch (state) {
227 case NOT_DEFAULT: 207 case NOT_DEFAULT:
228 callback_.Run(NOT_DEFAULT); 208 callback_.Run(NOT_DEFAULT);
229 break; 209 break;
230 case IS_DEFAULT: 210 case IS_DEFAULT:
231 callback_.Run(IS_DEFAULT); 211 callback_.Run(IS_DEFAULT);
(...skipping 18 matching lines...) Expand all
250 230
251 /////////////////////////////////////////////////////////////////////////////// 231 ///////////////////////////////////////////////////////////////////////////////
252 // DefaultBrowserWorker, private: 232 // DefaultBrowserWorker, private:
253 233
254 DefaultBrowserWorker::~DefaultBrowserWorker() = default; 234 DefaultBrowserWorker::~DefaultBrowserWorker() = default;
255 235
256 DefaultWebClientState DefaultBrowserWorker::CheckIsDefaultImpl() { 236 DefaultWebClientState DefaultBrowserWorker::CheckIsDefaultImpl() {
257 return GetDefaultBrowser(); 237 return GetDefaultBrowser();
258 } 238 }
259 239
260 DefaultWebClientWorker::AttemptResult DefaultBrowserWorker::SetAsDefaultImpl() { 240 void DefaultBrowserWorker::SetAsDefaultImpl() {
261 AttemptResult result = AttemptResult::FAILURE;
262 switch (CanSetAsDefaultBrowser()) { 241 switch (CanSetAsDefaultBrowser()) {
263 case SET_DEFAULT_NOT_ALLOWED: 242 case SET_DEFAULT_NOT_ALLOWED:
264 NOTREACHED(); 243 NOTREACHED();
265 break; 244 break;
266 case SET_DEFAULT_UNATTENDED: 245 case SET_DEFAULT_UNATTENDED:
267 if (SetAsDefaultBrowser()) 246 SetAsDefaultBrowser();
268 result = AttemptResult::SUCCESS;
269 break; 247 break;
270 case SET_DEFAULT_INTERACTIVE: 248 case SET_DEFAULT_INTERACTIVE:
271 if (interactive_permitted_ && SetAsDefaultBrowserInteractive()) 249 if (interactive_permitted_)
272 result = AttemptResult::SUCCESS; 250 SetAsDefaultBrowserInteractive();
273 break; 251 break;
274 } 252 }
275 return result;
276 } 253 }
277 254
278 /////////////////////////////////////////////////////////////////////////////// 255 ///////////////////////////////////////////////////////////////////////////////
279 // DefaultProtocolClientWorker 256 // DefaultProtocolClientWorker
280 // 257 //
281 258
282 DefaultProtocolClientWorker::DefaultProtocolClientWorker( 259 DefaultProtocolClientWorker::DefaultProtocolClientWorker(
283 const DefaultWebClientWorkerCallback& callback, 260 const DefaultWebClientWorkerCallback& callback,
284 const std::string& protocol) 261 const std::string& protocol)
285 : DefaultWebClientWorker(callback, "DefaultProtocolClient"), 262 : DefaultWebClientWorker(callback, "DefaultProtocolClient"),
286 protocol_(protocol) {} 263 protocol_(protocol) {}
287 264
288 /////////////////////////////////////////////////////////////////////////////// 265 ///////////////////////////////////////////////////////////////////////////////
289 // DefaultProtocolClientWorker, protected: 266 // DefaultProtocolClientWorker, protected:
290 267
291 DefaultProtocolClientWorker::~DefaultProtocolClientWorker() = default; 268 DefaultProtocolClientWorker::~DefaultProtocolClientWorker() = default;
292 269
293 /////////////////////////////////////////////////////////////////////////////// 270 ///////////////////////////////////////////////////////////////////////////////
294 // DefaultProtocolClientWorker, private: 271 // DefaultProtocolClientWorker, private:
295 272
296 DefaultWebClientState DefaultProtocolClientWorker::CheckIsDefaultImpl() { 273 DefaultWebClientState DefaultProtocolClientWorker::CheckIsDefaultImpl() {
297 return IsDefaultProtocolClient(protocol_); 274 return IsDefaultProtocolClient(protocol_);
298 } 275 }
299 276
300 DefaultWebClientWorker::AttemptResult 277 void DefaultProtocolClientWorker::SetAsDefaultImpl() {
301 DefaultProtocolClientWorker::SetAsDefaultImpl() {
302 AttemptResult result = AttemptResult::FAILURE;
303 switch (CanSetAsDefaultProtocolClient()) { 278 switch (CanSetAsDefaultProtocolClient()) {
304 case SET_DEFAULT_NOT_ALLOWED: 279 case SET_DEFAULT_NOT_ALLOWED:
305 // Not allowed, do nothing. 280 // Not allowed, do nothing.
306 break; 281 break;
307 case SET_DEFAULT_UNATTENDED: 282 case SET_DEFAULT_UNATTENDED:
308 if (SetAsDefaultProtocolClient(protocol_)) 283 SetAsDefaultProtocolClient(protocol_);
309 result = AttemptResult::SUCCESS;
310 break; 284 break;
311 case SET_DEFAULT_INTERACTIVE: 285 case SET_DEFAULT_INTERACTIVE:
312 if (interactive_permitted_ && 286 if (interactive_permitted_) {
313 SetAsDefaultProtocolClientInteractive(protocol_)) { 287 SetAsDefaultProtocolClientInteractive(protocol_);
314 result = AttemptResult::SUCCESS;
315 } 288 }
316 break; 289 break;
317 } 290 }
318 return result;
319 } 291 }
320 292
321 } // namespace shell_integration 293 } // namespace shell_integration
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698