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 // The DownloadManager object manages the process of downloading, including | 5 // The DownloadManager object manages the process of downloading, including |
6 // updates to the history system and providing the information for displaying | 6 // updates to the history system and providing the information for displaying |
7 // the downloads view in the Destinations tab. There is one DownloadManager per | 7 // the downloads view in the Destinations tab. There is one DownloadManager per |
8 // active browser context in Chrome. | 8 // active browser context in Chrome. |
9 // | 9 // |
10 // Download observers: | 10 // Download observers: |
(...skipping 10 matching lines...) Expand all Loading... | |
21 // The DownloadManager uses the history service for storing persistent | 21 // The DownloadManager uses the history service for storing persistent |
22 // information about the state of all downloads. The history system maintains a | 22 // information about the state of all downloads. The history system maintains a |
23 // separate table for this called 'downloads'. At the point that the | 23 // separate table for this called 'downloads'. At the point that the |
24 // DownloadManager is constructed, we query the history service for the state of | 24 // DownloadManager is constructed, we query the history service for the state of |
25 // all persisted downloads. | 25 // all persisted downloads. |
26 | 26 |
27 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 27 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
28 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 28 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
29 #pragma once | 29 #pragma once |
30 | 30 |
31 #include <map> | |
32 #include <set> | |
33 #include <string> | 31 #include <string> |
34 #include <vector> | 32 #include <vector> |
35 | 33 |
36 #include "base/basictypes.h" | 34 #include "base/basictypes.h" |
37 #include "base/callback.h" | 35 //#include "base/callback.h" |
jam
2011/11/10 17:19:09
nit: remove?
ahendrickson
2011/11/18 18:47:39
Done.
| |
38 #include "base/file_path.h" | 36 #include "base/file_path.h" |
39 #include "base/gtest_prod_util.h" | 37 #include "base/gtest_prod_util.h" |
40 #include "base/hash_tables.h" | |
41 #include "base/memory/ref_counted.h" | |
42 #include "base/memory/scoped_ptr.h" | |
43 #include "base/memory/weak_ptr.h" | |
44 #include "base/observer_list.h" | |
45 #include "base/synchronization/lock.h" | |
46 #include "base/time.h" | 38 #include "base/time.h" |
47 #include "content/browser/download/download_id.h" | 39 #include "content/browser/download/download_id.h" |
48 #include "content/browser/download/download_item.h" | 40 #include "content/browser/download/download_item.h" |
49 #include "content/browser/download/download_status_updater_delegate.h" | |
50 #include "content/browser/download/interrupt_reasons.h" | 41 #include "content/browser/download/interrupt_reasons.h" |
51 #include "content/common/content_export.h" | |
52 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
53 #include "net/base/net_errors.h" | 43 #include "net/base/net_errors.h" |
54 | 44 |
55 class DownloadFileManager; | 45 class DownloadFileManager; |
56 class DownloadIdFactory; | |
57 class DownloadRequestHandle; | 46 class DownloadRequestHandle; |
58 class DownloadStatusUpdater; | |
59 class GURL; | 47 class GURL; |
60 class ResourceDispatcherHost; | |
61 class TabContents; | 48 class TabContents; |
62 struct DownloadCreateInfo; | 49 struct DownloadCreateInfo; |
63 struct DownloadSaveInfo; | 50 struct DownloadSaveInfo; |
64 | 51 |
65 namespace content { | 52 namespace content { |
66 class BrowserContext; | 53 class BrowserContext; |
67 class DownloadManagerDelegate; | 54 class DownloadManagerDelegate; |
68 } | 55 } |
69 | 56 |
70 // Browser's download manager: manages all downloads and destination view. | 57 // Browser's download manager: manages all downloads and destination view. |
71 class CONTENT_EXPORT DownloadManager | 58 class CONTENT_EXPORT DownloadManager |
72 : public base::RefCountedThreadSafe< | 59 : public base::RefCountedThreadSafe< |
73 DownloadManager, content::BrowserThread::DeleteOnUIThread>, | 60 DownloadManager, content::BrowserThread::DeleteOnUIThread> { |
74 public DownloadStatusUpdaterDelegate { | |
75 public: | 61 public: |
76 DownloadManager(content::DownloadManagerDelegate* delegate, | 62 virtual ~DownloadManager() {} |
77 DownloadIdFactory* id_factory, | |
78 DownloadStatusUpdater* status_updater); | |
79 | 63 |
80 // Shutdown the download manager. Must be called before destruction. | 64 // Shutdown the download manager. Must be called before destruction. |
81 void Shutdown(); | 65 virtual void Shutdown() = 0; |
82 | 66 |
83 // Interface to implement for observers that wish to be informed of changes | 67 // Interface to implement for observers that wish to be informed of changes |
84 // to the DownloadManager's collection of downloads. | 68 // to the DownloadManager's collection of downloads. |
85 class CONTENT_EXPORT Observer { | 69 class CONTENT_EXPORT Observer { |
86 public: | 70 public: |
87 // New or deleted download, observers should query us for the current set | 71 // New or deleted download, observers should query us for the current set |
88 // of downloads. | 72 // of downloads. |
89 virtual void ModelChanged() = 0; | 73 virtual void ModelChanged() = 0; |
90 | 74 |
91 // Called when the DownloadManager is being destroyed to prevent Observers | 75 // Called when the DownloadManager is being destroyed to prevent Observers |
92 // from calling back to a stale pointer. | 76 // from calling back to a stale pointer. |
93 virtual void ManagerGoingDown() {} | 77 virtual void ManagerGoingDown() {} |
94 | 78 |
95 // Called immediately after the DownloadManager puts up a select file | 79 // Called immediately after the DownloadManager puts up a select file |
96 // dialog. | 80 // dialog. |
97 // |id| indicates which download opened the dialog. | 81 // |id| indicates which download opened the dialog. |
98 virtual void SelectFileDialogDisplayed(int32 id) {} | 82 virtual void SelectFileDialogDisplayed(int32 id) {} |
99 | 83 |
100 protected: | 84 protected: |
101 virtual ~Observer() {} | 85 virtual ~Observer() {} |
102 }; | 86 }; |
103 | 87 |
104 typedef std::vector<DownloadItem*> DownloadVector; | 88 typedef std::vector<DownloadItem*> DownloadVector; |
105 | 89 |
106 // Return all temporary downloads that reside in the specified directory. | 90 // Return all temporary downloads that reside in the specified directory. |
107 void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result); | 91 virtual void GetTemporaryDownloads(const FilePath& dir_path, |
92 DownloadVector* result) = 0; | |
108 | 93 |
109 // Return all non-temporary downloads in the specified directory that are | 94 // Return all non-temporary downloads in the specified directory that are |
110 // are in progress or have completed. | 95 // are in progress or have completed. |
111 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); | 96 virtual void GetAllDownloads(const FilePath& dir_path, |
97 DownloadVector* result) = 0; | |
112 | 98 |
113 // Returns all non-temporary downloads matching |query|. Empty query matches | 99 // Returns all non-temporary downloads matching |query|. Empty query matches |
114 // everything. | 100 // everything. |
115 void SearchDownloads(const string16& query, DownloadVector* result); | 101 virtual void SearchDownloads(const string16& query, |
102 DownloadVector* result) = 0; | |
116 | 103 |
117 // Returns true if initialized properly. | 104 // Returns true if initialized properly. |
118 bool Init(content::BrowserContext* browser_context); | 105 virtual bool Init(content::BrowserContext* browser_context) = 0; |
119 | 106 |
120 // Notifications sent from the download thread to the UI thread | 107 // Notifications sent from the download thread to the UI thread |
121 void StartDownload(int32 id); | 108 virtual void StartDownload(int32 id) = 0; |
122 void UpdateDownload(int32 download_id, int64 size); | 109 virtual void UpdateDownload(int32 download_id, int64 size) = 0; |
123 | 110 |
124 // |download_id| is the ID of the download. | 111 // |download_id| is the ID of the download. |
125 // |size| is the number of bytes that have been downloaded. | 112 // |size| is the number of bytes that have been downloaded. |
126 // |hash| is sha256 hash for the downloaded file. It is empty when the hash | 113 // |hash| is sha256 hash for the downloaded file. It is empty when the hash |
127 // is not available. | 114 // is not available. |
128 void OnResponseCompleted(int32 download_id, int64 size, | 115 virtual void OnResponseCompleted(int32 download_id, int64 size, |
129 const std::string& hash); | 116 const std::string& hash) = 0; |
130 | 117 |
131 // Offthread target for cancelling a particular download. Will be a no-op | 118 // Offthread target for cancelling a particular download. Will be a no-op |
132 // if the download has already been cancelled. | 119 // if the download has already been cancelled. |
133 void CancelDownload(int32 download_id); | 120 virtual void CancelDownload(int32 download_id) = 0; |
134 | 121 |
135 // Called when there is an error in the download. | 122 // Called when there is an error in the download. |
136 // |download_id| is the ID of the download. | 123 // |download_id| is the ID of the download. |
137 // |size| is the number of bytes that are currently downloaded. | 124 // |size| is the number of bytes that are currently downloaded. |
138 // |reason| is a download interrupt reason code. | 125 // |reason| is a download interrupt reason code. |
139 void OnDownloadInterrupted(int32 download_id, int64 size, | 126 virtual void OnDownloadInterrupted(int32 download_id, int64 size, |
140 InterruptReason reason); | 127 InterruptReason reason) = 0; |
141 | 128 |
142 // Called from DownloadItem to handle the DownloadManager portion of a | 129 // Called from DownloadItem to handle the DownloadManager portion of a |
143 // Cancel; should not be called from other locations. | 130 // Cancel; should not be called from other locations. |
144 void DownloadCancelledInternal(DownloadItem* download); | 131 virtual void DownloadCancelledInternal(DownloadItem* download) = 0; |
145 | 132 |
146 // Called from a view when a user clicks a UI button or link. | 133 // Called from a view when a user clicks a UI button or link. |
147 void RemoveDownload(int64 download_handle); | 134 virtual void RemoveDownload(int64 download_handle) = 0; |
148 | 135 |
149 // Determine if the download is ready for completion, i.e. has had | 136 // Determine if the download is ready for completion, i.e. has had |
150 // all data saved, and completed the filename determination and | 137 // all data saved, and completed the filename determination and |
151 // history insertion. | 138 // history insertion. |
152 bool IsDownloadReadyForCompletion(DownloadItem* download); | 139 virtual bool IsDownloadReadyForCompletion(DownloadItem* download) = 0; |
153 | 140 |
154 // If all pre-requisites have been met, complete download processing, i.e. | 141 // If all pre-requisites have been met, complete download processing, i.e. |
155 // do internal cleanup, file rename, and potentially auto-open. | 142 // do internal cleanup, file rename, and potentially auto-open. |
156 // (Dangerous downloads still may block on user acceptance after this | 143 // (Dangerous downloads still may block on user acceptance after this |
157 // point.) | 144 // point.) |
158 void MaybeCompleteDownload(DownloadItem* download); | 145 virtual void MaybeCompleteDownload(DownloadItem* download) = 0; |
159 | 146 |
160 // Called when the download is renamed to its final name. | 147 // Called when the download is renamed to its final name. |
161 // |uniquifier| is a number used to make unique names for the file. It is | 148 // |uniquifier| is a number used to make unique names for the file. It is |
162 // only valid for the DANGEROUS_BUT_VALIDATED state of the download item. | 149 // only valid for the DANGEROUS_BUT_VALIDATED state of the download item. |
163 void OnDownloadRenamedToFinalName(int download_id, | 150 virtual void OnDownloadRenamedToFinalName(int download_id, |
164 const FilePath& full_path, | 151 const FilePath& full_path, |
165 int uniquifier); | 152 int uniquifier) = 0; |
166 | 153 |
167 // Remove downloads after remove_begin (inclusive) and before remove_end | 154 // Remove downloads after remove_begin (inclusive) and before remove_end |
168 // (exclusive). You may pass in null Time values to do an unbounded delete | 155 // (exclusive). You may pass in null Time values to do an unbounded delete |
169 // in either direction. | 156 // in either direction. |
170 int RemoveDownloadsBetween(const base::Time remove_begin, | 157 virtual int RemoveDownloadsBetween(const base::Time remove_begin, |
171 const base::Time remove_end); | 158 const base::Time remove_end) = 0; |
172 | 159 |
173 // Remove downloads will delete all downloads that have a timestamp that is | 160 // Remove downloads will delete all downloads that have a timestamp that is |
174 // the same or more recent than |remove_begin|. The number of downloads | 161 // the same or more recent than |remove_begin|. The number of downloads |
175 // deleted is returned back to the caller. | 162 // deleted is returned back to the caller. |
176 int RemoveDownloads(const base::Time remove_begin); | 163 virtual int RemoveDownloads(const base::Time remove_begin) = 0; |
177 | 164 |
178 // Remove all downloads will delete all downloads. The number of downloads | 165 // Remove all downloads will delete all downloads. The number of downloads |
179 // deleted is returned back to the caller. | 166 // deleted is returned back to the caller. |
180 int RemoveAllDownloads(); | 167 virtual int RemoveAllDownloads() = 0; |
181 | 168 |
182 // Final download manager transition for download: Update the download | 169 // Final download manager transition for download: Update the download |
183 // history and remove the download from |active_downloads_|. | 170 // history and remove the download from |active_downloads_|. |
184 void DownloadCompleted(int32 download_id); | 171 virtual void DownloadCompleted(int32 download_id) = 0; |
185 | 172 |
186 // Download the object at the URL. Used in cases such as "Save Link As..." | 173 // Download the object at the URL. Used in cases such as "Save Link As..." |
187 void DownloadUrl(const GURL& url, | 174 virtual void DownloadUrl(const GURL& url, |
188 const GURL& referrer, | 175 const GURL& referrer, |
189 const std::string& referrer_encoding, | 176 const std::string& referrer_encoding, |
190 TabContents* tab_contents); | 177 TabContents* tab_contents) = 0; |
191 | 178 |
192 // Download the object at the URL and save it to the specified path. The | 179 // Download the object at the URL and save it to the specified path. The |
193 // download is treated as the temporary download and thus will not appear | 180 // download is treated as the temporary download and thus will not appear |
194 // in the download history. Used in cases such as drag and drop. | 181 // in the download history. Used in cases such as drag and drop. |
195 void DownloadUrlToFile(const GURL& url, | 182 virtual void DownloadUrlToFile(const GURL& url, |
196 const GURL& referrer, | 183 const GURL& referrer, |
197 const std::string& referrer_encoding, | 184 const std::string& referrer_encoding, |
198 const DownloadSaveInfo& save_info, | 185 const DownloadSaveInfo& save_info, |
199 TabContents* tab_contents); | 186 TabContents* tab_contents) = 0; |
200 | 187 |
201 // Allow objects to observe the download creation process. | 188 // Allow objects to observe the download creation process. |
202 void AddObserver(Observer* observer); | 189 virtual void AddObserver(Observer* observer) = 0; |
203 | 190 |
204 // Remove a download observer from ourself. | 191 // Remove a download observer from ourself. |
205 void RemoveObserver(Observer* observer); | 192 virtual void RemoveObserver(Observer* observer) = 0; |
206 | 193 |
207 // Called by the embedder, after creating the download manager, to let it know | 194 // Called by the embedder, after creating the download manager, to let it know |
208 // about downloads from previous runs of the browser. | 195 // about downloads from previous runs of the browser. |
209 void OnPersistentStoreQueryComplete( | 196 virtual void OnPersistentStoreQueryComplete( |
210 std::vector<DownloadPersistentStoreInfo>* entries); | 197 std::vector<DownloadPersistentStoreInfo>* entries) = 0; |
211 | 198 |
212 // Called by the embedder, in response to | 199 // Called by the embedder, in response to |
213 // DownloadManagerDelegate::AddItemToPersistentStore. | 200 // DownloadManagerDelegate::AddItemToPersistentStore. |
214 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); | 201 virtual void OnItemAddedToPersistentStore(int32 download_id, |
202 int64 db_handle) = 0; | |
215 | 203 |
216 // Display a new download in the appropriate browser UI. | 204 // Display a new download in the appropriate browser UI. |
217 void ShowDownloadInBrowser(DownloadItem* download); | 205 virtual void ShowDownloadInBrowser(DownloadItem* download) = 0; |
218 | 206 |
219 // The number of in progress (including paused) downloads. | 207 // The number of in progress (including paused) downloads. |
220 int in_progress_count() const { | 208 virtual int InProgressCount() const = 0; |
221 return static_cast<int>(in_progress_.size()); | 209 |
222 } | 210 virtual content::BrowserContext* BrowserContext() = 0; |
223 | 211 |
224 content::BrowserContext* browser_context() { return browser_context_; } | 212 virtual FilePath LastDownloadPath() = 0; |
225 | |
226 FilePath last_download_path() { return last_download_path_; } | |
227 | 213 |
228 // Creates the download item. Must be called on the UI thread. | 214 // Creates the download item. Must be called on the UI thread. |
229 void CreateDownloadItem(DownloadCreateInfo* info, | 215 virtual void CreateDownloadItem(DownloadCreateInfo* info, |
230 const DownloadRequestHandle& request_handle); | 216 const DownloadRequestHandle& request_handle) = 0; |
231 | 217 |
232 // Clears the last download path, used to initialize "save as" dialogs. | 218 // Clears the last download path, used to initialize "save as" dialogs. |
233 void ClearLastDownloadPath(); | 219 virtual void ClearLastDownloadPath() = 0; |
234 | |
235 // Overridden from DownloadStatusUpdaterDelegate: | |
236 virtual bool IsDownloadProgressKnown() const OVERRIDE; | |
237 virtual int64 GetInProgressDownloadCount() const OVERRIDE; | |
238 virtual int64 GetReceivedDownloadBytes() const OVERRIDE; | |
239 virtual int64 GetTotalDownloadBytes() const OVERRIDE; | |
240 | 220 |
241 // Called by the delegate after the save as dialog is closed. | 221 // Called by the delegate after the save as dialog is closed. |
242 void FileSelected(const FilePath& path, void* params); | 222 virtual void FileSelected(const FilePath& path, void* params) = 0; |
243 void FileSelectionCanceled(void* params); | 223 virtual void FileSelectionCanceled(void* params) = 0; |
244 | 224 |
245 // Called by the delegate if it delayed the download in | 225 // Called by the delegate if it delayed the download in |
246 // DownloadManagerDelegate::ShouldStartDownload and now is ready. | 226 // DownloadManagerDelegate::ShouldStartDownload and now is ready. |
247 void RestartDownload(int32 download_id); | 227 virtual void RestartDownload(int32 download_id) = 0; |
248 | 228 |
249 // Mark the download opened in the persistent store. | 229 // Mark the download opened in the persistent store. |
250 void MarkDownloadOpened(DownloadItem* download); | 230 virtual void MarkDownloadOpened(DownloadItem* download) = 0; |
251 | 231 |
252 // Checks whether downloaded files still exist. Updates state of downloads | 232 // Checks whether downloaded files still exist. Updates state of downloads |
253 // that refer to removed files. The check runs in the background and may | 233 // that refer to removed files. The check runs in the background and may |
254 // finish asynchronously after this method returns. | 234 // finish asynchronously after this method returns. |
255 void CheckForHistoryFilesRemoval(); | 235 virtual void CheckForHistoryFilesRemoval() = 0; |
256 | 236 |
257 // Checks whether a downloaded file still exists and updates the file's state | 237 // Checks whether a downloaded file still exists and updates the file's state |
258 // if the file is already removed. The check runs in the background and may | 238 // if the file is already removed. The check runs in the background and may |
259 // finish asynchronously after this method returns. | 239 // finish asynchronously after this method returns. |
260 void CheckForFileRemoval(DownloadItem* download_item); | 240 virtual void CheckForFileRemoval(DownloadItem* download_item) = 0; |
261 | 241 |
262 // Assert the named download item is on the correct queues | 242 // Assert the named download item is on the correct queues |
263 // in the DownloadManager. For debugging. | 243 // in the DownloadManager. For debugging. |
264 void AssertQueueStateConsistent(DownloadItem* download); | 244 virtual void AssertQueueStateConsistent(DownloadItem* download) = 0; |
265 | 245 |
266 // Get the download item from the history map. Useful after the item has | 246 // Get the download item from the history map. Useful after the item has |
267 // been removed from the active map, or was retrieved from the history DB. | 247 // been removed from the active map, or was retrieved from the history DB. |
268 DownloadItem* GetDownloadItem(int id); | 248 virtual DownloadItem* GetDownloadItem(int id) = 0; |
269 | 249 |
270 // Called when Save Page download starts. Transfers ownership of |download| | 250 // Called when Save Page download starts. Transfers ownership of |download| |
271 // to the DownloadManager. | 251 // to the DownloadManager. |
272 void SavePageDownloadStarted(DownloadItem* download); | 252 virtual void SavePageDownloadStarted(DownloadItem* download) = 0; |
273 | 253 |
274 // Called when Save Page download is done. | 254 // Called when Save Page download is done. |
275 void SavePageDownloadFinished(DownloadItem* download); | 255 virtual void SavePageDownloadFinished(DownloadItem* download) = 0; |
276 | 256 |
277 // Get the download item from the active map. Useful when the item is not | 257 // Get the download item from the active map. Useful when the item is not |
278 // yet in the history map. | 258 // yet in the history map. |
279 DownloadItem* GetActiveDownloadItem(int id); | 259 virtual DownloadItem* GetActiveDownloadItem(int id) = 0; |
280 | 260 |
281 content::DownloadManagerDelegate* delegate() const { return delegate_; } | 261 virtual content::DownloadManagerDelegate* delegate() const = 0; |
282 | 262 |
283 // For testing only. May be called from tests indirectly (through | 263 // For testing only. May be called from tests indirectly (through |
284 // other for testing only methods). | 264 // other for testing only methods). |
285 void SetDownloadManagerDelegate(content::DownloadManagerDelegate* delegate); | 265 virtual void SetDownloadManagerDelegate( |
286 | 266 content::DownloadManagerDelegate* delegate) = 0; |
287 DownloadId GetNextId(); | 267 |
288 | 268 virtual DownloadId GetNextId() = 0; |
289 private: | 269 |
290 typedef std::set<DownloadItem*> DownloadSet; | 270 protected: |
291 typedef base::hash_map<int64, DownloadItem*> DownloadMap; | 271 // These functions are here for unit tests. |
292 | 272 |
273 // Called back after a target path for the file to be downloaded to has been | |
274 // determined, either automatically based on the suggested file name, or by | |
275 // the user in a Save As dialog box. | |
276 virtual void ContinueDownloadWithPath(DownloadItem* download, | |
277 const FilePath& chosen_file) = 0; | |
278 | |
279 // Retrieves the download from the |download_id|. | |
280 // Returns NULL if the download is not active. | |
281 virtual DownloadItem* GetActiveDownload(int32 download_id) = 0; | |
282 | |
283 virtual void SetFileManager(DownloadFileManager* file_manager) = 0; | |
284 | |
285 private: | |
jam
2011/11/10 17:19:09
nit: spacing
ahendrickson
2011/11/18 18:47:39
Done.
| |
293 // For testing. | 286 // For testing. |
294 friend class DownloadManagerTest; | 287 friend class DownloadManagerTest; |
jam
2011/11/10 17:19:09
are all these friends still needed?
ahendrickson
2011/11/18 18:47:39
Was able to get rid of two.
| |
295 friend class DownloadTest; | 288 friend class DownloadTest; |
296 friend class MockDownloadManager; | 289 friend class MockDownloadManager; |
297 | 290 |
298 friend class base::RefCountedThreadSafe< | 291 friend class base::RefCountedThreadSafe< |
299 DownloadManager, content::BrowserThread::DeleteOnUIThread>; | 292 DownloadManager, content::BrowserThread::DeleteOnUIThread>; |
300 friend struct content::BrowserThread::DeleteOnThread< | 293 friend struct content::BrowserThread::DeleteOnThread< |
301 content::BrowserThread::UI>; | 294 content::BrowserThread::UI>; |
302 friend class DeleteTask<DownloadManager>; | 295 friend class DeleteTask<DownloadManager>; |
303 | |
304 virtual ~DownloadManager(); | |
305 | |
306 // Called on the FILE thread to check the existence of a downloaded file. | |
307 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); | |
308 | |
309 // Called on the UI thread if the FILE thread detects the removal of | |
310 // the downloaded file. The UI thread updates the state of the file | |
311 // and then notifies this update to the file's observer. | |
312 void OnFileRemovalDetected(int64 db_handle); | |
313 | |
314 // Called back after a target path for the file to be downloaded to has been | |
315 // determined, either automatically based on the suggested file name, or by | |
316 // the user in a Save As dialog box. | |
317 void ContinueDownloadWithPath(DownloadItem* download, | |
318 const FilePath& chosen_file); | |
319 | |
320 // Retrieves the download from the |download_id|. | |
321 // Returns NULL if the download is not active. | |
322 DownloadItem* GetActiveDownload(int32 download_id); | |
323 | |
324 // Removes |download| from the active and in progress maps. | |
325 // Called when the download is cancelled or has an error. | |
326 // Does nothing if the download is not in the history DB. | |
327 void RemoveFromActiveList(DownloadItem* download); | |
328 | |
329 // Updates the delegate about the overall download progress. | |
330 void UpdateDownloadProgress(); | |
331 | |
332 // Inform observers that the model has changed. | |
333 void NotifyModelChanged(); | |
334 | |
335 // Debugging routine to confirm relationship between below | |
336 // containers; no-op if NDEBUG. | |
337 void AssertContainersConsistent() const; | |
338 | |
339 // Add a DownloadItem to history_downloads_. | |
340 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); | |
341 | |
342 // Remove from internal maps. | |
343 int RemoveDownloadItems(const DownloadVector& pending_deletes); | |
344 | |
345 // Called when a download entry is committed to the persistent store. | |
346 void OnDownloadItemAddedToPersistentStore(int32 download_id, int64 db_handle); | |
347 | |
348 // Called when Save Page As entry is commited to the persistent store. | |
349 void OnSavePageItemAddedToPersistentStore(int32 download_id, int64 db_handle); | |
350 | |
351 // |downloads_| is the owning set for all downloads known to the | |
352 // DownloadManager. This includes downloads started by the user in | |
353 // this session, downloads initialized from the history system, and | |
354 // "save page as" downloads. All other DownloadItem containers in | |
355 // the DownloadManager are maps; they do not own the DownloadItems. | |
356 // Note that this is the only place (with any functional implications; | |
357 // see save_page_downloads_ below) that "save page as" downloads are | |
358 // kept, as the DownloadManager's only job is to hold onto those | |
359 // until destruction. | |
360 // | |
361 // |history_downloads_| is map of all downloads in this browser context. The | |
362 // key is the handle returned by the history system, which is unique across | |
363 // sessions. | |
364 // | |
365 // |active_downloads_| is a map of all downloads that are currently being | |
366 // processed. The key is the ID assigned by the DownloadFileManager, | |
367 // which is unique for the current session. | |
368 // | |
369 // |in_progress_| is a map of all downloads that are in progress and that have | |
370 // not yet received a valid history handle. The key is the ID assigned by the | |
371 // DownloadFileManager, which is unique for the current session. | |
372 // | |
373 // |save_page_downloads_| (if defined) is a collection of all the | |
374 // downloads the "save page as" system has given to us to hold onto | |
375 // until we are destroyed. They key is DownloadFileManager, so it is unique | |
376 // compared to download item. It is only used for debugging. | |
377 // | |
378 // When a download is created through a user action, the corresponding | |
379 // DownloadItem* is placed in |active_downloads_| and remains there until the | |
380 // download is in a terminal state (COMPLETE or CANCELLED). It is also | |
381 // placed in |in_progress_| and remains there until it has received a | |
382 // valid handle from the history system. Once it has a valid handle, the | |
383 // DownloadItem* is placed in the |history_downloads_| map. When the | |
384 // download reaches a terminal state, it is removed from |in_progress_|. | |
385 // Downloads from past sessions read from a persisted state from the | |
386 // history system are placed directly into |history_downloads_| since | |
387 // they have valid handles in the history system. | |
388 | |
389 DownloadSet downloads_; | |
390 DownloadMap history_downloads_; | |
391 DownloadMap in_progress_; | |
392 DownloadMap active_downloads_; | |
393 DownloadMap save_page_downloads_; | |
394 | |
395 // True if the download manager has been initialized and requires a shutdown. | |
396 bool shutdown_needed_; | |
397 | |
398 // Observers that want to be notified of changes to the set of downloads. | |
399 ObserverList<Observer> observers_; | |
400 | |
401 // The current active browser context. | |
402 content::BrowserContext* browser_context_; | |
403 | |
404 // Non-owning pointer for handling file writing on the download_thread_. | |
405 DownloadFileManager* file_manager_; | |
406 | |
407 // Non-owning pointer for updating the download status. | |
408 base::WeakPtr<DownloadStatusUpdater> status_updater_; | |
409 | |
410 // The user's last choice for download directory. This is only used when the | |
411 // user wants us to prompt for a save location for each download. | |
412 FilePath last_download_path_; | |
413 | |
414 // Allows an embedder to control behavior. Guaranteed to outlive this object. | |
415 content::DownloadManagerDelegate* delegate_; | |
416 | |
417 DownloadIdFactory* id_factory_; | |
418 | |
419 // TODO(rdsmith): Remove when http://crbug.com/85408 is fixed. | |
420 // For debugging only. | |
421 int64 largest_db_handle_in_history_; | |
422 | |
423 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | |
424 }; | 296 }; |
425 | 297 |
426 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 298 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |