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

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: Moved comment. 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Browser's download manager: manages all downloads and destination view.
71 class CONTENT_EXPORT DownloadManager 71 class CONTENT_EXPORT DownloadManager
72 : public base::RefCountedThreadSafe< 72 : public base::RefCountedThreadSafe<
73 DownloadManager, content::BrowserThread::DeleteOnUIThread>, 73 DownloadManager, content::BrowserThread::DeleteOnUIThread> {
74 public DownloadStatusUpdaterDelegate {
75 public: 74 public:
76 DownloadManager(content::DownloadManagerDelegate* delegate, 75 virtual ~DownloadManager() {}
77 DownloadIdFactory* id_factory,
78 DownloadStatusUpdater* status_updater);
79 76
80 // Shutdown the download manager. Must be called before destruction. 77 // Shutdown the download manager. Must be called before destruction.
81 void Shutdown(); 78 virtual void Shutdown() = 0;
82 79
83 // Interface to implement for observers that wish to be informed of changes 80 // Interface to implement for observers that wish to be informed of changes
84 // to the DownloadManager's collection of downloads. 81 // to the DownloadManager's collection of downloads.
85 class CONTENT_EXPORT Observer { 82 class CONTENT_EXPORT Observer {
86 public: 83 public:
87 // New or deleted download, observers should query us for the current set 84 // New or deleted download, observers should query us for the current set
88 // of downloads. 85 // of downloads.
89 virtual void ModelChanged() = 0; 86 virtual void ModelChanged() = 0;
90 87
91 // Called when the DownloadManager is being destroyed to prevent Observers 88 // Called when the DownloadManager is being destroyed to prevent Observers
92 // from calling back to a stale pointer. 89 // from calling back to a stale pointer.
93 virtual void ManagerGoingDown() {} 90 virtual void ManagerGoingDown() {}
94 91
95 // Called immediately after the DownloadManager puts up a select file 92 // Called immediately after the DownloadManager puts up a select file
96 // dialog. 93 // dialog.
97 // |id| indicates which download opened the dialog. 94 // |id| indicates which download opened the dialog.
98 virtual void SelectFileDialogDisplayed(int32 id) {} 95 virtual void SelectFileDialogDisplayed(int32 id) {}
99 96
100 protected: 97 protected:
101 virtual ~Observer() {} 98 virtual ~Observer() {}
102 }; 99 };
103 100
104 typedef std::vector<DownloadItem*> DownloadVector; 101 typedef std::vector<DownloadItem*> DownloadVector;
105 102
106 // Return all temporary downloads that reside in the specified directory. 103 // Return all temporary downloads that reside in the specified directory.
107 void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result); 104 virtual void GetTemporaryDownloads(const FilePath& dir_path,
105 DownloadVector* result) = 0;
108 106
109 // Return all non-temporary downloads in the specified directory that are 107 // Return all non-temporary downloads in the specified directory that are
110 // are in progress or have completed. 108 // are in progress or have completed.
111 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); 109 virtual void GetAllDownloads(const FilePath& dir_path,
110 DownloadVector* result) = 0;
112 111
113 // Returns all non-temporary downloads matching |query|. Empty query matches 112 // Returns all non-temporary downloads matching |query|. Empty query matches
114 // everything. 113 // everything.
115 void SearchDownloads(const string16& query, DownloadVector* result); 114 virtual void SearchDownloads(const string16& query,
115 DownloadVector* result) = 0;
116 116
117 // Returns true if initialized properly. 117 // Returns true if initialized properly.
118 bool Init(content::BrowserContext* browser_context); 118 virtual bool Init(content::BrowserContext* browser_context) = 0;
119 119
120 // Notifications sent from the download thread to the UI thread 120 // Notifications sent from the download thread to the UI thread
121 void StartDownload(int32 id); 121 virtual void StartDownload(int32 id) = 0;
122 void UpdateDownload(int32 download_id, int64 size); 122 virtual void UpdateDownload(int32 download_id, int64 size) = 0;
123 123
124 // |download_id| is the ID of the download. 124 // |download_id| is the ID of the download.
125 // |size| is the number of bytes that have been downloaded. 125 // |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 126 // |hash| is sha256 hash for the downloaded file. It is empty when the hash
127 // is not available. 127 // is not available.
128 void OnResponseCompleted(int32 download_id, int64 size, 128 virtual void OnResponseCompleted(int32 download_id, int64 size,
129 const std::string& hash); 129 const std::string& hash) = 0;
130 130
131 // Offthread target for cancelling a particular download. Will be a no-op 131 // Offthread target for cancelling a particular download. Will be a no-op
132 // if the download has already been cancelled. 132 // if the download has already been cancelled.
133 void CancelDownload(int32 download_id); 133 virtual void CancelDownload(int32 download_id) = 0;
134 134
135 // Called when there is an error in the download. 135 // Called when there is an error in the download.
136 // |download_id| is the ID of the download. 136 // |download_id| is the ID of the download.
137 // |size| is the number of bytes that are currently downloaded. 137 // |size| is the number of bytes that are currently downloaded.
138 // |reason| is a download interrupt reason code. 138 // |reason| is a download interrupt reason code.
139 void OnDownloadInterrupted(int32 download_id, int64 size, 139 virtual void OnDownloadInterrupted(int32 download_id, int64 size,
140 InterruptReason reason); 140 InterruptReason reason) = 0;
141 141
142 // Called from DownloadItem to handle the DownloadManager portion of a 142 // Called from DownloadItem to handle the DownloadManager portion of a
143 // Cancel; should not be called from other locations. 143 // Cancel; should not be called from other locations.
144 void DownloadCancelledInternal(DownloadItem* download); 144 virtual void DownloadCancelledInternal(DownloadItem* download) = 0;
145 145
146 // Called from a view when a user clicks a UI button or link. 146 // Called from a view when a user clicks a UI button or link.
147 void RemoveDownload(int64 download_handle); 147 virtual void RemoveDownload(int64 download_handle) = 0;
148 148
149 // Determine if the download is ready for completion, i.e. has had 149 // Determine if the download is ready for completion, i.e. has had
150 // all data saved, and completed the filename determination and 150 // all data saved, and completed the filename determination and
151 // history insertion. 151 // history insertion.
152 bool IsDownloadReadyForCompletion(DownloadItem* download); 152 virtual bool IsDownloadReadyForCompletion(DownloadItem* download) = 0;
153 153
154 // If all pre-requisites have been met, complete download processing, i.e. 154 // If all pre-requisites have been met, complete download processing, i.e.
155 // do internal cleanup, file rename, and potentially auto-open. 155 // do internal cleanup, file rename, and potentially auto-open.
156 // (Dangerous downloads still may block on user acceptance after this 156 // (Dangerous downloads still may block on user acceptance after this
157 // point.) 157 // point.)
158 void MaybeCompleteDownload(DownloadItem* download); 158 virtual void MaybeCompleteDownload(DownloadItem* download) = 0;
159 159
160 // Called when the download is renamed to its final name. 160 // 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 161 // |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. 162 // only valid for the DANGEROUS_BUT_VALIDATED state of the download item.
163 void OnDownloadRenamedToFinalName(int download_id, 163 virtual void OnDownloadRenamedToFinalName(int download_id,
164 const FilePath& full_path, 164 const FilePath& full_path,
165 int uniquifier); 165 int uniquifier) = 0;
166 166
167 // Remove downloads after remove_begin (inclusive) and before remove_end 167 // Remove downloads after remove_begin (inclusive) and before remove_end
168 // (exclusive). You may pass in null Time values to do an unbounded delete 168 // (exclusive). You may pass in null Time values to do an unbounded delete
169 // in either direction. 169 // in either direction.
170 int RemoveDownloadsBetween(const base::Time remove_begin, 170 virtual int RemoveDownloadsBetween(const base::Time remove_begin,
171 const base::Time remove_end); 171 const base::Time remove_end) = 0;
172 172
173 // Remove downloads will delete all downloads that have a timestamp that is 173 // 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 174 // the same or more recent than |remove_begin|. The number of downloads
175 // deleted is returned back to the caller. 175 // deleted is returned back to the caller.
176 int RemoveDownloads(const base::Time remove_begin); 176 virtual int RemoveDownloads(const base::Time remove_begin) = 0;
177 177
178 // Remove all downloads will delete all downloads. The number of downloads 178 // Remove all downloads will delete all downloads. The number of downloads
179 // deleted is returned back to the caller. 179 // deleted is returned back to the caller.
180 int RemoveAllDownloads(); 180 virtual int RemoveAllDownloads() = 0;
181 181
182 // Final download manager transition for download: Update the download 182 // Final download manager transition for download: Update the download
183 // history and remove the download from |active_downloads_|. 183 // history and remove the download from |active_downloads_|.
184 void DownloadCompleted(int32 download_id); 184 virtual void DownloadCompleted(int32 download_id) = 0;
185 185
186 // Download the object at the URL. Used in cases such as "Save Link As..." 186 // Download the object at the URL. Used in cases such as "Save Link As..."
187 void DownloadUrl(const GURL& url, 187 virtual void DownloadUrl(const GURL& url,
188 const GURL& referrer, 188 const GURL& referrer,
189 const std::string& referrer_encoding, 189 const std::string& referrer_encoding,
190 TabContents* tab_contents); 190 TabContents* tab_contents) = 0;
191 191
192 // Download the object at the URL and save it to the specified path. The 192 // 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 193 // 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. 194 // in the download history. Used in cases such as drag and drop.
195 void DownloadUrlToFile(const GURL& url, 195 virtual void DownloadUrlToFile(const GURL& url,
196 const GURL& referrer, 196 const GURL& referrer,
197 const std::string& referrer_encoding, 197 const std::string& referrer_encoding,
198 const DownloadSaveInfo& save_info, 198 const DownloadSaveInfo& save_info,
199 TabContents* tab_contents); 199 TabContents* tab_contents) = 0;
200 200
201 // Allow objects to observe the download creation process. 201 // Allow objects to observe the download creation process.
202 void AddObserver(Observer* observer); 202 virtual void AddObserver(Observer* observer) = 0;
203 203
204 // Remove a download observer from ourself. 204 // Remove a download observer from ourself.
205 void RemoveObserver(Observer* observer); 205 virtual void RemoveObserver(Observer* observer) = 0;
206 206
207 // Called by the embedder, after creating the download manager, to let it know 207 // Called by the embedder, after creating the download manager, to let it know
208 // about downloads from previous runs of the browser. 208 // about downloads from previous runs of the browser.
209 void OnPersistentStoreQueryComplete( 209 virtual void OnPersistentStoreQueryComplete(
210 std::vector<DownloadPersistentStoreInfo>* entries); 210 std::vector<DownloadPersistentStoreInfo>* entries) = 0;
211 211
212 // Called by the embedder, in response to 212 // Called by the embedder, in response to
213 // DownloadManagerDelegate::AddItemToPersistentStore. 213 // DownloadManagerDelegate::AddItemToPersistentStore.
214 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); 214 virtual void OnItemAddedToPersistentStore(int32 download_id,
215 int64 db_handle) = 0;
215 216
216 // Display a new download in the appropriate browser UI. 217 // Display a new download in the appropriate browser UI.
217 void ShowDownloadInBrowser(DownloadItem* download); 218 virtual void ShowDownloadInBrowser(DownloadItem* download) = 0;
218 219
219 // The number of in progress (including paused) downloads. 220 // The number of in progress (including paused) downloads.
220 int in_progress_count() const { 221 virtual int InProgressCount() const = 0;
221 return static_cast<int>(in_progress_.size()); 222
222 } 223 virtual content::BrowserContext* BrowserContext() = 0;
223 224
224 content::BrowserContext* browser_context() { return browser_context_; } 225 virtual FilePath LastDownloadPath() = 0;
225
226 FilePath last_download_path() { return last_download_path_; }
227 226
228 // Creates the download item. Must be called on the UI thread. 227 // Creates the download item. Must be called on the UI thread.
229 void CreateDownloadItem(DownloadCreateInfo* info, 228 virtual void CreateDownloadItem(DownloadCreateInfo* info,
230 const DownloadRequestHandle& request_handle); 229 const DownloadRequestHandle& request_handle) = 0;
231 230
232 // Clears the last download path, used to initialize "save as" dialogs. 231 // Clears the last download path, used to initialize "save as" dialogs.
233 void ClearLastDownloadPath(); 232 virtual void ClearLastDownloadPath() = 0;
233
234 // Called by the delegate after the save as dialog is closed.
235 virtual void FileSelected(const FilePath& path, void* params) = 0;
236 virtual void FileSelectionCanceled(void* params) = 0;
237
238 // Called by the delegate if it delayed the download in
239 // DownloadManagerDelegate::ShouldStartDownload and now is ready.
240 virtual void RestartDownload(int32 download_id) = 0;
241
242 // Mark the download opened in the persistent store.
243 virtual void MarkDownloadOpened(DownloadItem* download) = 0;
244
245 // Checks whether downloaded files still exist. Updates state of downloads
246 // that refer to removed files. The check runs in the background and may
247 // finish asynchronously after this method returns.
248 virtual void CheckForHistoryFilesRemoval() = 0;
249
250 // Checks whether a downloaded file still exists and updates the file's state
251 // if the file is already removed. The check runs in the background and may
252 // finish asynchronously after this method returns.
253 virtual void CheckForFileRemoval(DownloadItem* download_item) = 0;
254
255 // Assert the named download item is on the correct queues
256 // in the DownloadManager. For debugging.
257 virtual void AssertQueueStateConsistent(DownloadItem* download) = 0;
258
259 // Get the download item from the history map. Useful after the item has
260 // been removed from the active map, or was retrieved from the history DB.
261 virtual DownloadItem* GetDownloadItem(int id) = 0;
262
263 // Called when Save Page download starts. Transfers ownership of |download|
264 // to the DownloadManager.
265 virtual void SavePageDownloadStarted(DownloadItem* download) = 0;
266
267 // Called when Save Page download is done.
268 virtual void SavePageDownloadFinished(DownloadItem* download) = 0;
269
270 // Get the download item from the active map. Useful when the item is not
271 // yet in the history map.
272 virtual DownloadItem* GetActiveDownloadItem(int id) = 0;
273
274 virtual content::DownloadManagerDelegate* delegate() const = 0;
275
276 // For testing only. May be called from tests indirectly (through
277 // other for testing only methods).
278 virtual void SetDownloadManagerDelegate(
279 content::DownloadManagerDelegate* delegate) = 0;
280
281 virtual DownloadId GetNextId() = 0;
282
283 protected:
284 // These functions are here for unit tests.
285
286 // Called back after a target path for the file to be downloaded to has been
287 // determined, either automatically based on the suggested file name, or by
288 // the user in a Save As dialog box.
289 virtual void ContinueDownloadWithPath(DownloadItem* download,
290 const FilePath& chosen_file) = 0;
291
292 // Retrieves the download from the |download_id|.
293 // Returns NULL if the download is not active.
294 virtual DownloadItem* GetActiveDownload(int32 download_id) = 0;
295
296 virtual void SetFileManager(DownloadFileManager* file_manager) = 0;
297
298 private:
299 // For testing.
300 friend class DownloadManagerTest;
301 friend class DownloadTest;
302 friend class MockDownloadManager;
303
304 friend class base::RefCountedThreadSafe<
305 DownloadManager, content::BrowserThread::DeleteOnUIThread>;
306 friend struct content::BrowserThread::DeleteOnThread<
307 content::BrowserThread::UI>;
308 friend class DeleteTask<DownloadManager>;
309 };
310
311 class CONTENT_EXPORT DownloadManagerImpl
jam 2011/11/09 17:34:00 this need to go into a separate file, i.e .downloa
ahendrickson 2011/11/09 22:00:59 Done.
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
« no previous file with comments | « chrome/browser/ui/webui/downloads_dom_handler.cc ('k') | content/browser/download/download_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698