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

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: Results of self review. Created 6 years, 2 months 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 0f31d5cee8ad84e4ea2acacd8c06a52b786847b2..6010a9c4304f4e3b8301df5a6fe0c963f9b5607e 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 {
@@ -241,8 +242,7 @@ bool SdchManager::Dictionary::DomainMatch(const GURL& gurl,
}
//------------------------------------------------------------------------------
-SdchManager::SdchManager()
- : fetches_count_for_testing_(0) {
+SdchManager::SdchManager() {
DCHECK(CalledOnValidThread());
}
@@ -257,14 +257,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
@@ -272,11 +272,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;
@@ -377,13 +372,13 @@ 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,
@@ -499,6 +494,16 @@ void SdchManager::SetAllowLatencyExperiment(const GURL& url, bool enable) {
allow_latency_experiment_.erase(it);
}
+void SdchManager::AddObserver(SdchObserver* observer) {
+ observers_.AddObserver(observer);
+ observer->AddRef();
+}
+
+void SdchManager::RemoveObserver(SdchObserver* observer) {
+ observers_.RemoveObserver(observer);
+ observer->RemoveRef();
Ryan Sleevi 2014/10/20 22:42:04 This sort of manual ref-counting strikes me as all
Randy Smith (Not in Mondays) 2014/10/21 19:05:36 First, I want to call out that the Add/RemoveRef()
Ryan Sleevi 2014/10/21 23:09:29 I have a different judgement. I dislike re-inventi
Randy Smith (Not in Mondays) 2014/10/23 20:57:07 Done. (I tried to do an RAII pattern where Sdch
+}
+
void SdchManager::AddSdchDictionary(const std::string& dictionary_text,
const GURL& dictionary_url) {
DCHECK(CalledOnValidThread());

Powered by Google App Engine
This is Rietveld 408576698