Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / downloads / downloads_api.h
index acf9ac8..b24a938 100644 (file)
@@ -9,20 +9,16 @@
 #include <string>
 
 #include "base/files/file_path.h"
-#include "base/memory/singleton.h"
-#include "base/strings/string16.h"
-#include "base/values.h"
+#include "base/scoped_observer.h"
 #include "chrome/browser/download/all_download_item_notifier.h"
 #include "chrome/browser/download/download_danger_prompt.h"
 #include "chrome/browser/download/download_path_reservation_tracker.h"
 #include "chrome/browser/extensions/chrome_extension_function.h"
 #include "chrome/browser/extensions/extension_warning_set.h"
 #include "chrome/common/extensions/api/downloads.h"
-#include "content/public/browser/download_item.h"
 #include "content/public/browser/download_manager.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
 #include "extensions/browser/event_router.h"
+#include "extensions/browser/extension_registry_observer.h"
 
 class DownloadFileIconExtractor;
 class DownloadQuery;
@@ -32,6 +28,10 @@ class ResourceContext;
 class ResourceDispatcherHost;
 }
 
+namespace extensions {
+class ExtensionRegistry;
+}
+
 // Functions in the chrome.downloads namespace facilitate
 // controlling downloads from extensions. See the full API doc at
 // http://goo.gl/6hO1n
@@ -66,6 +66,7 @@ extern const char kUserGesture[];
 
 }  // namespace download_extension_errors
 
+namespace extensions {
 
 class DownloadedByExtension : public base::SupportsUserData::Data {
  public:
@@ -91,7 +92,7 @@ class DownloadsDownloadFunction : public ChromeAsyncExtensionFunction {
  public:
   DECLARE_EXTENSION_FUNCTION("downloads.download", DOWNLOADS_DOWNLOAD)
   DownloadsDownloadFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunAsync() OVERRIDE;
 
  protected:
   virtual ~DownloadsDownloadFunction();
@@ -110,7 +111,7 @@ class DownloadsSearchFunction : public ChromeSyncExtensionFunction {
  public:
   DECLARE_EXTENSION_FUNCTION("downloads.search", DOWNLOADS_SEARCH)
   DownloadsSearchFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunSync() OVERRIDE;
 
  protected:
   virtual ~DownloadsSearchFunction();
@@ -123,7 +124,7 @@ class DownloadsPauseFunction : public ChromeSyncExtensionFunction {
  public:
   DECLARE_EXTENSION_FUNCTION("downloads.pause", DOWNLOADS_PAUSE)
   DownloadsPauseFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunSync() OVERRIDE;
 
  protected:
   virtual ~DownloadsPauseFunction();
@@ -136,7 +137,7 @@ class DownloadsResumeFunction : public ChromeSyncExtensionFunction {
  public:
   DECLARE_EXTENSION_FUNCTION("downloads.resume", DOWNLOADS_RESUME)
   DownloadsResumeFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunSync() OVERRIDE;
 
  protected:
   virtual ~DownloadsResumeFunction();
@@ -149,7 +150,7 @@ class DownloadsCancelFunction : public ChromeSyncExtensionFunction {
  public:
   DECLARE_EXTENSION_FUNCTION("downloads.cancel", DOWNLOADS_CANCEL)
   DownloadsCancelFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunSync() OVERRIDE;
 
  protected:
   virtual ~DownloadsCancelFunction();
@@ -162,7 +163,7 @@ class DownloadsEraseFunction : public ChromeSyncExtensionFunction {
  public:
   DECLARE_EXTENSION_FUNCTION("downloads.erase", DOWNLOADS_ERASE)
   DownloadsEraseFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunSync() OVERRIDE;
 
  protected:
   virtual ~DownloadsEraseFunction();
@@ -175,7 +176,7 @@ class DownloadsRemoveFileFunction : public ChromeAsyncExtensionFunction {
  public:
   DECLARE_EXTENSION_FUNCTION("downloads.removeFile", DOWNLOADS_REMOVEFILE)
   DownloadsRemoveFileFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunAsync() OVERRIDE;
 
  protected:
   virtual ~DownloadsRemoveFileFunction();
@@ -196,7 +197,7 @@ class DownloadsAcceptDangerFunction : public ChromeAsyncExtensionFunction {
 
   DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER)
   DownloadsAcceptDangerFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunAsync() OVERRIDE;
 
  protected:
   virtual ~DownloadsAcceptDangerFunction();
@@ -214,7 +215,7 @@ class DownloadsShowFunction : public ChromeAsyncExtensionFunction {
  public:
   DECLARE_EXTENSION_FUNCTION("downloads.show", DOWNLOADS_SHOW)
   DownloadsShowFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunAsync() OVERRIDE;
 
  protected:
   virtual ~DownloadsShowFunction();
@@ -228,7 +229,7 @@ class DownloadsShowDefaultFolderFunction : public ChromeAsyncExtensionFunction {
   DECLARE_EXTENSION_FUNCTION(
       "downloads.showDefaultFolder", DOWNLOADS_SHOWDEFAULTFOLDER)
   DownloadsShowDefaultFolderFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunAsync() OVERRIDE;
 
  protected:
   virtual ~DownloadsShowDefaultFolderFunction();
@@ -241,7 +242,7 @@ class DownloadsOpenFunction : public ChromeSyncExtensionFunction {
  public:
   DECLARE_EXTENSION_FUNCTION("downloads.open", DOWNLOADS_OPEN)
   DownloadsOpenFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunSync() OVERRIDE;
 
  protected:
   virtual ~DownloadsOpenFunction();
@@ -255,7 +256,7 @@ class DownloadsSetShelfEnabledFunction : public ChromeSyncExtensionFunction {
   DECLARE_EXTENSION_FUNCTION("downloads.setShelfEnabled",
                              DOWNLOADS_SETSHELFENABLED)
   DownloadsSetShelfEnabledFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunSync() OVERRIDE;
 
  protected:
   virtual ~DownloadsSetShelfEnabledFunction();
@@ -268,7 +269,7 @@ class DownloadsDragFunction : public ChromeAsyncExtensionFunction {
  public:
   DECLARE_EXTENSION_FUNCTION("downloads.drag", DOWNLOADS_DRAG)
   DownloadsDragFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunAsync() OVERRIDE;
 
  protected:
   virtual ~DownloadsDragFunction();
@@ -281,7 +282,7 @@ class DownloadsGetFileIconFunction : public ChromeAsyncExtensionFunction {
  public:
   DECLARE_EXTENSION_FUNCTION("downloads.getFileIcon", DOWNLOADS_GETFILEICON)
   DownloadsGetFileIconFunction();
-  virtual bool RunImpl() OVERRIDE;
+  virtual bool RunAsync() OVERRIDE;
   void SetIconExtractorForTesting(DownloadFileIconExtractor* extractor);
 
  protected:
@@ -296,15 +297,18 @@ class DownloadsGetFileIconFunction : public ChromeAsyncExtensionFunction {
 
 // Observes a single DownloadManager and many DownloadItems and dispatches
 // onCreated and onErased events.
-class ExtensionDownloadsEventRouter : public extensions::EventRouter::Observer,
-                                      public content::NotificationObserver,
-                                      public AllDownloadItemNotifier::Observer {
+class ExtensionDownloadsEventRouter
+    : public extensions::EventRouter::Observer,
+      public extensions::ExtensionRegistryObserver,
+      public AllDownloadItemNotifier::Observer {
  public:
   typedef base::Callback<void(
       const base::FilePath& changed_filename,
       DownloadPathReservationTracker::FilenameConflictAction)>
     FilenameChangedCallback;
 
+  static void SetDetermineFilenameTimeoutSecondsForTesting(int s);
+
   // The logic for how to handle conflicting filename suggestions from multiple
   // extensions is split out here for testing.
   static void DetermineFilenameInternal(
@@ -355,7 +359,7 @@ class ExtensionDownloadsEventRouter : public extensions::EventRouter::Observer,
       const base::Closure& no_change,
       const FilenameChangedCallback& change);
 
-  // AllDownloadItemNotifier::Observer
+  // AllDownloadItemNotifier::Observer.
   virtual void OnDownloadCreated(
       content::DownloadManager* manager,
       content::DownloadItem* download_item) OVERRIDE;
@@ -366,7 +370,7 @@ class ExtensionDownloadsEventRouter : public extensions::EventRouter::Observer,
       content::DownloadManager* manager,
       content::DownloadItem* download_item) OVERRIDE;
 
-  // extensions::EventRouter::Observer
+  // extensions::EventRouter::Observer.
   virtual void OnListenerRemoved(
       const extensions::EventListenerInfo& details) OVERRIDE;
 
@@ -383,17 +387,24 @@ class ExtensionDownloadsEventRouter : public extensions::EventRouter::Observer,
       const extensions::Event::WillDispatchCallback& will_dispatch_callback,
       base::Value* json_arg);
 
-  // content::NotificationObserver
-  virtual void Observe(int type,
-                       const content::NotificationSource& source,
-                       const content::NotificationDetails& details) OVERRIDE;
+  // extensions::ExtensionRegistryObserver.
+  virtual void OnExtensionUnloaded(
+      content::BrowserContext* browser_context,
+      const extensions::Extension* extension,
+      extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE;
 
   Profile* profile_;
   AllDownloadItemNotifier notifier_;
   std::set<const extensions::Extension*> shelf_disabling_extensions_;
-  content::NotificationRegistrar registrar_;
+
+  // Listen to extension unloaded notifications.
+  ScopedObserver<extensions::ExtensionRegistry,
+                 extensions::ExtensionRegistryObserver>
+      extension_registry_observer_;
 
   DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter);
 };
 
+}  // namespace extensions
+
 #endif  // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_