Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: net/base/sdch_manager.cc

Issue 664263002: Restructure SDCH layering to allow more separation (observer/1->[0,n] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated comments. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/sdch_manager.cc
diff --git a/net/base/sdch_manager.cc b/net/base/sdch_manager.cc
index 122f01ff644630188a39e2c8ccd4f8bbe969e4aa..1365c60eb3db97a9f70dab7af65e1401e3530f08 100644
--- a/net/base/sdch_manager.cc
+++ b/net/base/sdch_manager.cc
@@ -11,6 +11,7 @@
#include "base/strings/string_util.h"
#include "crypto/sha2.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
+#include "net/base/sdch_observer.h"
#include "net/url_request/url_request_http_job.h"
namespace {
@@ -246,13 +247,12 @@ bool SdchManager::Dictionary::DomainMatch(const GURL& gurl,
}
//------------------------------------------------------------------------------
-SdchManager::SdchManager()
- : fetches_count_for_testing_(0) {
- DCHECK(CalledOnValidThread());
+SdchManager::SdchManager() {
+ DCHECK(thread_checker_.CalledOnValidThread());
}
SdchManager::~SdchManager() {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
while (!dictionaries_.empty()) {
DictionaryMap::iterator it = dictionaries_.begin();
dictionaries_.erase(it->first);
@@ -262,14 +262,14 @@ SdchManager::~SdchManager() {
void SdchManager::ClearData() {
blacklisted_domains_.clear();
allow_latency_experiment_.clear();
- if (fetcher_.get())
- fetcher_->Cancel();
// Note that this may result in not having dictionaries we've advertised
// for incoming responses. The window is relatively small (as ClearData()
// is not expected to be called frequently), so we rely on meta-refresh
// to handle this case.
dictionaries_.clear();
+
+ FOR_EACH_OBSERVER(SdchObserver, observers_, OnClearDictionaries(this));
}
// static
@@ -277,11 +277,6 @@ void SdchManager::SdchErrorRecovery(ProblemCodes problem) {
UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE);
}
-void SdchManager::set_sdch_fetcher(scoped_ptr<SdchFetcher> fetcher) {
- DCHECK(CalledOnValidThread());
- fetcher_ = fetcher.Pass();
-}
-
// static
void SdchManager::EnableSdchSupport(bool enabled) {
g_sdch_enabled_ = enabled;
@@ -352,7 +347,7 @@ int SdchManager::BlacklistDomainExponential(const std::string& domain) {
}
bool SdchManager::IsInSupportedDomain(const GURL& url) {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
if (!g_sdch_enabled_ )
return false;
@@ -382,18 +377,19 @@ bool SdchManager::IsInSupportedDomain(const GURL& url) {
return false;
}
-void SdchManager::FetchDictionary(const GURL& request_url,
+void SdchManager::OnGetDictionary(const GURL& request_url,
const GURL& dictionary_url) {
- DCHECK(CalledOnValidThread());
- if (CanFetchDictionary(request_url, dictionary_url) && fetcher_.get()) {
- ++fetches_count_for_testing_;
- fetcher_->Schedule(dictionary_url);
- }
+ if (!CanFetchDictionary(request_url, dictionary_url))
+ return;
+
+ FOR_EACH_OBSERVER(SdchObserver,
+ observers_,
+ OnGetDictionary(this, request_url, dictionary_url));
}
bool SdchManager::CanFetchDictionary(const GURL& referring_url,
const GURL& dictionary_url) const {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.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 and
@@ -402,7 +398,6 @@ bool SdchManager::CanFetchDictionary(const GURL& referring_url,
referrer URL host name
3 The parent domain of the referrer URL host name is not a top level
domain
- 4 The dictionary URL is not an HTTPS URL.
*/
// Item (1) above implies item (2). Spec should be updated.
// I take "host name match" to be "is identical to"
@@ -430,7 +425,7 @@ void SdchManager::GetVcdiffDictionary(
const std::string& server_hash,
const GURL& referring_url,
scoped_refptr<Dictionary>* dictionary) {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
*dictionary = NULL;
DictionaryMap::iterator it = dictionaries_.find(server_hash);
if (it == dictionaries_.end()) {
@@ -449,7 +444,7 @@ void SdchManager::GetVcdiffDictionary(
// instances that can be used if/when a server specifies one.
void SdchManager::GetAvailDictionaryList(const GURL& target_url,
std::string* list) {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
int count = 0;
for (DictionaryMap::iterator it = dictionaries_.begin();
it != dictionaries_.end(); ++it) {
@@ -486,13 +481,13 @@ void SdchManager::GenerateHash(const std::string& dictionary_text,
// Methods for supporting latency experiments.
bool SdchManager::AllowLatencyExperiment(const GURL& url) const {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
return allow_latency_experiment_.end() !=
allow_latency_experiment_.find(url.host());
}
void SdchManager::SetAllowLatencyExperiment(const GURL& url, bool enable) {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
if (enable) {
allow_latency_experiment_.insert(url.host());
return;
@@ -504,9 +499,17 @@ void SdchManager::SetAllowLatencyExperiment(const GURL& url, bool enable) {
allow_latency_experiment_.erase(it);
}
+void SdchManager::AddObserver(SdchObserver* observer) {
+ observers_.AddObserver(observer);
+}
+
+void SdchManager::RemoveObserver(SdchObserver* observer) {
+ observers_.RemoveObserver(observer);
+}
+
void SdchManager::AddSdchDictionary(const std::string& dictionary_text,
const GURL& dictionary_url) {
- DCHECK(CalledOnValidThread());
+ DCHECK(thread_checker_.CalledOnValidThread());
std::string client_hash;
std::string server_hash;
GenerateHash(dictionary_text, &client_hash, &server_hash);

Powered by Google App Engine
This is Rietveld 408576698