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 | 51 |
50 class DownloadFileManager; | 52 class DownloadFileManager; |
51 class DownloadManagerDelegate; | 53 class DownloadManagerDelegate; |
52 class DownloadStatusUpdater; | 54 class DownloadStatusUpdater; |
53 class GURL; | 55 class GURL; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result); | 101 void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result); |
100 | 102 |
101 // Return all non-temporary downloads in the specified directory that are | 103 // Return all non-temporary downloads in the specified directory that are |
102 // are in progress or have completed. | 104 // are in progress or have completed. |
103 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); | 105 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); |
104 | 106 |
105 // Returns all non-temporary downloads matching |query|. Empty query matches | 107 // Returns all non-temporary downloads matching |query|. Empty query matches |
106 // everything. | 108 // everything. |
107 void SearchDownloads(const string16& query, DownloadVector* result); | 109 void SearchDownloads(const string16& query, DownloadVector* result); |
108 | 110 |
| 111 // Returns the next download id in a DownloadId and increments the counter. |
| 112 // May be called on any thread. The incremented counter is not persisted, but |
| 113 // the base counter for this accessor is initialized from the largest id |
| 114 // actually saved to the download history database. |
| 115 DownloadId GetNextId(); |
| 116 |
| 117 // Instead of passing a DownloadManager* between threads and hoping users only |
| 118 // call GetNextId(), you can pass this thunk around instead. Pass the thunk |
| 119 // around by const ref and store it by copy per the base::Callback interface. |
| 120 // The thunk may be copied, including between threads. If you change |
| 121 // GetNextIdThunkType from base::Callback, then you should think about how |
| 122 // you're changing the ref-count of DownloadManager. Use it like: |
| 123 // const DownloadManager::GetNextIdThunkType& next_id_thunk = |
| 124 // download_manager->GetNextIdThunk(); |
| 125 // id = next_id_thunk.Run(); |
| 126 typedef base::Callback<DownloadId(void)> GetNextIdThunkType; |
| 127 GetNextIdThunkType GetNextIdThunk(); |
| 128 |
109 // Returns true if initialized properly. | 129 // Returns true if initialized properly. |
110 bool Init(content::BrowserContext* browser_context); | 130 bool Init(content::BrowserContext* browser_context); |
111 | 131 |
112 // Notifications sent from the download thread to the UI thread | 132 // Notifications sent from the download thread to the UI thread |
113 void StartDownload(int32 id); | 133 void StartDownload(int32 id); |
114 void UpdateDownload(int32 download_id, int64 size); | 134 void UpdateDownload(int32 download_id, int64 size); |
115 // |hash| is sha256 hash for the downloaded file. It is empty when the hash | 135 // |hash| is sha256 hash for the downloaded file. It is empty when the hash |
116 // is not available. | 136 // is not available. |
117 void OnResponseCompleted(int32 download_id, int64 size, int os_error, | 137 void OnResponseCompleted(int32 download_id, int64 size, int os_error, |
118 const std::string& hash); | 138 const std::string& hash); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 const std::string& referrer_encoding, | 199 const std::string& referrer_encoding, |
180 const DownloadSaveInfo& save_info, | 200 const DownloadSaveInfo& save_info, |
181 TabContents* tab_contents); | 201 TabContents* tab_contents); |
182 | 202 |
183 // Allow objects to observe the download creation process. | 203 // Allow objects to observe the download creation process. |
184 void AddObserver(Observer* observer); | 204 void AddObserver(Observer* observer); |
185 | 205 |
186 // Remove a download observer from ourself. | 206 // Remove a download observer from ourself. |
187 void RemoveObserver(Observer* observer); | 207 void RemoveObserver(Observer* observer); |
188 | 208 |
| 209 // Called by the embedder after creating the download manager to inform it of |
| 210 // the next available download id. |
| 211 // TODO(benjhayden): Separate this functionality out into a separate object. |
| 212 void OnPersistentStoreGetNextId(int next_id); |
| 213 |
189 // Called by the embedder, after creating the download manager, to let it know | 214 // Called by the embedder, after creating the download manager, to let it know |
190 // about downloads from previous runs of the browser. | 215 // about downloads from previous runs of the browser. |
191 void OnPersistentStoreQueryComplete( | 216 void OnPersistentStoreQueryComplete( |
192 std::vector<DownloadPersistentStoreInfo>* entries); | 217 std::vector<DownloadPersistentStoreInfo>* entries); |
193 | 218 |
194 // Called by the embedder, in response to | 219 // Called by the embedder, in response to |
195 // DownloadManagerDelegate::AddItemToPersistentStore. | 220 // DownloadManagerDelegate::AddItemToPersistentStore. |
196 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); | 221 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); |
197 | 222 |
198 // Display a new download in the appropriate browser UI. | 223 // Display a new download in the appropriate browser UI. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 386 |
362 // True if the download manager has been initialized and requires a shutdown. | 387 // True if the download manager has been initialized and requires a shutdown. |
363 bool shutdown_needed_; | 388 bool shutdown_needed_; |
364 | 389 |
365 // Observers that want to be notified of changes to the set of downloads. | 390 // Observers that want to be notified of changes to the set of downloads. |
366 ObserverList<Observer> observers_; | 391 ObserverList<Observer> observers_; |
367 | 392 |
368 // The current active browser context. | 393 // The current active browser context. |
369 content::BrowserContext* browser_context_; | 394 content::BrowserContext* browser_context_; |
370 | 395 |
| 396 base::Lock next_id_lock_; |
| 397 int next_id_; |
| 398 |
371 // Non-owning pointer for handling file writing on the download_thread_. | 399 // Non-owning pointer for handling file writing on the download_thread_. |
372 DownloadFileManager* file_manager_; | 400 DownloadFileManager* file_manager_; |
373 | 401 |
374 // Non-owning pointer for updating the download status. | 402 // Non-owning pointer for updating the download status. |
375 base::WeakPtr<DownloadStatusUpdater> status_updater_; | 403 base::WeakPtr<DownloadStatusUpdater> status_updater_; |
376 | 404 |
377 // The user's last choice for download directory. This is only used when the | 405 // The user's last choice for download directory. This is only used when the |
378 // user wants us to prompt for a save location for each download. | 406 // user wants us to prompt for a save location for each download. |
379 FilePath last_download_path_; | 407 FilePath last_download_path_; |
380 | 408 |
381 // Allows an embedder to control behavior. Guaranteed to outlive this object. | 409 // Allows an embedder to control behavior. Guaranteed to outlive this object. |
382 DownloadManagerDelegate* delegate_; | 410 DownloadManagerDelegate* delegate_; |
383 | 411 |
384 // TODO(rdsmith): Remove when http://crbug.com/84508 is fixed. | 412 // TODO(rdsmith): Remove when http://crbug.com/84508 is fixed. |
385 // For debugging only. | 413 // For debugging only. |
386 int64 largest_db_handle_in_history_; | 414 int64 largest_db_handle_in_history_; |
387 | 415 |
388 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 416 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
389 }; | 417 }; |
390 | 418 |
391 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 419 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |