Chromium Code Reviews| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 // Helper objects that handle checking if Chrome is the default browser | 213 // Helper objects that handle checking if Chrome is the default browser |
| 214 // or application for a url protocol on Windows and Linux, and also setting | 214 // or application for a url protocol on Windows and Linux, and also setting |
| 215 // it as the default. These operations are performed asynchronously on the | 215 // it as the default. These operations are performed asynchronously on the |
| 216 // file thread since registry access (on Windows) or the preference database | 216 // file thread since registry access (on Windows) or the preference database |
| 217 // (on Linux) are involved and this can be slow. | 217 // (on Linux) are involved and this can be slow. |
| 218 class DefaultWebClientWorker | 218 class DefaultWebClientWorker |
| 219 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { | 219 : public base::RefCountedThreadSafe<DefaultWebClientWorker> { |
| 220 public: | 220 public: |
| 221 explicit DefaultWebClientWorker(DefaultWebClientObserver* observer); | |
| 222 | |
| 223 // Checks to see if Chrome is the default web client application. The result | |
| 224 // will be passed back to the observer via the SetDefaultWebClientUIState | |
| 225 // function. If there is no observer, this function does not do anything. | |
| 226 void StartCheckIsDefault(); | |
| 227 | |
| 228 // Sets Chrome as the default web client application. If there is an | |
| 229 // observer, once the operation has completed the new default will be | |
| 230 // queried and the current status reported via SetDefaultWebClientUIState. | |
| 231 void StartSetAsDefault(); | |
| 232 | |
| 233 // Called to notify the worker that the view is gone. | |
| 234 void ObserverDestroyed(); | |
| 235 | |
| 236 protected: | |
| 237 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; | |
| 238 | |
| 239 // Possible result codes for a set-as-default operation. | 221 // Possible result codes for a set-as-default operation. |
| 240 // Do not modify the ordering as it is important for UMA. | 222 // Do not modify the ordering as it is important for UMA. |
| 241 enum AttemptResult { | 223 enum AttemptResult { |
|
grt (UTC plus 2)
2015/11/10 20:04:30
did you make this public so that it could be seen
Patrick Monette
2015/11/11 22:03:35
Done.
| |
| 242 // No errors encountered. | 224 // Chrome was set as the default web client. |
| 243 SUCCESS, | 225 SUCCESS, |
| 244 // Chrome was already the default web client. This counts as a successful | 226 // Chrome was already the default web client. This counts as a successful |
| 245 // attempt. | 227 // attempt. |
| 246 ALREADY_DEFAULT, | 228 ALREADY_DEFAULT, |
| 247 // Chrome was not set as the default web client. | 229 // Chrome was not set as the default web client. |
| 248 FAILURE, | 230 FAILURE, |
| 249 // The attempt was abandoned because the observer was destroyed. | 231 // The attempt was abandoned because the observer was destroyed. |
| 250 ABANDONED, | 232 ABANDONED, |
| 251 // Failed to launch the process to set Chrome as the default web client | 233 // Failed to launch the process to set Chrome as the default web client |
| 252 // asynchronously. | 234 // asynchronously. |
| 253 LAUNCH_FAILURE, | 235 LAUNCH_FAILURE, |
| 254 // Another worker is already in progress to make Chrome the default web | 236 // Another worker is already in progress to make Chrome the default web |
| 255 // client. | 237 // client. |
| 256 OTHER_WORKER, | 238 OTHER_WORKER, |
| 257 // The user initiated another attempt while the asynchronous operation was | 239 // The user initiated another attempt while the asynchronous operation was |
| 258 // already in progress. | 240 // already in progress. |
| 259 RETRY, | 241 RETRY, |
| 242 // No errors were encountered yet Chrome is still not the default web | |
| 243 // client. | |
| 244 NO_ERRORS_NOT_DEFAULT, | |
| 260 NUM_ATTEMPT_RESULT_TYPES | 245 NUM_ATTEMPT_RESULT_TYPES |
| 261 }; | 246 }; |
| 262 | 247 |
| 248 explicit DefaultWebClientWorker(DefaultWebClientObserver* observer); | |
| 249 | |
| 250 // Checks to see if Chrome is the default web client application. The result | |
| 251 // will be passed back to the observer via the SetDefaultWebClientUIState | |
| 252 // function. If there is no observer, this function does not do anything. | |
| 253 void StartCheckIsDefault(); | |
| 254 | |
| 255 // Sets Chrome as the default web client application. If there is an | |
| 256 // observer, once the operation has completed the new default will be | |
| 257 // queried and the current status reported via SetDefaultWebClientUIState. | |
| 258 void StartSetAsDefault(); | |
| 259 | |
| 260 // Called to notify the worker that the view is gone. | |
| 261 void ObserverDestroyed(); | |
| 262 | |
| 263 protected: | |
| 264 friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; | |
| 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 |
| 270 // Called when the set as default operation is completed. This then invokes | 273 // Called when the set as default operation is completed. This then invokes |
| 271 // FinalizeSetAsDefault() and, if an observer is present, starts the check | 274 // FinalizeSetAsDefault() and, if an observer is present, starts the check |
| 272 // is default process. | 275 // is default process. |
| (...skipping 15 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 |
| 316 DefaultWebClientObserver* observer_; | 320 DefaultWebClientObserver* observer_; |
| 317 | 321 |
| 318 // Flag that indicates the return value of InitializeSetAsDefault(). If | 322 // Flag that indicates the return value of InitializeSetAsDefault(). If |
| 319 // true, FinalizeSetAsDefault() will be called to clear what was | 323 // true, FinalizeSetAsDefault() will be called to clear what was |
| 320 // initialized. | 324 // initialized. |
| 321 bool set_as_default_initialized_ = false; | 325 bool set_as_default_initialized_ = false; |
| 322 | 326 |
| 323 // Records the time it takes to set the default browser. | 327 // Records the time it takes to set the default browser. |
| 324 base::TimeTicks start_time_; | 328 base::TimeTicks start_time_; |
| 325 | 329 |
| 330 // Wait until Chrome has been confirmed as the default browser before | |
| 331 // reporting a successful attempt. | |
| 332 bool check_default_should_report_success_ = false; | |
| 333 | |
| 326 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); | 334 DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); |
| 327 }; | 335 }; |
| 328 | 336 |
| 329 // Worker for checking and setting the default browser. | 337 // Worker for checking and setting the default browser. |
| 330 class DefaultBrowserWorker : public DefaultWebClientWorker { | 338 class DefaultBrowserWorker : public DefaultWebClientWorker { |
| 331 public: | 339 public: |
| 332 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); | 340 explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); |
| 333 | 341 |
| 334 private: | 342 private: |
| 335 ~DefaultBrowserWorker() override; | 343 ~DefaultBrowserWorker() override; |
| 336 | 344 |
| 337 // Check if Chrome is the default browser. | 345 // Check if Chrome is the default browser. |
| 338 void CheckIsDefault() override; | 346 void CheckIsDefault() override; |
| 339 | 347 |
| 340 // Set Chrome as the default browser. | 348 // Set Chrome as the default browser. |
| 341 void SetAsDefault(bool interactive_permitted) override; | 349 void SetAsDefault(bool interactive_permitted) override; |
| 342 | 350 |
| 351 const char* GetHistogramPrefix() override { return "SetDefaultBrowser"; } | |
|
grt (UTC plus 2)
2015/11/10 20:04:30
move the definition of this into the .cc file (see
Patrick Monette
2015/11/11 22:03:35
Done.
| |
| 352 | |
| 343 #if defined(OS_WIN) | 353 #if defined(OS_WIN) |
| 344 // On Windows 10+, adds the default browser callback and starts the timer | 354 // On Windows 10+, adds the default browser callback and starts the timer |
| 345 // that determines if the operation was successful or not. | 355 // that determines if the operation was successful or not. |
| 346 bool InitializeSetAsDefault() override; | 356 bool InitializeSetAsDefault() override; |
| 347 | 357 |
| 348 // On Windows 10+, removes the default browser callback and stops the timer. | 358 // On Windows 10+, removes the default browser callback and stops the timer. |
| 349 void FinalizeSetAsDefault() override; | 359 void FinalizeSetAsDefault() override; |
| 350 | 360 |
| 351 // Prompts the user to select the default browser by trying to open the help | 361 // 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 | 362 // 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. | 363 // false if the process needed to set Chrome default failed to launch. |
| 354 static bool SetAsDefaultBrowserAsynchronous(); | 364 static bool SetAsDefaultBrowserAsynchronous(); |
| 355 | 365 |
| 356 // Used to determine if setting the default browser was unsuccesful. | 366 // Used to determine if setting the default browser was unsuccesful. |
| 357 scoped_ptr<base::OneShotTimer> async_timer_; | 367 scoped_ptr<base::OneShotTimer> async_timer_; |
| 358 #endif // !defined(OS_WIN) | 368 #endif // defined(OS_WIN) |
| 359 | 369 |
| 360 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); | 370 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
| 361 }; | 371 }; |
| 362 | 372 |
| 363 // Worker for checking and setting the default client application | 373 // Worker for checking and setting the default client application |
| 364 // for a given protocol. A different worker instance is needed for each | 374 // 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 | 375 // protocol you are interested in, so to check or set the default for |
| 366 // multiple protocols you should use multiple worker objects. | 376 // multiple protocols you should use multiple worker objects. |
| 367 class DefaultProtocolClientWorker : public DefaultWebClientWorker { | 377 class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
| 368 public: | 378 public: |
| 369 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, | 379 DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
| 370 const std::string& protocol); | 380 const std::string& protocol); |
| 371 | 381 |
| 372 const std::string& protocol() const { return protocol_; } | 382 const std::string& protocol() const { return protocol_; } |
| 373 | 383 |
| 374 protected: | 384 protected: |
| 375 ~DefaultProtocolClientWorker() override; | 385 ~DefaultProtocolClientWorker() override; |
| 376 | 386 |
| 377 private: | 387 private: |
| 378 // Check is Chrome is the default handler for this protocol. | 388 // Check is Chrome is the default handler for this protocol. |
| 379 void CheckIsDefault() override; | 389 void CheckIsDefault() override; |
| 380 | 390 |
| 381 // Set Chrome as the default handler for this protocol. | 391 // Set Chrome as the default handler for this protocol. |
| 382 void SetAsDefault(bool interactive_permitted) override; | 392 void SetAsDefault(bool interactive_permitted) override; |
| 383 | 393 |
| 394 const char* GetHistogramPrefix() override { | |
| 395 return "SetDefaultProtocolClient"; | |
| 396 } | |
| 397 | |
| 384 std::string protocol_; | 398 std::string protocol_; |
| 385 | 399 |
| 386 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); | 400 DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
| 387 }; | 401 }; |
| 388 }; | 402 }; |
| 389 | 403 |
| 390 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ | 404 #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |
| OLD | NEW |