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 "chrome/browser/extensions/extension_function.h" | 17 #include "chrome/browser/extensions/extension_function.h" |
17 #include "content/browser/download/download_state_info.h" | 18 #include "content/browser/download/download_state_info.h" |
18 #include "content/public/browser/download_item.h" | 19 #include "content/public/browser/download_item.h" |
19 #include "content/public/browser/download_manager.h" | 20 #include "content/public/browser/download_manager.h" |
20 | 21 |
21 class DownloadFileIconExtractor; | 22 class DownloadFileIconExtractor; |
22 class ResourceDispatcherHost; | 23 class ResourceDispatcherHost; |
23 | 24 |
24 namespace content { | 25 namespace content { |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 virtual bool RunInternal() OVERRIDE; | 283 virtual bool RunInternal() OVERRIDE; |
283 | 284 |
284 private: | 285 private: |
285 void OnIconURLExtracted(const std::string& url); | 286 void OnIconURLExtracted(const std::string& url); |
286 FilePath path_; | 287 FilePath path_; |
287 int icon_size_; | 288 int icon_size_; |
288 scoped_ptr<DownloadFileIconExtractor> icon_extractor_; | 289 scoped_ptr<DownloadFileIconExtractor> icon_extractor_; |
289 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction); | 290 DISALLOW_COPY_AND_ASSIGN(DownloadsGetFileIconFunction); |
290 }; | 291 }; |
291 | 292 |
292 class ExtensionDownloadsEventRouter | 293 // Observes a single DownloadManager and many DownloadItems and dispatches |
293 : public content::DownloadManager::Observer { | 294 // onCreated and onErased events. |
| 295 class ExtensionDownloadsEventRouter : public content::DownloadManager::Observer, |
| 296 public content::DownloadItem::Observer { |
294 public: | 297 public: |
295 explicit ExtensionDownloadsEventRouter(Profile* profile); | 298 explicit ExtensionDownloadsEventRouter(Profile* profile); |
296 virtual ~ExtensionDownloadsEventRouter(); | 299 virtual ~ExtensionDownloadsEventRouter(); |
297 | 300 |
298 virtual void ModelChanged() OVERRIDE; | 301 virtual void ModelChanged() OVERRIDE; |
299 virtual void ManagerGoingDown() OVERRIDE; | 302 virtual void ManagerGoingDown() OVERRIDE; |
| 303 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; |
| 304 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; |
300 | 305 |
301 private: | 306 private: |
| 307 struct OnChangedStat { |
| 308 OnChangedStat(); |
| 309 ~OnChangedStat(); |
| 310 int fires; |
| 311 int total; |
| 312 }; |
| 313 |
| 314 typedef std::map<int, content::DownloadItem*> ItemMap; |
| 315 typedef std::map<int, base::DictionaryValue*> ItemJsonMap; |
| 316 typedef std::map<int, OnChangedStat*> OnChangedStatMap; |
| 317 |
302 void Init(content::DownloadManager* manager); | 318 void Init(content::DownloadManager* manager); |
303 void DispatchEvent(const char* event_name, base::Value* json_arg); | 319 void DispatchEvent(const char* event_name, base::Value* json_arg); |
304 typedef base::hash_map<int, content::DownloadItem*> ItemMap; | |
305 typedef std::set<int> DownloadIdSet; | |
306 | 320 |
307 Profile* profile_; | 321 Profile* profile_; |
308 content::DownloadManager* manager_; | 322 content::DownloadManager* manager_; |
309 DownloadIdSet downloads_; | 323 ItemMap downloads_; |
| 324 ItemJsonMap item_jsons_; |
| 325 STLValueDeleter<ItemJsonMap> delete_item_jsons_; |
| 326 OnChangedStatMap on_changed_stats_; |
| 327 STLValueDeleter<OnChangedStatMap> delete_on_changed_stats_; |
310 | 328 |
311 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); | 329 DISALLOW_COPY_AND_ASSIGN(ExtensionDownloadsEventRouter); |
312 }; | 330 }; |
313 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_EXTENSION_API_H_ | 331 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_EXTENSION_API_H_ |
OLD | NEW |