Chromium Code Reviews| Index: chrome/browser/shell_integration.h |
| diff --git a/chrome/browser/shell_integration.h b/chrome/browser/shell_integration.h |
| index 575575e9175ecc92cc9f805e1c3f5acca2e4febd..bad39a280b7f06c782bf99ac64ac0e774ca8f16b 100644 |
| --- a/chrome/browser/shell_integration.h |
| +++ b/chrome/browser/shell_integration.h |
| @@ -30,26 +30,35 @@ class ShellIntegration { |
| // this operation fails. |
| static bool SetAsDefaultBrowser(); |
| + // Sets Chrome as client application for the given protocol (only for |
|
Mark Mentovai
2011/05/24 16:28:53
as the client application
benwells
2011/05/25 08:07:19
Done.
|
| + // current user). Returns false if this operation fails. |
|
Mark Mentovai
2011/05/24 16:28:53
for the current user
benwells
2011/05/25 08:07:19
Done.
|
| + static bool SetAsDefaultProtocolClient(const std::string& protocol); |
| + |
| // On Linux, it may not be possible to determine or set the default browser |
| // on some desktop environments or configurations. So, we use this enum and |
| // not a plain bool. (Note however that if used like a bool, this enum will |
| // have reasonable behavior.) |
| - enum DefaultBrowserState { |
| - NOT_DEFAULT_BROWSER = 0, |
| - IS_DEFAULT_BROWSER, |
| - UNKNOWN_DEFAULT_BROWSER |
| + enum DefaultWebClientState { |
| + NOT_DEFAULT_WEB_CLIENT = 0, |
| + IS_DEFAULT_WEB_CLIENT, |
| + UNKNOWN_DEFAULT_WEB_CLIENT = -1 |
| }; |
| // Attempt to determine if this instance of Chrome is the default browser and |
| // return the appropriate state. (Defined as being the handler for HTTP/HTTPS |
| // protocols; we don't want to report "no" here if the user has simply chosen |
| // to open HTML files in a text editor and FTP links with an FTP client.) |
| - static DefaultBrowserState IsDefaultBrowser(); |
| + static DefaultWebClientState IsDefaultBrowser(); |
| // Returns true if Firefox is likely to be the default browser for the current |
| // user. This method is very fast so it can be invoked in the UI thread. |
| static bool IsFirefoxDefaultBrowser(); |
| + // Attempt to determine if this instance of Chrome is the default client |
| + // application for the given protocol and return the appropriate state. |
| + static DefaultWebClientState |
| + IsDefaultProtocolClient(const std::string& protocol); |
| + |
| struct ShortcutInfo { |
| ShortcutInfo(); |
| ~ShortcutInfo(); |
| @@ -123,66 +132,121 @@ class ShellIntegration { |
| static void MigrateChromiumShortcuts(); |
| #endif // defined(OS_WIN) |
| - // The current default browser UI state |
| - enum DefaultBrowserUIState { |
| + // The current default browser / client application UI state |
|
xiyuan
2011/05/24 17:55:20
nit: did you mean "web client application"?
benwells
2011/05/25 08:07:19
Done.
|
| + enum DefaultWebClientUIState { |
| STATE_PROCESSING, |
| STATE_NOT_DEFAULT, |
| STATE_IS_DEFAULT, |
| STATE_UNKNOWN |
| }; |
| - class DefaultBrowserObserver { |
| + class DefaultWebClientObserver { |
| public: |
| // Updates the UI state to reflect the current default browser state. |
| - virtual void SetDefaultBrowserUIState(DefaultBrowserUIState state) = 0; |
| - virtual ~DefaultBrowserObserver() {} |
| + virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; |
| + virtual ~DefaultWebClientObserver() {} |
|
Mark Mentovai
2011/05/24 16:28:53
Nit (to fix the existing code): within public, pri
benwells
2011/05/25 08:07:19
Done.
|
| }; |
| - // A helper object that handles checking if Chrome is the default browser on |
| - // Windows and also setting it as the default browser. These operations are |
| - // performed asynchronously on the file thread since registry access is |
| - // involved and this can be slow. |
| - // |
| - class DefaultBrowserWorker |
| - : public base::RefCountedThreadSafe<DefaultBrowserWorker> { |
| + |
| + // Helper objects that handle checking if Chrome is the default browser |
| + // or application for a url protocol on Windows and Linux, and also setting |
| + // 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. |
| + class DefaultWebClientWorker |
| + : public base::RefCountedThreadSafe<DefaultWebClientWorker> { |
| public: |
| - explicit DefaultBrowserWorker(DefaultBrowserObserver* observer); |
| + explicit DefaultWebClientWorker(DefaultWebClientObserver* observer); |
| - // Checks if Chrome is the default browser. |
| - void StartCheckDefaultBrowser(); |
| + // Checks to see if Chrome is the default web client application. |
|
Mark Mentovai
2011/05/24 16:28:53
For this and the next “Start” call, the header com
benwells
2011/05/25 08:07:19
Done.
|
| + void StartCheckIsDefault(); |
| - // Sets Chrome as the default browser. |
| - void StartSetAsDefaultBrowser(); |
| + // Sets Chrome as the default web client application. |
| + void StartSetAsDefault(); |
| // Called to notify the worker that the view is gone. |
| void ObserverDestroyed(); |
| + protected: |
| + friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; |
| + |
| + virtual ~DefaultWebClientWorker() {} |
| + |
| private: |
| - friend class base::RefCountedThreadSafe<DefaultBrowserWorker>; |
| + // Function that performs the check. |
| + virtual DefaultWebClientState CheckIsDefault() = 0; |
| - virtual ~DefaultBrowserWorker() {} |
| + // Function that sets Chrome as the default web client. |
| + virtual void SetAsDefault() = 0; |
| + |
| + // Function that handles performing the check on the file thread. This |
| + // function is posted as a task onto the file thread, where it performs |
| + // the check and sends the result back to the UI thread. |
|
Mark Mentovai
2011/05/24 16:28:53
Instead of “sends the result back to the UI thread
benwells
2011/05/25 08:07:19
Done.
|
| + void ExecuteCheckIsDefault(); |
| + |
| + // Function that handles setting Chrome as the default web client on the |
| + // file thread. This function is posted as a task onto the file thread. |
| + // Once it is finished it posts a task back to the UI thread to complete |
|
Mark Mentovai
2011/05/24 16:28:53
Same: say what will be called on the UI thread.
benwells
2011/05/25 08:07:19
Done.
|
| + // the job. |
| + void ExecuteSetAsDefault(); |
| + |
| + // Communicate results to the observer. This function is posted as a task |
| + // back to the UI thread from the file thread. |
|
Mark Mentovai
2011/05/24 16:28:53
And again, for this and the next one, it’s more us
benwells
2011/05/25 08:07:19
Done.
|
| + void CompleteCheckIsDefault(DefaultWebClientState state); |
| + |
| + // When the action to set Chrome as the default has completed this function |
| + // is posted as a task back to the UI thread. If an observer is present |
| + // it will execute a check, which will report the status of Chrome as the |
| + // default web client back to the observer. |
| + void CompleteSetAsDefault(); |
| + |
| + // Updates the UI in our associated view with the current default web |
| + // client state. |
| + void UpdateUI(DefaultWebClientState state); |
| + |
| + DefaultWebClientObserver* observer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); |
| + }; |
| - // Functions that track the process of checking if Chrome is the default |
| - // browser. |ExecuteCheckDefaultBrowser| checks the registry on the file |
| - // thread. |CompleteCheckDefaultBrowser| notifies the view to update on the |
| - // UI thread. |
| - void ExecuteCheckDefaultBrowser(); |
| - void CompleteCheckDefaultBrowser(DefaultBrowserState state); |
| + // Worker for checking and setting the default browser. |
| + class DefaultBrowserWorker : public DefaultWebClientWorker { |
| + public: |
| + explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); |
| - // Functions that track the process of setting Chrome as the default |
| - // browser. |ExecuteSetAsDefaultBrowser| updates the registry on the file |
| - // thread. |CompleteSetAsDefaultBrowser| notifies the view to update on the |
| - // UI thread. |
| - void ExecuteSetAsDefaultBrowser(); |
| - void CompleteSetAsDefaultBrowser(); |
| + private: |
| + virtual ~DefaultBrowserWorker() {} |
| - // Updates the UI in our associated view with the current default browser |
| - // state. |
| - void UpdateUI(DefaultBrowserState state); |
| + // Check if Chrome is the default browser. |
| + virtual DefaultWebClientState CheckIsDefault(); |
| - DefaultBrowserObserver* observer_; |
| + // Set Chrome as the default browser. |
| + virtual void SetAsDefault(); |
| DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); |
| }; |
| + |
| + // Worker for checking and setting the default client application |
| + // for a given protocol. A different worker instance is needed for each |
| + // protocol you are interested in, so to check or set the default for |
| + // multiple protocols you should use multiple worker objects. |
| + class DefaultProtocolClientWorker : public DefaultWebClientWorker { |
| + public: |
| + DefaultProtocolClientWorker(DefaultWebClientObserver* observer, |
| + const std::string& protocol); |
| + |
| + private: |
| + virtual ~DefaultProtocolClientWorker() {} |
| + |
| + // Check is Chrome is the default handler for this protocol. |
| + virtual DefaultWebClientState CheckIsDefault(); |
| + |
| + // Set Chrome as the default handler for this protocol. |
| + virtual void SetAsDefault(); |
| + |
| + std::string protocol_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); |
| + }; |
| }; |
| #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ |