DescriptionMake 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.
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.
See also http://codereview.chromium.org/7192016
LMK what to write a test for if anything.
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=98656
Patch Set 1 : DownloadPrefs::GetNextId() #
Total comments: 3
Patch Set 2 : sql::MetaTable.next_download_id, DownloadId, DownloadManager::GetNextId() #
Total comments: 40
Patch Set 3 : " #
Total comments: 39
Patch Set 4 : " #
Total comments: 11
Patch Set 5 : " #
Total comments: 12
Patch Set 6 : " #Patch Set 7 : " #Patch Set 8 : MSVC requires operator< for hash_map #
Total comments: 2
Patch Set 9 : resource_context.h includes download_manager.h #Patch Set 10 : merge #Patch Set 11 : merged #Patch Set 12 : fix check_deps l10n #Patch Set 13 : merge #Patch Set 14 : trying again #Patch Set 15 : seriously, patch, come on #Patch Set 16 : fix unit_tests.IgnoreCancelForDownloads #Patch Set 17 : merge AGAIN #
Total comments: 8
Patch Set 18 : comments #Patch Set 19 : merge #Patch Set 20 : fix ResourceDispatcherHostTest.CancelRequestsForContext #Patch Set 21 : merge #Patch Set 22 : fix merge #Messages
Total messages: 42 (0 generated)
|