diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-23 06:33:31 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-23 06:33:31 +0000 |
commit | be180c8044f145310f9eb13fd2cab5fd20e88220 (patch) | |
tree | 707ac9f3f95f5191664dbdac2ff3f34ab08ad8e7 /chrome/browser/download | |
parent | 4cb1d3be9986c105608991f3dde12c6346335060 (diff) | |
download | chromium_src-be180c8044f145310f9eb13fd2cab5fd20e88220.zip chromium_src-be180c8044f145310f9eb13fd2cab5fd20e88220.tar.gz chromium_src-be180c8044f145310f9eb13fd2cab5fd20e88220.tar.bz2 |
Move initialization of ChromeURLRequestContexts to the IO thread.
Before, these URLRequestContexts were lazily created from the UI thread. Unfortunately that model made it easy for consumers on the UI thread to poke at stuff which was being used from the IO thread, and introduce races.
So instead of providing a URLRequestContext*, the Profile now vends a URLRequestContextGetter*.
The consequence of this is:
* Consumers on the UI thread can no longer get access to a URLRequestContext.
* Consumers on the IO thread need to call URLRequestContextGetter::GetURLRequestContext() to get at the context. This uses the same style lazy-creation of URLRequestContexts, albeit from the IO thread.
OK, so now the smelly part:
There were a couple of consumers of URLRequestContext on the UI thread that can't easily be moved to the IO thread -- these are the consumers of the cookie store. Before they could happily mess with the cookie store from the UI thread, and this was fine since CookieStore is threadsafe. However under the new model, they have no way to get at the URLRequestContext from the UI thread, hence can't get a pointer to the cookie store.
To support that use-cases, I bastardized the API some by adding a URLRequestContextGetter::GetCookieStore() method that lets UI thread consumers get a pointer to the cookie store, since we know this particular cross-thread usage is safe.
BUG=http://crbug.com/22294
Review URL: http://codereview.chromium.org/258008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29880 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/download_file.cc | 34 | ||||
-rw-r--r-- | chrome/browser/download/download_file.h | 9 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.cc | 7 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.h | 4 | ||||
-rw-r--r-- | chrome/browser/download/save_file_manager.cc | 19 | ||||
-rw-r--r-- | chrome/browser/download/save_file_manager.h | 6 | ||||
-rw-r--r-- | chrome/browser/download/save_package.cc | 5 | ||||
-rw-r--r-- | chrome/browser/download/save_package.h | 4 |
8 files changed, 53 insertions, 35 deletions
diff --git a/chrome/browser/download/download_file.cc b/chrome/browser/download/download_file.cc index b340d00..6bb0866 100644 --- a/chrome/browser/download/download_file.cc +++ b/chrome/browser/download/download_file.cc @@ -13,6 +13,7 @@ #include "build/build_config.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/download/download_manager.h" +#include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/tab_contents/tab_util.h" @@ -423,11 +424,13 @@ void DownloadFileManager::OnDownloadFinished(int id, RemoveDownloadFromUIProgress(id); } -void DownloadFileManager::DownloadUrl(const GURL& url, - const GURL& referrer, - int render_process_host_id, - int render_view_id, - URLRequestContext* request_context) { +void DownloadFileManager::DownloadUrl( + const GURL& url, + const GURL& referrer, + const std::string& referrer_charset, + int render_process_host_id, + int render_view_id, + URLRequestContextGetter* request_context_getter) { DCHECK(MessageLoop::current() == ui_loop_); base::Thread* thread = g_browser_process->io_thread(); if (thread) { @@ -436,9 +439,10 @@ void DownloadFileManager::DownloadUrl(const GURL& url, &DownloadFileManager::OnDownloadUrl, url, referrer, + referrer_charset, render_process_host_id, render_view_id, - request_context)); + request_context_getter)); } } @@ -517,17 +521,23 @@ void DownloadFileManager::RemoveDownloadManager(DownloadManager* manager) { // Notifications from the UI thread and run on the IO thread // Initiate a request for URL to be downloaded. -void DownloadFileManager::OnDownloadUrl(const GURL& url, - const GURL& referrer, - int render_process_host_id, - int render_view_id, - URLRequestContext* request_context) { +void DownloadFileManager::OnDownloadUrl( + const GURL& url, + const GURL& referrer, + const std::string& referrer_charset, + int render_process_host_id, + int render_view_id, + URLRequestContextGetter* request_context_getter) { DCHECK(MessageLoop::current() == io_loop_); + + URLRequestContext* context = request_context_getter->GetURLRequestContext(); + context->set_referrer_charset(referrer_charset); + resource_dispatcher_host_->BeginDownload(url, referrer, render_process_host_id, render_view_id, - request_context); + context); } // Actions from the UI thread and run on the download thread diff --git a/chrome/browser/download/download_file.h b/chrome/browser/download/download_file.h index 66d3e7c..2e24a17 100644 --- a/chrome/browser/download/download_file.h +++ b/chrome/browser/download/download_file.h @@ -42,6 +42,7 @@ #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ #include <map> +#include <string> #include <vector> #include "app/gfx/native_widget_types.h" @@ -61,7 +62,7 @@ struct DownloadCreateInfo; class DownloadManager; class MessageLoop; class ResourceDispatcherHost; -class URLRequestContext; +class URLRequestContextGetter; // DownloadBuffer -------------------------------------------------------------- @@ -193,16 +194,18 @@ class DownloadFileManager // ResourceDispatcherHost on the IO thread. void DownloadUrl(const GURL& url, const GURL& referrer, + const std::string& referrer_charset, int render_process_host_id, int render_view_id, - URLRequestContext* request_context); + URLRequestContextGetter* request_context_getter); // Run on the IO thread to initiate the download of a URL. void OnDownloadUrl(const GURL& url, const GURL& referrer, + const std::string& referrer_charset, int render_process_host_id, int render_view_id, - URLRequestContext* request_context); + URLRequestContextGetter* request_context_getter); // Called on the UI thread to remove a download item or manager. void RemoveDownloadManager(DownloadManager* manager); diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index fb68114..f412e33 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -23,6 +23,7 @@ #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_install_ui.h" #include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" @@ -475,7 +476,7 @@ bool DownloadManager::Init(Profile* profile) { shutdown_needed_ = true; profile_ = profile; - request_context_ = profile_->GetRequestContext(); + request_context_getter_ = profile_->GetRequestContext(); // 'incognito mode' will have access to past downloads, but we won't store // information about new downloads while in that mode. @@ -1119,12 +1120,12 @@ void DownloadManager::DownloadUrl(const GURL& url, const std::string& referrer_charset, TabContents* tab_contents) { DCHECK(tab_contents); - request_context_->set_referrer_charset(referrer_charset); file_manager_->DownloadUrl(url, referrer, + referrer_charset, tab_contents->process()->id(), tab_contents->render_view_host()->routing_id(), - request_context_.get()); + request_context_getter_); } void DownloadManager::GenerateExtension( diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h index f2fea6e..b2d6b3c 100644 --- a/chrome/browser/download/download_manager.h +++ b/chrome/browser/download/download_manager.h @@ -63,7 +63,7 @@ class MessageLoop; class PrefService; class Profile; class ResourceDispatcherHost; -class URLRequestContext; +class URLRequestContextGetter; class TabContents; namespace base { @@ -585,7 +585,7 @@ class DownloadManager : public base::RefCountedThreadSafe<DownloadManager>, // The current active profile. Profile* profile_; - scoped_refptr<URLRequestContext> request_context_; + scoped_refptr<URLRequestContextGetter> request_context_getter_; // Used for history service request management. CancelableRequestConsumerTSimple<Observer*> cancelable_consumer_; diff --git a/chrome/browser/download/save_file_manager.cc b/chrome/browser/download/save_file_manager.cc index 063c6b1..3289799 100644 --- a/chrome/browser/download/save_file_manager.cc +++ b/chrome/browser/download/save_file_manager.cc @@ -15,6 +15,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/download/save_file.h" #include "chrome/browser/download/save_package.h" +#include "chrome/browser/net/url_request_context_getter.h" #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_util.h" @@ -153,7 +154,7 @@ void SaveFileManager::SaveURL(const GURL& url, int render_view_id, SaveFileCreateInfo::SaveFileSource save_source, const FilePath& file_full_path, - URLRequestContext* request_context, + URLRequestContextGetter* request_context_getter, SavePackage* save_package) { DCHECK_EQ(MessageLoop::current(), ui_loop_); if (!io_loop_) { @@ -173,7 +174,7 @@ void SaveFileManager::SaveURL(const GURL& url, referrer, render_process_host_id, render_view_id, - request_context)); + request_context_getter)); } else { // We manually start the save job. SaveFileCreateInfo* info = new SaveFileCreateInfo(file_full_path, @@ -393,17 +394,19 @@ void SaveFileManager::OnCancelSaveRequest(int render_process_id, // Notifications sent from the UI thread and run on the IO thread. -void SaveFileManager::OnSaveURL(const GURL& url, - const GURL& referrer, - int render_process_host_id, - int render_view_id, - URLRequestContext* request_context) { +void SaveFileManager::OnSaveURL( + const GURL& url, + const GURL& referrer, + int render_process_host_id, + int render_view_id, + URLRequestContextGetter* request_context_getter) { DCHECK_EQ(MessageLoop::current(), io_loop_); + URLRequestContext* context = request_context_getter->GetURLRequestContext(); resource_dispatcher_host_->BeginSaveFile(url, referrer, render_process_host_id, render_view_id, - request_context); + context); } void SaveFileManager::OnRequireSaveJobFromOtherSource( diff --git a/chrome/browser/download/save_file_manager.h b/chrome/browser/download/save_file_manager.h index f85fee7..5f3d564 100644 --- a/chrome/browser/download/save_file_manager.h +++ b/chrome/browser/download/save_file_manager.h @@ -75,7 +75,7 @@ class SavePackage; class MessageLoop; class ResourceDispatcherHost; class Task; -class URLRequestContext; +class URLRequestContextGetter; class SaveFileManager : public base::RefCountedThreadSafe<SaveFileManager> { @@ -99,7 +99,7 @@ class SaveFileManager int render_view_id, SaveFileCreateInfo::SaveFileSource save_source, const FilePath& file_full_path, - URLRequestContext* request_context, + URLRequestContextGetter* request_context_getter, SavePackage* save_package); // Notifications sent from the IO thread and run on the file thread: @@ -218,7 +218,7 @@ class SaveFileManager const GURL& referrer, int render_process_host_id, int render_view_id, - URLRequestContext* request_context); + URLRequestContextGetter* request_context_getter); // Handler for a notification sent to the IO thread for generating save id. void OnRequireSaveJobFromOtherSource(SaveFileCreateInfo* info); // Call ResourceDispatcherHost's CancelRequest method to execute cancel diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index 97487c0..20cb15b 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -20,6 +20,7 @@ #include "chrome/browser/download/save_file.h" #include "chrome/browser/download/save_file_manager.h" #include "chrome/browser/download/save_item.h" +#include "chrome/browser/net/url_request_context_getter.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/renderer_host/render_view_host.h" @@ -295,7 +296,7 @@ bool SavePackage::Init() { return false; } - request_context_ = profile->GetRequestContext(); + request_context_getter_ = profile->GetRequestContext(); // Create the fake DownloadItem and display the view. download_ = new DownloadItem(1, saved_main_file_path_, 0, page_url_, GURL(), @@ -764,7 +765,7 @@ void SavePackage::SaveNextFile(bool process_all_remaining_items) { tab_contents_->render_view_host()->routing_id(), save_item->save_source(), save_item->full_path(), - request_context_.get(), + request_context_getter_.get(), this); } while (process_all_remaining_items && waiting_item_queue_.size()); } diff --git a/chrome/browser/download/save_package.h b/chrome/browser/download/save_package.h index 4e84c25..a20f027 100644 --- a/chrome/browser/download/save_package.h +++ b/chrome/browser/download/save_package.h @@ -28,7 +28,7 @@ class MessageLoop; class PrefService; class Profile; class TabContents; -class URLRequestContext; +class URLRequestContextGetter; class TabContents; namespace base { @@ -265,7 +265,7 @@ class SavePackage : public base::RefCountedThreadSafe<SavePackage>, // The request context which provides application-specific context for // URLRequest instances. - scoped_refptr<URLRequestContext> request_context_; + scoped_refptr<URLRequestContextGetter> request_context_getter_; // Non-owning pointer for handling file writing on the file thread. SaveFileManager* file_manager_; |