Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(789)

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api.h

Issue 11574006: Implement chrome.downloads.onDeterminingFilename() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r176065 Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DownloadsEraseFunction(); 121 DownloadsEraseFunction();
122 virtual bool RunImpl() OVERRIDE; 122 virtual bool RunImpl() OVERRIDE;
123 123
124 protected: 124 protected:
125 virtual ~DownloadsEraseFunction(); 125 virtual ~DownloadsEraseFunction();
126 126
127 private: 127 private:
128 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction); 128 DISALLOW_COPY_AND_ASSIGN(DownloadsEraseFunction);
129 }; 129 };
130 130
131 class DownloadsSetDestinationFunction : public AsyncExtensionFunction {
132 public:
133 DECLARE_EXTENSION_FUNCTION_NAME("downloads.setDestination");
134 DownloadsSetDestinationFunction();
135 virtual bool RunImpl() OVERRIDE;
136
137 protected:
138 virtual ~DownloadsSetDestinationFunction();
139
140 private:
141 DISALLOW_COPY_AND_ASSIGN(DownloadsSetDestinationFunction);
142 };
143
144 class DownloadsAcceptDangerFunction : public AsyncExtensionFunction { 131 class DownloadsAcceptDangerFunction : public AsyncExtensionFunction {
145 public: 132 public:
146 DECLARE_EXTENSION_FUNCTION_NAME("downloads.acceptDanger"); 133 DECLARE_EXTENSION_FUNCTION_NAME("downloads.acceptDanger");
147 DownloadsAcceptDangerFunction(); 134 DownloadsAcceptDangerFunction();
148 virtual bool RunImpl() OVERRIDE; 135 virtual bool RunImpl() OVERRIDE;
149 136
150 protected: 137 protected:
151 virtual ~DownloadsAcceptDangerFunction(); 138 virtual ~DownloadsAcceptDangerFunction();
152 139
153 private: 140 private:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 192
206 private: 193 private:
207 void OnIconURLExtracted(const std::string& url); 194 void OnIconURLExtracted(const std::string& url);
208 FilePath path_; 195 FilePath path_;
209 scoped_ptr<DownloadFileIconExtractor> icon_extractor_; 196 scoped_ptr<DownloadFileIconExtractor> icon_extractor_;
210 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction); 197 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction);
211 }; 198 };
212 199
213 // Observes a single DownloadManager and many DownloadItems and dispatches 200 // Observes a single DownloadManager and many DownloadItems and dispatches
214 // onCreated and onErased events. 201 // onCreated and onErased events.
215 class ExtensionDownloadsEventRouter 202 class ExtensionDownloadsEventRouter : public content::NotificationObserver,
216 : public AllDownloadItemNotifier::Observer { 203 public AllDownloadItemNotifier::Observer {
217 public: 204 public:
205 typedef base::Callback<void(const FilePath& changed_filename,
206 bool overwrite)> FilenameChangedCallback;
207
208 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.
209 Profile* profile,
210 bool include_incognito,
211 const std::string& ext_id,
212 const std::string& determiner_id);
213
214 static bool RemoveFilenameDeterminer(
215 Profile* profile,
216 bool include_incognito,
217 const std::string& ext_id,
218 const std::string& determiner_id);
219
220 static bool DetermineFilename(
221 Profile* profile,
222 bool include_incognito,
223 const std::string& ext_id,
224 const std::string& determiner_id,
225 int download_id,
226 const FilePath& filename,
227 bool overwrite);
228
218 explicit ExtensionDownloadsEventRouter( 229 explicit ExtensionDownloadsEventRouter(
219 Profile* profile, content::DownloadManager* manager); 230 Profile* profile, content::DownloadManager* manager);
220 virtual ~ExtensionDownloadsEventRouter(); 231 virtual ~ExtensionDownloadsEventRouter();
221 232
233 // Called by ChromeDownloadManagerDelegate during the filename determination
234 // process, allows extensions to change the item's target filename. If no
235 // extension wants to change the target filename, then |no_change| will be
236 // called and the filename determination process will continue as normal. If
237 // an extension wants to change the target filename, then |change| will be
238 // called with the new filename and a flag indicating whether the new file
239 // should overwrite any old files of the same name.
240 void OnDownloadFilenameDetermined(
241 content::DownloadItem* item,
242 const FilePath& suggested_path,
243 const base::Closure& no_change,
244 const FilenameChangedCallback& change);
245
222 // AllDownloadItemNotifier::Observer interface 246 // AllDownloadItemNotifier::Observer interface
223 virtual void OnDownloadCreated( 247 virtual void OnDownloadCreated(
224 content::DownloadManager* manager, 248 content::DownloadManager* manager,
225 content::DownloadItem* download_item) OVERRIDE; 249 content::DownloadItem* download_item) OVERRIDE;
226 virtual void OnDownloadUpdated( 250 virtual void OnDownloadUpdated(
227 content::DownloadManager* manager, 251 content::DownloadManager* manager,
228 content::DownloadItem* download_item) OVERRIDE; 252 content::DownloadItem* download_item) OVERRIDE;
229 virtual void OnDownloadRemoved( 253 virtual void OnDownloadRemoved(
230 content::DownloadManager* manager, 254 content::DownloadManager* manager,
231 content::DownloadItem* download_item) OVERRIDE; 255 content::DownloadItem* download_item) OVERRIDE;
232 256
233 // Used for testing. 257 // Used for testing.
234 struct DownloadsNotificationSource { 258 struct DownloadsNotificationSource {
235 std::string event_name; 259 std::string event_name;
236 Profile* profile; 260 Profile* profile;
237 }; 261 };
238 262
239 private: 263 private:
240 void DispatchEvent(const char* event_name, base::Value* json_arg); 264 void DispatchEvent(const char* event_name, base::Value* json_arg);
265 virtual void Observe(
266 int type,
267 const content::NotificationSource& source,
268 const content::NotificationDetails& details) OVERRIDE;
241 269
242 Profile* profile_; 270 Profile* profile_;
271 content::NotificationRegistrar registrar_;
243 AllDownloadItemNotifier notifier_; 272 AllDownloadItemNotifier notifier_;
244 273
274 // Each key in this map is a determiner id as returned by
275 // GetFilenameDeterminerId. Each string in the set values is an extension id
276 // that is listening to the subEvent named
277 // "chrome.downloads.onDeterminingFilename/$DETERMINER_ID". When
278 // onDeterminingFilename is dispatched for a DownloadItem, that item's EDERD
279 // UserData is given the set of strings of the form
280 // "$EXTENSION_ID-$DETERMINER_ID" so that it can know when all determiners
281 // have reported.
282 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.
283 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
284 DeterminerMap filename_determiners_;
285
245 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); 286 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter);
246 }; 287 };
247 288
248 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ 289 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698