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

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

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

Powered by Google App Engine
This is Rietveld 408576698