diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 20:52:56 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-12 20:52:56 +0000 |
commit | d11f566be9d149ea081607d0dbb12be7aebb4de6 (patch) | |
tree | 14fad2b08a19246ee3d223d61b67b23b8d241e38 /chrome/browser/safe_browsing/protocol_manager.cc | |
parent | 7520d82219786cae7484e4a9ca5e80879d56e036 (diff) | |
download | chromium_src-d11f566be9d149ea081607d0dbb12be7aebb4de6.zip chromium_src-d11f566be9d149ea081607d0dbb12be7aebb4de6.tar.gz chromium_src-d11f566be9d149ea081607d0dbb12be7aebb4de6.tar.bz2 |
Fix a crash during shutdown where SafeBrowsingProtocolManager could end up getting back NULL for Profile::GetDefaultRequestContext() and consequently URLFetcher would crash.
During shutdown the Profile is first deleted, and THEN the IO thread is torn down.
This means there is a window of time when Profile::GetDefaultRequestContext() will return NULL, but tasks are still running on the IO thread.
Instead, SafeBrowsingProtocolManager now gets passed an explicit context, and holds a reference throughout its lifetime.
This way it is guaranteed a valid pointer throughout the lifetime of the IO thread, even if the default Profile has already been deleted.
BUG=27074
Review URL: http://codereview.chromium.org/392010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31821 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing/protocol_manager.cc')
-rw-r--r-- | chrome/browser/safe_browsing/protocol_manager.cc | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc index 855359b..341ddd8 100644 --- a/chrome/browser/safe_browsing/protocol_manager.cc +++ b/chrome/browser/safe_browsing/protocol_manager.cc @@ -14,6 +14,7 @@ #include "base/task.h" #include "base/timer.h" #include "chrome/browser/chrome_thread.h" +#include "chrome/browser/net/url_request_context_getter.h" #include "chrome/browser/profile.h" #include "chrome/browser/safe_browsing/protocol_parser.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" @@ -61,7 +62,8 @@ SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( SafeBrowsingService* sb_service, const std::string& client_name, const std::string& client_key, - const std::string& wrapped_key) + const std::string& wrapped_key, + URLRequestContextGetter* request_context_getter) : sb_service_(sb_service), request_type_(NO_REQUEST), update_error_count_(0), @@ -75,7 +77,8 @@ SafeBrowsingProtocolManager::SafeBrowsingProtocolManager( client_key_(client_key), wrapped_key_(wrapped_key), update_size_(0), - client_name_(client_name) { + client_name_(client_name), + request_context_getter_(request_context_getter) { // Set the backoff multiplier fuzz to a random value between 0 and 1. back_off_fuzz_ = static_cast<float>(base::RandDouble()); @@ -135,7 +138,7 @@ void SafeBrowsingProtocolManager::GetFullHash( parser.FormatGetHash(prefixes, &get_hash); fetcher->set_load_flags(net::LOAD_DISABLE_CACHE); - fetcher->set_request_context(Profile::GetDefaultRequestContext()); + fetcher->set_request_context(request_context_getter_); fetcher->set_upload_data("text/plain", get_hash); fetcher->Start(); } @@ -511,7 +514,7 @@ void SafeBrowsingProtocolManager::IssueChunkRequest() { request_type_ = CHUNK_REQUEST; request_.reset(new URLFetcher(chunk_url, URLFetcher::GET, this)); request_->set_load_flags(net::LOAD_DISABLE_CACHE); - request_->set_request_context(Profile::GetDefaultRequestContext()); + request_->set_request_context(request_context_getter_); chunk_request_start_ = base::Time::Now(); request_->Start(); } @@ -523,7 +526,7 @@ void SafeBrowsingProtocolManager::IssueKeyRequest() { request_type_ = GETKEY_REQUEST; request_.reset(new URLFetcher(key_url, URLFetcher::GET, this)); request_->set_load_flags(net::LOAD_DISABLE_CACHE); - request_->set_request_context(Profile::GetDefaultRequestContext()); + request_->set_request_context(request_context_getter_); request_->Start(); } @@ -573,7 +576,7 @@ void SafeBrowsingProtocolManager::OnGetChunksComplete( GURL update_url(url); request_.reset(new URLFetcher(update_url, URLFetcher::POST, this)); request_->set_load_flags(net::LOAD_DISABLE_CACHE); - request_->set_request_context(Profile::GetDefaultRequestContext()); + request_->set_request_context(request_context_getter_); request_->set_upload_data("text/plain", list_data); request_->Start(); @@ -615,7 +618,7 @@ void SafeBrowsingProtocolManager::ReportMalware(const GURL& malware_url, GURL report_url(report_str); URLFetcher* report = new URLFetcher(report_url, URLFetcher::GET, this); report->set_load_flags(net::LOAD_DISABLE_CACHE); - report->set_request_context(Profile::GetDefaultRequestContext()); + report->set_request_context(request_context_getter_); report->Start(); malware_reports_.insert(report); } |