Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / updater / extension_updater.h
index 15319dd..29faf71 100644 (file)
 #include "base/gtest_prod_util.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/memory/weak_ptr.h"
+#include "base/scoped_observer.h"
 #include "base/time/time.h"
 #include "base/timer/timer.h"
+#include "chrome/browser/extensions/updater/extension_downloader.h"
 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h"
 #include "chrome/browser/extensions/updater/manifest_fetch_data.h"
 #include "content/public/browser/notification_observer.h"
 #include "content/public/browser/notification_registrar.h"
+#include "extensions/browser/extension_registry_observer.h"
 #include "url/gurl.h"
 
 class ExtensionServiceInterface;
 class PrefService;
 class Profile;
 
+namespace content {
+class BrowserContext;
+}
+
 namespace extensions {
 
 class ExtensionCache;
-class ExtensionDownloader;
 class ExtensionPrefs;
+class ExtensionRegistry;
 class ExtensionSet;
 class ExtensionUpdaterTest;
 
@@ -43,11 +50,13 @@ class ExtensionUpdaterTest;
 //                                                  extension_prefs,
 //                                                  pref_service,
 //                                                  profile,
-//                                                  update_frequency_secs);
+//                                                  update_frequency_secs,
+//                                                  downloader_factory);
 // updater->Start();
 // ....
 // updater->Stop();
 class ExtensionUpdater : public ExtensionDownloaderDelegate,
+                         public ExtensionRegistryObserver,
                          public content::NotificationObserver {
  public:
   typedef base::Closure FinishedCallback;
@@ -79,7 +88,8 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate,
                    PrefService* prefs,
                    Profile* profile,
                    int frequency_seconds,
-                   ExtensionCache* cache);
+                   ExtensionCache* cache,
+                   const ExtensionDownloader::Factory& downloader_factory);
 
   virtual ~ExtensionUpdater();
 
@@ -147,6 +157,10 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate,
 
   struct ThrottleInfo;
 
+  // Ensure that we have a valid ExtensionDownloader instance referenced by
+  // |downloader|.
+  void EnsureDownloaderCreated();
+
   // Computes when to schedule the first update check.
   base::TimeDelta DetermineFirstCheckDelay();
 
@@ -168,7 +182,7 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate,
   // Posted by CheckSoon().
   void DoCheckSoon();
 
-  // Implenentation of ExtensionDownloaderDelegate.
+  // Implementation of ExtensionDownloaderDelegate.
   virtual void OnExtensionDownloadFailed(
       const std::string& id,
       Error error,
@@ -184,6 +198,14 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate,
       const PingResult& ping,
       const std::set<int>& request_id) OVERRIDE;
 
+  // Implementation of ExtensionRegistryObserver.
+  virtual void OnExtensionWillBeInstalled(
+      content::BrowserContext* browser_context,
+      const Extension* extension,
+      bool is_update,
+      bool from_ephemeral,
+      const std::string& old_name) OVERRIDE;
+
   virtual bool GetPingDataForExtension(
       const std::string& id,
       ManifestFetchData::PingData* ping_data) OVERRIDE;
@@ -222,6 +244,10 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate,
   // Pointer back to the service that owns this ExtensionUpdater.
   ExtensionServiceInterface* service_;
 
+  // A closure passed into the ExtensionUpdater to teach it how to construct
+  // new ExtensionDownloader instances.
+  const ExtensionDownloader::Factory downloader_factory_;
+
   // Fetches the crx files for the extensions that have an available update.
   scoped_ptr<ExtensionDownloader> downloader_;
 
@@ -239,6 +265,9 @@ class ExtensionUpdater : public ExtensionDownloaderDelegate,
   // Observes CRX installs we initiate.
   content::NotificationRegistrar registrar_;
 
+  ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
+      extension_registry_observer_;
+
   // True when a CrxInstaller is doing an install.  Used in MaybeUpdateCrxFile()
   // to keep more than one install from running at once.
   bool crx_install_is_running_;