summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-02 12:00:45 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-02 12:00:45 +0000
commitcf956b98be25b8c06fb72a1bfa3c114281bbb9fc (patch)
tree2b8884a73e09bd069c86fb4259cf65360711b9cb
parentacabd73105f7b20fa8bb03b8772ba58fa9063ef8 (diff)
downloadchromium_src-cf956b98be25b8c06fb72a1bfa3c114281bbb9fc.zip
chromium_src-cf956b98be25b8c06fb72a1bfa3c114281bbb9fc.tar.gz
chromium_src-cf956b98be25b8c06fb72a1bfa3c114281bbb9fc.tar.bz2
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
-rw-r--r--chrome/browser/browser_process_impl.cc3
-rw-r--r--chrome/browser/net/sdch_dictionary_fetcher.cc4
-rw-r--r--chrome/browser/net/sdch_dictionary_fetcher.h7
-rw-r--r--net/base/sdch_manager.cc17
-rw-r--r--net/base/sdch_manager.h5
-rw-r--r--tools/valgrind/tsan/suppressions.txt6
6 files changed, 30 insertions, 12 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index e84a219..d95941e 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -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
diff --git a/chrome/browser/net/sdch_dictionary_fetcher.cc b/chrome/browser/net/sdch_dictionary_fetcher.cc
index 4a96f8f..24bdf93 100644
--- a/chrome/browser/net/sdch_dictionary_fetcher.cc
+++ b/chrome/browser/net/sdch_dictionary_fetcher.cc
@@ -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.
diff --git a/chrome/browser/net/sdch_dictionary_fetcher.h b/chrome/browser/net/sdch_dictionary_fetcher.h
index d6cd795..0eaa0b9 100644
--- a/chrome/browser/net/sdch_dictionary_fetcher.h
+++ b/chrome/browser/net/sdch_dictionary_fetcher.h
@@ -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();
diff --git a/net/base/sdch_manager.cc b/net/base/sdch_manager.cc
index aef04f6..dd2b9ae 100644
--- a/net/base/sdch_manager.cc
+++ b/net/base/sdch_manager.cc
@@ -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;
diff --git a/net/base/sdch_manager.h b/net/base/sdch_manager.h
index 4324f40..00e2a71 100644
--- a/net/base/sdch_manager.h
+++ b/net/base/sdch_manager.h
@@ -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);
diff --git a/tools/valgrind/tsan/suppressions.txt b/tools/valgrind/tsan/suppressions.txt
index 6dd5e27..a096d4f 100644
--- a/tools/valgrind/tsan/suppressions.txt
+++ b/tools/valgrind/tsan/suppressions.txt
@@ -704,9 +704,3 @@
fun:ChromeMain
fun:main
}
-{
- bug_105579
- ThreadSanitizer:Race
- fun:net::SdchManager::EnableSdchSupport
- fun:net::SdchManager::Shutdown
-}