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 #ifndef CHROME_BROWSER_SHELL_INTEGRATION_H_ | 5 #ifndef CHROME_BROWSER_SHELL_INTEGRATION_H_ |
6 #define CHROME_BROWSER_SHELL_INTEGRATION_H_ | 6 #define CHROME_BROWSER_SHELL_INTEGRATION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 232 |
233 // Called to notify the worker that the view is gone. | 233 // Called to notify the worker that the view is gone. |
234 void ObserverDestroyed(); | 234 void ObserverDestroyed(); |
235 | 235 |
236 protected: | 236 protected: |
237 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; | 237 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; |
238 | 238 |
239 // Possible result codes for a set-as-default operation. | 239 // Possible result codes for a set-as-default operation. |
240 // Do not modify the ordering as it is important for UMA. | 240 // Do not modify the ordering as it is important for UMA. |
241 enum AttemptResult { | 241 enum AttemptResult { |
242 // No errors encountered. | 242 // Chrome was set as the default web client. |
243 SUCCESS, | 243 SUCCESS, |
244 // Chrome was already the default web client. This counts as a successful | 244 // Chrome was already the default web client. This counts as a successful |
245 // attempt. | 245 // attempt. |
246 ALREADY_DEFAULT, | 246 ALREADY_DEFAULT, |
247 // Chrome was not set as the default web client. | 247 // Chrome was not set as the default web client. |
248 FAILURE, | 248 FAILURE, |
249 // The attempt was abandoned because the observer was destroyed. | 249 // The attempt was abandoned because the observer was destroyed. |
250 ABANDONED, | 250 ABANDONED, |
251 // Failed to launch the process to set Chrome as the default web client | 251 // Failed to launch the process to set Chrome as the default web client |
252 // asynchronously. | 252 // asynchronously. |
253 LAUNCH_FAILURE, | 253 LAUNCH_FAILURE, |
254 // Another worker is already in progress to make Chrome the default web | 254 // Another worker is already in progress to make Chrome the default web |
255 // client. | 255 // client. |
256 OTHER_WORKER, | 256 OTHER_WORKER, |
257 // The user initiated another attempt while the asynchronous operation was | 257 // The user initiated another attempt while the asynchronous operation was |
258 // already in progress. | 258 // already in progress. |
259 RETRY, | 259 RETRY, |
| 260 // No errors were encountered yet Chrome is still not the default web |
| 261 // client. |
| 262 NO_ERRORS_NOT_DEFAULT, |
260 NUM_ATTEMPT_RESULT_TYPES | 263 NUM_ATTEMPT_RESULT_TYPES |
261 }; | 264 }; |
262 | 265 |
263 virtual ~DefaultWebClientWorker(); | 266 virtual ~DefaultWebClientWorker(); |
264 | 267 |
265 // Communicates the result to the observer. In contrast to | 268 // Communicates the result to the observer. In contrast to |
266 // OnSetAsDefaultAttemptComplete(), this should not be called multiple | 269 // OnSetAsDefaultAttemptComplete(), this should not be called multiple |
267 // times. | 270 // times. |
268 void OnCheckIsDefaultComplete(DefaultWebClientState state); | 271 void OnCheckIsDefaultComplete(DefaultWebClientState state); |
269 | 272 |
(...skipping 18 matching lines...) Expand all Loading... |
288 // FILE thread. Subclasses are responsible for calling | 291 // FILE thread. Subclasses are responsible for calling |
289 // OnCheckIsDefaultComplete() on the UI thread. | 292 // OnCheckIsDefaultComplete() on the UI thread. |
290 virtual void CheckIsDefault() = 0; | 293 virtual void CheckIsDefault() = 0; |
291 | 294 |
292 // Sets Chrome as the default web client. Always called on the FILE thread. | 295 // Sets Chrome as the default web client. Always called on the FILE thread. |
293 // |interactive_permitted| will make SetAsDefault() fail if it requires | 296 // |interactive_permitted| will make SetAsDefault() fail if it requires |
294 // interaction with the user. Subclasses are responsible for calling | 297 // interaction with the user. Subclasses are responsible for calling |
295 // OnSetAsDefaultAttemptComplete() on the UI thread. | 298 // OnSetAsDefaultAttemptComplete() on the UI thread. |
296 virtual void SetAsDefault(bool interactive_permitted) = 0; | 299 virtual void SetAsDefault(bool interactive_permitted) = 0; |
297 | 300 |
| 301 // Returns the prefix used for metrics to differentiate UMA metrics for |
| 302 // setting the default browser and setting the default protocol client. |
| 303 virtual const char* GetHistogramPrefix() = 0; |
| 304 |
298 // Invoked on the UI thread prior to starting a set-as-default operation. | 305 // Invoked on the UI thread prior to starting a set-as-default operation. |
299 // Returns true if the initialization succeeded and a subsequent call to | 306 // Returns true if the initialization succeeded and a subsequent call to |
300 // FinalizeSetAsDefault() is required. | 307 // FinalizeSetAsDefault() is required. |
301 virtual bool InitializeSetAsDefault(); | 308 virtual bool InitializeSetAsDefault(); |
302 | 309 |
303 // Invoked on the UI thread following a set-as-default operation. | 310 // Invoked on the UI thread following a set-as-default operation. |
304 virtual void FinalizeSetAsDefault(); | 311 virtual void FinalizeSetAsDefault(); |
305 | 312 |
306 // Returns true if the attempt results should be reported to UMA. | |
307 static bool ShouldReportAttemptResults(); | |
308 | |
309 // Reports the result and duration for one set-as-default attempt. | 313 // Reports the result and duration for one set-as-default attempt. |
310 void ReportAttemptResult(AttemptResult result); | 314 void ReportAttemptResult(AttemptResult result); |
311 | 315 |
312 // Updates the UI in our associated view with the current default web | 316 // Updates the UI in our associated view with the current default web |
313 // client state. | 317 // client state. |
314 void UpdateUI(DefaultWebClientState state); | 318 void UpdateUI(DefaultWebClientState state); |
315 | 319 |
| 320 // Returns true if the duration of an attempt to set the default web client |
| 321 // should be reported to UMA for |result|. |
| 322 static bool ShouldReportDurationForResult(AttemptResult result); |
| 323 |
| 324 // Returns a string based on |result|. This is used for UMA reports. |
| 325 static const char* AttemptResultToString(AttemptResult result); |
| 326 |
316 DefaultWebClientObserver* observer_; | 327 DefaultWebClientObserver* observer_; |
317 | 328 |
318 // Flag that indicates the return value of InitializeSetAsDefault(). If | 329 // Flag that indicates the return value of InitializeSetAsDefault(). If |
319 // true, FinalizeSetAsDefault() will be called to clear what was | 330 // true, FinalizeSetAsDefault() will be called to clear what was |
320 // initialized. | 331 // initialized. |
321 bool set_as_default_initialized_ = false; | 332 bool set_as_default_initialized_ = false; |
322 | 333 |
323 // Records the time it takes to set the default browser. | 334 // Records the time it takes to set the default browser. |
324 base::TimeTicks start_time_; | 335 base::TimeTicks start_time_; |
325 | 336 |
| 337 // Wait until Chrome has been confirmed as the default browser before |
| 338 // reporting a successful attempt. |
| 339 bool check_default_should_report_success_ = false; |
| 340 |
326 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); | 341 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); |
327 }; | 342 }; |
328 | 343 |
329 // Worker for checking and setting the default browser. | 344 // Worker for checking and setting the default browser. |
330 class DefaultBrowserWorker : public DefaultWebClientWorker { | 345 class DefaultBrowserWorker : public DefaultWebClientWorker { |
331 public: | 346 public: |
332 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); | 347 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); |
333 | 348 |
334 private: | 349 private: |
335 ~DefaultBrowserWorker() override; | 350 ~DefaultBrowserWorker() override; |
336 | 351 |
337 // Check if Chrome is the default browser. | 352 // Check if Chrome is the default browser. |
338 void CheckIsDefault() override; | 353 void CheckIsDefault() override; |
339 | 354 |
340 // Set Chrome as the default browser. | 355 // Set Chrome as the default browser. |
341 void SetAsDefault(bool interactive_permitted) override; | 356 void SetAsDefault(bool interactive_permitted) override; |
342 | 357 |
| 358 // Returns the histogram prefix for DefaultBrowserWorker. |
| 359 const char* GetHistogramPrefix() override; |
| 360 |
343 #if defined(OS_WIN) | 361 #if defined(OS_WIN) |
344 // On Windows 10+, adds the default browser callback and starts the timer | 362 // On Windows 10+, adds the default browser callback and starts the timer |
345 // that determines if the operation was successful or not. | 363 // that determines if the operation was successful or not. |
346 bool InitializeSetAsDefault() override; | 364 bool InitializeSetAsDefault() override; |
347 | 365 |
348 // On Windows 10+, removes the default browser callback and stops the timer. | 366 // On Windows 10+, removes the default browser callback and stops the timer. |
349 void FinalizeSetAsDefault() override; | 367 void FinalizeSetAsDefault() override; |
350 | 368 |
351 // Prompts the user to select the default browser by trying to open the help | 369 // Prompts the user to select the default browser by trying to open the help |
352 // page that explains how to set Chrome as the default browser. Returns | 370 // page that explains how to set Chrome as the default browser. Returns |
353 // false if the process needed to set Chrome default failed to launch. | 371 // false if the process needed to set Chrome default failed to launch. |
354 static bool SetAsDefaultBrowserAsynchronous(); | 372 static bool SetAsDefaultBrowserAsynchronous(); |
355 | 373 |
356 // Used to determine if setting the default browser was unsuccesful. | 374 // Used to determine if setting the default browser was unsuccesful. |
357 scoped_ptr<base::OneShotTimer> async_timer_; | 375 scoped_ptr<base::OneShotTimer> async_timer_; |
358 #endif // !defined(OS_WIN) | 376 #endif // defined(OS_WIN) |
359 | 377 |
360 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 378 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
361 }; | 379 }; |
362 | 380 |
363 // Worker for checking and setting the default client application | 381 // Worker for checking and setting the default client application |
364 // for a given protocol. A different worker instance is needed for each | 382 // for a given protocol. A different worker instance is needed for each |
365 // protocol you are interested in, so to check or set the default for | 383 // protocol you are interested in, so to check or set the default for |
366 // multiple protocols you should use multiple worker objects. | 384 // multiple protocols you should use multiple worker objects. |
367 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | 385 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
368 public: | 386 public: |
369 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, | 387 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
370 const std::string& protocol); | 388 const std::string& protocol); |
371 | 389 |
372 const std::string& protocol() const { return protocol_; } | 390 const std::string& protocol() const { return protocol_; } |
373 | 391 |
374 protected: | 392 protected: |
375 ~DefaultProtocolClientWorker() override; | 393 ~DefaultProtocolClientWorker() override; |
376 | 394 |
377 private: | 395 private: |
378 // Check is Chrome is the default handler for this protocol. | 396 // Check is Chrome is the default handler for this protocol. |
379 void CheckIsDefault() override; | 397 void CheckIsDefault() override; |
380 | 398 |
381 // Set Chrome as the default handler for this protocol. | 399 // Set Chrome as the default handler for this protocol. |
382 void SetAsDefault(bool interactive_permitted) override; | 400 void SetAsDefault(bool interactive_permitted) override; |
383 | 401 |
| 402 // Returns the histogram prefix for DefaultProtocolClientWorker. |
| 403 const char* GetHistogramPrefix() override; |
| 404 |
384 std::string protocol_; | 405 std::string protocol_; |
385 | 406 |
386 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | 407 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
387 }; | 408 }; |
388 }; | 409 }; |
389 | 410 |
390 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 411 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
OLD | NEW |