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

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

Issue 7192016: chrome.experimental.downloads (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: DownloadQuery, single DownloadMap Created 9 years, 5 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
« no previous file with comments | « chrome/browser/download/download_item.cc ('k') | chrome/browser/download/download_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "chrome/browser/download/download_request_handle.h" 45 #include "chrome/browser/download/download_request_handle.h"
46 #include "chrome/browser/download/download_status_updater_delegate.h" 46 #include "chrome/browser/download/download_status_updater_delegate.h"
47 #include "chrome/browser/ui/shell_dialogs.h" 47 #include "chrome/browser/ui/shell_dialogs.h"
48 #include "content/browser/browser_thread.h" 48 #include "content/browser/browser_thread.h"
49 49
50 class DownloadFileManager; 50 class DownloadFileManager;
51 class DownloadHistory; 51 class DownloadHistory;
52 class DownloadPrefs; 52 class DownloadPrefs;
53 class DownloadStatusUpdater; 53 class DownloadStatusUpdater;
54 class GURL; 54 class GURL;
55 class ListValue;
55 class Profile; 56 class Profile;
56 class ResourceDispatcherHost; 57 class ResourceDispatcherHost;
57 class TabContents; 58 class TabContents;
58 struct DownloadCreateInfo; 59 struct DownloadCreateInfo;
59 struct DownloadHistoryInfo; 60 struct DownloadHistoryInfo;
60 struct DownloadSaveInfo; 61 struct DownloadSaveInfo;
62 namespace download_util {
63 class DownloadQuery;
64 } // namespace download_util
61 65
62 // Browser's download manager: manages all downloads and destination view. 66 // Browser's download manager: manages all downloads and destination view.
63 class DownloadManager 67 class DownloadManager
64 : public base::RefCountedThreadSafe<DownloadManager, 68 : public base::RefCountedThreadSafe<DownloadManager,
65 BrowserThread::DeleteOnUIThread>, 69 BrowserThread::DeleteOnUIThread>,
66 public DownloadStatusUpdaterDelegate, 70 public DownloadStatusUpdaterDelegate,
67 public SelectFileDialog::Listener { 71 public SelectFileDialog::Listener {
68 public: 72 public:
69 explicit DownloadManager(DownloadStatusUpdater* status_updater); 73 explicit DownloadManager(DownloadStatusUpdater* status_updater);
70 74
(...skipping 28 matching lines...) Expand all
99 // Return all non-temporary downloads in the specified directory that are 103 // Return all non-temporary downloads in the specified directory that are
100 // are in progress or have completed. 104 // are in progress or have completed.
101 void GetAllDownloads(const FilePath& dir_path, 105 void GetAllDownloads(const FilePath& dir_path,
102 std::vector<DownloadItem*>* result); 106 std::vector<DownloadItem*>* result);
103 107
104 // Return all non-temporary downloads in the specified directory that are 108 // Return all non-temporary downloads in the specified directory that are
105 // in-progress (including dangerous downloads waiting for user confirmation). 109 // in-progress (including dangerous downloads waiting for user confirmation).
106 void GetCurrentDownloads(const FilePath& dir_path, 110 void GetCurrentDownloads(const FilePath& dir_path,
107 std::vector<DownloadItem*>* result); 111 std::vector<DownloadItem*>* result);
108 112
113 bool Search(const download_util::DownloadQuery& query,
114 std::vector<DownloadItem*>* results = NULL,
115 std::string* error_msg = NULL,
116 ListValue* json_results = NULL) const;
117
109 // Returns all non-temporary downloads matching |query|. Empty query matches 118 // Returns all non-temporary downloads matching |query|. Empty query matches
110 // everything. 119 // everything.
111 void SearchDownloads(const string16& query, 120 void SearchDownloads(const string16& query,
112 std::vector<DownloadItem*>* result); 121 std::vector<DownloadItem*>* result);
113 122
114 // Returns true if initialized properly. 123 // Returns true if initialized properly.
115 bool Init(Profile* profile); 124 bool Init(Profile* profile);
116 125
117 // Notifications sent from the download thread to the UI thread 126 // Notifications sent from the download thread to the UI thread
118 void StartDownload(int32 id); 127 void StartDownload(int32 id);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Methods called on completion of a query sent to the history system. 200 // Methods called on completion of a query sent to the history system.
192 void OnQueryDownloadEntriesComplete( 201 void OnQueryDownloadEntriesComplete(
193 std::vector<DownloadHistoryInfo>* entries); 202 std::vector<DownloadHistoryInfo>* entries);
194 void OnCreateDownloadEntryComplete(int32 download_id, int64 db_handle); 203 void OnCreateDownloadEntryComplete(int32 download_id, int64 db_handle);
195 204
196 // Display a new download in the appropriate browser UI. 205 // Display a new download in the appropriate browser UI.
197 void ShowDownloadInBrowser(DownloadItem* download); 206 void ShowDownloadInBrowser(DownloadItem* download);
198 207
199 // The number of in progress (including paused) downloads. 208 // The number of in progress (including paused) downloads.
200 int in_progress_count() const { 209 int in_progress_count() const {
201 return static_cast<int>(in_progress_.size()); 210 return static_cast<int>(downloads_.size());
202 } 211 }
203 212
204 Profile* profile() { return profile_; } 213 Profile* profile() { return profile_; }
205 214
206 DownloadPrefs* download_prefs() { return download_prefs_.get(); } 215 DownloadPrefs* download_prefs() { return download_prefs_.get(); }
207 216
208 // Creates the download item. Must be called on the UI thread. 217 // Creates the download item. Must be called on the UI thread.
209 void CreateDownloadItem(DownloadCreateInfo* info); 218 void CreateDownloadItem(DownloadCreateInfo* info);
210 219
211 // Clears the last download path, used to initialize "save as" dialogs. 220 // Clears the last download path, used to initialize "save as" dialogs.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 void NotifyModelChanged(); 353 void NotifyModelChanged();
345 354
346 // Get the download item from the active map. Useful when the item is not 355 // Get the download item from the active map. Useful when the item is not
347 // yet in the history map. 356 // yet in the history map.
348 DownloadItem* GetActiveDownloadItem(int id); 357 DownloadItem* GetActiveDownloadItem(int id);
349 358
350 // Debugging routine to confirm relationship between below 359 // Debugging routine to confirm relationship between below
351 // containers; no-op if NDEBUG. 360 // containers; no-op if NDEBUG.
352 void AssertContainersConsistent() const; 361 void AssertContainersConsistent() const;
353 362
354 // |downloads_| is the owning set for all downloads known to the
355 // DownloadManager. This includes downloads started by the user in
356 // this session, downloads initialized from the history system, and
357 // "save page as" downloads. All other DownloadItem containers in
358 // the DownloadManager are maps; they do not own the DownloadItems.
359 // Note that this is the only place (with any functional implications;
360 // see save_page_as_downloads_ below) that "save page as" downloads are
361 // kept, as the DownloadManager's only job is to hold onto those
362 // until destruction.
363 //
364 // |history_downloads_| is map of all downloads in this profile. The key
365 // is the handle returned by the history system, which is unique
366 // across sessions.
367 //
368 // |active_downloads_| is a map of all downloads that are currently being
369 // processed. The key is the ID assigned by the ResourceDispatcherHost,
370 // which is unique for the current session.
371 //
372 // |in_progress_| is a map of all downloads that are in progress and that have
373 // not yet received a valid history handle. The key is the ID assigned by the
374 // ResourceDispatcherHost, which is unique for the current session.
375 //
376 // |save_page_as_downloads_| (if defined) is a collection of all the
377 // downloads the "save page as" system has given to us to hold onto
378 // until we are destroyed. It is only used for debugging.
379 //
380 // When a download is created through a user action, the corresponding
381 // DownloadItem* is placed in |active_downloads_| and remains there until the
382 // download is in a terminal state (COMPLETE or CANCELLED). It is also
383 // placed in |in_progress_| and remains there until it has received a
384 // valid handle from the history system. Once it has a valid handle, the
385 // DownloadItem* is placed in the |history_downloads_| map. When the
386 // download reaches a terminal state, it is removed from |in_progress_|.
387 // Downloads from past sessions read from a persisted state from the
388 // history system are placed directly into |history_downloads_| since
389 // they have valid handles in the history system.
390 typedef std::set<DownloadItem*> DownloadSet; 363 typedef std::set<DownloadItem*> DownloadSet;
391 typedef base::hash_map<int64, DownloadItem*> DownloadMap; 364 typedef base::hash_map<int64, DownloadItem*> DownloadMap;
392 365
393 DownloadSet downloads_;
394 DownloadMap history_downloads_;
395 DownloadMap in_progress_;
396 DownloadMap active_downloads_;
397 #if !defined(NDEBUG) 366 #if !defined(NDEBUG)
398 DownloadSet save_page_as_downloads_; 367 DownloadSet save_page_as_downloads_;
399 #endif 368 #endif
400 369
370 // Map from id to DownloadItem. Owns the DownloadItem.
371 DownloadMap downloads_;
372
401 // True if the download manager has been initialized and requires a shutdown. 373 // True if the download manager has been initialized and requires a shutdown.
402 bool shutdown_needed_; 374 bool shutdown_needed_;
403 375
404 // Observers that want to be notified of changes to the set of downloads. 376 // Observers that want to be notified of changes to the set of downloads.
405 ObserverList<Observer> observers_; 377 ObserverList<Observer> observers_;
406 378
407 // The current active profile. 379 // The current active profile.
408 Profile* profile_; 380 Profile* profile_;
409 381
410 scoped_ptr<DownloadHistory> download_history_; 382 scoped_ptr<DownloadHistory> download_history_;
(...skipping 13 matching lines...) Expand all
424 // The "Save As" dialog box used to ask the user where a file should be 396 // The "Save As" dialog box used to ask the user where a file should be
425 // saved. 397 // saved.
426 scoped_refptr<SelectFileDialog> select_file_dialog_; 398 scoped_refptr<SelectFileDialog> select_file_dialog_;
427 399
428 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; 400 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_;
429 401
430 DISALLOW_COPY_AND_ASSIGN(DownloadManager); 402 DISALLOW_COPY_AND_ASSIGN(DownloadManager);
431 }; 403 };
432 404
433 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ 405 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/download/download_item.cc ('k') | chrome/browser/download/download_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698