OLD | NEW |
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 <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/download/all_download_item_notifier.h" | 15 #include "chrome/browser/download/all_download_item_notifier.h" |
16 #include "chrome/browser/download/download_danger_prompt.h" | 16 #include "chrome/browser/download/download_danger_prompt.h" |
17 #include "chrome/browser/download/download_path_reservation_tracker.h" | 17 #include "chrome/browser/download/download_path_reservation_tracker.h" |
18 #include "chrome/browser/extensions/event_router.h" | 18 #include "chrome/browser/extensions/event_router.h" |
19 #include "chrome/browser/extensions/extension_function.h" | 19 #include "chrome/browser/extensions/extension_function.h" |
| 20 #include "chrome/browser/extensions/extension_warning_set.h" |
20 #include "chrome/common/extensions/api/downloads.h" | 21 #include "chrome/common/extensions/api/downloads.h" |
21 #include "content/public/browser/download_item.h" | 22 #include "content/public/browser/download_item.h" |
22 #include "content/public/browser/download_manager.h" | 23 #include "content/public/browser/download_manager.h" |
23 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
24 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
25 | 26 |
26 class DownloadFileIconExtractor; | 27 class DownloadFileIconExtractor; |
27 class DownloadQuery; | 28 class DownloadQuery; |
28 | 29 |
29 namespace content { | 30 namespace content { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 // onCreated and onErased events. | 292 // onCreated and onErased events. |
292 class ExtensionDownloadsEventRouter : public extensions::EventRouter::Observer, | 293 class ExtensionDownloadsEventRouter : public extensions::EventRouter::Observer, |
293 public content::NotificationObserver, | 294 public content::NotificationObserver, |
294 public AllDownloadItemNotifier::Observer { | 295 public AllDownloadItemNotifier::Observer { |
295 public: | 296 public: |
296 typedef base::Callback<void( | 297 typedef base::Callback<void( |
297 const base::FilePath& changed_filename, | 298 const base::FilePath& changed_filename, |
298 DownloadPathReservationTracker::FilenameConflictAction)> | 299 DownloadPathReservationTracker::FilenameConflictAction)> |
299 FilenameChangedCallback; | 300 FilenameChangedCallback; |
300 | 301 |
| 302 // The logic for how to handle conflicting filename suggestions from multiple |
| 303 // extensions is split out here for testing. |
| 304 static void DetermineFilenameInternal( |
| 305 const base::FilePath& filename, |
| 306 extensions::api::downloads::FilenameConflictAction conflict_action, |
| 307 const std::string& suggesting_extension_id, |
| 308 const base::Time& suggesting_install_time, |
| 309 const std::string& incumbent_extension_id, |
| 310 const base::Time& incumbent_install_time, |
| 311 std::string* winner_extension_id, |
| 312 base::FilePath* determined_filename, |
| 313 extensions::api::downloads::FilenameConflictAction* |
| 314 determined_conflict_action, |
| 315 extensions::ExtensionWarningSet* warnings); |
| 316 |
301 // A downloads.onDeterminingFilename listener has returned. If the extension | 317 // A downloads.onDeterminingFilename listener has returned. If the extension |
302 // wishes to override the download's filename, then |filename| will be | 318 // wishes to override the download's filename, then |filename| will be |
303 // non-empty. |filename| will be interpreted as a relative path, appended to | 319 // non-empty. |filename| will be interpreted as a relative path, appended to |
304 // the default downloads directory. If the extension wishes to overwrite any | 320 // the default downloads directory. If the extension wishes to overwrite any |
305 // existing files, then |overwrite| will be true. Returns true on success, | 321 // existing files, then |overwrite| will be true. Returns true on success, |
306 // false otherwise. | 322 // false otherwise. |
307 static bool DetermineFilename( | 323 static bool DetermineFilename( |
308 Profile* profile, | 324 Profile* profile, |
309 bool include_incognito, | 325 bool include_incognito, |
310 const std::string& ext_id, | 326 const std::string& ext_id, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 384 |
369 Profile* profile_; | 385 Profile* profile_; |
370 AllDownloadItemNotifier notifier_; | 386 AllDownloadItemNotifier notifier_; |
371 std::set<const extensions::Extension*> shelf_disabling_extensions_; | 387 std::set<const extensions::Extension*> shelf_disabling_extensions_; |
372 content::NotificationRegistrar registrar_; | 388 content::NotificationRegistrar registrar_; |
373 | 389 |
374 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); | 390 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
375 }; | 391 }; |
376 | 392 |
377 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ | 393 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
OLD | NEW |