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

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

Issue 8697006: DownloadManager intereface refactoring to allow cleaner DownloadItem unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improved isolation of MockDownloadManager. Created 9 years 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 // Offthread target for cancelling a particular download. Will be a no-op 117 // Offthread target for cancelling a particular download. Will be a no-op
118 // if the download has already been cancelled. 118 // if the download has already been cancelled.
119 virtual void CancelDownload(int32 download_id) = 0; 119 virtual void CancelDownload(int32 download_id) = 0;
120 120
121 // Called when there is an error in the download. 121 // Called when there is an error in the download.
122 // |download_id| is the ID of the download. 122 // |download_id| is the ID of the download.
123 // |size| is the number of bytes that are currently downloaded. 123 // |size| is the number of bytes that are currently downloaded.
124 // |reason| is a download interrupt reason code. 124 // |reason| is a download interrupt reason code.
125 virtual void OnDownloadInterrupted(int32 download_id, int64 size, 125 virtual void OnDownloadInterrupted(int32 download_id, int64 size,
126 InterruptReason reason) = 0; 126 InterruptReason reason) = 0;
127 127
128 // Called from DownloadItem to handle the DownloadManager portion of a 128 // If all pre-requisites have been met, complete download processing, i.e.
129 // Cancel; should not be called from other locations.
130 virtual void DownloadCancelledInternal(DownloadItem* download) = 0;
131
132 // Called from a view when a user clicks a UI button or link.
133 virtual void RemoveDownload(int64 download_handle) = 0;
134
135 // Determine if the download is ready for completion, i.e. has had
136 // all data saved, and completed the filename determination and
137 // history insertion.
138 virtual bool IsDownloadReadyForCompletion(DownloadItem* download) = 0;
139
140 // If all pre-requisites have been met, complete download processing, i.e.
141 // do internal cleanup, file rename, and potentially auto-open. 129 // do internal cleanup, file rename, and potentially auto-open.
142 // (Dangerous downloads still may block on user acceptance after this 130 // (Dangerous downloads still may block on user acceptance after this
143 // point.) 131 // point.)
144 virtual void MaybeCompleteDownload(DownloadItem* download) = 0; 132 virtual void MaybeCompleteDownload(DownloadItem* download) = 0;
145 133
146 // Called when the download is renamed to its final name. 134 // Called when the download is renamed to its final name.
147 // |uniquifier| is a number used to make unique names for the file. It is 135 // |uniquifier| is a number used to make unique names for the file. It is
148 // only valid for the DANGEROUS_BUT_VALIDATED state of the download item. 136 // only valid for the DANGEROUS_BUT_VALIDATED state of the download item.
149 virtual void OnDownloadRenamedToFinalName(int download_id, 137 virtual void OnDownloadRenamedToFinalName(int download_id,
150 const FilePath& full_path, 138 const FilePath& full_path,
151 int uniquifier) = 0; 139 int uniquifier) = 0;
152 140
153 // Remove downloads after remove_begin (inclusive) and before remove_end 141 // Remove downloads after remove_begin (inclusive) and before remove_end
154 // (exclusive). You may pass in null Time values to do an unbounded delete 142 // (exclusive). You may pass in null Time values to do an unbounded delete
155 // in either direction. 143 // in either direction.
156 virtual int RemoveDownloadsBetween(const base::Time remove_begin, 144 virtual int RemoveDownloadsBetween(const base::Time remove_begin,
157 const base::Time remove_end) = 0; 145 const base::Time remove_end) = 0;
158 146
159 // Remove downloads will delete all downloads that have a timestamp that is 147 // Remove downloads will delete all downloads that have a timestamp that is
160 // the same or more recent than |remove_begin|. The number of downloads 148 // the same or more recent than |remove_begin|. The number of downloads
161 // deleted is returned back to the caller. 149 // deleted is returned back to the caller.
162 virtual int RemoveDownloads(const base::Time remove_begin) = 0; 150 virtual int RemoveDownloads(const base::Time remove_begin) = 0;
163 151
164 // Remove all downloads will delete all downloads. The number of downloads 152 // Remove all downloads will delete all downloads. The number of downloads
165 // deleted is returned back to the caller. 153 // deleted is returned back to the caller.
166 virtual int RemoveAllDownloads() = 0; 154 virtual int RemoveAllDownloads() = 0;
167 155
168 // Final download manager transition for download: Update the download
169 // history and remove the download from |active_downloads_|.
170 virtual void DownloadCompleted(int32 download_id) = 0;
171
172 // Download the object at the URL. Used in cases such as "Save Link As..." 156 // Download the object at the URL. Used in cases such as "Save Link As..."
173 virtual void DownloadUrl(const GURL& url, 157 virtual void DownloadUrl(const GURL& url,
174 const GURL& referrer, 158 const GURL& referrer,
175 const std::string& referrer_encoding, 159 const std::string& referrer_encoding,
176 TabContents* tab_contents) = 0; 160 TabContents* tab_contents) = 0;
177 161
178 // Download the object at the URL and save it to the specified path. The 162 // Download the object at the URL and save it to the specified path. The
179 // download is treated as the temporary download and thus will not appear 163 // download is treated as the temporary download and thus will not appear
180 // in the download history. Used in cases such as drag and drop. 164 // in the download history. Used in cases such as drag and drop.
181 virtual void DownloadUrlToFile(const GURL& url, 165 virtual void DownloadUrlToFile(const GURL& url,
(...skipping 11 matching lines...) Expand all
193 // Called by the embedder, after creating the download manager, to let it know 177 // Called by the embedder, after creating the download manager, to let it know
194 // about downloads from previous runs of the browser. 178 // about downloads from previous runs of the browser.
195 virtual void OnPersistentStoreQueryComplete( 179 virtual void OnPersistentStoreQueryComplete(
196 std::vector<DownloadPersistentStoreInfo>* entries) = 0; 180 std::vector<DownloadPersistentStoreInfo>* entries) = 0;
197 181
198 // Called by the embedder, in response to 182 // Called by the embedder, in response to
199 // DownloadManagerDelegate::AddItemToPersistentStore. 183 // DownloadManagerDelegate::AddItemToPersistentStore.
200 virtual void OnItemAddedToPersistentStore(int32 download_id, 184 virtual void OnItemAddedToPersistentStore(int32 download_id,
201 int64 db_handle) = 0; 185 int64 db_handle) = 0;
202 186
203 // Display a new download in the appropriate browser UI.
204 virtual void ShowDownloadInBrowser(DownloadItem* download) = 0;
205
206 // The number of in progress (including paused) downloads. 187 // The number of in progress (including paused) downloads.
207 virtual int InProgressCount() const = 0; 188 virtual int InProgressCount() const = 0;
208 189
209 virtual content::BrowserContext* BrowserContext() = 0; 190 virtual content::BrowserContext* BrowserContext() const = 0;
210 191
211 virtual FilePath LastDownloadPath() = 0; 192 virtual FilePath LastDownloadPath() = 0;
212 193
213 // Creates the download item. Must be called on the UI thread. 194 // Creates the download item. Must be called on the UI thread.
214 virtual void CreateDownloadItem(DownloadCreateInfo* info, 195 virtual void CreateDownloadItem(
215 const DownloadRequestHandle& request_handle) = 0; 196 DownloadCreateInfo* info,
197 const DownloadRequestHandle& request_handle) = 0;
198
199 // Creates a download item for the SavePackage system.
200 // Must be called on the UI thread. Note that the DownloadManager
201 // retains ownership.
202 virtual DownloadItem* CreateSavePackageDownloadItem(
203 const FilePath& main_file_path,
204 const GURL& page_url,
205 bool is_otr,
206 DownloadItem::Observer* observer) = 0;
216 207
217 // Clears the last download path, used to initialize "save as" dialogs. 208 // Clears the last download path, used to initialize "save as" dialogs.
218 virtual void ClearLastDownloadPath() = 0; 209 virtual void ClearLastDownloadPath() = 0;
219 210
220 // Called by the delegate after the save as dialog is closed. 211 // Called by the delegate after the save as dialog is closed.
221 virtual void FileSelected(const FilePath& path, void* params) = 0; 212 virtual void FileSelected(const FilePath& path, void* params) = 0;
222 virtual void FileSelectionCanceled(void* params) = 0; 213 virtual void FileSelectionCanceled(void* params) = 0;
223 214
224 // Called by the delegate if it delayed the download in 215 // Called by the delegate if it delayed the download in
225 // DownloadManagerDelegate::ShouldStartDownload and now is ready. 216 // DownloadManagerDelegate::ShouldStartDownload and now is ready.
226 virtual void RestartDownload(int32 download_id) = 0; 217 virtual void RestartDownload(int32 download_id) = 0;
227 218
228 // Mark the download opened in the persistent store.
229 virtual void MarkDownloadOpened(DownloadItem* download) = 0;
230
231 // Checks whether downloaded files still exist. Updates state of downloads 219 // Checks whether downloaded files still exist. Updates state of downloads
232 // that refer to removed files. The check runs in the background and may 220 // that refer to removed files. The check runs in the background and may
233 // finish asynchronously after this method returns. 221 // finish asynchronously after this method returns.
234 virtual void CheckForHistoryFilesRemoval() = 0; 222 virtual void CheckForHistoryFilesRemoval() = 0;
235 223
236 // Checks whether a downloaded file still exists and updates the file's state
237 // if the file is already removed. The check runs in the background and may
238 // finish asynchronously after this method returns.
239 virtual void CheckForFileRemoval(DownloadItem* download_item) = 0;
240
241 // Assert the named download item is on the correct queues
242 // in the DownloadManager. For debugging.
243 virtual void AssertQueueStateConsistent(DownloadItem* download) = 0;
244
245 // Get the download item from the history map. Useful after the item has 224 // Get the download item from the history map. Useful after the item has
246 // been removed from the active map, or was retrieved from the history DB. 225 // been removed from the active map, or was retrieved from the history DB.
247 virtual DownloadItem* GetDownloadItem(int id) = 0; 226 virtual DownloadItem* GetDownloadItem(int id) = 0;
248 227
249 // Called when Save Page download starts. Transfers ownership of |download|
250 // to the DownloadManager.
251 virtual void SavePageDownloadStarted(DownloadItem* download) = 0;
252
253 // Called when Save Page download is done. 228 // Called when Save Page download is done.
254 virtual void SavePageDownloadFinished(DownloadItem* download) = 0; 229 virtual void SavePageDownloadFinished(DownloadItem* download) = 0;
255 230
256 // Get the download item from the active map. Useful when the item is not 231 // Get the download item from the active map. Useful when the item is not
257 // yet in the history map. 232 // yet in the history map.
258 virtual DownloadItem* GetActiveDownloadItem(int id) = 0; 233 virtual DownloadItem* GetActiveDownloadItem(int id) = 0;
259 234
260 virtual content::DownloadManagerDelegate* delegate() const = 0; 235 virtual content::DownloadManagerDelegate* delegate() const = 0;
261 236
262 // For testing only. May be called from tests indirectly (through 237 // For testing only. May be called from tests indirectly (through
263 // other for testing only methods). 238 // other for testing only methods).
264 virtual void SetDownloadManagerDelegate( 239 virtual void SetDownloadManagerDelegate(
265 content::DownloadManagerDelegate* delegate) = 0; 240 content::DownloadManagerDelegate* delegate) = 0;
266 241
267 virtual DownloadId GetNextId() = 0;
268
269 protected: 242 protected:
270 // These functions are here for unit tests. 243 // These functions are here for unit tests.
271 244
272 // Called back after a target path for the file to be downloaded to has been 245 // Called back after a target path for the file to be downloaded to has been
273 // determined, either automatically based on the suggested file name, or by 246 // determined, either automatically based on the suggested file name, or by
274 // the user in a Save As dialog box. 247 // the user in a Save As dialog box.
275 virtual void ContinueDownloadWithPath(DownloadItem* download, 248 virtual void ContinueDownloadWithPath(DownloadItem* download,
276 const FilePath& chosen_file) = 0; 249 const FilePath& chosen_file) = 0;
277 250
278 // Retrieves the download from the |download_id|. 251 // Retrieves the download from the |download_id|.
279 // Returns NULL if the download is not active. 252 // Returns NULL if the download is not active.
280 virtual DownloadItem* GetActiveDownload(int32 download_id) = 0; 253 virtual DownloadItem* GetActiveDownload(int32 download_id) = 0;
281 254
282 virtual void SetFileManager(DownloadFileManager* file_manager) = 0; 255 virtual void SetFileManager(DownloadFileManager* file_manager) = 0;
283 256
284 private: 257 private:
285 // For testing. 258 // For testing.
286 friend class DownloadManagerTest; 259 friend class DownloadManagerTest;
287 260
288 friend class base::RefCountedThreadSafe< 261 friend class base::RefCountedThreadSafe<
289 DownloadManager, content::BrowserThread::DeleteOnUIThread>; 262 DownloadManager, content::BrowserThread::DeleteOnUIThread>;
290 friend struct content::BrowserThread::DeleteOnThread< 263 friend struct content::BrowserThread::DeleteOnThread<
291 content::BrowserThread::UI>; 264 content::BrowserThread::UI>;
292 friend class DeleteTask<DownloadManager>; 265 friend class DeleteTask<DownloadManager>;
293 }; 266 };
294 267
295 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ 268 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698