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( | 353 explicit ExtensionDownloadsEventRouter(Profile* profile); |
354 Profile* profile, content::DownloadManager* manager); | |
355 virtual ~ExtensionDownloadsEventRouter(); | 354 virtual ~ExtensionDownloadsEventRouter(); |
356 | 355 |
357 virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE; | 356 virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE; |
358 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; | 357 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; |
359 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; | 358 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; |
360 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; | 359 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; |
361 | 360 |
362 // Used for testing. | |
363 struct DownloadsNotificationSource { | |
364 std::string event_name; | |
365 Profile* profile; | |
366 }; | |
367 | |
368 private: | 361 private: |
369 struct OnChangedStat { | 362 struct OnChangedStat { |
370 OnChangedStat(); | 363 OnChangedStat(); |
371 ~OnChangedStat(); | 364 ~OnChangedStat(); |
372 int fires; | 365 int fires; |
373 int total; | 366 int total; |
374 }; | 367 }; |
375 | 368 |
376 typedef std::map<int, content::DownloadItem*> ItemMap; | 369 typedef std::map<int, content::DownloadItem*> ItemMap; |
377 typedef std::map<int, base::DictionaryValue*> ItemJsonMap; | 370 typedef std::map<int, base::DictionaryValue*> ItemJsonMap; |
378 typedef std::map<int, OnChangedStat*> OnChangedStatMap; | 371 typedef std::map<int, OnChangedStat*> OnChangedStatMap; |
379 | 372 |
| 373 void Init(content::DownloadManager* manager); |
380 void DispatchEvent(const char* event_name, base::Value* json_arg); | 374 void DispatchEvent(const char* event_name, base::Value* json_arg); |
381 | 375 |
382 Profile* profile_; | 376 Profile* profile_; |
383 content::DownloadManager* manager_; | 377 content::DownloadManager* manager_; |
384 ItemMap downloads_; | 378 ItemMap downloads_; |
385 ItemJsonMap item_jsons_; | 379 ItemJsonMap item_jsons_; |
386 OnChangedStatMap on_changed_stats_; | 380 OnChangedStatMap on_changed_stats_; |
387 | 381 |
388 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); | 382 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
389 }; | 383 }; |
390 | 384 |
391 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ | 385 #endif // CHROME_BROWSER_EXTENSIONS_API_DOWNLOADS_DOWNLOADS_API_H_ |
OLD | NEW |