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

Unified Diff: chrome/browser/net/http_server_properties_manager.cc

Issue 375083002: Break out the IO thread aspects of HttpServerPropertiesManager into a new ChromeHttpServerPropertie… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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: chrome/browser/net/http_server_properties_manager.cc
diff --git a/chrome/browser/net/http_server_properties_manager.cc b/chrome/browser/net/http_server_properties_manager.cc
index d99af2c82767c90d19089934cc737c739a68c1fc..85961e0035efcea1023583c25b3b00b33ab1b8bd 100644
--- a/chrome/browser/net/http_server_properties_manager.cc
+++ b/chrome/browser/net/http_server_properties_manager.cc
@@ -30,11 +30,6 @@ namespace {
// timer.
const int64 kUpdateCacheDelayMs = 1000;
-// Time to wait before starting an update the preferences from the
-// http_server_properties_impl_ cache. Scheduling another update during this
-// period will reset the timer.
-const int64 kUpdatePrefsDelayMs = 5000;
-
// "version" 0 indicates, http_server_properties doesn't have "version"
// property.
const int kMissingVersion = 0;
@@ -53,9 +48,6 @@ const int kMaxAlternateProtocolHostsToPersist = 1000;
// Persist 200 MRU SpdySettingsHostPortPairs.
const int kMaxSpdySettingsHostsToPersist = 200;
-// Persist 300 MRU SupportsSpdyServerHostPortPairs.
-const int kMaxSupportsSpdyServerHostsToPersist = 300;
-
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -80,18 +72,18 @@ HttpServerPropertiesManager::HttpServerPropertiesManager(
}
HttpServerPropertiesManager::~HttpServerPropertiesManager() {
+ // Why does destruction happen on the IO thread?
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- io_weak_ptr_factory_.reset();
}
void HttpServerPropertiesManager::InitializeOnIOThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- io_weak_ptr_factory_.reset(
- new base::WeakPtrFactory<HttpServerPropertiesManager>(this));
- http_server_properties_impl_.reset(new net::HttpServerPropertiesImpl());
+ ChromeHttpServerProperties::UpdateCallback io_callback =
+ base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnIO,
+ ui_weak_ptr_);
- io_prefs_update_timer_.reset(
- new base::OneShotTimer<HttpServerPropertiesManager>);
+ http_server_properties_impl_.reset(
+ new ChromeHttpServerProperties(io_callback));
BrowserThread::PostTask(
BrowserThread::UI,
@@ -108,6 +100,11 @@ void HttpServerPropertiesManager::ShutdownOnUIThread() {
pref_change_registrar_.RemoveAll();
}
+net::HttpServerProperties* HttpServerPropertiesManager::http_server_properties() {
+ return http_server_properties_impl_.get();
+}
+
+
// static
void HttpServerPropertiesManager::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* prefs) {
@@ -127,159 +124,6 @@ void HttpServerPropertiesManager::SetVersion(
http_server_properties_dict->SetInteger("version", version_number);
}
-// This is required for conformance with the HttpServerProperties interface.
-base::WeakPtr<net::HttpServerProperties>
- HttpServerPropertiesManager::GetWeakPtr() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return io_weak_ptr_factory_->GetWeakPtr();
-}
-
-void HttpServerPropertiesManager::Clear() {
- Clear(base::Closure());
-}
-
-void HttpServerPropertiesManager::Clear(const base::Closure& completion) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- http_server_properties_impl_->Clear();
- UpdatePrefsFromCacheOnIO(completion);
-}
-
-bool HttpServerPropertiesManager::SupportsSpdy(
- const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return http_server_properties_impl_->SupportsSpdy(server);
-}
-
-void HttpServerPropertiesManager::SetSupportsSpdy(
- const net::HostPortPair& server,
- bool support_spdy) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- http_server_properties_impl_->SetSupportsSpdy(server, support_spdy);
- ScheduleUpdatePrefsOnIO();
-}
-
-bool HttpServerPropertiesManager::HasAlternateProtocol(
- const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return http_server_properties_impl_->HasAlternateProtocol(server);
-}
-
-net::PortAlternateProtocolPair
-HttpServerPropertiesManager::GetAlternateProtocol(
- const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return http_server_properties_impl_->GetAlternateProtocol(server);
-}
-
-void HttpServerPropertiesManager::SetAlternateProtocol(
- const net::HostPortPair& server,
- uint16 alternate_port,
- net::AlternateProtocol alternate_protocol) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- http_server_properties_impl_->SetAlternateProtocol(
- server, alternate_port, alternate_protocol);
- ScheduleUpdatePrefsOnIO();
-}
-
-void HttpServerPropertiesManager::SetBrokenAlternateProtocol(
- const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- http_server_properties_impl_->SetBrokenAlternateProtocol(server);
- ScheduleUpdatePrefsOnIO();
-}
-
-bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken(
- const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken(
- server);
-}
-
-void HttpServerPropertiesManager::ConfirmAlternateProtocol(
- const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- http_server_properties_impl_->ConfirmAlternateProtocol(server);
- ScheduleUpdatePrefsOnIO();
-}
-
-void HttpServerPropertiesManager::ClearAlternateProtocol(
- const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- http_server_properties_impl_->ClearAlternateProtocol(server);
- ScheduleUpdatePrefsOnIO();
-}
-
-const net::AlternateProtocolMap&
-HttpServerPropertiesManager::alternate_protocol_map() const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return http_server_properties_impl_->alternate_protocol_map();
-}
-
-void HttpServerPropertiesManager::SetAlternateProtocolExperiment(
- net::AlternateProtocolExperiment experiment) {
- http_server_properties_impl_->SetAlternateProtocolExperiment(experiment);
-}
-
-net::AlternateProtocolExperiment
-HttpServerPropertiesManager::GetAlternateProtocolExperiment() const {
- return http_server_properties_impl_->GetAlternateProtocolExperiment();
-}
-
-const net::SettingsMap&
-HttpServerPropertiesManager::GetSpdySettings(
- const net::HostPortPair& host_port_pair) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return http_server_properties_impl_->GetSpdySettings(host_port_pair);
-}
-
-bool HttpServerPropertiesManager::SetSpdySetting(
- const net::HostPortPair& host_port_pair,
- net::SpdySettingsIds id,
- net::SpdySettingsFlags flags,
- uint32 value) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- bool persist = http_server_properties_impl_->SetSpdySetting(
- host_port_pair, id, flags, value);
- if (persist)
- ScheduleUpdatePrefsOnIO();
- return persist;
-}
-
-void HttpServerPropertiesManager::ClearSpdySettings(
- const net::HostPortPair& host_port_pair) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- http_server_properties_impl_->ClearSpdySettings(host_port_pair);
- ScheduleUpdatePrefsOnIO();
-}
-
-void HttpServerPropertiesManager::ClearAllSpdySettings() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- http_server_properties_impl_->ClearAllSpdySettings();
- ScheduleUpdatePrefsOnIO();
-}
-
-const net::SpdySettingsMap&
-HttpServerPropertiesManager::spdy_settings_map() const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return http_server_properties_impl_->spdy_settings_map();
-}
-
-void HttpServerPropertiesManager::SetServerNetworkStats(
- const net::HostPortPair& host_port_pair,
- NetworkStats stats) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats);
-}
-
-const HttpServerPropertiesManager::NetworkStats*
-HttpServerPropertiesManager::GetServerNetworkStats(
- const net::HostPortPair& host_port_pair) const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- return http_server_properties_impl_->GetServerNetworkStats(host_port_pair);
-}
-
//
// Update the HttpServerPropertiesImpl's cache with data from preferences.
//
@@ -451,9 +295,9 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
BrowserThread::PostTask(
BrowserThread::IO,
FROM_HERE,
- base::Bind(&HttpServerPropertiesManager::
+ base::Bind(&ChromeHttpServerProperties::
UpdateCacheFromPrefsOnIO,
- base::Unretained(this),
+ base::Unretained(http_server_properties_impl_.get()),
base::Owned(spdy_servers.release()),
base::Owned(spdy_settings_map.release()),
base::Owned(alternate_protocol_map.release()),
@@ -461,117 +305,6 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
detected_corrupted_prefs));
}
-void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO(
- StringVector* spdy_servers,
- net::SpdySettingsMap* spdy_settings_map,
- net::AlternateProtocolMap* alternate_protocol_map,
- net::AlternateProtocolExperiment alternate_protocol_experiment,
- bool detected_corrupted_prefs) {
- // Preferences have the master data because admins might have pushed new
- // preferences. Update the cached data with new data from preferences.
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size());
- http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true);
-
- // Update the cached data and use the new spdy_settings from preferences.
- UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size());
- http_server_properties_impl_->InitializeSpdySettingsServers(
- spdy_settings_map);
-
- // Update the cached data and use the new Alternate-Protocol server list from
- // preferences.
- UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers",
- alternate_protocol_map->size());
- http_server_properties_impl_->InitializeAlternateProtocolServers(
- alternate_protocol_map);
- http_server_properties_impl_->SetAlternateProtocolExperiment(
- alternate_protocol_experiment);
-
- // Update the prefs with what we have read (delete all corrupted prefs).
- if (detected_corrupted_prefs)
- ScheduleUpdatePrefsOnIO();
-}
-
-
-//
-// Update Preferences with data from the cached data.
-//
-void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- // Cancel pending updates, if any.
- io_prefs_update_timer_->Stop();
- StartPrefsUpdateTimerOnIO(
- base::TimeDelta::FromMilliseconds(kUpdatePrefsDelayMs));
-}
-
-void HttpServerPropertiesManager::StartPrefsUpdateTimerOnIO(
- base::TimeDelta delay) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- // This is overridden in tests to post the task without the delay.
- io_prefs_update_timer_->Start(
- FROM_HERE, delay, this,
- &HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO);
-}
-
-// This is required so we can set this as the callback for a timer.
-void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO() {
- UpdatePrefsFromCacheOnIO(base::Closure());
-}
-
-void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(
- const base::Closure& completion) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- base::ListValue* spdy_server_list = new base::ListValue;
- http_server_properties_impl_->GetSpdyServerList(
- spdy_server_list, kMaxSupportsSpdyServerHostsToPersist);
-
- net::SpdySettingsMap* spdy_settings_map =
- new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist);
- const net::SpdySettingsMap& main_map =
- http_server_properties_impl_->spdy_settings_map();
- int count = 0;
- for (net::SpdySettingsMap::const_iterator it = main_map.begin();
- it != main_map.end() && count < kMaxSpdySettingsHostsToPersist;
- ++it, ++count) {
- spdy_settings_map->Put(it->first, it->second);
- }
-
- net::AlternateProtocolMap* alternate_protocol_map =
- new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist);
- const net::AlternateProtocolMap& map =
- http_server_properties_impl_->alternate_protocol_map();
- count = 0;
- typedef std::map<std::string, bool> CanonicalHostPersistedMap;
- CanonicalHostPersistedMap persisted_map;
- for (net::AlternateProtocolMap::const_iterator it = map.begin();
- it != map.end() && count < kMaxAlternateProtocolHostsToPersist;
- ++it) {
- const net::HostPortPair& server = it->first;
- std::string canonical_suffix =
- http_server_properties_impl_->GetCanonicalSuffix(server);
- if (!canonical_suffix.empty()) {
- if (persisted_map.find(canonical_suffix) != persisted_map.end())
- continue;
- persisted_map[canonical_suffix] = true;
- }
- alternate_protocol_map->Put(server, it->second);
- ++count;
- }
-
- // Update the preferences on the UI thread.
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI,
- ui_weak_ptr_,
- base::Owned(spdy_server_list),
- base::Owned(spdy_settings_map),
- base::Owned(alternate_protocol_map),
- completion));
-}
-
// A local or temporary data structure to hold |supports_spdy|, SpdySettings,
// and PortAlternateProtocolPair preferences for a server. This is used only in
// UpdatePrefsOnUI.
@@ -717,6 +450,25 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI(
completion.Run();
}
+// static
+void HttpServerPropertiesManager::UpdatePrefsOnIO(
+ base::WeakPtr<HttpServerPropertiesManager> ui_weak_ptr,
+ base::ListValue* spdy_server_list,
+ net::SpdySettingsMap* spdy_settings_map,
+ net::AlternateProtocolMap* alternate_protocol_map,
+ const base::Closure& completion) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI,
+ ui_weak_ptr,
+ spdy_server_list,
+ spdy_settings_map,
+ alternate_protocol_map,
+ completion));
+}
+
void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!setting_prefs_)
« no previous file with comments | « chrome/browser/net/http_server_properties_manager.h ('k') | chrome/browser/net/http_server_properties_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698