| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // Errors that can be returned through chrome.extension.lastError.message. | 36 // Errors that can be returned through chrome.extension.lastError.message. |
| 37 extern const char kGenericError[]; | 37 extern const char kGenericError[]; |
| 38 extern const char kIconNotFoundError[]; | 38 extern const char kIconNotFoundError[]; |
| 39 extern const char kInvalidDangerTypeError[]; | 39 extern const char kInvalidDangerTypeError[]; |
| 40 extern const char kInvalidFilterError[]; | 40 extern const char kInvalidFilterError[]; |
| 41 extern const char kInvalidOperationError[]; | 41 extern const char kInvalidOperationError[]; |
| 42 extern const char kInvalidOrderByError[]; | 42 extern const char kInvalidOrderByError[]; |
| 43 extern const char kInvalidQueryLimit[]; | 43 extern const char kInvalidQueryLimit[]; |
| 44 extern const char kInvalidStateError[]; | 44 extern const char kInvalidStateError[]; |
| 45 extern const char kInvalidUrlError[]; | 45 extern const char kInvalidURLError[]; |
| 46 extern const char kNotImplementedError[]; | 46 extern const char kNotImplementedError[]; |
| 47 | 47 |
| 48 } // namespace download_extension_errors | 48 } // namespace download_extension_errors |
| 49 | 49 |
| 50 class DownloadsFunctionInterface { | 50 class DownloadsFunctionInterface { |
| 51 public: | 51 public: |
| 52 enum DownloadsFunctionName { | 52 enum DownloadsFunctionName { |
| 53 DOWNLOADS_FUNCTION_DOWNLOAD = 0, | 53 DOWNLOADS_FUNCTION_DOWNLOAD = 0, |
| 54 DOWNLOADS_FUNCTION_SEARCH = 1, | 54 DOWNLOADS_FUNCTION_SEARCH = 1, |
| 55 DOWNLOADS_FUNCTION_PAUSE = 2, | 55 DOWNLOADS_FUNCTION_PAUSE = 2, |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 int icon_size_; | 343 int icon_size_; |
| 344 scoped_ptr<DownloadFileIconExtractor> icon_extractor_; | 344 scoped_ptr<DownloadFileIconExtractor> icon_extractor_; |
| 345 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction); | 345 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction); |
| 346 }; | 346 }; |
| 347 | 347 |
| 348 // Observes a single DownloadManager and many DownloadItems and dispatches | 348 // Observes a single DownloadManager and many DownloadItems and dispatches |
| 349 // onCreated and onErased events. | 349 // onCreated and onErased events. |
| 350 class ExtensionDownloadsEventRouter : public content::DownloadManager::Observer, | 350 class ExtensionDownloadsEventRouter : public content::DownloadManager::Observer, |
| 351 public content::DownloadItem::Observer { | 351 public content::DownloadItem::Observer { |
| 352 public: | 352 public: |
| 353 explicit ExtensionDownloadsEventRouter(Profile* profile); | 353 explicit ExtensionDownloadsEventRouter( |
| 354 Profile* profile, content::DownloadManager* manager); |
| 354 virtual ~ExtensionDownloadsEventRouter(); | 355 virtual ~ExtensionDownloadsEventRouter(); |
| 355 | 356 |
| 356 virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE; | 357 virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE; |
| 357 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; | 358 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; |
| 358 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; | 359 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; |
| 359 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; | 360 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; |
| 360 | 361 |
| 362 // Used for testing. |
| 363 struct DownloadsNotificationSource { |
| 364 std::string event_name; |
| 365 Profile* profile; |
| 366 }; |
| 367 |
| 361 private: | 368 private: |
| 362 struct OnChangedStat { | 369 struct OnChangedStat { |
| 363 OnChangedStat(); | 370 OnChangedStat(); |
| 364 ~OnChangedStat(); | 371 ~OnChangedStat(); |
| 365 int fires; | 372 int fires; |
| 366 int total; | 373 int total; |
| 367 }; | 374 }; |
| 368 | 375 |
| 369 typedef std::map<int, content::DownloadItem*> ItemMap; | 376 typedef std::map<int, content::DownloadItem*> ItemMap; |
| 370 typedef std::map<int, base::DictionaryValue*> ItemJsonMap; | 377 typedef std::map<int, base::DictionaryValue*> ItemJsonMap; |
| 371 typedef std::map<int, OnChangedStat*> OnChangedStatMap; | 378 typedef std::map<int, OnChangedStat*> OnChangedStatMap; |
| 372 | 379 |
| 373 void Init(content::DownloadManager* manager); | |
| 374 void DispatchEvent(const char* event_name, base::Value* json_arg); | 380 void DispatchEvent(const char* event_name, base::Value* json_arg); |
| 375 | 381 |
| 376 Profile* profile_; | 382 Profile* profile_; |
| 377 content::DownloadManager* manager_; | 383 content::DownloadManager* manager_; |
| 378 ItemMap downloads_; | 384 ItemMap downloads_; |
| 379 ItemJsonMap item_jsons_; | 385 ItemJsonMap item_jsons_; |
| 380 OnChangedStatMap on_changed_stats_; | 386 OnChangedStatMap on_changed_stats_; |
| 381 | 387 |
| 382 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); | 388 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
| 383 }; | 389 }; |
| 384 | 390 |
| 385 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ | 391 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
| OLD | NEW |