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

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

Issue 6969009: Reduced the lifetime of DownloadCreateInfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed spurious DCHECK. Created 9 years, 7 months 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 profile in Chrome. 8 // active profile in Chrome.
9 // 9 //
10 // Download observers: 10 // Download observers:
(...skipping 23 matching lines...) Expand all
34 #include <vector> 34 #include <vector>
35 35
36 #include "base/basictypes.h" 36 #include "base/basictypes.h"
37 #include "base/file_path.h" 37 #include "base/file_path.h"
38 #include "base/gtest_prod_util.h" 38 #include "base/gtest_prod_util.h"
39 #include "base/memory/ref_counted.h" 39 #include "base/memory/ref_counted.h"
40 #include "base/memory/weak_ptr.h" 40 #include "base/memory/weak_ptr.h"
41 #include "base/observer_list.h" 41 #include "base/observer_list.h"
42 #include "base/scoped_ptr.h" 42 #include "base/scoped_ptr.h"
43 #include "base/time.h" 43 #include "base/time.h"
44 #include "chrome/browser/download/download_item.h"
44 #include "chrome/browser/download/download_status_updater_delegate.h" 45 #include "chrome/browser/download/download_status_updater_delegate.h"
45 #include "chrome/browser/download/download_process_handle.h" 46 #include "chrome/browser/download/download_process_handle.h"
46 #include "chrome/browser/ui/shell_dialogs.h" 47 #include "chrome/browser/ui/shell_dialogs.h"
47 #include "content/browser/browser_thread.h" 48 #include "content/browser/browser_thread.h"
48 49
49 class DownloadFileManager; 50 class DownloadFileManager;
50 class DownloadHistory; 51 class DownloadHistory;
51 class DownloadItem;
52 class DownloadPrefs; 52 class DownloadPrefs;
53 class DownloadStatusUpdater; 53 class DownloadStatusUpdater;
54 class GURL; 54 class GURL;
55 class Profile; 55 class Profile;
56 class ResourceDispatcherHost; 56 class ResourceDispatcherHost;
57 class TabContents; 57 class TabContents;
58 struct DownloadCreateInfo; 58 struct DownloadCreateInfo;
59 struct DownloadHistoryInfo;
59 struct DownloadSaveInfo; 60 struct DownloadSaveInfo;
60 61
61 // Browser's download manager: manages all downloads and destination view. 62 // Browser's download manager: manages all downloads and destination view.
62 class DownloadManager 63 class DownloadManager
63 : public base::RefCountedThreadSafe<DownloadManager, 64 : public base::RefCountedThreadSafe<DownloadManager,
64 BrowserThread::DeleteOnUIThread>, 65 BrowserThread::DeleteOnUIThread>,
65 public DownloadStatusUpdaterDelegate, 66 public DownloadStatusUpdaterDelegate,
66 public SelectFileDialog::Listener { 67 public SelectFileDialog::Listener {
67 public: 68 public:
68 explicit DownloadManager(DownloadStatusUpdater* status_updater); 69 explicit DownloadManager(DownloadStatusUpdater* status_updater);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 108
108 // Returns all non-temporary downloads matching |query|. Empty query matches 109 // Returns all non-temporary downloads matching |query|. Empty query matches
109 // everything. 110 // everything.
110 void SearchDownloads(const string16& query, 111 void SearchDownloads(const string16& query,
111 std::vector<DownloadItem*>* result); 112 std::vector<DownloadItem*>* result);
112 113
113 // Returns true if initialized properly. 114 // Returns true if initialized properly.
114 bool Init(Profile* profile); 115 bool Init(Profile* profile);
115 116
116 // Notifications sent from the download thread to the UI thread 117 // Notifications sent from the download thread to the UI thread
117 void StartDownload(DownloadCreateInfo* info); 118 void StartDownload(int32 id);
118 void UpdateDownload(int32 download_id, int64 size); 119 void UpdateDownload(int32 download_id, int64 size);
119 // |hash| is sha256 hash for the downloaded file. It is empty when the hash 120 // |hash| is sha256 hash for the downloaded file. It is empty when the hash
120 // is not available. 121 // is not available.
121 void OnResponseCompleted(int32 download_id, int64 size, int os_error, 122 void OnResponseCompleted(int32 download_id, int64 size, int os_error,
122 const std::string& hash); 123 const std::string& hash);
123 124
124 // Called from a view when a user clicks a UI button or link. 125 // Called from a view when a user clicks a UI button or link.
125 void DownloadCancelled(int32 download_id); 126 void DownloadCancelled(int32 download_id);
126 void PauseDownload(int32 download_id, bool pause); 127 void PauseDownload(int32 download_id, bool pause);
127 void RemoveDownload(int64 download_handle); 128 void RemoveDownload(int64 download_handle);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 TabContents* tab_contents); 184 TabContents* tab_contents);
184 185
185 // Allow objects to observe the download creation process. 186 // Allow objects to observe the download creation process.
186 void AddObserver(Observer* observer); 187 void AddObserver(Observer* observer);
187 188
188 // Remove a download observer from ourself. 189 // Remove a download observer from ourself.
189 void RemoveObserver(Observer* observer); 190 void RemoveObserver(Observer* observer);
190 191
191 // Methods called on completion of a query sent to the history system. 192 // Methods called on completion of a query sent to the history system.
192 void OnQueryDownloadEntriesComplete( 193 void OnQueryDownloadEntriesComplete(
193 std::vector<DownloadCreateInfo>* entries); 194 std::vector<DownloadHistoryInfo>* entries);
194 void OnCreateDownloadEntryComplete( 195 void OnCreateDownloadEntryComplete(int32 download_id, int64 db_handle);
195 DownloadCreateInfo info, int64 db_handle);
196 196
197 // Display a new download in the appropriate browser UI. 197 // Display a new download in the appropriate browser UI.
198 void ShowDownloadInBrowser(DownloadProcessHandle* process_handle, 198 void ShowDownloadInBrowser(DownloadItem* download);
199 DownloadItem* download);
200 199
201 // The number of in progress (including paused) downloads. 200 // The number of in progress (including paused) downloads.
202 int in_progress_count() const { 201 int in_progress_count() const {
203 return static_cast<int>(in_progress_.size()); 202 return static_cast<int>(in_progress_.size());
204 } 203 }
205 204
206 Profile* profile() { return profile_; } 205 Profile* profile() { return profile_; }
207 206
208 DownloadHistory* download_history() { return download_history_.get(); } 207 DownloadHistory* download_history() { return download_history_.get(); }
209 208
(...skipping 15 matching lines...) Expand all
225 virtual int64 GetTotalDownloadBytes(); 224 virtual int64 GetTotalDownloadBytes();
226 225
227 // Overridden from SelectFileDialog::Listener: 226 // Overridden from SelectFileDialog::Listener:
228 virtual void FileSelected(const FilePath& path, int index, void* params); 227 virtual void FileSelected(const FilePath& path, int index, void* params);
229 virtual void FileSelectionCanceled(void* params); 228 virtual void FileSelectionCanceled(void* params);
230 229
231 // Called when the user has validated the download of a dangerous file. 230 // Called when the user has validated the download of a dangerous file.
232 void DangerousDownloadValidated(DownloadItem* download); 231 void DangerousDownloadValidated(DownloadItem* download);
233 232
234 // Callback function after url is checked with safebrowsing service. 233 // Callback function after url is checked with safebrowsing service.
235 void CheckDownloadUrlDone(DownloadCreateInfo* info, bool is_dangerous_url); 234 void CheckDownloadUrlDone(int32 download_id, bool is_dangerous_url);
236 235
237 // Callback function after download file hash is checked with safebrowsing 236 // Callback function after download file hash is checked with safebrowsing
238 // service. 237 // service.
239 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash); 238 void CheckDownloadHashDone(int32 download_id, bool is_dangerous_hash);
240 239
241 private: 240 private:
242 // For testing. 241 // For testing.
243 friend class DownloadManagerTest; 242 friend class DownloadManagerTest;
244 friend class MockDownloadManager; 243 friend class MockDownloadManager;
245 244
(...skipping 20 matching lines...) Expand all
266 265
267 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>; 266 friend struct BrowserThread::DeleteOnThread<BrowserThread::UI>;
268 friend class DeleteTask<DownloadManager>; 267 friend class DeleteTask<DownloadManager>;
269 friend class OtherDownloadManagerObserver; 268 friend class OtherDownloadManagerObserver;
270 269
271 ~DownloadManager(); 270 ~DownloadManager();
272 271
273 // Called on the download thread to check whether the suggested file path 272 // Called on the download thread to check whether the suggested file path
274 // exists. We don't check if the file exists on the UI thread to avoid UI 273 // exists. We don't check if the file exists on the UI thread to avoid UI
275 // stalls from interacting with the file system. 274 // stalls from interacting with the file system.
276 void CheckIfSuggestedPathExists(DownloadCreateInfo* info, 275 void CheckIfSuggestedPathExists(int32 download_id,
276 DownloadItem::DownloadStateInfo state,
277 const FilePath& default_path); 277 const FilePath& default_path);
278 278
279 // Called on the UI thread once the DownloadManager has determined whether the 279 // Called on the UI thread once the DownloadManager has determined whether the
280 // suggested file path exists. 280 // suggested file path exists.
281 void OnPathExistenceAvailable(DownloadCreateInfo* info); 281 void OnPathExistenceAvailable(int32 download_id,
282 DownloadItem::DownloadStateInfo new_state);
282 283
283 // Called back after a target path for the file to be downloaded to has been 284 // Called back after a target path for the file to be downloaded to has been
284 // determined, either automatically based on the suggested file name, or by 285 // determined, either automatically based on the suggested file name, or by
285 // the user in a Save As dialog box. 286 // the user in a Save As dialog box.
286 void AttachDownloadItem(DownloadCreateInfo* info); 287 void ContinueDownloadWithPath(DownloadItem* download,
288 const FilePath& chosen_file);
287 289
288 // Download cancel helper function. 290 // Download cancel helper function.
289 // |process_handle| is passed by value because it is ultimately passed to 291 // |process_handle| is passed by value because it is ultimately passed to
290 // other threads, and this way we don't have to worry about object lifetimes. 292 // other threads, and this way we don't have to worry about object lifetimes.
291 void DownloadCancelledInternal(int download_id, 293 void DownloadCancelledInternal(int download_id,
292 DownloadProcessHandle process_handle); 294 DownloadProcessHandle process_handle);
293 295
294 // All data has been downloaded. 296 // All data has been downloaded.
295 // |hash| is sha256 hash for the downloaded file. It is empty when the hash 297 // |hash| is sha256 hash for the downloaded file. It is empty when the hash
296 // is not available. 298 // is not available.
297 void OnAllDataSaved(int32 download_id, int64 size, const std::string& hash); 299 void OnAllDataSaved(int32 download_id, int64 size, const std::string& hash);
298 300
299 // An error occurred in the download. 301 // An error occurred in the download.
300 void OnDownloadError(int32 download_id, int64 size, int os_error); 302 void OnDownloadError(int32 download_id, int64 size, int os_error);
301 303
302 // Updates the app icon about the overall download progress. 304 // Updates the app icon about the overall download progress.
303 void UpdateAppIcon(); 305 void UpdateAppIcon();
304 306
305 // Makes the ResourceDispatcherHost pause/un-pause a download request. 307 // Makes the ResourceDispatcherHost pause/un-pause a download request.
306 // Called on the IO thread. 308 // Called on the IO thread.
307 // |process_handle| is passed by value because this is called from other 309 // |process_handle| is passed by value because this is called from other
308 // threads, and this way we don't have to worry about object lifetimes. 310 // threads, and this way we don't have to worry about object lifetimes.
309 void PauseDownloadRequest(ResourceDispatcherHost* rdh, 311 void PauseDownloadRequest(ResourceDispatcherHost* rdh,
310 DownloadProcessHandle process_handle, 312 DownloadProcessHandle process_handle,
311 bool pause); 313 bool pause);
312 314
313 // Inform observers that the model has changed. 315 // Inform observers that the model has changed.
314 void NotifyModelChanged(); 316 void NotifyModelChanged();
315 317
318 // Get the download item from the history map. Useful after the item has
319 // been remove from the active map, or was retrieved from the history DB.
Paweł Hajdan Jr. 2011/05/20 09:04:42 nit: "remove" -> "removed"
ahendrickson 2011/05/20 18:31:25 Done.
316 DownloadItem* GetDownloadItem(int id); 320 DownloadItem* GetDownloadItem(int id);
317 321
322 // Get the download item from the active map. Useful when the item is not
323 // yet in the history map.
324 DownloadItem* GetActiveDownloadItem(int id);
325
318 // Debugging routine to confirm relationship between below 326 // Debugging routine to confirm relationship between below
319 // containers; no-op if NDEBUG. 327 // containers; no-op if NDEBUG.
320 void AssertContainersConsistent() const; 328 void AssertContainersConsistent() const;
321 329
322 // |downloads_| is the owning set for all downloads known to the 330 // |downloads_| is the owning set for all downloads known to the
323 // DownloadManager. This includes downloads started by the user in 331 // DownloadManager. This includes downloads started by the user in
324 // this session, downloads initialized from the history system, and 332 // this session, downloads initialized from the history system, and
325 // "save page as" downloads. All other DownloadItem containers in 333 // "save page as" downloads. All other DownloadItem containers in
326 // the DownloadManager are maps; they do not own the DownloadItems. 334 // the DownloadManager are maps; they do not own the DownloadItems.
327 // Note that this is the only place (with any functional implications; 335 // Note that this is the only place (with any functional implications;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 // The "Save As" dialog box used to ask the user where a file should be 400 // The "Save As" dialog box used to ask the user where a file should be
393 // saved. 401 // saved.
394 scoped_refptr<SelectFileDialog> select_file_dialog_; 402 scoped_refptr<SelectFileDialog> select_file_dialog_;
395 403
396 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; 404 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_;
397 405
398 DISALLOW_COPY_AND_ASSIGN(DownloadManager); 406 DISALLOW_COPY_AND_ASSIGN(DownloadManager);
399 }; 407 };
400 408
401 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ 409 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698