| 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_DOWNLOAD_DOWNLOAD_EXTENSION_API_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_EXTENSION_API_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_EXTENSION_API_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_EXTENSION_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/stl_util.h" |
| 15 #include "base/string16.h" | 16 #include "base/string16.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "chrome/browser/extensions/extension_function.h" | 18 #include "chrome/browser/extensions/extension_function.h" |
| 18 #include "content/public/browser/download_id.h" | 19 #include "content/public/browser/download_id.h" |
| 19 #include "content/public/browser/download_item.h" | 20 #include "content/public/browser/download_item.h" |
| 20 #include "content/public/browser/download_manager.h" | 21 #include "content/public/browser/download_manager.h" |
| 21 | 22 |
| 22 class DownloadFileIconExtractor; | 23 class DownloadFileIconExtractor; |
| 23 class DownloadQuery; | 24 class DownloadQuery; |
| 24 class ResourceDispatcherHost; | 25 class ResourceDispatcherHost; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 virtual bool RunInternal() OVERRIDE; | 295 virtual bool RunInternal() OVERRIDE; |
| 295 | 296 |
| 296 private: | 297 private: |
| 297 void OnIconURLExtracted(const std::string& url); | 298 void OnIconURLExtracted(const std::string& url); |
| 298 FilePath path_; | 299 FilePath path_; |
| 299 int icon_size_; | 300 int icon_size_; |
| 300 scoped_ptr<DownloadFileIconExtractor> icon_extractor_; | 301 scoped_ptr<DownloadFileIconExtractor> icon_extractor_; |
| 301 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction); | 302 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction); |
| 302 }; | 303 }; |
| 303 | 304 |
| 304 class ExtensionDownloadsEventRouter | 305 // Observes a single DownloadManager and many DownloadItems and dispatches |
| 305 : public content::DownloadManager::Observer { | 306 // onCreated and onErased events. |
| 307 class ExtensionDownloadsEventRouter : public content::DownloadManager::Observer, |
| 308 public content::DownloadItem::Observer { |
| 306 public: | 309 public: |
| 307 explicit ExtensionDownloadsEventRouter(Profile* profile); | 310 explicit ExtensionDownloadsEventRouter(Profile* profile); |
| 308 virtual ~ExtensionDownloadsEventRouter(); | 311 virtual ~ExtensionDownloadsEventRouter(); |
| 309 | 312 |
| 310 virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE; | 313 virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE; |
| 311 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; | 314 virtual void ManagerGoingDown(content::DownloadManager* manager) OVERRIDE; |
| 315 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; |
| 316 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; |
| 312 | 317 |
| 313 private: | 318 private: |
| 319 struct OnChangedStat { |
| 320 OnChangedStat(); |
| 321 ~OnChangedStat(); |
| 322 int fires; |
| 323 int total; |
| 324 }; |
| 325 |
| 326 typedef std::map<int, content::DownloadItem*> ItemMap; |
| 327 typedef std::map<int, base::DictionaryValue*> ItemJsonMap; |
| 328 typedef std::map<int, OnChangedStat*> OnChangedStatMap; |
| 329 |
| 314 void Init(content::DownloadManager* manager); | 330 void Init(content::DownloadManager* manager); |
| 315 void DispatchEvent(const char* event_name, base::Value* json_arg); | 331 void DispatchEvent(const char* event_name, base::Value* json_arg); |
| 316 typedef base::hash_map<int, content::DownloadItem*> ItemMap; | |
| 317 typedef std::set<int> DownloadIdSet; | |
| 318 | 332 |
| 319 Profile* profile_; | 333 Profile* profile_; |
| 320 content::DownloadManager* manager_; | 334 content::DownloadManager* manager_; |
| 321 DownloadIdSet downloads_; | 335 ItemMap downloads_; |
| 336 ItemJsonMap item_jsons_; |
| 337 STLValueDeleter<ItemJsonMap> delete_item_jsons_; |
| 338 OnChangedStatMap on_changed_stats_; |
| 339 STLValueDeleter<OnChangedStatMap> delete_on_changed_stats_; |
| 322 | 340 |
| 323 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); | 341 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
| 324 }; | 342 }; |
| 325 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_EXTENSION_API_H_ | 343 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_EXTENSION_API_H_ |
| OLD | NEW |