Index: chrome/browser/download/download_manager.h |
diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h |
index fe4e602c479933382dcec440de37772a24a674bd..ae9e183c1831bbd8289ed610c46ad36a6f075baa 100644 |
--- a/chrome/browser/download/download_manager.h |
+++ b/chrome/browser/download/download_manager.h |
@@ -34,6 +34,7 @@ |
#include <vector> |
#include "base/basictypes.h" |
+#include "base/callback.h" |
#include "base/file_path.h" |
#include "base/gtest_prod_util.h" |
#include "base/hash_tables.h" |
@@ -41,9 +42,11 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/weak_ptr.h" |
#include "base/observer_list.h" |
+#include "base/synchronization/lock.h" |
#include "base/time.h" |
#include "chrome/browser/download/download_item.h" |
#include "chrome/browser/download/download_request_handle.h" |
+#include "chrome/browser/download/download_state_info.h" |
#include "chrome/browser/download/download_status_updater_delegate.h" |
#include "content/browser/browser_thread.h" |
@@ -110,6 +113,24 @@ class DownloadManager |
// everything. |
void SearchDownloads(const string16& query, DownloadVector* result); |
+ // Returns the next download id in a DownloadId and increments the counter. |
+ // May be called on any thread. The incremented counter is not persisted, but |
+ // the base counter for this accessor is initialized from the largest id |
+ // actually saved to the download history database. |
+ DownloadId GetNextId(); |
+ |
+ // Instead of passing a DownloadManager* between threads and hoping users only |
+ // call GetNextId(), you can pass this thunk around instead. Pass the thunk |
+ // around by const ref and store it by copy per the base::Callback interface. |
+ // The thunk may be copied, including between threads. If you change |
+ // GetNextIdThunkType from base::Callback, then you should think about how |
+ // you're changing the ref-count of DownloadManager. Use it like: |
+ // const DownloadManager::GetNextIdThunkType& next_id_thunk = |
+ // download_manager->GetNextIdThunk(); |
+ // id = next_id_thunk.Run(); |
+ typedef base::Callback<DownloadId(void)> GetNextIdThunkType; |
+ GetNextIdThunkType GetNextIdThunk(); |
+ |
// Returns true if initialized properly. |
bool Init(Profile* profile); |
@@ -369,6 +390,11 @@ class DownloadManager |
// Remove from internal maps. |
int RemoveDownloadItems(const DownloadVector& pending_deletes); |
+ // The DownloadHistory grabbed the next_id counter from the sql MetaTable. |
+ // TODO(benjhayden) Make ProfileImpl pass this into DownloadManager's |
+ // constructor. |
+ void OnHistoryGetNextId(int next_id); |
+ |
// |downloads_| is the owning set for all downloads known to the |
// DownloadManager. This includes downloads started by the user in |
// this session, downloads initialized from the history system, and |
@@ -418,6 +444,9 @@ class DownloadManager |
// Observers that want to be notified of changes to the set of downloads. |
ObserverList<Observer> observers_; |
+ base::Lock next_id_lock_; |
+ int next_id_; |
+ |
// The current active profile. |
Profile* profile_; |