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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 const std::string& referrer_encoding, | 192 const std::string& referrer_encoding, |
173 const DownloadSaveInfo& save_info, | 193 const DownloadSaveInfo& save_info, |
174 TabContents* tab_contents); | 194 TabContents* tab_contents); |
175 | 195 |
176 // Allow objects to observe the download creation process. | 196 // Allow objects to observe the download creation process. |
177 void AddObserver(Observer* observer); | 197 void AddObserver(Observer* observer); |
178 | 198 |
179 // Remove a download observer from ourself. | 199 // Remove a download observer from ourself. |
180 void RemoveObserver(Observer* observer); | 200 void RemoveObserver(Observer* observer); |
181 | 201 |
| 202 // Called by the embedder after creating the download manager to inform it of |
| 203 // the next available download id. |
| 204 // TODO(benjhayden): Separate this functionality out into a separate object. |
| 205 void OnPersistentStoreGetNextId(int next_id); |
| 206 |
182 // Called by the embedder, after creating the download manager, to let it know | 207 // Called by the embedder, after creating the download manager, to let it know |
183 // about downloads from previous runs of the browser. | 208 // about downloads from previous runs of the browser. |
184 void OnPersistentStoreQueryComplete( | 209 void OnPersistentStoreQueryComplete( |
185 std::vector<DownloadPersistentStoreInfo>* entries); | 210 std::vector<DownloadPersistentStoreInfo>* entries); |
186 | 211 |
187 // Called by the embedder, in response to | 212 // Called by the embedder, in response to |
188 // DownloadManagerDelegate::AddItemToPersistentStore. | 213 // DownloadManagerDelegate::AddItemToPersistentStore. |
189 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); | 214 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); |
190 | 215 |
191 // Display a new download in the appropriate browser UI. | 216 // Display a new download in the appropriate browser UI. |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 383 |
359 // True if the download manager has been initialized and requires a shutdown. | 384 // True if the download manager has been initialized and requires a shutdown. |
360 bool shutdown_needed_; | 385 bool shutdown_needed_; |
361 | 386 |
362 // Observers that want to be notified of changes to the set of downloads. | 387 // Observers that want to be notified of changes to the set of downloads. |
363 ObserverList<Observer> observers_; | 388 ObserverList<Observer> observers_; |
364 | 389 |
365 // The current active browser context. | 390 // The current active browser context. |
366 content::BrowserContext* browser_context_; | 391 content::BrowserContext* browser_context_; |
367 | 392 |
| 393 base::Lock next_id_lock_; |
| 394 int next_id_; |
| 395 |
368 // Non-owning pointer for handling file writing on the download_thread_. | 396 // Non-owning pointer for handling file writing on the download_thread_. |
369 DownloadFileManager* file_manager_; | 397 DownloadFileManager* file_manager_; |
370 | 398 |
371 // Non-owning pointer for updating the download status. | 399 // Non-owning pointer for updating the download status. |
372 base::WeakPtr<DownloadStatusUpdater> status_updater_; | 400 base::WeakPtr<DownloadStatusUpdater> status_updater_; |
373 | 401 |
374 // The user's last choice for download directory. This is only used when the | 402 // The user's last choice for download directory. This is only used when the |
375 // user wants us to prompt for a save location for each download. | 403 // user wants us to prompt for a save location for each download. |
376 FilePath last_download_path_; | 404 FilePath last_download_path_; |
377 | 405 |
378 // Allows an embedder to control behavior. Guaranteed to outlive this object. | 406 // Allows an embedder to control behavior. Guaranteed to outlive this object. |
379 DownloadManagerDelegate* delegate_; | 407 DownloadManagerDelegate* delegate_; |
380 | 408 |
381 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 409 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
382 }; | 410 }; |
383 | 411 |
384 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 412 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |