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

Unified Diff: net/http/http_server_properties_manager.cc

Issue 378823002: Move http_server_properties_manager from chrome/browser/net to net/http. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments. 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: net/http/http_server_properties_manager.cc
diff --git a/chrome/browser/net/http_server_properties_manager.cc b/net/http/http_server_properties_manager.cc
similarity index 79%
rename from chrome/browser/net/http_server_properties_manager.cc
rename to net/http/http_server_properties_manager.cc
index d99af2c82767c90d19089934cc737c739a68c1fc..d7da1fa1b052158402f9a33f69f533e5399b01e7 100644
--- a/chrome/browser/net/http_server_properties_manager.cc
+++ b/net/http/http_server_properties_manager.cc
@@ -2,26 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/net/http_server_properties_manager.h"
+#include "net/http/http_server_properties_manager.h"
#include "base/bind.h"
+#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/prefs/pref_service.h"
#include "base/rand_util.h"
+#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/common/pref_names.h"
-#include "components/pref_registry/pref_registry_syncable.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_source.h"
-using content::BrowserThread;
-
-namespace chrome_browser_net {
+namespace net {
namespace {
@@ -62,30 +56,34 @@ const int kMaxSupportsSpdyServerHostsToPersist = 300;
// HttpServerPropertiesManager
HttpServerPropertiesManager::HttpServerPropertiesManager(
- PrefService* pref_service)
- : pref_service_(pref_service),
- setting_prefs_(false) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ PrefService* pref_service,
+ const char* pref_path,
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
+ : pref_task_runner_(base::MessageLoop::current()->message_loop_proxy()),
Ryan Sleevi 2014/07/08 18:19:26 use ThreadTaskRunnerHandle::Get() (see Chromium-de
mef 2014/07/09 12:12:04 Done.
+ pref_service_(pref_service),
+ setting_prefs_(false),
+ path_(pref_path),
+ io_task_runner_(io_task_runner) {
DCHECK(pref_service);
- ui_weak_ptr_factory_.reset(
+ pref_weak_ptr_factory_.reset(
new base::WeakPtrFactory<HttpServerPropertiesManager>(this));
- ui_weak_ptr_ = ui_weak_ptr_factory_->GetWeakPtr();
- ui_cache_update_timer_.reset(
+ pref_weak_ptr_ = pref_weak_ptr_factory_->GetWeakPtr();
+ pref_cache_update_timer_.reset(
new base::OneShotTimer<HttpServerPropertiesManager>);
pref_change_registrar_.Init(pref_service_);
pref_change_registrar_.Add(
- prefs::kHttpServerProperties,
+ path_,
base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged,
base::Unretained(this)));
}
HttpServerPropertiesManager::~HttpServerPropertiesManager() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
io_weak_ptr_factory_.reset();
}
void HttpServerPropertiesManager::InitializeOnIOThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
io_weak_ptr_factory_.reset(
new base::WeakPtrFactory<HttpServerPropertiesManager>(this));
http_server_properties_impl_.reset(new net::HttpServerPropertiesImpl());
@@ -93,35 +91,26 @@ void HttpServerPropertiesManager::InitializeOnIOThread() {
io_prefs_update_timer_.reset(
new base::OneShotTimer<HttpServerPropertiesManager>);
- BrowserThread::PostTask(
- BrowserThread::UI,
+ pref_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI,
- ui_weak_ptr_));
+ base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnPref,
+ pref_weak_ptr_));
}
-void HttpServerPropertiesManager::ShutdownOnUIThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+void HttpServerPropertiesManager::ShutdownOnPrefThread() {
+ DCHECK(pref_task_runner_->BelongsToCurrentThread());
// Cancel any pending updates, and stop listening for pref change updates.
- ui_cache_update_timer_->Stop();
- ui_weak_ptr_factory_.reset();
+ pref_cache_update_timer_->Stop();
+ pref_weak_ptr_factory_.reset();
pref_change_registrar_.RemoveAll();
}
// static
-void HttpServerPropertiesManager::RegisterProfilePrefs(
- user_prefs::PrefRegistrySyncable* prefs) {
- prefs->RegisterDictionaryPref(
- prefs::kHttpServerProperties,
- user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
-}
-
-// static
void HttpServerPropertiesManager::SetVersion(
base::DictionaryValue* http_server_properties_dict,
int version_number) {
if (version_number < 0)
- version_number = kVersionNumber;
+ version_number = kVersionNumber;
DCHECK_LE(version_number, kVersionNumber);
if (version_number <= kVersionNumber)
http_server_properties_dict->SetInteger("version", version_number);
@@ -129,8 +118,8 @@ void HttpServerPropertiesManager::SetVersion(
// This is required for conformance with the HttpServerProperties interface.
base::WeakPtr<net::HttpServerProperties>
- HttpServerPropertiesManager::GetWeakPtr() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+HttpServerPropertiesManager::GetWeakPtr() {
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
return io_weak_ptr_factory_->GetWeakPtr();
}
@@ -139,7 +128,7 @@ void HttpServerPropertiesManager::Clear() {
}
void HttpServerPropertiesManager::Clear(const base::Closure& completion) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
http_server_properties_impl_->Clear();
UpdatePrefsFromCacheOnIO(completion);
@@ -147,14 +136,14 @@ void HttpServerPropertiesManager::Clear(const base::Closure& completion) {
bool HttpServerPropertiesManager::SupportsSpdy(
const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
return http_server_properties_impl_->SupportsSpdy(server);
}
void HttpServerPropertiesManager::SetSupportsSpdy(
const net::HostPortPair& server,
bool support_spdy) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
http_server_properties_impl_->SetSupportsSpdy(server, support_spdy);
ScheduleUpdatePrefsOnIO();
@@ -162,14 +151,14 @@ void HttpServerPropertiesManager::SetSupportsSpdy(
bool HttpServerPropertiesManager::HasAlternateProtocol(
const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
return http_server_properties_impl_->HasAlternateProtocol(server);
}
net::PortAlternateProtocolPair
HttpServerPropertiesManager::GetAlternateProtocol(
const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
Ryan Sleevi 2014/07/08 18:19:26 All of the BelongsTo will be replaced with "RunsTa
mef 2014/07/09 12:12:04 Done.
return http_server_properties_impl_->GetAlternateProtocol(server);
}
@@ -177,7 +166,7 @@ void HttpServerPropertiesManager::SetAlternateProtocol(
const net::HostPortPair& server,
uint16 alternate_port,
net::AlternateProtocol alternate_protocol) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
http_server_properties_impl_->SetAlternateProtocol(
server, alternate_port, alternate_protocol);
ScheduleUpdatePrefsOnIO();
@@ -185,35 +174,35 @@ void HttpServerPropertiesManager::SetAlternateProtocol(
void HttpServerPropertiesManager::SetBrokenAlternateProtocol(
const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
http_server_properties_impl_->SetBrokenAlternateProtocol(server);
ScheduleUpdatePrefsOnIO();
}
bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken(
const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken(
server);
}
void HttpServerPropertiesManager::ConfirmAlternateProtocol(
const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
http_server_properties_impl_->ConfirmAlternateProtocol(server);
ScheduleUpdatePrefsOnIO();
}
void HttpServerPropertiesManager::ClearAlternateProtocol(
const net::HostPortPair& server) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
http_server_properties_impl_->ClearAlternateProtocol(server);
ScheduleUpdatePrefsOnIO();
}
const net::AlternateProtocolMap&
HttpServerPropertiesManager::alternate_protocol_map() const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
return http_server_properties_impl_->alternate_protocol_map();
}
@@ -227,10 +216,9 @@ HttpServerPropertiesManager::GetAlternateProtocolExperiment() const {
return http_server_properties_impl_->GetAlternateProtocolExperiment();
}
-const net::SettingsMap&
-HttpServerPropertiesManager::GetSpdySettings(
+const net::SettingsMap& HttpServerPropertiesManager::GetSpdySettings(
const net::HostPortPair& host_port_pair) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
return http_server_properties_impl_->GetSpdySettings(host_port_pair);
}
@@ -239,7 +227,7 @@ bool HttpServerPropertiesManager::SetSpdySetting(
net::SpdySettingsIds id,
net::SpdySettingsFlags flags,
uint32 value) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
bool persist = http_server_properties_impl_->SetSpdySetting(
host_port_pair, id, flags, value);
if (persist)
@@ -249,70 +237,72 @@ bool HttpServerPropertiesManager::SetSpdySetting(
void HttpServerPropertiesManager::ClearSpdySettings(
const net::HostPortPair& host_port_pair) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
http_server_properties_impl_->ClearSpdySettings(host_port_pair);
ScheduleUpdatePrefsOnIO();
}
void HttpServerPropertiesManager::ClearAllSpdySettings() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
http_server_properties_impl_->ClearAllSpdySettings();
ScheduleUpdatePrefsOnIO();
}
-const net::SpdySettingsMap&
-HttpServerPropertiesManager::spdy_settings_map() const {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+const net::SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map()
+ const {
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
return http_server_properties_impl_->spdy_settings_map();
}
void HttpServerPropertiesManager::SetServerNetworkStats(
const net::HostPortPair& host_port_pair,
NetworkStats stats) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
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));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
return http_server_properties_impl_->GetServerNetworkStats(host_port_pair);
}
//
// Update the HttpServerPropertiesImpl's cache with data from preferences.
//
-void HttpServerPropertiesManager::ScheduleUpdateCacheOnUI() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+void HttpServerPropertiesManager::ScheduleUpdateCacheOnPref() {
+ DCHECK(pref_task_runner_->BelongsToCurrentThread());
// Cancel pending updates, if any.
- ui_cache_update_timer_->Stop();
- StartCacheUpdateTimerOnUI(
+ pref_cache_update_timer_->Stop();
+ StartCacheUpdateTimerOnPref(
base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs));
}
-void HttpServerPropertiesManager::StartCacheUpdateTimerOnUI(
+void HttpServerPropertiesManager::StartCacheUpdateTimerOnPref(
base::TimeDelta delay) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- ui_cache_update_timer_->Start(
- FROM_HERE, delay, this,
- &HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI);
+ DCHECK(pref_task_runner_->BelongsToCurrentThread());
+ pref_cache_update_timer_->Start(
+ FROM_HERE,
+ delay,
+ this,
+ &HttpServerPropertiesManager::UpdateCacheFromPrefsOnPref);
}
-void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
+void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPref() {
// The preferences can only be read on the UI thread.
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(pref_task_runner_->BelongsToCurrentThread());
- if (!pref_service_->HasPrefPath(prefs::kHttpServerProperties))
+ if (!pref_service_->HasPrefPath(path_))
return;
bool detected_corrupted_prefs = false;
const base::DictionaryValue& http_server_properties_dict =
- *pref_service_->GetDictionary(prefs::kHttpServerProperties);
+ *pref_service_->GetDictionary(path_);
int version = kMissingVersion;
- if (!http_server_properties_dict.GetIntegerWithoutPathExpansion(
- "version", &version)) {
+ if (!http_server_properties_dict.GetIntegerWithoutPathExpansion("version",
+ &version)) {
DVLOG(1) << "Missing version. Clearing all properties.";
return;
}
@@ -321,7 +311,7 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
// http_server_properties_dict["servers"][server].
const base::DictionaryValue* servers_dict = NULL;
if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion(
- "servers", &servers_dict)) {
+ "servers", &servers_dict)) {
DVLOG(1) << "Malformed http_server_properties for servers.";
return;
}
@@ -370,8 +360,8 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
// Get if server supports Spdy.
bool supports_spdy = false;
- if ((server_pref_dict->GetBoolean(
- "supports_spdy", &supports_spdy)) && supports_spdy) {
+ if ((server_pref_dict->GetBoolean("supports_spdy", &supports_spdy)) &&
+ supports_spdy) {
spdy_servers->push_back(server_str);
}
@@ -379,27 +369,27 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end());
const base::DictionaryValue* spdy_settings_dict = NULL;
if (server_pref_dict->GetDictionaryWithoutPathExpansion(
- "settings", &spdy_settings_dict)) {
+ "settings", &spdy_settings_dict)) {
net::SettingsMap settings_map;
for (base::DictionaryValue::Iterator dict_it(*spdy_settings_dict);
- !dict_it.IsAtEnd(); dict_it.Advance()) {
+ !dict_it.IsAtEnd();
+ dict_it.Advance()) {
const std::string& id_str = dict_it.key();
int id = 0;
if (!base::StringToInt(id_str, &id)) {
- DVLOG(1) << "Malformed id in SpdySettings for server: " <<
- server_str;
+ DVLOG(1) << "Malformed id in SpdySettings for server: " << server_str;
NOTREACHED();
continue;
}
int value = 0;
if (!dict_it.value().GetAsInteger(&value)) {
- DVLOG(1) << "Malformed value in SpdySettings for server: " <<
- server_str;
+ DVLOG(1) << "Malformed value in SpdySettings for server: "
+ << server_str;
NOTREACHED();
continue;
}
- net::SettingsFlagsAndValue flags_and_value(
- net::SETTINGS_FLAG_PERSISTED, value);
+ net::SettingsFlagsAndValue flags_and_value(net::SETTINGS_FLAG_PERSISTED,
+ value);
settings_map[static_cast<net::SpdySettingsIds>(id)] = flags_and_value;
}
spdy_settings_map->Put(server, settings_map);
@@ -410,7 +400,7 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
alternate_protocol_map->end());
const base::DictionaryValue* port_alternate_protocol_dict = NULL;
if (!server_pref_dict->GetDictionaryWithoutPathExpansion(
- "alternate_protocol", &port_alternate_protocol_dict)) {
+ "alternate_protocol", &port_alternate_protocol_dict)) {
continue;
}
@@ -419,7 +409,8 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
do {
int port = 0;
if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion(
- "port", &port) || (port > (1 << 16))) {
+ "port", &port) ||
+ (port > (1 << 16))) {
DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
detected_corrupted_prefs = true;
continue;
@@ -448,11 +439,9 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI() {
} while (false);
}
- BrowserThread::PostTask(
- BrowserThread::IO,
+ io_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&HttpServerPropertiesManager::
- UpdateCacheFromPrefsOnIO,
+ base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO,
base::Unretained(this),
base::Owned(spdy_servers.release()),
base::Owned(spdy_settings_map.release()),
@@ -469,7 +458,7 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO(
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));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size());
http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true);
@@ -493,12 +482,11 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnIO(
ScheduleUpdatePrefsOnIO();
}
-
//
// Update Preferences with data from the cached data.
//
void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
// Cancel pending updates, if any.
io_prefs_update_timer_->Stop();
StartPrefsUpdateTimerOnIO(
@@ -507,10 +495,12 @@ void HttpServerPropertiesManager::ScheduleUpdatePrefsOnIO() {
void HttpServerPropertiesManager::StartPrefsUpdateTimerOnIO(
base::TimeDelta delay) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
// This is overridden in tests to post the task without the delay.
io_prefs_update_timer_->Start(
- FROM_HERE, delay, this,
+ FROM_HERE,
+ delay,
+ this,
&HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO);
}
@@ -521,7 +511,7 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO() {
void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(
const base::Closure& completion) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(io_task_runner_->BelongsToCurrentThread());
base::ListValue* spdy_server_list = new base::ListValue;
http_server_properties_impl_->GetSpdyServerList(
@@ -561,11 +551,10 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(
}
// Update the preferences on the UI thread.
- BrowserThread::PostTask(
- BrowserThread::UI,
+ pref_task_runner_->PostTask(
FROM_HERE,
- base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnUI,
- ui_weak_ptr_,
+ base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnPref,
+ pref_weak_ptr_,
base::Owned(spdy_server_list),
base::Owned(spdy_settings_map),
base::Owned(alternate_protocol_map),
@@ -577,37 +566,33 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(
// UpdatePrefsOnUI.
struct ServerPref {
ServerPref()
- : supports_spdy(false),
- settings_map(NULL),
- alternate_protocol(NULL) {
- }
+ : supports_spdy(false), settings_map(NULL), alternate_protocol(NULL) {}
ServerPref(bool supports_spdy,
const net::SettingsMap* settings_map,
const net::PortAlternateProtocolPair* alternate_protocol)
: supports_spdy(supports_spdy),
settings_map(settings_map),
- alternate_protocol(alternate_protocol) {
- }
+ alternate_protocol(alternate_protocol) {}
bool supports_spdy;
const net::SettingsMap* settings_map;
const net::PortAlternateProtocolPair* alternate_protocol;
};
-void HttpServerPropertiesManager::UpdatePrefsOnUI(
+void HttpServerPropertiesManager::UpdatePrefsOnPref(
base::ListValue* spdy_server_list,
net::SpdySettingsMap* spdy_settings_map,
net::AlternateProtocolMap* alternate_protocol_map,
const base::Closure& completion) {
-
typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap;
ServerPrefMap server_pref_map;
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(pref_task_runner_->BelongsToCurrentThread());
// Add servers that support spdy to server_pref_map.
std::string s;
for (base::ListValue::const_iterator list_it = spdy_server_list->begin();
- list_it != spdy_server_list->end(); ++list_it) {
+ list_it != spdy_server_list->end();
+ ++list_it) {
if ((*list_it)->GetAsString(&s)) {
net::HostPortPair server = net::HostPortPair::FromString(s);
@@ -623,7 +608,8 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI(
// Add servers that have SpdySettings to server_pref_map.
for (net::SpdySettingsMap::iterator map_it = spdy_settings_map->begin();
- map_it != spdy_settings_map->end(); ++map_it) {
+ map_it != spdy_settings_map->end();
+ ++map_it) {
const net::HostPortPair& server = map_it->first;
ServerPrefMap::iterator it = server_pref_map.find(server);
@@ -638,7 +624,8 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI(
// Add AlternateProtocol servers to server_pref_map.
for (net::AlternateProtocolMap::const_iterator map_it =
alternate_protocol_map->begin();
- map_it != alternate_protocol_map->end(); ++map_it) {
+ map_it != alternate_protocol_map->end();
+ ++map_it) {
const net::HostPortPair& server = map_it->first;
const net::PortAlternateProtocolPair& port_alternate_protocol =
map_it->second;
@@ -655,12 +642,12 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI(
}
}
- // Persist the prefs::kHttpServerProperties.
+ // Persist properties to the |path_|.
base::DictionaryValue http_server_properties_dict;
base::DictionaryValue* servers_dict = new base::DictionaryValue;
- for (ServerPrefMap::const_iterator map_it =
- server_pref_map.begin();
- map_it != server_pref_map.end(); ++map_it) {
+ for (ServerPrefMap::const_iterator map_it = server_pref_map.begin();
+ map_it != server_pref_map.end();
+ ++map_it) {
const net::HostPortPair& server = map_it->first;
const ServerPref& server_pref = map_it->second;
@@ -674,8 +661,9 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI(
if (server_pref.settings_map) {
base::DictionaryValue* spdy_settings_dict = new base::DictionaryValue;
for (net::SettingsMap::const_iterator it =
- server_pref.settings_map->begin();
- it != server_pref.settings_map->end(); ++it) {
+ server_pref.settings_map->begin();
+ it != server_pref.settings_map->end();
+ ++it) {
net::SpdySettingsIds id = it->first;
uint32 value = it->second.second;
std::string key = base::StringPrintf("%u", id);
@@ -690,13 +678,13 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI(
new base::DictionaryValue;
const net::PortAlternateProtocolPair* port_alternate_protocol =
server_pref.alternate_protocol;
- port_alternate_protocol_dict->SetInteger(
- "port", port_alternate_protocol->port);
+ port_alternate_protocol_dict->SetInteger("port",
+ port_alternate_protocol->port);
const char* protocol_str =
net::AlternateProtocolToString(port_alternate_protocol->protocol);
port_alternate_protocol_dict->SetString("protocol_str", protocol_str);
- server_pref_dict->SetWithoutPathExpansion(
- "alternate_protocol", port_alternate_protocol_dict);
+ server_pref_dict->SetWithoutPathExpansion("alternate_protocol",
+ port_alternate_protocol_dict);
}
servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict);
@@ -705,8 +693,7 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI(
http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict);
SetVersion(&http_server_properties_dict, kVersionNumber);
setting_prefs_ = true;
- pref_service_->Set(prefs::kHttpServerProperties,
- http_server_properties_dict);
+ pref_service_->Set(path_, http_server_properties_dict);
setting_prefs_ = false;
// Note that |completion| will be fired after we have written everything to
@@ -718,9 +705,9 @@ void HttpServerPropertiesManager::UpdatePrefsOnUI(
}
void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(pref_task_runner_->BelongsToCurrentThread());
if (!setting_prefs_)
- ScheduleUpdateCacheOnUI();
+ ScheduleUpdateCacheOnPref();
}
} // namespace chrome_browser_net

Powered by Google App Engine
This is Rietveld 408576698