Chromium Code Reviews| Index: chrome/browser/apps/ephemeral_app_launcher.h |
| diff --git a/chrome/browser/apps/ephemeral_app_launcher.h b/chrome/browser/apps/ephemeral_app_launcher.h |
| index 92a82a5fb1800b80be838fd638fc0b0c0b2e35f8..4499313bd6a205e0d387cbcdd3ea45cc2b8874fa 100644 |
| --- a/chrome/browser/apps/ephemeral_app_launcher.h |
| +++ b/chrome/browser/apps/ephemeral_app_launcher.h |
| @@ -6,8 +6,10 @@ |
| #define CHROME_BROWSER_APPS_EPHEMERAL_APP_LAUNCHER_H_ |
| #include <string> |
| +#include <vector> |
| #include "base/basictypes.h" |
| +#include "base/callback.h" |
| #include "base/scoped_observer.h" |
| #include "chrome/browser/extensions/webstore_standalone_installer.h" |
| #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" |
| @@ -22,6 +24,7 @@ class WebContents; |
| namespace extensions { |
| class Extension; |
| +class ExtensionInstallChecker; |
| class ExtensionRegistry; |
| } |
| @@ -32,38 +35,98 @@ class EphemeralAppLauncher : public extensions::WebstoreStandaloneInstaller, |
| public content::WebContentsObserver, |
| public ExtensionEnableFlowDelegate { |
| public: |
| - typedef WebstoreStandaloneInstaller::Callback Callback; |
| + // All possible result codes returned in the LaunchCallback. |
| + enum LaunchResult { |
| + // Successful launch. |
| + LAUNCH_SUCCESS, |
| + // Unknown or unspecified error. |
| + LAUNCH_UNKNOWN_ERROR, |
| + // Invalid extension ID for the app. |
| + LAUNCH_INVALID_ID, |
| + // An error occurred while parsing the app manifest. |
| + LAUNCH_INVALID_MANIFEST, |
| + // An error occurred while attempting to install the app ephemerally. |
| + LAUNCH_INSTALL_ERROR, |
| + // The user cancelled the launch. |
| + LAUNCH_USER_CANCELLED, |
| + // The feature is not available. |
| + LAUNCH_FEATURE_DISABLED, |
| + // The feature is not supported for the extension type. |
| + LAUNCH_UNSUPPORTED_EXTENSION_TYPE, |
| + // The app is blacklisted. |
| + LAUNCH_BLACKLISTED, |
| + // Unsatisfied dependencies (such as shared modules) or requirements. |
| + LAUNCH_MISSING_DEPENDENCIES, |
| + // The app is blocked by management policies. |
| + LAUNCH_BLOCKED_BY_POLICY |
|
asargent_no_longer_on_chrome
2014/06/18 20:25:10
Hmm, this enum seems to have a lot of overlap with
tmdiep
2014/06/18 22:28:34
I went back and forth with this issue a fair bit.
asargent_no_longer_on_chrome
2014/06/19 00:16:43
I think it might be ok to have a single enum somew
|
| + }; |
| + |
| + typedef base::Callback<void(LaunchResult result, const std::string& error)> |
| + LaunchCallback; |
| + |
| + // Returns true if launching ephemeral apps is enabled. |
| + static bool IsFeatureEnabled(); |
| // Create for the app launcher. |
| static scoped_refptr<EphemeralAppLauncher> CreateForLauncher( |
| const std::string& webstore_item_id, |
| Profile* profile, |
| gfx::NativeWindow parent_window, |
| - const Callback& callback); |
| + const LaunchCallback& callback); |
| - // Create for a link within a browser tab. |
| - static scoped_refptr<EphemeralAppLauncher> CreateForLink( |
| + // Create for a web contents. |
| + static scoped_refptr<EphemeralAppLauncher> CreateForWebContents( |
| const std::string& webstore_item_id, |
| - content::WebContents* web_contents); |
| + content::WebContents* web_contents, |
| + const LaunchCallback& callback); |
| // Initiate app launch. |
| void Start(); |
| - private: |
| - friend class base::RefCountedThreadSafe<EphemeralAppLauncher>; |
| - |
| + protected: |
| EphemeralAppLauncher(const std::string& webstore_item_id, |
| Profile* profile, |
| gfx::NativeWindow parent_window, |
| - const Callback& callback); |
| + const LaunchCallback& callback); |
| EphemeralAppLauncher(const std::string& webstore_item_id, |
| content::WebContents* web_contents, |
| - const Callback& callback); |
| + const LaunchCallback& callback); |
| virtual ~EphemeralAppLauncher(); |
| + // Returns true if an app that is already installed in extension system can |
| + // be launched. |
| + bool CanLaunchInstalledApp(const extensions::Extension* extension, |
| + LaunchResult* reason, |
| + std::string* error); |
| + |
| + // Initiates the enable flow for an app before it can be launched. |
| + void EnableInstalledApp(const extensions::Extension* extension); |
| + |
| + // After the ephemeral installation or enable flow are complete, attempts to |
| + // launch the app and notify the client of the outcome. |
| + void MaybeLaunchApp(); |
| + |
| + // Launches an app. At this point, it is assumed that the app is enabled and |
| + // can be launched. |
| void LaunchApp(const extensions::Extension* extension) const; |
| + // Notifies the client of the launch outcome. |
| + void InvokeCallback(LaunchResult result, const std::string& error); |
| + |
| + // Aborts the ephemeral install and notifies the client of the outcome. |
| + void AbortLaunch(LaunchResult result, const std::string& error); |
| + |
| + // Creates an install checker. Allows tests to mock the install checker. |
| + virtual scoped_ptr<extensions::ExtensionInstallChecker> |
| + CreateInstallChecker(); |
| + |
| + // Determines whether the app can be installed ephemerally. |
| + void CheckEphemeralInstallPermitted(); |
| + |
| + // Install checker callback. |
| + void OnInstallChecked(int check_failures); |
| + |
| // WebstoreStandaloneInstaller implementation. |
| virtual bool CheckRequestorAlive() const OVERRIDE; |
| virtual const GURL& GetRequestorURL() const OVERRIDE; |
| @@ -78,13 +141,12 @@ class EphemeralAppLauncher : public extensions::WebstoreStandaloneInstaller, |
| virtual bool CheckRequestorPermitted( |
| const base::DictionaryValue& webstore_data, |
| std::string* error) const OVERRIDE; |
| - virtual bool CheckInstallValid( |
| - const base::DictionaryValue& manifest, |
| - std::string* error) OVERRIDE; |
| + virtual void OnManifestParsed() OVERRIDE; |
| virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() OVERRIDE; |
| virtual scoped_ptr<extensions::WebstoreInstaller::Approval> |
| CreateApproval() const OVERRIDE; |
| - virtual void CompleteInstall(const std::string& error) OVERRIDE; |
| + virtual void CompleteInstall(InstallResult result, |
| + const std::string& error) OVERRIDE; |
| // content::WebContentsObserver implementation. |
| virtual void WebContentsDestroyed() OVERRIDE; |
| @@ -93,14 +155,19 @@ class EphemeralAppLauncher : public extensions::WebstoreStandaloneInstaller, |
| virtual void ExtensionEnableFlowFinished() OVERRIDE; |
| virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; |
| + private: |
| + friend class base::RefCountedThreadSafe<EphemeralAppLauncher>; |
| + friend class EphemeralAppLauncherTest; |
| + |
| + LaunchCallback launch_callback_; |
| + |
| gfx::NativeWindow parent_window_; |
| scoped_ptr<content::WebContents> dummy_web_contents_; |
| - // Created in CheckInstallValid(). |
| - scoped_refptr<extensions::Extension> extension_; |
| - |
| scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; |
| + scoped_ptr<extensions::ExtensionInstallChecker> install_checker_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(EphemeralAppLauncher); |
| }; |