Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / webstore_standalone_installer.h
index e102944..07d2af0 100644 (file)
 #include "base/callback.h"
 #include "base/memory/ref_counted.h"
 #include "base/memory/scoped_ptr.h"
+#include "chrome/browser/extensions/active_install_data.h"
 #include "chrome/browser/extensions/extension_install_prompt.h"
 #include "chrome/browser/extensions/webstore_data_fetcher_delegate.h"
 #include "chrome/browser/extensions/webstore_install_helper.h"
 #include "chrome/browser/extensions/webstore_installer.h"
+#include "chrome/common/extensions/webstore_install_result.h"
 #include "net/url_request/url_fetcher_delegate.h"
 #include "third_party/skia/include/core/SkBitmap.h"
 
@@ -50,7 +52,9 @@ class WebstoreStandaloneInstaller
   // A callback for when the install process completes, successfully or not. If
   // there was a failure, |success| will be false and |error| may contain a
   // developer-readable error message about why it failed.
-  typedef base::Callback<void(bool success, const std::string& error)> Callback;
+  typedef base::Callback<void(bool success,
+                              const std::string& error,
+                              webstore_install::Result result)> Callback;
 
   WebstoreStandaloneInstaller(const std::string& webstore_item_id,
                               Profile* profile,
@@ -60,11 +64,32 @@ class WebstoreStandaloneInstaller
  protected:
   virtual ~WebstoreStandaloneInstaller();
 
+  // Called when the install should be aborted. The callback is cleared.
   void AbortInstall();
-  void CompleteInstall(const std::string& error);
+
+  // Checks InstallTracker and returns true if the same extension is not
+  // currently being installed. Registers this install with the InstallTracker.
+  bool EnsureUniqueInstall(webstore_install::Result* reason,
+                           std::string* error);
+
+  // Called when the install is complete.
+  virtual void CompleteInstall(webstore_install::Result result,
+                               const std::string& error);
+
+  // Called when the installer should proceed to prompt the user.
+  void ProceedWithInstallPrompt();
+
+  // Lazily creates a dummy extension for display from the parsed manifest. This
+  // is safe to call from OnManifestParsed() onwards. The manifest may be
+  // invalid, thus the caller must check that the return value is not NULL.
+  scoped_refptr<const Extension> GetLocalizedExtensionForDisplay();
 
   // Template Method's hooks to be implemented by subclasses.
 
+  // Called when this install is about to be registered with the InstallTracker.
+  // Allows subclasses to set properties of the install data.
+  virtual void InitInstallData(ActiveInstallData* install_data) const;
+
   // Called at certain check points of the workflow to decide whether it makes
   // sense to proceed with installation. A requestor can be a website that
   // initiated an inline installation, or a command line option.
@@ -90,8 +115,8 @@ class WebstoreStandaloneInstaller
 
   // Should return an installation prompt with desired properties or NULL if
   // no prompt should be shown.
-  virtual scoped_ptr<ExtensionInstallPrompt::Prompt>
-      CreateInstallPrompt() const = 0;
+  virtual scoped_refptr<ExtensionInstallPrompt::Prompt> CreateInstallPrompt()
+      const = 0;
 
   // Perform all necessary checks to make sure inline install is permitted,
   // e.g. in the extension's properties in the store. The implementation may
@@ -107,10 +132,20 @@ class WebstoreStandaloneInstaller
       const base::DictionaryValue& webstore_data,
       std::string* error) const = 0;
 
+  // Will be called after the extension's manifest has been successfully parsed.
+  // Subclasses can perform asynchronous checks at this point and call
+  // ProceedWithInstallPrompt() to proceed with the install or otherwise call
+  // CompleteInstall() with an error code. The default implementation calls
+  // ProceedWithInstallPrompt().
+  virtual void OnManifestParsed();
+
   // Returns an install UI to be shown. By default, this returns an install UI
   // that is a transient child of the host window for GetWebContents().
   virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI();
 
+  // Create an approval to pass installation parameters to the CrxInstaller.
+  virtual scoped_ptr<WebstoreInstaller::Approval> CreateApproval() const;
+
   // Accessors to be used by subclasses.
   bool show_user_count() const { return show_user_count_; }
   const std::string& localized_user_count() const {
@@ -126,7 +161,10 @@ class WebstoreStandaloneInstaller
   }
   Profile* profile() const { return profile_; }
   const std::string& id() const { return id_; }
-  const DictionaryValue* manifest() const { return manifest_.get(); }
+  const base::DictionaryValue* manifest() const { return manifest_.get(); }
+  const Extension* localized_extension_for_display() const {
+    return localized_extension_for_display_.get();
+  }
 
  private:
   friend class base::RefCountedThreadSafe<WebstoreStandaloneInstaller>;
@@ -149,7 +187,7 @@ class WebstoreStandaloneInstaller
   virtual void OnWebstoreRequestFailure() OVERRIDE;
 
   virtual void OnWebstoreResponseParseSuccess(
-      base::DictionaryValue* webstore_data) OVERRIDE;
+      scoped_ptr<base::DictionaryValue> webstore_data) OVERRIDE;
 
   virtual void OnWebstoreResponseParseFailure(
       const std::string& error) OVERRIDE;
@@ -176,6 +214,7 @@ class WebstoreStandaloneInstaller
       WebstoreInstaller::FailureReason reason) OVERRIDE;
 
   void ShowInstallUI();
+  void OnWebStoreDataFetcherDone();
 
   // Input configuration.
   std::string id_;
@@ -185,7 +224,7 @@ class WebstoreStandaloneInstaller
 
   // Installation dialog and its underlying prompt.
   scoped_ptr<ExtensionInstallPrompt> install_ui_;
-  scoped_ptr<ExtensionInstallPrompt::Prompt> install_prompt_;
+  scoped_refptr<ExtensionInstallPrompt::Prompt> install_prompt_;
 
   // For fetching webstore JSON data.
   scoped_ptr<WebstoreDataFetcher> webstore_data_fetcher_;
@@ -197,10 +236,13 @@ class WebstoreStandaloneInstaller
   std::string localized_user_count_;
   double average_rating_;
   int rating_count_;
-  scoped_ptr<DictionaryValue> webstore_data_;
-  scoped_ptr<DictionaryValue> manifest_;
+  scoped_ptr<base::DictionaryValue> webstore_data_;
+  scoped_ptr<base::DictionaryValue> manifest_;
   SkBitmap icon_;
 
+  // Active install registered with the InstallTracker.
+  scoped_ptr<ScopedActiveInstall> scoped_active_install_;
+
   // Created by ShowInstallUI() when a prompt is shown (if
   // the implementor returns a non-NULL in CreateInstallPrompt()).
   scoped_refptr<Extension> localized_extension_for_display_;