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

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