Chromium Code Reviews| Index: chrome/browser/shell_integration.h |
| diff --git a/chrome/browser/shell_integration.h b/chrome/browser/shell_integration.h |
| index c0e4491af74708c2b046874540e6fdb4dd300842..cf223115488ae7ee975be6034756fc405116d984 100644 |
| --- a/chrome/browser/shell_integration.h |
| +++ b/chrome/browser/shell_integration.h |
| @@ -11,6 +11,7 @@ |
| #include "base/files/file_path.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/strings/string16.h" |
| +#include "base/timer/timer.h" |
| #include "ui/gfx/image/image_family.h" |
| #include "url/gurl.h" |
| @@ -32,6 +33,21 @@ class ShellIntegration { |
| // shown and this method returns true. |
| static bool SetAsDefaultBrowserInteractive(); |
| + // Returns true if setting the default browser is an asynchronous operation. |
| + // In practice, this is only true on Windows 10+. |
| + static bool IsSetAsDefaultAsynchronous(); |
| + |
| + // Prompt the user to select the default browser by trying to open |
| + // https://support.google.com/chrome?p=default_browser which is the "How to |
| + // set Chrome as your default browser" help page. Only call this if |
| + // |IsSetAsDefaultAsynchronous| is true. |
| + // |
| + // The caller should add an URL filter to intercept the link navigation (See |
| + // startup_browser_creator.h). |
| + // The caller should also set up a timer to represent an unsuccessful attempt |
| + // after a certain amount of time. |
| + static void SetAsDefaultBrowserAsynchronous(); |
| + |
| // Sets Chrome as the default client application for the given protocol |
| // (only for the current user). Returns false if this operation fails. |
| static bool SetAsDefaultProtocolClient(const std::string& protocol); |
| @@ -52,6 +68,7 @@ class ShellIntegration { |
| SET_DEFAULT_NOT_ALLOWED, |
| SET_DEFAULT_UNATTENDED, |
| SET_DEFAULT_INTERACTIVE, |
| + SET_DEFAULT_ASYNCHRONOUS, |
| }; |
| // Returns requirements for making the running browser the user's default. |
| @@ -203,6 +220,17 @@ class ShellIntegration { |
| // it as the default. These operations are performed asynchronously on the |
| // file thread since registry access (on Windows) or the preference database |
| // (on Linux) are involved and this can be slow. |
| + // |
| + // On windows 10+, there is no official way to prompt the user to set a |
| + // default browser. This is the workaround: |
| + // 1. Unregister the default browser. |
| + // 2. Open "How to make Chrome my default browser" link with ShellExecute. |
| + // 3. Windows prompt the user with "How would you link to open this?". |
| + // 4. If Chrome is selected, the http url is intercepted and |
| + // CompleteSetAsDefault is called with succeeded equals to true. |
| + // 5. If Chrome is not selected, the url is opened in the selected browser. |
| + // After a certain amount of time, we notify the observer that the |
| + // process failed. |
| class DefaultWebClientWorker |
| : public base::RefCountedThreadSafe<DefaultWebClientWorker> { |
| public: |
| @@ -226,13 +254,34 @@ class ShellIntegration { |
| virtual ~DefaultWebClientWorker() {} |
| + // When the action to set Chrome as the default has completed this function |
| + // is run. This function will call UninitializeSetAsDefault and then start |
| + // the check process, which, if an observer is present, reports to it the |
| + // new status. |succeeded| is true if the actual call to a set-default |
| + // function (from ExecuteSetAsDefault) was successful. |
| + void CompleteSetAsDefault(bool succeeded); |
| + |
| +#if defined(OS_WIN) |
| + // Used to determine if setting the default browser was unsuccesful. |
| + scoped_ptr<base::OneShotTimer<DefaultWebClientWorker>> async_timer_; |
|
grt (UTC plus 2)
2015/09/22 19:19:56
FYI: it looks like OneShotTimer is getting a bit o
Patrick Monette
2015/09/23 22:40:45
Acknowledged.
|
| + |
| + // Records the time it takes to set the default browser asynchronously. |
| + base::TimeTicks start_time_; |
| +#endif // !defined(OS_WIN) |
| + |
| private: |
| // Function that performs the check. |
| virtual DefaultWebClientState CheckIsDefault() = 0; |
| - // Function that sets Chrome as the default web client. Returns false if |
| - // the operation fails or has been cancelled by the user. |
| - virtual bool SetAsDefault(bool interactive_permitted) = 0; |
| + // Function that sets Chrome as the default web client. |
|
grt (UTC plus 2)
2015/09/22 18:21:48
please add to the comment that implementations MUS
Patrick Monette
2015/09/23 22:40:45
Done.
|
| + virtual void SetAsDefault(bool interactive_permitted) = 0; |
| + |
| + // Executed before calling |ExecuteSetAsDefault|. |
|
grt (UTC plus 2)
2015/09/22 19:17:48
comment suggestion:
// Invoked on the UI thread
Patrick Monette
2015/09/23 22:40:45
Done.
|
| + virtual void InitializeSetAsDefault() {} |
| + |
| + // Called in CompleteSetAsDefault right. Should return true to notify the |
| + // observer of the result of setting Chrome as the default browser. |
| + virtual bool UninitializeSetAsDefault(bool succeeded) { return true; } |
|
grt (UTC plus 2)
2015/09/22 19:17:48
suggestion:
// Invoked on the UI thread followin
Patrick Monette
2015/09/23 22:40:45
Done.
|
| // Function that handles performing the check on the file thread. This |
| // function is posted as a task onto the file thread, where it performs |
| @@ -251,20 +300,10 @@ class ShellIntegration { |
| // returns SET_DEFAULT_INTERACTIVE). |
| void ExecuteSetAsDefault(bool interactive_permitted); |
| - // Communicate results to the observer. This function is posted as a task |
| - // onto the UI thread by the ExecuteCheckIsDefault function running in the |
| - // file thread. |
| + // Calls |UninitializeSetAsDefault| and then communicate results to the |
| + // observer. |
| void CompleteCheckIsDefault(DefaultWebClientState state); |
| - // When the action to set Chrome as the default has completed this function |
| - // is run. It is posted as a task back onto the UI thread by the |
| - // ExecuteSetAsDefault function running in the file thread. This function |
| - // will the start the check process, which, if an observer is present, |
| - // reports to it the new status. |
| - // |succeeded| is true if the actual call to a set-default function (from |
| - // ExecuteSetAsDefault) was successful. |
| - void CompleteSetAsDefault(bool succeeded); |
| - |
| // Updates the UI in our associated view with the current default web |
| // client state. |
| void UpdateUI(DefaultWebClientState state); |
| @@ -286,7 +325,14 @@ class ShellIntegration { |
| DefaultWebClientState CheckIsDefault() override; |
| // Set Chrome as the default browser. |
| - bool SetAsDefault(bool interactive_permitted) override; |
| + void SetAsDefault(bool interactive_permitted) override; |
| + |
| + // On windows 10+, add the URL filter and starts the timer that determines |
| + // if the operation was successful or not. |
| + void InitializeSetAsDefault() override; |
| + |
| + // On windows 10+, remove the URL filter and stops the timer. |
| + bool UninitializeSetAsDefault(bool succeeded) override; |
| DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
| }; |
| @@ -310,7 +356,7 @@ class ShellIntegration { |
| DefaultWebClientState CheckIsDefault() override; |
| // Set Chrome as the default handler for this protocol. |
| - bool SetAsDefault(bool interactive_permitted) override; |
| + void SetAsDefault(bool interactive_permitted) override; |
| std::string protocol_; |