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

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

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

Powered by Google App Engine
This is Rietveld 408576698