Chromium Code Reviews| 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 dafd4d4e92d9d513790b678cfc5a4a7febd81491..dbaaac08c10074aa26accdd7a6c9c91549a404d0 100644 |
| --- a/chrome/browser/extensions/api/downloads/downloads_api.h |
| +++ b/chrome/browser/extensions/api/downloads/downloads_api.h |
| @@ -128,19 +128,6 @@ class DownloadsEraseFunction : public SyncExtensionFunction { |
| DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); |
| }; |
| -class DownloadsSetDestinationFunction : public AsyncExtensionFunction { |
| - public: |
| - DECLARE_EXTENSION_FUNCTION_NAME("downloads.setDestination"); |
| - DownloadsSetDestinationFunction(); |
| - virtual bool RunImpl() OVERRIDE; |
| - |
| - protected: |
| - virtual ~DownloadsSetDestinationFunction(); |
| - |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(DownloadsSetDestinationFunction); |
| -}; |
| - |
| class DownloadsAcceptDangerFunction : public AsyncExtensionFunction { |
| public: |
| DECLARE_EXTENSION_FUNCTION_NAME("downloads.acceptDanger"); |
| @@ -212,13 +199,50 @@ 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; |
| + |
| + static bool AddFilenameDeterminer( |
|
battre
2013/01/11 14:29:37
These functions need descriptions. What are Filena
benjhayden
2013/01/11 21:21:27
Done.
|
| + Profile* profile, |
| + bool include_incognito, |
| + const std::string& ext_id, |
| + const std::string& determiner_id); |
| + |
| + static bool RemoveFilenameDeterminer( |
| + Profile* profile, |
| + bool include_incognito, |
| + const std::string& ext_id, |
| + const std::string& determiner_id); |
| + |
| + static bool DetermineFilename( |
| + Profile* profile, |
| + bool include_incognito, |
| + const std::string& ext_id, |
| + const std::string& determiner_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 OnDownloadFilenameDetermined( |
| + content::DownloadItem* item, |
| + const FilePath& suggested_path, |
| + const base::Closure& no_change, |
| + const FilenameChangedCallback& change); |
| + |
| // AllDownloadItemNotifier::Observer interface |
| virtual void OnDownloadCreated( |
| content::DownloadManager* manager, |
| @@ -238,10 +262,27 @@ class ExtensionDownloadsEventRouter |
| private: |
| void DispatchEvent(const char* event_name, 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_; |
| + // Each key in this map is a determiner id as returned by |
| + // GetFilenameDeterminerId. Each string in the set values is an extension id |
| + // that is listening to the subEvent named |
| + // "chrome.downloads.onDeterminingFilename/$DETERMINER_ID". When |
| + // onDeterminingFilename is dispatched for a DownloadItem, that item's EDERD |
| + // UserData is given the set of strings of the form |
| + // "$EXTENSION_ID-$DETERMINER_ID" so that it can know when all determiners |
| + // have reported. |
| + typedef std::set<std::string> ExtensionIdSet; |
|
vabr (Chromium)
2013/01/11 12:43:40
According to http://google-styleguide.googlecode.c
benjhayden
2013/01/11 21:21:27
Done.
|
| + typedef base::hash_map<std::string, ExtensionIdSet> DeterminerMap; |
|
vabr (Chromium)
2013/01/11 12:43:40
The lint says: "Add #include for hash_map<>"
(I u
benjhayden
2013/01/11 21:21:27
I added base/hash_tables.h, but got a compiler war
vabr (Chromium)
2013/01/15 08:19:22
That sounds right, base/hash_tables.h includes <ha
|
| + DeterminerMap filename_determiners_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
| }; |