OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 5 |
6 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 6 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
7 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 7 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
8 #pragma once | 8 #pragma once |
9 | 9 |
10 #include "content/browser/download/download_manager.h" | 10 #include "content/browser/download/download_manager.h" |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <set> | 13 #include <set> |
14 | 14 |
15 #include "base/hash_tables.h" | 15 #include "base/hash_tables.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
| 21 #include "content/browser/download/download_item_impl.h" |
21 #include "content/browser/download/download_status_updater_delegate.h" | 22 #include "content/browser/download/download_status_updater_delegate.h" |
22 #include "content/common/content_export.h" | 23 #include "content/common/content_export.h" |
23 | 24 |
24 class DownloadIdFactory; | 25 class DownloadIdFactory; |
25 class DownloadStatusUpdater; | 26 class DownloadStatusUpdater; |
26 | 27 |
27 class CONTENT_EXPORT DownloadManagerImpl | 28 class CONTENT_EXPORT DownloadManagerImpl |
28 : public DownloadManager, | 29 : public DownloadManager, |
| 30 public DownloadItemImpl::Delegate, |
29 public DownloadStatusUpdaterDelegate { | 31 public DownloadStatusUpdaterDelegate { |
30 public: | 32 public: |
31 DownloadManagerImpl(content::DownloadManagerDelegate* delegate, | 33 DownloadManagerImpl(content::DownloadManagerDelegate* delegate, |
32 DownloadIdFactory* id_factory, | 34 DownloadIdFactory* id_factory, |
33 DownloadStatusUpdater* status_updater); | 35 DownloadStatusUpdater* status_updater); |
34 | 36 |
35 // DownloadManager functions. | 37 // DownloadManager functions. |
36 virtual void Shutdown() OVERRIDE; | 38 virtual void Shutdown() OVERRIDE; |
37 virtual void GetTemporaryDownloads(const FilePath& dir_path, | 39 virtual void GetTemporaryDownloads(const FilePath& dir_path, |
38 DownloadVector* result) OVERRIDE; | 40 DownloadVector* result) OVERRIDE; |
39 virtual void GetAllDownloads(const FilePath& dir_path, | 41 virtual void GetAllDownloads(const FilePath& dir_path, |
40 DownloadVector* result) OVERRIDE; | 42 DownloadVector* result) OVERRIDE; |
41 virtual void SearchDownloads(const string16& query, | 43 virtual void SearchDownloads(const string16& query, |
42 DownloadVector* result) OVERRIDE; | 44 DownloadVector* result) OVERRIDE; |
43 virtual bool Init(content::BrowserContext* browser_context) OVERRIDE; | 45 virtual bool Init(content::BrowserContext* browser_context) OVERRIDE; |
44 virtual void StartDownload(int32 id) OVERRIDE; | 46 virtual void StartDownload(int32 id) OVERRIDE; |
45 virtual void UpdateDownload(int32 download_id, int64 bytes_so_far, | 47 virtual void UpdateDownload(int32 download_id, int64 bytes_so_far, |
46 int64 bytes_per_sec) OVERRIDE; | 48 int64 bytes_per_sec) OVERRIDE; |
47 virtual void OnResponseCompleted(int32 download_id, int64 size, | 49 virtual void OnResponseCompleted(int32 download_id, int64 size, |
48 const std::string& hash) OVERRIDE; | 50 const std::string& hash) OVERRIDE; |
49 virtual void CancelDownload(int32 download_id) OVERRIDE; | 51 virtual void CancelDownload(int32 download_id) OVERRIDE; |
50 virtual void OnDownloadInterrupted(int32 download_id, int64 size, | 52 virtual void OnDownloadInterrupted(int32 download_id, int64 size, |
51 InterruptReason reason) OVERRIDE; | 53 InterruptReason reason) OVERRIDE; |
52 virtual void DownloadCancelledInternal(DownloadItem* download) OVERRIDE; | |
53 virtual void RemoveDownload(int64 download_handle) OVERRIDE; | |
54 virtual bool IsDownloadReadyForCompletion(DownloadItem* download) OVERRIDE; | |
55 virtual void MaybeCompleteDownload(DownloadItem* download) OVERRIDE; | |
56 virtual void OnDownloadRenamedToFinalName(int download_id, | 54 virtual void OnDownloadRenamedToFinalName(int download_id, |
57 const FilePath& full_path, | 55 const FilePath& full_path, |
58 int uniquifier) OVERRIDE; | 56 int uniquifier) OVERRIDE; |
59 virtual int RemoveDownloadsBetween(const base::Time remove_begin, | 57 virtual int RemoveDownloadsBetween(const base::Time remove_begin, |
60 const base::Time remove_end) OVERRIDE; | 58 const base::Time remove_end) OVERRIDE; |
61 virtual int RemoveDownloads(const base::Time remove_begin) OVERRIDE; | 59 virtual int RemoveDownloads(const base::Time remove_begin) OVERRIDE; |
62 virtual int RemoveAllDownloads() OVERRIDE; | 60 virtual int RemoveAllDownloads() OVERRIDE; |
63 virtual void DownloadCompleted(int32 download_id) OVERRIDE; | |
64 virtual void DownloadUrl(const GURL& url, | 61 virtual void DownloadUrl(const GURL& url, |
65 const GURL& referrer, | 62 const GURL& referrer, |
66 const std::string& referrer_encoding, | 63 const std::string& referrer_encoding, |
67 TabContents* tab_contents) OVERRIDE; | 64 TabContents* tab_contents) OVERRIDE; |
68 virtual void DownloadUrlToFile(const GURL& url, | 65 virtual void DownloadUrlToFile(const GURL& url, |
69 const GURL& referrer, | 66 const GURL& referrer, |
70 const std::string& referrer_encoding, | 67 const std::string& referrer_encoding, |
71 const DownloadSaveInfo& save_info, | 68 const DownloadSaveInfo& save_info, |
72 TabContents* tab_contents) OVERRIDE; | 69 TabContents* tab_contents) OVERRIDE; |
73 virtual void AddObserver(Observer* observer) OVERRIDE; | 70 virtual void AddObserver(Observer* observer) OVERRIDE; |
74 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 71 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
75 virtual void OnPersistentStoreQueryComplete( | 72 virtual void OnPersistentStoreQueryComplete( |
76 std::vector<DownloadPersistentStoreInfo>* entries) OVERRIDE; | 73 std::vector<DownloadPersistentStoreInfo>* entries) OVERRIDE; |
77 virtual void OnItemAddedToPersistentStore(int32 download_id, | 74 virtual void OnItemAddedToPersistentStore(int32 download_id, |
78 int64 db_handle) OVERRIDE; | 75 int64 db_handle) OVERRIDE; |
79 virtual void ShowDownloadInBrowser(DownloadItem* download) OVERRIDE; | |
80 virtual int InProgressCount() const OVERRIDE; | 76 virtual int InProgressCount() const OVERRIDE; |
81 virtual content::BrowserContext* BrowserContext() OVERRIDE; | 77 virtual content::BrowserContext* BrowserContext() const OVERRIDE; |
82 virtual FilePath LastDownloadPath() OVERRIDE; | 78 virtual FilePath LastDownloadPath() OVERRIDE; |
83 virtual void CreateDownloadItem( | 79 virtual void CreateDownloadItem( |
84 DownloadCreateInfo* info, | 80 DownloadCreateInfo* info, |
85 const DownloadRequestHandle& request_handle) OVERRIDE; | 81 const DownloadRequestHandle& request_handle) OVERRIDE; |
| 82 virtual DownloadItem* CreateSavePackageDownloadItem( |
| 83 const FilePath& main_file_path, |
| 84 const GURL& page_url, |
| 85 bool is_otr, |
| 86 DownloadItem::Observer* observer) OVERRIDE; |
86 virtual void ClearLastDownloadPath() OVERRIDE; | 87 virtual void ClearLastDownloadPath() OVERRIDE; |
87 virtual void FileSelected(const FilePath& path, void* params) OVERRIDE; | 88 virtual void FileSelected(const FilePath& path, void* params) OVERRIDE; |
88 virtual void FileSelectionCanceled(void* params) OVERRIDE; | 89 virtual void FileSelectionCanceled(void* params) OVERRIDE; |
89 virtual void RestartDownload(int32 download_id) OVERRIDE; | 90 virtual void RestartDownload(int32 download_id) OVERRIDE; |
90 virtual void MarkDownloadOpened(DownloadItem* download) OVERRIDE; | |
91 virtual void CheckForHistoryFilesRemoval() OVERRIDE; | 91 virtual void CheckForHistoryFilesRemoval() OVERRIDE; |
92 virtual void CheckForFileRemoval(DownloadItem* download_item) OVERRIDE; | |
93 virtual void AssertQueueStateConsistent(DownloadItem* download) OVERRIDE; | |
94 virtual DownloadItem* GetDownloadItem(int id) OVERRIDE; | 92 virtual DownloadItem* GetDownloadItem(int id) OVERRIDE; |
95 virtual void SavePageDownloadStarted(DownloadItem* download) OVERRIDE; | |
96 virtual void SavePageDownloadFinished(DownloadItem* download) OVERRIDE; | 93 virtual void SavePageDownloadFinished(DownloadItem* download) OVERRIDE; |
97 virtual DownloadItem* GetActiveDownloadItem(int id) OVERRIDE; | 94 virtual DownloadItem* GetActiveDownloadItem(int id) OVERRIDE; |
98 virtual content::DownloadManagerDelegate* delegate() const OVERRIDE; | 95 virtual content::DownloadManagerDelegate* delegate() const OVERRIDE; |
99 virtual void SetDownloadManagerDelegate( | 96 virtual void SetDownloadManagerDelegate( |
100 content::DownloadManagerDelegate* delegate) OVERRIDE; | 97 content::DownloadManagerDelegate* delegate) OVERRIDE; |
101 virtual DownloadId GetNextId() OVERRIDE; | 98 |
| 99 // Overridden from DownloadItemImpl::Delegate |
| 100 // (Note that |BrowserContext| are present in both interfaces.) |
| 101 virtual bool ShouldOpenDownload(DownloadItem* item) OVERRIDE; |
| 102 virtual bool ShouldOpenFileBasedOnExtension( |
| 103 const FilePath& path) OVERRIDE; |
| 104 virtual void CheckForFileRemoval(DownloadItem* download_item) OVERRIDE; |
| 105 virtual void MaybeCompleteDownload(DownloadItem* download) OVERRIDE; |
| 106 virtual void DownloadCancelled(DownloadItem* download) OVERRIDE; |
| 107 virtual void DownloadCompleted(DownloadItem* download) OVERRIDE; |
| 108 virtual void DownloadOpened(DownloadItem* download) OVERRIDE; |
| 109 virtual void DownloadRemoved(DownloadItem* download) OVERRIDE; |
| 110 virtual void AssertStateConsistent(DownloadItem* download) const OVERRIDE; |
102 | 111 |
103 // Overridden from DownloadStatusUpdaterDelegate: | 112 // Overridden from DownloadStatusUpdaterDelegate: |
104 virtual bool IsDownloadProgressKnown() const OVERRIDE; | 113 virtual bool IsDownloadProgressKnown() const OVERRIDE; |
105 virtual int64 GetInProgressDownloadCount() const OVERRIDE; | 114 virtual int64 GetInProgressDownloadCount() const OVERRIDE; |
106 virtual int64 GetReceivedDownloadBytes() const OVERRIDE; | 115 virtual int64 GetReceivedDownloadBytes() const OVERRIDE; |
107 virtual int64 GetTotalDownloadBytes() const OVERRIDE; | 116 virtual int64 GetTotalDownloadBytes() const OVERRIDE; |
108 | 117 |
109 private: | 118 private: |
110 typedef std::set<DownloadItem*> DownloadSet; | 119 typedef std::set<DownloadItem*> DownloadSet; |
111 typedef base::hash_map<int64, DownloadItem*> DownloadMap; | 120 typedef base::hash_map<int64, DownloadItem*> DownloadMap; |
112 | 121 |
113 // For testing. | 122 // For testing. |
114 friend class DownloadManagerTest; | 123 friend class DownloadManagerTest; |
115 friend class DownloadTest; | 124 friend class DownloadTest; |
116 friend class MockDownloadManager; | |
117 | 125 |
118 friend class base::RefCountedThreadSafe< | 126 friend class base::RefCountedThreadSafe< |
119 DownloadManagerImpl, content::BrowserThread::DeleteOnUIThread>; | 127 DownloadManagerImpl, content::BrowserThread::DeleteOnUIThread>; |
120 friend struct content::BrowserThread::DeleteOnThread< | 128 friend struct content::BrowserThread::DeleteOnThread< |
121 content::BrowserThread::UI>; | 129 content::BrowserThread::UI>; |
122 friend class DeleteTask<DownloadManagerImpl>; | 130 friend class DeleteTask<DownloadManagerImpl>; |
123 | 131 |
124 virtual ~DownloadManagerImpl(); | 132 virtual ~DownloadManagerImpl(); |
125 | 133 |
| 134 // Determine if the download is ready for completion, i.e. has had |
| 135 // all data saved, and completed the filename determination and |
| 136 // history insertion. |
| 137 bool IsDownloadReadyForCompletion(DownloadItem* download); |
| 138 |
| 139 // Show the download in the browser. |
| 140 void ShowDownloadInBrowser(DownloadItem* download); |
| 141 |
| 142 // Get next download id from factory. |
| 143 DownloadId GetNextId(); |
| 144 |
126 // Called on the FILE thread to check the existence of a downloaded file. | 145 // Called on the FILE thread to check the existence of a downloaded file. |
127 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); | 146 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); |
128 | 147 |
129 // Called on the UI thread if the FILE thread detects the removal of | 148 // Called on the UI thread if the FILE thread detects the removal of |
130 // the downloaded file. The UI thread updates the state of the file | 149 // the downloaded file. The UI thread updates the state of the file |
131 // and then notifies this update to the file's observer. | 150 // and then notifies this update to the file's observer. |
132 void OnFileRemovalDetected(int64 db_handle); | 151 void OnFileRemovalDetected(int64 db_handle); |
133 | 152 |
134 // Called back after a target path for the file to be downloaded to has been | 153 // Called back after a target path for the file to be downloaded to has been |
135 // determined, either automatically based on the suggested file name, or by | 154 // determined, either automatically based on the suggested file name, or by |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 DownloadIdFactory* id_factory_; | 259 DownloadIdFactory* id_factory_; |
241 | 260 |
242 // TODO(rdsmith): Remove when http://crbug.com/85408 is fixed. | 261 // TODO(rdsmith): Remove when http://crbug.com/85408 is fixed. |
243 // For debugging only. | 262 // For debugging only. |
244 int64 largest_db_handle_in_history_; | 263 int64 largest_db_handle_in_history_; |
245 | 264 |
246 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); | 265 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); |
247 }; | 266 }; |
248 | 267 |
249 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 268 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
OLD | NEW |