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() {
// a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do
// a PostDelayedTask onto the IO thread. This shutdown call will both discard
// 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,
// IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService
......
......@@ -14,9 +14,11 @@
SdchDictionaryFetcher::SdchDictionaryFetcher()
: ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
task_is_pending_(false) {
DCHECK(CalledOnValidThread());
}
SdchDictionaryFetcher::~SdchDictionaryFetcher() {
DCHECK(CalledOnValidThread());
}
// static
......@@ -25,6 +27,8 @@ void SdchDictionaryFetcher::Shutdown() {
}
void SdchDictionaryFetcher::Schedule(const GURL& dictionary_url) {
DCHECK(CalledOnValidThread());
// 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
// queue twice at one time.
......
......@@ -16,11 +16,14 @@
#include "base/memory/scoped_ptr.h"
#include "base/task.h"
#include "base/threading/non_thread_safe.h"
#include "content/public/common/url_fetcher_delegate.h"
#include "net/base/sdch_manager.h"
class SdchDictionaryFetcher : public content::URLFetcherDelegate,
public net::SdchFetcher {
class SdchDictionaryFetcher
: public content::URLFetcherDelegate,
public net::SdchFetcher,
public base::NonThreadSafe {
public:
SdchDictionaryFetcher();
virtual ~SdchDictionaryFetcher();
......
......@@ -206,11 +206,13 @@ bool SdchManager::Dictionary::DomainMatch(const GURL& gurl,
//------------------------------------------------------------------------------
SdchManager::SdchManager() {
DCHECK(!global_);
DCHECK(CalledOnValidThread());
global_ = this;
}
SdchManager::~SdchManager() {
DCHECK_EQ(this, global_);
DCHECK(CalledOnValidThread());
while (!dictionaries_.empty()) {
DictionaryMap::iterator it = dictionaries_.begin();
it->second->Release();
......@@ -224,7 +226,7 @@ void SdchManager::Shutdown() {
EnableSdchSupport(false);
if (!global_ )
return;
global_->fetcher_.reset(NULL);
global_->set_sdch_fetcher(NULL);
}
// static
......@@ -237,6 +239,11 @@ void SdchManager::SdchErrorRecovery(ProblemCodes problem) {
UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE);
}
void SdchManager::set_sdch_fetcher(SdchFetcher* fetcher) {
DCHECK(CalledOnValidThread());
fetcher_.reset(fetcher);
}
// static
void SdchManager::EnableSdchSupport(bool enabled) {
g_sdch_enabled_ = enabled;
......@@ -301,6 +308,7 @@ int SdchManager::BlacklistDomainExponential(const std::string& domain) {
}
bool SdchManager::IsInSupportedDomain(const GURL& url) {
DCHECK(CalledOnValidThread());
if (!g_sdch_enabled_ )
return false;
......@@ -323,6 +331,7 @@ bool SdchManager::IsInSupportedDomain(const GURL& url) {
void SdchManager::FetchDictionary(const GURL& request_url,
const GURL& dictionary_url) {
DCHECK(CalledOnValidThread());
if (SdchManager::Global()->CanFetchDictionary(request_url, dictionary_url) &&
fetcher_.get())
fetcher_->Schedule(dictionary_url);
......@@ -330,6 +339,7 @@ void SdchManager::FetchDictionary(const GURL& request_url,
bool SdchManager::CanFetchDictionary(const GURL& referring_url,
const GURL& dictionary_url) const {
DCHECK(CalledOnValidThread());
/* The user agent may retrieve a dictionary from the dictionary URL if all of
the following are true:
1 The dictionary URL host name matches the referrer URL host name
......@@ -362,6 +372,7 @@ bool SdchManager::CanFetchDictionary(const GURL& referring_url,
bool SdchManager::AddSdchDictionary(const std::string& dictionary_text,
const GURL& dictionary_url) {
DCHECK(CalledOnValidThread());
std::string client_hash;
std::string server_hash;
GenerateHash(dictionary_text, &client_hash, &server_hash);
......@@ -460,6 +471,7 @@ bool SdchManager::AddSdchDictionary(const std::string& dictionary_text,
void SdchManager::GetVcdiffDictionary(const std::string& server_hash,
const GURL& referring_url, Dictionary** dictionary) {
DCHECK(CalledOnValidThread());
*dictionary = NULL;
DictionaryMap::iterator it = dictionaries_.find(server_hash);
if (it == dictionaries_.end()) {
......@@ -476,6 +488,7 @@ void SdchManager::GetVcdiffDictionary(const std::string& server_hash,
// instances that can be used if/when a server specifies one.
void SdchManager::GetAvailDictionaryList(const GURL& target_url,
std::string* list) {
DCHECK(CalledOnValidThread());
int count = 0;
for (DictionaryMap::iterator it = dictionaries_.begin();
it != dictionaries_.end(); ++it) {
......@@ -510,11 +523,13 @@ void SdchManager::GenerateHash(const std::string& dictionary_text,
// Methods for supporting latency experiments.
bool SdchManager::AllowLatencyExperiment(const GURL& url) const {
DCHECK(CalledOnValidThread());
return allow_latency_experiment_.end() !=
allow_latency_experiment_.find(url.host());
}
void SdchManager::SetAllowLatencyExperiment(const GURL& url, bool enable) {
DCHECK(CalledOnValidThread());
if (enable) {
allow_latency_experiment_.insert(url.host());
return;
......
......@@ -29,6 +29,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
#include "base/threading/non_thread_safe.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_export.h"
......@@ -55,7 +56,7 @@ class SdchFetcher {
//------------------------------------------------------------------------------
class NET_EXPORT SdchManager {
class NET_EXPORT SdchManager : public NON_EXPORTED_BASE(base::NonThreadSafe) {
public:
// A list of errors that appeared and were either resolved, or used to turn
// off sdch encoding.
......@@ -244,7 +245,7 @@ class NET_EXPORT SdchManager {
static void SdchErrorRecovery(ProblemCodes problem);
// 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.
static void EnableSdchSupport(bool enabled);
......
......@@ -704,9 +704,3 @@
fun:ChromeMain
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