| Index: chrome/browser/extensions/api/downloads/downloads_api.h
|
| diff --git a/chrome/browser/extensions/api/downloads/downloads_api.h b/chrome/browser/extensions/api/downloads/downloads_api.h
|
| index 725d11453657adf94b85775b6c43d2ef5e939e49..d0a3297e5a21d727ebf4c1ad43a8b9b9ae1ac687 100644
|
| --- a/chrome/browser/extensions/api/downloads/downloads_api.h
|
| +++ b/chrome/browser/extensions/api/downloads/downloads_api.h
|
| @@ -8,6 +8,7 @@
|
| #include <string>
|
|
|
| #include "base/file_path.h"
|
| +#include "base/hash_tables.h"
|
| #include "base/memory/singleton.h"
|
| #include "base/string16.h"
|
| #include "base/values.h"
|
| @@ -126,20 +127,6 @@ class DownloadsEraseFunction : public SyncExtensionFunction {
|
| DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction);
|
| };
|
|
|
| -class DownloadsSetDestinationFunction : public AsyncExtensionFunction {
|
| - public:
|
| - DECLARE_EXTENSION_FUNCTION("downloads.setDestination",
|
| - DOWNLOADS_SETDESTINATION)
|
| - DownloadsSetDestinationFunction();
|
| - virtual bool RunImpl() OVERRIDE;
|
| -
|
| - protected:
|
| - virtual ~DownloadsSetDestinationFunction();
|
| -
|
| - private:
|
| - DISALLOW_COPY_AND_ASSIGN(DownloadsSetDestinationFunction);
|
| -};
|
| -
|
| class DownloadsAcceptDangerFunction : public AsyncExtensionFunction {
|
| public:
|
| DECLARE_EXTENSION_FUNCTION("downloads.acceptDanger", DOWNLOADS_ACCEPTDANGER)
|
| @@ -212,13 +199,61 @@ class DownloadsGetFileIconFunction : public AsyncExtensionFunction {
|
|
|
| // Observes a single DownloadManager and many DownloadItems and dispatches
|
| // onCreated and onErased events.
|
| -class ExtensionDownloadsEventRouter
|
| - : public AllDownloadItemNotifier::Observer {
|
| +class ExtensionDownloadsEventRouter : public content::NotificationObserver,
|
| + public AllDownloadItemNotifier::Observer {
|
| public:
|
| + typedef base::Callback<void(const FilePath& changed_filename,
|
| + bool overwrite)> FilenameChangedCallback;
|
| +
|
| + // An extension has added a listener for downloads.onDeterminingFilename. When
|
| + // that event is dispatched, the filename determination process will be
|
| + // blocked until all listeners return. Returns true on success, false
|
| + // otherwise.
|
| + static bool AddFilenameDeterminer(
|
| + Profile* profile,
|
| + const std::string& ext_id,
|
| + const std::string& sub_event_id);
|
| +
|
| + // An extension has removed a listener for downloads.onDeterminingFilename.
|
| + // The filename determination process should not wait for this listener,
|
| + // because it won't be run. Returns true on success, false otherwise.
|
| + static bool RemoveFilenameDeterminer(
|
| + Profile* profile,
|
| + const std::string& ext_id,
|
| + const std::string& sub_event_id);
|
| +
|
| + // A downloads.onDeterminingFilename listener has returned. If the extension
|
| + // wishes to override the download's filename, then |filename| will be
|
| + // non-empty. |filename| will be interpreted as a relative path, appended to
|
| + // the default downloads directory. If the extension wishes to overwrite any
|
| + // existing files, then |overwrite| will be true. Returns true on success,
|
| + // false otherwise.
|
| + static bool DetermineFilename(
|
| + Profile* profile,
|
| + bool include_incognito,
|
| + const std::string& ext_id,
|
| + const std::string& sub_event_id,
|
| + int download_id,
|
| + const FilePath& filename,
|
| + bool overwrite);
|
| +
|
| explicit ExtensionDownloadsEventRouter(
|
| Profile* profile, content::DownloadManager* manager);
|
| virtual ~ExtensionDownloadsEventRouter();
|
|
|
| + // Called by ChromeDownloadManagerDelegate during the filename determination
|
| + // process, allows extensions to change the item's target filename. If no
|
| + // extension wants to change the target filename, then |no_change| will be
|
| + // called and the filename determination process will continue as normal. If
|
| + // an extension wants to change the target filename, then |change| will be
|
| + // called with the new filename and a flag indicating whether the new file
|
| + // should overwrite any old files of the same name.
|
| + void OnDeterminingFilename(
|
| + content::DownloadItem* item,
|
| + const FilePath& suggested_path,
|
| + const base::Closure& no_change,
|
| + const FilenameChangedCallback& change);
|
| +
|
| // AllDownloadItemNotifier::Observer interface
|
| virtual void OnDownloadCreated(
|
| content::DownloadManager* manager,
|
| @@ -237,11 +272,46 @@ class ExtensionDownloadsEventRouter
|
| };
|
|
|
| private:
|
| - void DispatchEvent(const char* event_name, base::Value* json_arg);
|
| + // first: extension id; second: sub event id from GetFilenameDeterminerId
|
| + struct DeterminerId {
|
| + DeterminerId(
|
| + const std::string& ext_id,
|
| + const std::string& sub_id);
|
| + ~DeterminerId();
|
| +
|
| + std::string extension_id;
|
| + std::string sub_event_id;
|
| + base::Time installed;
|
| + };
|
| +
|
| + typedef std::vector<DeterminerId> DeterminerVector;
|
| +
|
| + static void GetInstallTime(
|
| + const std::string& ext_id,
|
| + ExtensionInfoMap* info_map,
|
| + base::Time* install_time);
|
| +
|
| + void DispatchEvent(
|
| + const char* event_name,
|
| + bool include_incognito,
|
| + base::Value* json_arg);
|
| +
|
| + virtual void Observe(
|
| + int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) OVERRIDE;
|
|
|
| Profile* profile_;
|
| + content::NotificationRegistrar registrar_;
|
| AllDownloadItemNotifier notifier_;
|
|
|
| + // AddFilenameDeterminer appends to this; RemoveFilenameDeterminer removes
|
| + // from this. When onDeterminingFilename is dispatched for a DownloadItem,
|
| + // that item's EDERD UserData is given a copy of this so that it can know when
|
| + // all determiners have reported. The last determiner added has the highest
|
| + // priority.
|
| + DeterminerVector determiners_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter);
|
| };
|
|
|
|
|