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