Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: content/browser/download/download_manager.h

Issue 8351052: Created a DownloadManager interface, for use in unit tests.. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created a non-inlined destructor for MockDownloadManager. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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.
71 class CONTENT_EXPORT DownloadManager 70 class CONTENT_EXPORT DownloadManager
72 : public base::RefCountedThreadSafe< 71 : public base::RefCountedThreadSafe<
73 DownloadManager, content::BrowserThread::DeleteOnUIThread>, 72 DownloadManager, content::BrowserThread::DeleteOnUIThread> {
74 public DownloadStatusUpdaterDelegate {
75 public: 73 public:
76 DownloadManager(content::DownloadManagerDelegate* delegate, 74 virtual ~DownloadManager() {}
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<
304 DownloadManager, content::BrowserThread::DeleteOnUIThread>;
305 friend struct content::BrowserThread::DeleteOnThread<
306 content::BrowserThread::UI>;
307 friend class DeleteTask<DownloadManager>;
308 };
309
310 // Browser's download manager: manages all downloads and destination view.
Randy Smith (Not in Mondays) 2011/11/08 22:10:51 I *think* this comment is more appropriate next to
ahendrickson 2011/11/09 17:09:02 Done.
311 class CONTENT_EXPORT DownloadManagerImpl
312 : public DownloadManager,
313 public DownloadStatusUpdaterDelegate {
314 public:
315 DownloadManagerImpl(content::DownloadManagerDelegate* delegate,
316 DownloadIdFactory* id_factory,
317 DownloadStatusUpdater* status_updater);
318
319 // DownloadManager functions.
320 virtual void Shutdown() OVERRIDE;
321 virtual void GetTemporaryDownloads(const FilePath& dir_path,
322 DownloadVector* result) OVERRIDE;
323 virtual void GetAllDownloads(const FilePath& dir_path,
324 DownloadVector* result) OVERRIDE;
325 virtual void SearchDownloads(const string16& query,
326 DownloadVector* result) OVERRIDE;
327 virtual bool Init(content::BrowserContext* browser_context) OVERRIDE;
328 virtual void StartDownload(int32 id) OVERRIDE;
329 virtual void UpdateDownload(int32 download_id, int64 size) OVERRIDE;
330 virtual void OnResponseCompleted(int32 download_id, int64 size,
331 const std::string& hash) OVERRIDE;
332 virtual void CancelDownload(int32 download_id) OVERRIDE;
333 virtual void OnDownloadInterrupted(int32 download_id, int64 size,
334 InterruptReason reason) OVERRIDE;
335 virtual void DownloadCancelledInternal(DownloadItem* download) OVERRIDE;
336 virtual void RemoveDownload(int64 download_handle) OVERRIDE;
337 virtual bool IsDownloadReadyForCompletion(DownloadItem* download) OVERRIDE;
338 virtual void MaybeCompleteDownload(DownloadItem* download) OVERRIDE;
339 virtual void OnDownloadRenamedToFinalName(int download_id,
340 const FilePath& full_path,
341 int uniquifier) OVERRIDE;
342 virtual int RemoveDownloadsBetween(const base::Time remove_begin,
343 const base::Time remove_end) OVERRIDE;
344 virtual int RemoveDownloads(const base::Time remove_begin) OVERRIDE;
345 virtual int RemoveAllDownloads() OVERRIDE;
346 virtual void DownloadCompleted(int32 download_id) OVERRIDE;
347 virtual void DownloadUrl(const GURL& url,
348 const GURL& referrer,
349 const std::string& referrer_encoding,
350 TabContents* tab_contents) OVERRIDE;
351 virtual void DownloadUrlToFile(const GURL& url,
352 const GURL& referrer,
353 const std::string& referrer_encoding,
354 const DownloadSaveInfo& save_info,
355 TabContents* tab_contents) OVERRIDE;
356 virtual void AddObserver(Observer* observer) OVERRIDE;
357 virtual void RemoveObserver(Observer* observer) OVERRIDE;
358 virtual void OnPersistentStoreQueryComplete(
359 std::vector<DownloadPersistentStoreInfo>* entries) OVERRIDE;
360 virtual void OnItemAddedToPersistentStore(int32 download_id,
361 int64 db_handle) OVERRIDE;
362 virtual void ShowDownloadInBrowser(DownloadItem* download) OVERRIDE;
363 virtual int InProgressCount() const OVERRIDE;
364 virtual content::BrowserContext* BrowserContext() OVERRIDE;
365 virtual FilePath LastDownloadPath() OVERRIDE;
366 virtual void CreateDownloadItem(
367 DownloadCreateInfo* info,
368 const DownloadRequestHandle& request_handle) OVERRIDE;
369 virtual void ClearLastDownloadPath() OVERRIDE;
234 370
235 // Overridden from DownloadStatusUpdaterDelegate: 371 // Overridden from DownloadStatusUpdaterDelegate:
236 virtual bool IsDownloadProgressKnown() const OVERRIDE; 372 virtual bool IsDownloadProgressKnown() const OVERRIDE;
237 virtual int64 GetInProgressDownloadCount() const OVERRIDE; 373 virtual int64 GetInProgressDownloadCount() const OVERRIDE;
238 virtual int64 GetReceivedDownloadBytes() const OVERRIDE; 374 virtual int64 GetReceivedDownloadBytes() const OVERRIDE;
239 virtual int64 GetTotalDownloadBytes() const OVERRIDE; 375 virtual int64 GetTotalDownloadBytes() const OVERRIDE;
240 376
241 // Called by the delegate after the save as dialog is closed. 377 // More DownloadManager functions.
242 void FileSelected(const FilePath& path, void* params); 378 virtual void FileSelected(const FilePath& path, void* params) OVERRIDE;
243 void FileSelectionCanceled(void* params); 379 virtual void FileSelectionCanceled(void* params) OVERRIDE;
244 380 virtual void RestartDownload(int32 download_id) OVERRIDE;
245 // Called by the delegate if it delayed the download in 381 virtual void MarkDownloadOpened(DownloadItem* download) OVERRIDE;
246 // DownloadManagerDelegate::ShouldStartDownload and now is ready. 382 virtual void CheckForHistoryFilesRemoval() OVERRIDE;
247 void RestartDownload(int32 download_id); 383 virtual void CheckForFileRemoval(DownloadItem* download_item) OVERRIDE;
248 384 virtual void AssertQueueStateConsistent(DownloadItem* download) OVERRIDE;
249 // Mark the download opened in the persistent store. 385 virtual DownloadItem* GetDownloadItem(int id) OVERRIDE;
250 void MarkDownloadOpened(DownloadItem* download); 386 virtual void SavePageDownloadStarted(DownloadItem* download) OVERRIDE;
251 387 virtual void SavePageDownloadFinished(DownloadItem* download) OVERRIDE;
252 // Checks whether downloaded files still exist. Updates state of downloads 388 virtual DownloadItem* GetActiveDownloadItem(int id) OVERRIDE;
253 // that refer to removed files. The check runs in the background and may 389 virtual content::DownloadManagerDelegate* delegate() const OVERRIDE;
254 // finish asynchronously after this method returns. 390 virtual void SetDownloadManagerDelegate(
255 void CheckForHistoryFilesRemoval(); 391 content::DownloadManagerDelegate* delegate) OVERRIDE;
256 392 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 393
289 private: 394 private:
290 typedef std::set<DownloadItem*> DownloadSet; 395 typedef std::set<DownloadItem*> DownloadSet;
291 typedef base::hash_map<int64, DownloadItem*> DownloadMap; 396 typedef base::hash_map<int64, DownloadItem*> DownloadMap;
292 397
293 // For testing. 398 // For testing.
294 friend class DownloadManagerTest; 399 friend class DownloadManagerTest;
295 friend class DownloadTest; 400 friend class DownloadTest;
296 friend class MockDownloadManager; 401 friend class MockDownloadManager;
297 402
298 friend class base::RefCountedThreadSafe< 403 friend class base::RefCountedThreadSafe<
299 DownloadManager, content::BrowserThread::DeleteOnUIThread>; 404 DownloadManagerImpl, content::BrowserThread::DeleteOnUIThread>;
300 friend struct content::BrowserThread::DeleteOnThread< 405 friend struct content::BrowserThread::DeleteOnThread<
301 content::BrowserThread::UI>; 406 content::BrowserThread::UI>;
302 friend class DeleteTask<DownloadManager>; 407 friend class DeleteTask<DownloadManagerImpl>;
303 408
304 virtual ~DownloadManager(); 409 virtual ~DownloadManagerImpl();
305 410
306 // Called on the FILE thread to check the existence of a downloaded file. 411 // Called on the FILE thread to check the existence of a downloaded file.
307 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path); 412 void CheckForFileRemovalOnFileThread(int64 db_handle, const FilePath& path);
308 413
309 // Called on the UI thread if the FILE thread detects the removal of 414 // 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 415 // the downloaded file. The UI thread updates the state of the file
311 // and then notifies this update to the file's observer. 416 // and then notifies this update to the file's observer.
312 void OnFileRemovalDetected(int64 db_handle); 417 void OnFileRemovalDetected(int64 db_handle);
313 418
314 // Called back after a target path for the file to be downloaded to has been 419 // 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 420 // determined, either automatically based on the suggested file name, or by
316 // the user in a Save As dialog box. 421 // the user in a Save As dialog box.
317 void ContinueDownloadWithPath(DownloadItem* download, 422 virtual void ContinueDownloadWithPath(DownloadItem* download,
318 const FilePath& chosen_file); 423 const FilePath& chosen_file) OVERRIDE;
319 424
320 // Retrieves the download from the |download_id|. 425 // Retrieves the download from the |download_id|.
321 // Returns NULL if the download is not active. 426 // Returns NULL if the download is not active.
322 DownloadItem* GetActiveDownload(int32 download_id); 427 virtual DownloadItem* GetActiveDownload(int32 download_id) OVERRIDE;
323 428
324 // Removes |download| from the active and in progress maps. 429 // Removes |download| from the active and in progress maps.
325 // Called when the download is cancelled or has an error. 430 // Called when the download is cancelled or has an error.
326 // Does nothing if the download is not in the history DB. 431 // Does nothing if the download is not in the history DB.
327 void RemoveFromActiveList(DownloadItem* download); 432 void RemoveFromActiveList(DownloadItem* download);
328 433
329 // Updates the delegate about the overall download progress. 434 // Updates the delegate about the overall download progress.
330 void UpdateDownloadProgress(); 435 void UpdateDownloadProgress();
331 436
332 // Inform observers that the model has changed. 437 // Inform observers that the model has changed.
333 void NotifyModelChanged(); 438 void NotifyModelChanged();
334 439
335 // Debugging routine to confirm relationship between below 440 // Debugging routine to confirm relationship between below
336 // containers; no-op if NDEBUG. 441 // containers; no-op if NDEBUG.
337 void AssertContainersConsistent() const; 442 void AssertContainersConsistent() const;
338 443
339 // Add a DownloadItem to history_downloads_. 444 // Add a DownloadItem to history_downloads_.
340 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle); 445 void AddDownloadItemToHistory(DownloadItem* item, int64 db_handle);
341 446
342 // Remove from internal maps. 447 // Remove from internal maps.
343 int RemoveDownloadItems(const DownloadVector& pending_deletes); 448 int RemoveDownloadItems(const DownloadVector& pending_deletes);
344 449
345 // Called when a download entry is committed to the persistent store. 450 // Called when a download entry is committed to the persistent store.
346 void OnDownloadItemAddedToPersistentStore(int32 download_id, int64 db_handle); 451 void OnDownloadItemAddedToPersistentStore(int32 download_id, int64 db_handle);
347 452
348 // Called when Save Page As entry is commited to the persistent store. 453 // Called when Save Page As entry is committed to the persistent store.
349 void OnSavePageItemAddedToPersistentStore(int32 download_id, int64 db_handle); 454 void OnSavePageItemAddedToPersistentStore(int32 download_id, int64 db_handle);
350 455
456 // For unit tests only.
457 virtual void SetFileManager(DownloadFileManager* file_manager) OVERRIDE;
458
351 // |downloads_| is the owning set for all downloads known to the 459 // |downloads_| is the owning set for all downloads known to the
352 // DownloadManager. This includes downloads started by the user in 460 // DownloadManager. This includes downloads started by the user in
353 // this session, downloads initialized from the history system, and 461 // this session, downloads initialized from the history system, and
354 // "save page as" downloads. All other DownloadItem containers in 462 // "save page as" downloads. All other DownloadItem containers in
355 // the DownloadManager are maps; they do not own the DownloadItems. 463 // the DownloadManager are maps; they do not own the DownloadItems.
356 // Note that this is the only place (with any functional implications; 464 // Note that this is the only place (with any functional implications;
357 // see save_page_downloads_ below) that "save page as" downloads are 465 // see save_page_downloads_ below) that "save page as" downloads are
358 // kept, as the DownloadManager's only job is to hold onto those 466 // kept, as the DownloadManager's only job is to hold onto those
359 // until destruction. 467 // until destruction.
360 // 468 //
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 521
414 // Allows an embedder to control behavior. Guaranteed to outlive this object. 522 // Allows an embedder to control behavior. Guaranteed to outlive this object.
415 content::DownloadManagerDelegate* delegate_; 523 content::DownloadManagerDelegate* delegate_;
416 524
417 DownloadIdFactory* id_factory_; 525 DownloadIdFactory* id_factory_;
418 526
419 // TODO(rdsmith): Remove when http://crbug.com/85408 is fixed. 527 // TODO(rdsmith): Remove when http://crbug.com/85408 is fixed.
420 // For debugging only. 528 // For debugging only.
421 int64 largest_db_handle_in_history_; 529 int64 largest_db_handle_in_history_;
422 530
423 DISALLOW_COPY_AND_ASSIGN(DownloadManager); 531 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl);
424 }; 532 };
425 533
426 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ 534 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698