| 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" | |
| 38 #include "base/file_path.h" | 37 #include "base/file_path.h" |
| 39 #include "base/gtest_prod_util.h" | 38 #include "base/gtest_prod_util.h" |
| 40 #include "base/hash_tables.h" | 39 #include "base/hash_tables.h" |
| 41 #include "base/memory/ref_counted.h" | 40 #include "base/memory/ref_counted.h" |
| 42 #include "base/memory/scoped_ptr.h" | 41 #include "base/memory/scoped_ptr.h" |
| 43 #include "base/memory/weak_ptr.h" | 42 #include "base/memory/weak_ptr.h" |
| 44 #include "base/observer_list.h" | 43 #include "base/observer_list.h" |
| 45 #include "base/synchronization/lock.h" | |
| 46 #include "base/time.h" | 44 #include "base/time.h" |
| 47 #include "content/browser/browser_thread.h" | 45 #include "content/browser/browser_thread.h" |
| 48 #include "content/browser/download/download_item.h" | 46 #include "content/browser/download/download_item.h" |
| 49 #include "content/browser/download/download_request_handle.h" | 47 #include "content/browser/download/download_request_handle.h" |
| 50 #include "content/browser/download/download_status_updater_delegate.h" | 48 #include "content/browser/download/download_status_updater_delegate.h" |
| 51 | 49 |
| 52 class DownloadFileManager; | 50 class DownloadFileManager; |
| 53 class DownloadManagerDelegate; | 51 class DownloadManagerDelegate; |
| 54 class DownloadStatusUpdater; | 52 class DownloadStatusUpdater; |
| 55 class GURL; | 53 class GURL; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result); | 99 void GetTemporaryDownloads(const FilePath& dir_path, DownloadVector* result); |
| 102 | 100 |
| 103 // Return all non-temporary downloads in the specified directory that are | 101 // Return all non-temporary downloads in the specified directory that are |
| 104 // are in progress or have completed. | 102 // are in progress or have completed. |
| 105 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); | 103 void GetAllDownloads(const FilePath& dir_path, DownloadVector* result); |
| 106 | 104 |
| 107 // Returns all non-temporary downloads matching |query|. Empty query matches | 105 // Returns all non-temporary downloads matching |query|. Empty query matches |
| 108 // everything. | 106 // everything. |
| 109 void SearchDownloads(const string16& query, DownloadVector* result); | 107 void SearchDownloads(const string16& query, DownloadVector* result); |
| 110 | 108 |
| 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 | |
| 129 // Returns true if initialized properly. | 109 // Returns true if initialized properly. |
| 130 bool Init(content::BrowserContext* browser_context); | 110 bool Init(content::BrowserContext* browser_context); |
| 131 | 111 |
| 132 // Notifications sent from the download thread to the UI thread | 112 // Notifications sent from the download thread to the UI thread |
| 133 void StartDownload(int32 id); | 113 void StartDownload(int32 id); |
| 134 void UpdateDownload(int32 download_id, int64 size); | 114 void UpdateDownload(int32 download_id, int64 size); |
| 135 // |hash| is sha256 hash for the downloaded file. It is empty when the hash | 115 // |hash| is sha256 hash for the downloaded file. It is empty when the hash |
| 136 // is not available. | 116 // is not available. |
| 137 void OnResponseCompleted(int32 download_id, int64 size, int os_error, | 117 void OnResponseCompleted(int32 download_id, int64 size, int os_error, |
| 138 const std::string& hash); | 118 const std::string& hash); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 const std::string& referrer_encoding, | 179 const std::string& referrer_encoding, |
| 200 const DownloadSaveInfo& save_info, | 180 const DownloadSaveInfo& save_info, |
| 201 TabContents* tab_contents); | 181 TabContents* tab_contents); |
| 202 | 182 |
| 203 // Allow objects to observe the download creation process. | 183 // Allow objects to observe the download creation process. |
| 204 void AddObserver(Observer* observer); | 184 void AddObserver(Observer* observer); |
| 205 | 185 |
| 206 // Remove a download observer from ourself. | 186 // Remove a download observer from ourself. |
| 207 void RemoveObserver(Observer* observer); | 187 void RemoveObserver(Observer* observer); |
| 208 | 188 |
| 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 | |
| 214 // Called by the embedder, after creating the download manager, to let it know | 189 // Called by the embedder, after creating the download manager, to let it know |
| 215 // about downloads from previous runs of the browser. | 190 // about downloads from previous runs of the browser. |
| 216 void OnPersistentStoreQueryComplete( | 191 void OnPersistentStoreQueryComplete( |
| 217 std::vector<DownloadPersistentStoreInfo>* entries); | 192 std::vector<DownloadPersistentStoreInfo>* entries); |
| 218 | 193 |
| 219 // Called by the embedder, in response to | 194 // Called by the embedder, in response to |
| 220 // DownloadManagerDelegate::AddItemToPersistentStore. | 195 // DownloadManagerDelegate::AddItemToPersistentStore. |
| 221 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); | 196 void OnItemAddedToPersistentStore(int32 download_id, int64 db_handle); |
| 222 | 197 |
| 223 // Display a new download in the appropriate browser UI. | 198 // Display a new download in the appropriate browser UI. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 361 |
| 387 // True if the download manager has been initialized and requires a shutdown. | 362 // True if the download manager has been initialized and requires a shutdown. |
| 388 bool shutdown_needed_; | 363 bool shutdown_needed_; |
| 389 | 364 |
| 390 // Observers that want to be notified of changes to the set of downloads. | 365 // Observers that want to be notified of changes to the set of downloads. |
| 391 ObserverList<Observer> observers_; | 366 ObserverList<Observer> observers_; |
| 392 | 367 |
| 393 // The current active browser context. | 368 // The current active browser context. |
| 394 content::BrowserContext* browser_context_; | 369 content::BrowserContext* browser_context_; |
| 395 | 370 |
| 396 base::Lock next_id_lock_; | |
| 397 int next_id_; | |
| 398 | |
| 399 // Non-owning pointer for handling file writing on the download_thread_. | 371 // Non-owning pointer for handling file writing on the download_thread_. |
| 400 DownloadFileManager* file_manager_; | 372 DownloadFileManager* file_manager_; |
| 401 | 373 |
| 402 // Non-owning pointer for updating the download status. | 374 // Non-owning pointer for updating the download status. |
| 403 base::WeakPtr<DownloadStatusUpdater> status_updater_; | 375 base::WeakPtr<DownloadStatusUpdater> status_updater_; |
| 404 | 376 |
| 405 // The user's last choice for download directory. This is only used when the | 377 // The user's last choice for download directory. This is only used when the |
| 406 // user wants us to prompt for a save location for each download. | 378 // user wants us to prompt for a save location for each download. |
| 407 FilePath last_download_path_; | 379 FilePath last_download_path_; |
| 408 | 380 |
| 409 // Allows an embedder to control behavior. Guaranteed to outlive this object. | 381 // Allows an embedder to control behavior. Guaranteed to outlive this object. |
| 410 DownloadManagerDelegate* delegate_; | 382 DownloadManagerDelegate* delegate_; |
| 411 | 383 |
| 412 // TODO(rdsmith): Remove when http://crbug.com/84508 is fixed. | 384 // TODO(rdsmith): Remove when http://crbug.com/84508 is fixed. |
| 413 // For debugging only. | 385 // For debugging only. |
| 414 int64 largest_db_handle_in_history_; | 386 int64 largest_db_handle_in_history_; |
| 415 | 387 |
| 416 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 388 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
| 417 }; | 389 }; |
| 418 | 390 |
| 419 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 391 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
| OLD | NEW |