Commit cf956b98 authored by joi@chromium.org's avatar joi@chromium.org

Make SDCH classes IO-thread-only. Remove TSan suppression.

BUG=105579


Review URL: http://codereview.chromium.org/8749016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112677 0039d316-1c4b-4281-b951-d872f2087c98
parent acabd731
...@@ -184,7 +184,8 @@ void BrowserProcessImpl::StartTearDown() { ...@@ -184,7 +184,8 @@ void BrowserProcessImpl::StartTearDown() {
// a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
// a PostDelayedTask onto the IO thread. This shutdown call will both discard // a PostDelayedTask onto the IO thread. This shutdown call will both discard
// any pending URLFetchers, and avoid creating any more. // any pending URLFetchers, and avoid creating any more.
SdchDictionaryFetcher::Shutdown(); BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&SdchDictionaryFetcher::Shutdown));
// We need to destroy the MetricsService, GoogleURLTracker, // We need to destroy the MetricsService, GoogleURLTracker,
// IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService
......
...@@ -14,9 +14,11 @@ ...@@ -14,9 +14,11 @@
SdchDictionaryFetcher::SdchDictionaryFetcher() SdchDictionaryFetcher::SdchDictionaryFetcher()
: ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
task_is_pending_(false) { task_is_pending_(false) {
DCHECK(CalledOnValidThread());
} }
SdchDictionaryFetcher::~SdchDictionaryFetcher() { SdchDictionaryFetcher::~SdchDictionaryFetcher() {
DCHECK(CalledOnValidThread());
} }
// static // static
...@@ -25,6 +27,8 @@ void SdchDictionaryFetcher::Shutdown() { ...@@ -25,6 +27,8 @@ void SdchDictionaryFetcher::Shutdown() {
} }
void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) { void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) {
DCHECK(CalledOnValidThread());
// Avoid pushing duplicate copy onto queue. We may fetch this url again later // Avoid pushing duplicate copy onto queue. We may fetch this url again later
// and get a different dictionary, but there is no reason to have it in the // and get a different dictionary, but there is no reason to have it in the
// queue twice at one time. // queue twice at one time.
......
...@@ -16,11 +16,14 @@ ...@@ -16,11 +16,14 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/task.h" #include "base/task.h"
#include "base/threading/non_thread_safe.h"
#include "content/public/common/url_fetcher_delegate.h" #include "content/public/common/url_fetcher_delegate.h"
#include "net/base/sdch_manager.h" #include "net/base/sdch_manager.h"
class SdchDictionaryFetcher : public content::URLFetcherDelegate, class SdchDictionaryFetcher
public net::SdchFetcher { : public content::URLFetcherDelegate,
public net::SdchFetcher,
public base::NonThreadSafe {
public: public:
SdchDictionaryFetcher(); SdchDictionaryFetcher();
virtual ~SdchDictionaryFetcher(); virtual ~SdchDictionaryFetcher();
......
...@@ -206,11 +206,13 @@ bool SdchManager::Dictionary::DomainMatch(const GURL& gurl, ...@@ -206,11 +206,13 @@ bool SdchManager::Dictionary::DomainMatch(const GURL& gurl,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
SdchManager::SdchManager() { SdchManager::SdchManager() {
DCHECK(!global_); DCHECK(!global_);
DCHECK(CalledOnValidThread());
global_ = this; global_ = this;
} }
SdchManager::~SdchManager() { SdchManager::~SdchManager() {
DCHECK_EQ(this, global_); DCHECK_EQ(this, global_);
DCHECK(CalledOnValidThread());
while (!dictionaries_.empty()) { while (!dictionaries_.empty()) {
DictionaryMap::iterator it = dictionaries_.begin(); DictionaryMap::iterator it = dictionaries_.begin();
it->second->Release(); it->second->Release();
...@@ -224,7 +226,7 @@ void SdchManager::Shutdown() { ...@@ -224,7 +226,7 @@ void SdchManager::Shutdown() {
EnableSdchSupport(false); EnableSdchSupport(false);
if (!global_ ) if (!global_ )
return; return;
global_->fetcher_.reset(NULL); global_->set_sdch_fetcher(NULL);
} }
// static // static
...@@ -237,6 +239,11 @@ void SdchManager::SdchErrorRecovery(ProblemCodes problem) { ...@@ -237,6 +239,11 @@ void SdchManager::SdchErrorRecovery(ProblemCodes problem) {
UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE);
} }
void SdchManager::set_sdch_fetcher(SdchFetcher* fetcher) {
DCHECK(CalledOnValidThread());
fetcher_.reset(fetcher);
}
// static // static
void SdchManager::EnableSdchSupport(bool enabled) { void SdchManager::EnableSdchSupport(bool enabled) {
g_sdch_enabled_ = enabled; g_sdch_enabled_ = enabled;
...@@ -301,6 +308,7 @@ int SdchManager::BlacklistDomainExponential(const std::string& domain) { ...@@ -301,6 +308,7 @@ int SdchManager::BlacklistDomainExponential(const std::string& domain) {
} }
bool SdchManager::IsInSupportedDomain(const GURL& url) { bool SdchManager::IsInSupportedDomain(const GURL& url) {
DCHECK(CalledOnValidThread());
if (!g_sdch_enabled_ ) if (!g_sdch_enabled_ )
return false; return false;
...@@ -323,6 +331,7 @@ bool SdchManager::IsInSupportedDomain(const GURL& url) { ...@@ -323,6 +331,7 @@ bool SdchManager::IsInSupportedDomain(const GURL& url) {
void SdchManager::FetchDictionary(const GURL& request_url, void SdchManager::FetchDictionary(const GURL& request_url,
const GURL& dictionary_url) { const GURL& dictionary_url) {
DCHECK(CalledOnValidThread());
if (SdchManager::Global()->CanFetchDictionary(request_url, dictionary_url) && if (SdchManager::Global()->CanFetchDictionary(request_url, dictionary_url) &&
fetcher_.get()) fetcher_.get())
fetcher_->Schedule(dictionary_url); fetcher_->Schedule(dictionary_url);
...@@ -330,6 +339,7 @@ void SdchManager::FetchDictionary(const GURL& request_url, ...@@ -330,6 +339,7 @@ void SdchManager::FetchDictionary(const GURL& request_url,
bool SdchManager::CanFetchDictionary(const GURL& referring_url, bool SdchManager::CanFetchDictionary(const GURL& referring_url,
const GURL& dictionary_url) const { const GURL& dictionary_url) const {
DCHECK(CalledOnValidThread());
/* The user agent may retrieve a dictionary from the dictionary URL if all of /* The user agent may retrieve a dictionary from the dictionary URL if all of
the following are true: the following are true:
1 The dictionary URL host name matches the referrer URL host name 1 The dictionary URL host name matches the referrer URL host name
...@@ -362,6 +372,7 @@ bool SdchManager::CanFetchDictionary(const GURL& referring_url, ...@@ -362,6 +372,7 @@ bool SdchManager::CanFetchDictionary(const GURL& referring_url,
bool SdchManager::AddSdchDictionary(const std::string& dictionary_text, bool SdchManager::AddSdchDictionary(const std::string& dictionary_text,
const GURL& dictionary_url) { const GURL& dictionary_url) {
DCHECK(CalledOnValidThread());
std::string client_hash; std::string client_hash;
std::string server_hash; std::string server_hash;
GenerateHash(dictionary_text, &client_hash, &server_hash); GenerateHash(dictionary_text, &client_hash, &server_hash);
...@@ -460,6 +471,7 @@ bool SdchManager::AddSdchDictionary(const std::string& dictionary_text, ...@@ -460,6 +471,7 @@ bool SdchManager::AddSdchDictionary(const std::string& dictionary_text,
void SdchManager::GetVcdiffDictionary(const std::string& server_hash, void SdchManager::GetVcdiffDictionary(const std::string& server_hash,
const GURL& referring_url, Dictionary** dictionary) { const GURL& referring_url, Dictionary** dictionary) {
DCHECK(CalledOnValidThread());
*dictionary = NULL; *dictionary = NULL;
DictionaryMap::iterator it = dictionaries_.find(server_hash); DictionaryMap::iterator it = dictionaries_.find(server_hash);
if (it == dictionaries_.end()) { if (it == dictionaries_.end()) {
...@@ -476,6 +488,7 @@ void SdchManager::GetVcdiffDictionary(const std::string& server_hash, ...@@ -476,6 +488,7 @@ void SdchManager::GetVcdiffDictionary(const std::string& server_hash,
// instances that can be used if/when a server specifies one. // instances that can be used if/when a server specifies one.
void SdchManager::GetAvailDictionaryList(const GURL& target_url, void SdchManager::GetAvailDictionaryList(const GURL& target_url,
std::string* list) { std::string* list) {
DCHECK(CalledOnValidThread());
int count = 0; int count = 0;
for (DictionaryMap::iterator it = dictionaries_.begin(); for (DictionaryMap::iterator it = dictionaries_.begin();
it != dictionaries_.end(); ++it) { it != dictionaries_.end(); ++it) {
...@@ -510,11 +523,13 @@ void SdchManager::GenerateHash(const std::string& dictionary_text, ...@@ -510,11 +523,13 @@ void SdchManager::GenerateHash(const std::string& dictionary_text,
// Methods for supporting latency experiments. // Methods for supporting latency experiments.
bool SdchManager::AllowLatencyExperiment(const GURL& url) const { bool SdchManager::AllowLatencyExperiment(const GURL& url) const {
DCHECK(CalledOnValidThread());
return allow_latency_experiment_.end() != return allow_latency_experiment_.end() !=
allow_latency_experiment_.find(url.host()); allow_latency_experiment_.find(url.host());
} }
void SdchManager::SetAllowLatencyExperiment(const GURL& url, bool enable) { void SdchManager::SetAllowLatencyExperiment(const GURL& url, bool enable) {
DCHECK(CalledOnValidThread());
if (enable) { if (enable) {
allow_latency_experiment_.insert(url.host()); allow_latency_experiment_.insert(url.host());
return; return;
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/time.h" #include "base/time.h"
#include "base/threading/non_thread_safe.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
...@@ -55,7 +56,7 @@ class SdchFetcher { ...@@ -55,7 +56,7 @@ class SdchFetcher {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
class NET_EXPORT SdchManager { class NET_EXPORT SdchManager : public NON_EXPORTED_BASE(base::NonThreadSafe) {
public: public:
// A list of errors that appeared and were either resolved, or used to turn // A list of errors that appeared and were either resolved, or used to turn
// off sdch encoding. // off sdch encoding.
...@@ -244,7 +245,7 @@ class NET_EXPORT SdchManager { ...@@ -244,7 +245,7 @@ class NET_EXPORT SdchManager {
static void SdchErrorRecovery(ProblemCodes problem); static void SdchErrorRecovery(ProblemCodes problem);
// Register a fetcher that this class can use to obtain dictionaries. // Register a fetcher that this class can use to obtain dictionaries.
void set_sdch_fetcher(SdchFetcher* fetcher) { fetcher_.reset(fetcher); } void set_sdch_fetcher(SdchFetcher* fetcher);
// Enables or disables SDCH compression. // Enables or disables SDCH compression.
static void EnableSdchSupport(bool enabled); static void EnableSdchSupport(bool enabled);
......
...@@ -704,9 +704,3 @@ ...@@ -704,9 +704,3 @@
fun:ChromeMain fun:ChromeMain
fun:main fun:main
} }
{
bug_105579
ThreadSanitizer:Race
fun:net::SdchManager::EnableSdchSupport
fun:net::SdchManager::Shutdown
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment