diff options
author | benjhayden@chromium.org <benjhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-07 21:09:12 +0000 |
---|---|---|
committer | benjhayden@chromium.org <benjhayden@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-07 21:09:12 +0000 |
commit | 5d051ea84671aa5092500360d5ab619e108ebadd (patch) | |
tree | b9a39fd5d583b9a10b1472932298fcd58e934754 /chrome/browser/history/history.h | |
parent | 7179d2f456e41eca799a6c2070fca9ad123e0b65 (diff) | |
download | chromium_src-5d051ea84671aa5092500360d5ab619e108ebadd.zip chromium_src-5d051ea84671aa5092500360d5ab619e108ebadd.tar.gz chromium_src-5d051ea84671aa5092500360d5ab619e108ebadd.tar.bz2 |
Make a new integer field in sql::MetaTable (a per-profile db) containing a counter for the next download id, so that this id is unique across sessions. This id will allow us to merge download id with db_handle and merge most/all of the maps in DownloadManager in future CLs.
(Retry of r98656 again. That CL included <iostream> in a "promiscuous" header file, dramatically increasing the number of static initializers, and was reverted. This is the same CL, but includes <iosfwd> instead of <iostream>.)
Make DownloadManager read this field to initialize its next_id_ counter in Init().
Put a fine-grained mutex in DownloadManager::GetNextId() so that it can be called directly from any thread.
Define a thunk wrapping DM::GNI() to be passed around between threads to guard against other threads calling any other DM methods.
This thunk owns a scoped_refptr<DM> to manage life-time issues. This pattern is implemented for DM elsewhere.
Store this thunk in ResourceContext to be called by ResourceDispatchHost/DownloadThrottlingResourceHandler on the IO thread. Pass the returned DownloadId into DownloadResourceHandler.
The alternative way to obtain ids on the IO thread is to jump over to the UI thread and back. This way would add significant latency to a critical path. GetNextId() should be fast and easily accessible from any thread.
Now that ids are per-profile, define a class DownloadId containing a per-profile id and an indication of which profile, currently the DownloadManager*. DownloadIds are hashable, comparable, globally unique, not persistent, and are used by DownloadFileManager.
When the download is added to the history, MetaTable.next_download_id will be set to the new download's id +1 if that number is greater than MT.next_download_id. Increasing this counter at the same time as the download is added to the db prevents the counter from desyncing from the db, which was the primary concern re storing the counter in the BrowserPrefs.
Review URL: http://codereview.chromium.org/7776012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100017 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history/history.h')
-rw-r--r-- | chrome/browser/history/history.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/chrome/browser/history/history.h b/chrome/browser/history/history.h index 120d764..0a09a6a 100644 --- a/chrome/browser/history/history.h +++ b/chrome/browser/history/history.h @@ -423,6 +423,13 @@ class HistoryService : public CancelableRequestProvider, CancelableRequestConsumerBase* consumer, DownloadCreateCallback* callback); + // Implemented by the caller of 'GetNextDownloadId' below. + typedef Callback1<int/*next_download_id*/>::Type DownloadNextIdCallback; + + // Runs the callback with the next available download id. + Handle GetNextDownloadId(CancelableRequestConsumerBase* consumer, + DownloadNextIdCallback* callback); + // Implemented by the caller of 'QueryDownloads' below, and is called when the // history service has retrieved a list of all download state. The call typedef Callback1<std::vector<DownloadPersistentStoreInfo>*>::Type |