OLD | NEW |
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 16 matching lines...) Expand all Loading... |
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> | 31 #include <map> |
32 #include <set> | 32 #include <set> |
33 #include <string> | 33 #include <string> |
34 #include <vector> | 34 #include <vector> |
35 | 35 |
36 #include "base/basictypes.h" | 36 #include "base/basictypes.h" |
| 37 #include "base/callback.h" |
37 #include "base/file_path.h" | 38 #include "base/file_path.h" |
38 #include "base/gtest_prod_util.h" | 39 #include "base/gtest_prod_util.h" |
39 #include "base/hash_tables.h" | 40 #include "base/hash_tables.h" |
40 #include "base/memory/ref_counted.h" | 41 #include "base/memory/ref_counted.h" |
41 #include "base/memory/scoped_ptr.h" | 42 #include "base/memory/scoped_ptr.h" |
42 #include "base/memory/weak_ptr.h" | 43 #include "base/memory/weak_ptr.h" |
43 #include "base/observer_list.h" | 44 #include "base/observer_list.h" |
| 45 #include "base/synchronization/lock.h" |
44 #include "base/time.h" | 46 #include "base/time.h" |
45 #include "content/browser/browser_thread.h" | 47 #include "content/browser/browser_thread.h" |
46 #include "content/browser/download/download_item.h" | 48 #include "content/browser/download/download_item.h" |
47 #include "content/browser/download/download_request_handle.h" | 49 #include "content/browser/download/download_request_handle.h" |
48 #include "content/browser/download/download_status_updater_delegate.h" | 50 #include "content/browser/download/download_status_updater_delegate.h" |
49 #include "content/common/content_export.h" | 51 #include "content/common/content_export.h" |
50 #include "net/base/net_errors.h" | 52 #include "net/base/net_errors.h" |
51 | 53 |
52 class DownloadFileManager; | 54 class DownloadFileManager; |
53 class DownloadManagerDelegate; | 55 class DownloadManagerDelegate; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result); | 103 void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result); |
102 | 104 |
103 // Return all non-temporary downloads in the specified directory that are | 105 // Return all non-temporary downloads in the specified directory that are |
104 // are in progress or have completed. | 106 // are in progress or have completed. |
105 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); | 107 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); |
106 | 108 |
107 // Returns all non-temporary downloads matching |query|. Empty query matches | 109 // Returns all non-temporary downloads matching |query|. Empty query matches |
108 // everything. | 110 // everything. |
109 void SearchDownloads(const string16& query, DownloadVector* result); | 111 void SearchDownloads(const string16& query, DownloadVector* result); |
110 | 112 |
| 113 // Returns the next download id in a DownloadId and increments the counter. |
| 114 // May be called on any thread. The incremented counter is not persisted, but |
| 115 // the base counter for this accessor is initialized from the largest id |
| 116 // actually saved to the download history database. |
| 117 DownloadId GetNextId(); |
| 118 |
| 119 // Instead of passing a DownloadManager* between threads and hoping users only |
| 120 // call GetNextId(), you can pass this thunk around instead. Pass the thunk |
| 121 // around by const ref and store it by copy per the base::Callback interface. |
| 122 // The thunk may be copied, including between threads. If you change |
| 123 // GetNextIdThunkType from base::Callback, then you should think about how |
| 124 // you're changing the ref-count of DownloadManager. Use it like: |
| 125 // const DownloadManager::GetNextIdThunkType& next_id_thunk = |
| 126 // download_manager->GetNextIdThunk(); |
| 127 // id = next_id_thunk.Run(); |
| 128 typedef base::Callback<DownloadId(void)> GetNextIdThunkType; |
| 129 GetNextIdThunkType GetNextIdThunk(); |
| 130 |
111 // Returns true if initialized properly. | 131 // Returns true if initialized properly. |
112 bool Init(content::BrowserContext* browser_context); | 132 bool Init(content::BrowserContext* browser_context); |
113 | 133 |
114 // Notifications sent from the download thread to the UI thread | 134 // Notifications sent from the download thread to the UI thread |
115 void StartDownload(int32 id); | 135 void StartDownload(int32 id); |
116 void UpdateDownload(int32 download_id, int64 size); | 136 void UpdateDownload(int32 download_id, int64 size); |
117 | 137 |
118 // |download_id| is the ID of the download. | 138 // |download_id| is the ID of the download. |
119 // |size| is the number of bytes that have been downloaded. | 139 // |size| is the number of bytes that have been downloaded. |
120 // |hash| is sha256 hash for the downloaded file. It is empty when the hash | 140 // |hash| is sha256 hash for the downloaded file. It is empty when the hash |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 const std::string& referrer_encoding, | 210 const std::string& referrer_encoding, |
191 const DownloadSaveInfo& save_info, | 211 const DownloadSaveInfo& save_info, |
192 TabContents* tab_contents); | 212 TabContents* tab_contents); |
193 | 213 |
194 // Allow objects to observe the download creation process. | 214 // Allow objects to observe the download creation process. |
195 void AddObserver(Observer* observer); | 215 void AddObserver(Observer* observer); |
196 | 216 |
197 // Remove a download observer from ourself. | 217 // Remove a download observer from ourself. |
198 void RemoveObserver(Observer* observer); | 218 void RemoveObserver(Observer* observer); |
199 | 219 |
| 220 // Called by the embedder after creating the download manager to inform it of |
| 221 // the next available download id. |
| 222 // TODO(benjhayden): Separate this functionality out into a separate object. |
| 223 void OnPersistentStoreGetNextId(int next_id); |
| 224 |
200 // Called by the embedder, after creating the download manager, to let it know | 225 // Called by the embedder, after creating the download manager, to let it know |
201 // about downloads from previous runs of the browser. | 226 // about downloads from previous runs of the browser. |
202 void OnPersistentStoreQueryComplete( | 227 void OnPersistentStoreQueryComplete( |
203 std::vector<DownloadPersistentStoreInfo>* entries); | 228 std::vector<DownloadPersistentStoreInfo>* entries); |
204 | 229 |
205 // Called by the embedder, in response to | 230 // Called by the embedder, in response to |
206 // DownloadManagerDelegate::AddItemToPersistentStore. | 231 // DownloadManagerDelegate::AddItemToPersistentStore. |
207 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); | 232 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); |
208 | 233 |
209 // Display a new download in the appropriate browser UI. | 234 // Display a new download in the appropriate browser UI. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 403 |
379 // True if the download manager has been initialized and requires a shutdown. | 404 // True if the download manager has been initialized and requires a shutdown. |
380 bool shutdown_needed_; | 405 bool shutdown_needed_; |
381 | 406 |
382 // Observers that want to be notified of changes to the set of downloads. | 407 // Observers that want to be notified of changes to the set of downloads. |
383 ObserverList<Observer> observers_; | 408 ObserverList<Observer> observers_; |
384 | 409 |
385 // The current active browser context. | 410 // The current active browser context. |
386 content::BrowserContext* browser_context_; | 411 content::BrowserContext* browser_context_; |
387 | 412 |
| 413 base::Lock next_id_lock_; |
| 414 int next_id_; |
| 415 |
388 // Non-owning pointer for handling file writing on the download_thread_. | 416 // Non-owning pointer for handling file writing on the download_thread_. |
389 DownloadFileManager* file_manager_; | 417 DownloadFileManager* file_manager_; |
390 | 418 |
391 // Non-owning pointer for updating the download status. | 419 // Non-owning pointer for updating the download status. |
392 base::WeakPtr<DownloadStatusUpdater> status_updater_; | 420 base::WeakPtr<DownloadStatusUpdater> status_updater_; |
393 | 421 |
394 // The user's last choice for download directory. This is only used when the | 422 // The user's last choice for download directory. This is only used when the |
395 // user wants us to prompt for a save location for each download. | 423 // user wants us to prompt for a save location for each download. |
396 FilePath last_download_path_; | 424 FilePath last_download_path_; |
397 | 425 |
398 // Allows an embedder to control behavior. Guaranteed to outlive this object. | 426 // Allows an embedder to control behavior. Guaranteed to outlive this object. |
399 DownloadManagerDelegate* delegate_; | 427 DownloadManagerDelegate* delegate_; |
400 | 428 |
401 // TODO(rdsmith): Remove when http://crbug.com/84508 is fixed. | 429 // TODO(rdsmith): Remove when http://crbug.com/84508 is fixed. |
402 // For debugging only. | 430 // For debugging only. |
403 int64 largest_db_handle_in_history_; | 431 int64 largest_db_handle_in_history_; |
404 | 432 |
405 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 433 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
406 }; | 434 }; |
407 | 435 |
408 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 436 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |