#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;
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
} // namespace download_extension_errors
+namespace extensions {
class DownloadedByExtension : public base::SupportsUserData::Data {
public:
public:
DECLARE_EXTENSION_FUNCTION("downloads.download", DOWNLOADS_DOWNLOAD)
DownloadsDownloadFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunAsync() OVERRIDE;
protected:
virtual ~DownloadsDownloadFunction();
public:
DECLARE_EXTENSION_FUNCTION("downloads.search", DOWNLOADS_SEARCH)
DownloadsSearchFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunSync() OVERRIDE;
protected:
virtual ~DownloadsSearchFunction();
public:
DECLARE_EXTENSION_FUNCTION("downloads.pause", DOWNLOADS_PAUSE)
DownloadsPauseFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunSync() OVERRIDE;
protected:
virtual ~DownloadsPauseFunction();
public:
DECLARE_EXTENSION_FUNCTION("downloads.resume", DOWNLOADS_RESUME)
DownloadsResumeFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunSync() OVERRIDE;
protected:
virtual ~DownloadsResumeFunction();
public:
DECLARE_EXTENSION_FUNCTION("downloads.cancel", DOWNLOADS_CANCEL)
DownloadsCancelFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunSync() OVERRIDE;
protected:
virtual ~DownloadsCancelFunction();
public:
DECLARE_EXTENSION_FUNCTION("downloads.erase", DOWNLOADS_ERASE)
DownloadsEraseFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunSync() OVERRIDE;
protected:
virtual ~DownloadsEraseFunction();
public:
DECLARE_EXTENSION_FUNCTION("downloads.removeFile", DOWNLOADS_REMOVEFILE)
DownloadsRemoveFileFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunAsync() OVERRIDE;
protected:
virtual ~DownloadsRemoveFileFunction();
DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER)
DownloadsAcceptDangerFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunAsync() OVERRIDE;
protected:
virtual ~DownloadsAcceptDangerFunction();
public:
DECLARE_EXTENSION_FUNCTION("downloads.show", DOWNLOADS_SHOW)
DownloadsShowFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunAsync() OVERRIDE;
protected:
virtual ~DownloadsShowFunction();
DECLARE_EXTENSION_FUNCTION(
"downloads.showDefaultFolder", DOWNLOADS_SHOWDEFAULTFOLDER)
DownloadsShowDefaultFolderFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunAsync() OVERRIDE;
protected:
virtual ~DownloadsShowDefaultFolderFunction();
public:
DECLARE_EXTENSION_FUNCTION("downloads.open", DOWNLOADS_OPEN)
DownloadsOpenFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunSync() OVERRIDE;
protected:
virtual ~DownloadsOpenFunction();
DECLARE_EXTENSION_FUNCTION("downloads.setShelfEnabled",
DOWNLOADS_SETSHELFENABLED)
DownloadsSetShelfEnabledFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunSync() OVERRIDE;
protected:
virtual ~DownloadsSetShelfEnabledFunction();
public:
DECLARE_EXTENSION_FUNCTION("downloads.drag", DOWNLOADS_DRAG)
DownloadsDragFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunAsync() OVERRIDE;
protected:
virtual ~DownloadsDragFunction();
public:
DECLARE_EXTENSION_FUNCTION("downloads.getFileIcon", DOWNLOADS_GETFILEICON)
DownloadsGetFileIconFunction();
- virtual bool RunImpl() OVERRIDE;
+ virtual bool RunAsync() OVERRIDE;
void SetIconExtractorForTesting(DownloadFileIconExtractor* extractor);
protected:
// 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(
const base::Closure& no_change,
const FilenameChangedCallback& change);
- // AllDownloadItemNotifier::Observer
+ // AllDownloadItemNotifier::Observer.
virtual void OnDownloadCreated(
content::DownloadManager* manager,
content::DownloadItem* download_item) OVERRIDE;
content::DownloadManager* manager,
content::DownloadItem* download_item) OVERRIDE;
- // extensions::EventRouter::Observer
+ // extensions::EventRouter::Observer.
virtual void OnListenerRemoved(
const extensions::EventListenerInfo& details) OVERRIDE;
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_