summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/net/http_server_properties_manager_factory.cc49
-rw-r--r--components/cronet/android/cronet_url_request_context_adapter.cc45
-rw-r--r--ios/chrome/browser/net/http_server_properties_manager_factory.cc45
-rw-r--r--net/http/http_server_properties_manager.cc25
-rw-r--r--net/http/http_server_properties_manager.h40
-rw-r--r--net/http/http_server_properties_manager_unittest.cc161
6 files changed, 263 insertions, 102 deletions
diff --git a/chrome/browser/net/http_server_properties_manager_factory.cc b/chrome/browser/net/http_server_properties_manager_factory.cc
index ecd09e1..5c566d7 100644
--- a/chrome/browser/net/http_server_properties_manager_factory.cc
+++ b/chrome/browser/net/http_server_properties_manager_factory.cc
@@ -4,11 +4,57 @@
#include "chrome/browser/net/http_server_properties_manager_factory.h"
+#include "base/prefs/pref_change_registrar.h"
+#include "base/prefs/pref_service.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "net/http/http_server_properties_manager.h"
+namespace {
+
+// Connects the HttpServerPropertiesManager's storage to the Chrome prefs.
+class PrefServiceAdapter
+ : public net::HttpServerPropertiesManager::PrefDelegate {
+ public:
+ explicit PrefServiceAdapter(PrefService* pref_service)
+ : pref_service_(pref_service),
+ path_(prefs::kHttpServerProperties) {
+ pref_change_registrar_.Init(pref_service_);
+ }
+
+ ~PrefServiceAdapter() override {
+ }
+
+ // PrefDelegate implementation.
+ bool HasServerProperties() override {
+ return pref_service_->HasPrefPath(path_);
+ }
+ const base::DictionaryValue& GetServerProperties() const override {
+ // Guaranteed not to return null when the pref is registered
+ // (RegisterProfilePrefs was called).
+ return *pref_service_->GetDictionary(path_);
+ }
+ void SetServerProperties(const base::DictionaryValue& value) override {
+ return pref_service_->Set(path_, value);
+ }
+ void StartListeningForUpdates(const base::Closure& callback) override {
+ pref_change_registrar_.Add(path_, callback);
+ }
+ void StopListeningForUpdates() override {
+ pref_change_registrar_.RemoveAll();
+ }
+
+ private:
+ PrefService* pref_service_;
+ const std::string path_;
+ PrefChangeRegistrar pref_change_registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefServiceAdapter);
+};
+
+} // namespace
+
namespace chrome_browser_net {
/* static */
@@ -16,8 +62,7 @@ net::HttpServerPropertiesManager*
HttpServerPropertiesManagerFactory::CreateManager(PrefService* pref_service) {
using content::BrowserThread;
return new net::HttpServerPropertiesManager(
- pref_service,
- prefs::kHttpServerProperties,
+ new PrefServiceAdapter(pref_service), // Transfers ownership.
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
}
diff --git a/components/cronet/android/cronet_url_request_context_adapter.cc b/components/cronet/android/cronet_url_request_context_adapter.cc
index d6106af..ef1fde0 100644
--- a/components/cronet/android/cronet_url_request_context_adapter.cc
+++ b/components/cronet/android/cronet_url_request_context_adapter.cc
@@ -21,6 +21,7 @@
#include "base/memory/scoped_vector.h"
#include "base/message_loop/message_loop.h"
#include "base/metrics/statistics_recorder.h"
+#include "base/prefs/pref_change_registrar.h"
#include "base/prefs/pref_filter.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
@@ -55,6 +56,44 @@ namespace {
const char kHttpServerProperties[] = "net.http_server_properties";
+// Connects the HttpServerPropertiesManager's storage to the prefs.
+class PrefServiceAdapter
+ : public net::HttpServerPropertiesManager::PrefDelegate {
+ public:
+ explicit PrefServiceAdapter(PrefService* pref_service)
+ : pref_service_(pref_service), path_(kHttpServerProperties) {
+ pref_change_registrar_.Init(pref_service_);
+ }
+
+ ~PrefServiceAdapter() override {}
+
+ // PrefDelegate implementation.
+ bool HasServerProperties() override {
+ return pref_service_->HasPrefPath(path_);
+ }
+ const base::DictionaryValue& GetServerProperties() const override {
+ // Guaranteed not to return null when the pref is registered
+ // (RegisterProfilePrefs was called).
+ return *pref_service_->GetDictionary(path_);
+ }
+ void SetServerProperties(const base::DictionaryValue& value) override {
+ return pref_service_->Set(path_, value);
+ }
+ void StartListeningForUpdates(const base::Closure& callback) override {
+ pref_change_registrar_.Add(path_, callback);
+ }
+ void StopListeningForUpdates() override {
+ pref_change_registrar_.RemoveAll();
+ }
+
+ private:
+ PrefService* pref_service_;
+ std::string path_;
+ PrefChangeRegistrar pref_change_registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefServiceAdapter);
+};
+
class BasicNetworkDelegate : public net::NetworkDelegateImpl {
public:
BasicNetworkDelegate() {}
@@ -313,9 +352,9 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
pref_service_ = factory.Create(registry.get());
scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager(
- new net::HttpServerPropertiesManager(pref_service_.get(),
- kHttpServerProperties,
- GetNetworkTaskRunner()));
+ new net::HttpServerPropertiesManager(
+ new PrefServiceAdapter(pref_service_.get()),
+ GetNetworkTaskRunner()));
http_server_properties_manager->InitializeOnNetworkThread();
http_server_properties_manager_ = http_server_properties_manager.get();
context_builder.SetHttpServerProperties(
diff --git a/ios/chrome/browser/net/http_server_properties_manager_factory.cc b/ios/chrome/browser/net/http_server_properties_manager_factory.cc
index bf827e3..59263a3 100644
--- a/ios/chrome/browser/net/http_server_properties_manager_factory.cc
+++ b/ios/chrome/browser/net/http_server_properties_manager_factory.cc
@@ -4,16 +4,59 @@
#include "ios/chrome/browser/net/http_server_properties_manager_factory.h"
+#include "base/prefs/pref_change_registrar.h"
+#include "base/prefs/pref_service.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "ios/chrome/browser/pref_names.h"
#include "ios/web/public/web_thread.h"
#include "net/http/http_server_properties_manager.h"
+namespace {
+
+class PrefServiceAdapter
+ : public net::HttpServerPropertiesManager::PrefDelegate {
+ public:
+ explicit PrefServiceAdapter(PrefService* pref_service)
+ : pref_service_(pref_service), path_(prefs::kHttpServerProperties) {
+ pref_change_registrar_.Init(pref_service_);
+ }
+
+ ~PrefServiceAdapter() override {}
+
+ // PrefDelegate implementation.
+ bool HasServerProperties() override {
+ return pref_service_->HasPrefPath(path_);
+ }
+ const base::DictionaryValue& GetServerProperties() const override {
+ // Guaranteed not to return null when the pref is registered
+ // (RegisterProfilePrefs was called).
+ return *pref_service_->GetDictionary(path_);
+ }
+ void SetServerProperties(const base::DictionaryValue& value) override {
+ return pref_service_->Set(path_, value);
+ }
+ void StartListeningForUpdates(const base::Closure& callback) override {
+ pref_change_registrar_.Add(path_, callback);
+ }
+ void StopListeningForUpdates() override {
+ pref_change_registrar_.RemoveAll();
+ }
+
+ private:
+ PrefService* pref_service_;
+ const std::string path_;
+ PrefChangeRegistrar pref_change_registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefServiceAdapter);
+};
+
+} // namespace
+
// static
net::HttpServerPropertiesManager*
HttpServerPropertiesManagerFactory::CreateManager(PrefService* pref_service) {
return new net::HttpServerPropertiesManager(
- pref_service, prefs::kHttpServerProperties,
+ new PrefServiceAdapter(pref_service), // Transfers ownership.
web::WebThread::GetTaskRunnerForThread(web::WebThread::IO));
}
diff --git a/net/http/http_server_properties_manager.cc b/net/http/http_server_properties_manager.cc
index f7493ff..79ed491 100644
--- a/net/http/http_server_properties_manager.cc
+++ b/net/http/http_server_properties_manager.cc
@@ -6,7 +6,6 @@
#include "base/bind.h"
#include "base/metrics/histogram_macros.h"
-#include "base/prefs/pref_service.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
@@ -72,23 +71,21 @@ const char kSrttKey[] = "srtt";
////////////////////////////////////////////////////////////////////////////////
// HttpServerPropertiesManager
+HttpServerPropertiesManager::PrefDelegate::~PrefDelegate() {}
+
HttpServerPropertiesManager::HttpServerPropertiesManager(
- PrefService* pref_service,
- const char* pref_path,
+ PrefDelegate* pref_delegate,
scoped_refptr<base::SequencedTaskRunner> network_task_runner)
: pref_task_runner_(base::ThreadTaskRunnerHandle::Get()),
- pref_service_(pref_service),
+ pref_delegate_(pref_delegate),
setting_prefs_(false),
- path_(pref_path),
network_task_runner_(network_task_runner) {
- DCHECK(pref_service);
+ DCHECK(pref_delegate_);
pref_weak_ptr_factory_.reset(
new base::WeakPtrFactory<HttpServerPropertiesManager>(this));
pref_weak_ptr_ = pref_weak_ptr_factory_->GetWeakPtr();
pref_cache_update_timer_.reset(new base::OneShotTimer);
- pref_change_registrar_.Init(pref_service_);
- pref_change_registrar_.Add(
- path_,
+ pref_delegate_->StartListeningForUpdates(
base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged,
base::Unretained(this)));
}
@@ -117,7 +114,7 @@ void HttpServerPropertiesManager::ShutdownOnPrefThread() {
// Cancel any pending updates, and stop listening for pref change updates.
pref_cache_update_timer_->Stop();
pref_weak_ptr_factory_.reset();
- pref_change_registrar_.RemoveAll();
+ pref_delegate_->StopListeningForUpdates();
}
// static
@@ -445,12 +442,12 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() {
// The preferences can only be read on the pref thread.
DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
- if (!pref_service_->HasPrefPath(path_))
+ if (!pref_delegate_->HasServerProperties())
return;
bool detected_corrupted_prefs = false;
const base::DictionaryValue& http_server_properties_dict =
- *pref_service_->GetDictionary(path_);
+ pref_delegate_->GetServerProperties();
int version = kMissingVersion;
if (!http_server_properties_dict.GetIntegerWithoutPathExpansion(kVersionKey,
@@ -1117,7 +1114,7 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
}
}
- // Persist properties to the |path_| in the MRU order.
+ // Persist properties to the prefs in the MRU order.
base::DictionaryValue http_server_properties_dict;
base::ListValue* servers_list = new base::ListValue;
for (ServerPrefMap::const_reverse_iterator map_it = server_pref_map.rbegin();
@@ -1152,7 +1149,7 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
&http_server_properties_dict);
setting_prefs_ = true;
- pref_service_->Set(path_, http_server_properties_dict);
+ pref_delegate_->SetServerProperties(http_server_properties_dict);
setting_prefs_ = false;
// Note that |completion| will be fired after we have written everything to
diff --git a/net/http/http_server_properties_manager.h b/net/http/http_server_properties_manager.h
index b08ae16..39f6ec5 100644
--- a/net/http/http_server_properties_manager.h
+++ b/net/http/http_server_properties_manager.h
@@ -15,7 +15,6 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "base/prefs/pref_change_registrar.h"
#include "base/timer/timer.h"
#include "base/values.h"
#include "net/base/host_port_pair.h"
@@ -54,12 +53,36 @@ namespace net {
// and grab a WeakPtr.
class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties {
public:
- // Create an instance of the HttpServerPropertiesManager. The lifetime of the
- // PrefService objects must be longer than that of the
- // HttpServerPropertiesManager object. Must be constructed on the Pref thread.
+ // Provides an interface to interface with persistent preferences storage
+ // implemented by the embedder.
+ class NET_EXPORT PrefDelegate {
+ public:
+ virtual ~PrefDelegate();
+
+ // Returns true if the pref system has data for the server properties.
+ virtual bool HasServerProperties() = 0;
+
+ // Returns the branch of the preferences system for the server properties.
+ virtual const base::DictionaryValue& GetServerProperties() const = 0;
+
+ // Sets the server properties to the given value.
+ virtual void SetServerProperties(const base::DictionaryValue& value) = 0;
+
+ // Start and stop listening for external storage changes. There will only
+ // be one callback active at a time.
+ virtual void StartListeningForUpdates(const base::Closure& callback) = 0;
+ virtual void StopListeningForUpdates() = 0;
+ };
+
+ // Create an instance of the HttpServerPropertiesManager.
+ //
+ // Ownership of the PrefDelegate pointer is taken by this class. This is
+ // passed as a raw pointer rather than a scoped_refptr currently because
+ // the test uses gmock and it doesn't forward move semantics properly.
+ //
+ // Must be constructed on the Pref thread.
HttpServerPropertiesManager(
- PrefService* pref_service,
- const char* pref_path,
+ PrefDelegate* pref_delegate,
scoped_refptr<base::SequencedTaskRunner> network_task_runner);
~HttpServerPropertiesManager() override;
@@ -277,11 +300,8 @@ class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties {
// Used to post cache update tasks.
scoped_ptr<base::OneShotTimer> pref_cache_update_timer_;
- // Used to track the spdy servers changes.
- PrefChangeRegistrar pref_change_registrar_;
- PrefService* pref_service_; // Weak.
+ scoped_ptr<PrefDelegate> pref_delegate_;
bool setting_prefs_;
- const char* path_;
// --------------
// Network thread
diff --git a/net/http/http_server_properties_manager_unittest.cc b/net/http/http_server_properties_manager_unittest.cc
index 49d19db..87ddbfa 100644
--- a/net/http/http_server_properties_manager_unittest.cc
+++ b/net/http/http_server_properties_manager_unittest.cc
@@ -8,8 +8,6 @@
#include "base/json/json_writer.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
-#include "base/prefs/pref_registry_simple.h"
-#include "base/prefs/testing_pref_service.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
@@ -32,15 +30,52 @@ using ::testing::Invoke;
using ::testing::Mock;
using ::testing::StrictMock;
-const char kTestHttpServerProperties[] = "TestHttpServerProperties";
+class MockPrefDelegate : public net::HttpServerPropertiesManager::PrefDelegate {
+ public:
+ MockPrefDelegate() {}
+ ~MockPrefDelegate() override {}
+
+ // HttpServerPropertiesManager::PrefDelegate implementation.
+ bool HasServerProperties() override { return true; }
+ const base::DictionaryValue& GetServerProperties() const override {
+ return prefs_;
+ }
+ void SetServerProperties(const base::DictionaryValue& value) override {
+ prefs_.Clear();
+ prefs_.MergeDictionary(&value);
+ if (!prefs_changed_callback_.is_null())
+ prefs_changed_callback_.Run();
+ }
+ void StartListeningForUpdates(const base::Closure& callback) override {
+ CHECK(prefs_changed_callback_.is_null());
+ prefs_changed_callback_ = callback;
+ }
+ void StopListeningForUpdates() override {
+ CHECK(!prefs_changed_callback_.is_null());
+ prefs_changed_callback_ = base::Closure();
+ }
+
+ void SetPrefs(const base::DictionaryValue& value) {
+ // prefs_ = value;
+ prefs_.Clear();
+ prefs_.MergeDictionary(&value);
+ if (!prefs_changed_callback_.is_null())
+ prefs_changed_callback_.Run();
+ }
+
+ private:
+ base::DictionaryValue prefs_;
+ base::Closure prefs_changed_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockPrefDelegate);
+};
class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager {
public:
TestingHttpServerPropertiesManager(
- PrefService* pref_service,
- const char* pref_path,
+ HttpServerPropertiesManager::PrefDelegate* pref_delegate,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
- : HttpServerPropertiesManager(pref_service, pref_path, io_task_runner) {
+ : HttpServerPropertiesManager(pref_delegate, io_task_runner) {
InitializeOnNetworkThread();
}
@@ -116,11 +151,10 @@ class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> {
void SetUp() override {
one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1);
- pref_service_.registry()->RegisterDictionaryPref(kTestHttpServerProperties);
+ pref_delegate_ = new MockPrefDelegate;
http_server_props_manager_.reset(
new StrictMock<TestingHttpServerPropertiesManager>(
- &pref_service_, kTestHttpServerProperties,
- base::ThreadTaskRunnerHandle::Get()));
+ pref_delegate_, base::ThreadTaskRunnerHandle::Get()));
ExpectCacheUpdate();
base::RunLoop().RunUntilIdle();
}
@@ -178,8 +212,7 @@ class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> {
return !alternative_service_vector.empty();
}
- //base::RunLoop loop_;
- TestingPrefServiceSimple pref_service_;
+ MockPrefDelegate* pref_delegate_; // Owned by HttpServerPropertiesManager.
scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_;
base::Time one_day_from_now_;
@@ -256,25 +289,24 @@ TEST_P(HttpServerPropertiesManagerTest,
// Set the server preference for mail.google.com:80.
servers_dict->SetWithoutPathExpansion("mail.google.com:80",
server_pref_dict1);
- base::DictionaryValue* http_server_properties_dict =
- new base::DictionaryValue;
+ base::DictionaryValue http_server_properties_dict;
if (GetParam() == 4) {
// |servers_list| takes ownership of |servers_dict|.
servers_list->AppendIfNotPresent(servers_dict);
- HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
- http_server_properties_dict->SetWithoutPathExpansion("servers",
- servers_list);
+ HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1);
+ http_server_properties_dict.SetWithoutPathExpansion("servers",
+ servers_list);
} else {
- HttpServerPropertiesManager::SetVersion(http_server_properties_dict,
+ HttpServerPropertiesManager::SetVersion(&http_server_properties_dict,
GetParam());
- http_server_properties_dict->SetWithoutPathExpansion("servers",
- servers_dict);
+ http_server_properties_dict.SetWithoutPathExpansion("servers",
+ servers_dict);
}
base::DictionaryValue* supports_quic = new base::DictionaryValue;
supports_quic->SetBoolean("used_quic", true);
supports_quic->SetString("address", "127.0.0.1");
- http_server_properties_dict->SetWithoutPathExpansion("supports_quic",
- supports_quic);
+ http_server_properties_dict.SetWithoutPathExpansion("supports_quic",
+ supports_quic);
// Set quic_server_info for www.google.com:80, mail.google.com:80 and
// play.google.com:80 and verify the MRU.
@@ -304,16 +336,12 @@ TEST_P(HttpServerPropertiesManagerTest,
QuicServerId play_quic_server_id("play.google.com", 80);
quic_servers_dict->SetWithoutPathExpansion(play_quic_server_id.ToString(),
quic_server_pref_dict3);
- http_server_properties_dict->SetWithoutPathExpansion("quic_servers",
- quic_servers_dict);
+ http_server_properties_dict.SetWithoutPathExpansion("quic_servers",
+ quic_servers_dict);
// Set the same value for kHttpServerProperties multiple times.
- pref_service_.SetManagedPref(kTestHttpServerProperties,
- http_server_properties_dict);
- base::DictionaryValue* http_server_properties_dict2 =
- http_server_properties_dict->DeepCopy();
- pref_service_.SetManagedPref(kTestHttpServerProperties,
- http_server_properties_dict2);
+ pref_delegate_->SetPrefs(http_server_properties_dict);
+ pref_delegate_->SetPrefs(http_server_properties_dict);
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
@@ -427,20 +455,19 @@ TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
base::DictionaryValue* servers_dict = new base::DictionaryValue;
servers_dict->SetWithoutPathExpansion("www.google.com:65536",
server_pref_dict);
- base::DictionaryValue* http_server_properties_dict =
- new base::DictionaryValue;
+ base::DictionaryValue http_server_properties_dict;
if (GetParam() == 4) {
base::ListValue* servers_list = new base::ListValue;
// |servers_list| takes ownership of |servers_dict|.
servers_list->AppendIfNotPresent(servers_dict);
- HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
- http_server_properties_dict->SetWithoutPathExpansion("servers",
- servers_list);
+ HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1);
+ http_server_properties_dict.SetWithoutPathExpansion("servers",
+ servers_list);
} else {
- HttpServerPropertiesManager::SetVersion(http_server_properties_dict,
+ HttpServerPropertiesManager::SetVersion(&http_server_properties_dict,
GetParam());
- http_server_properties_dict->SetWithoutPathExpansion("servers",
- servers_dict);
+ http_server_properties_dict.SetWithoutPathExpansion("servers",
+ servers_dict);
}
// Set quic_server_info for www.google.com:65536.
@@ -451,12 +478,11 @@ TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
quic_servers_dict->SetWithoutPathExpansion("http://mail.google.com:65536",
quic_server_pref_dict1);
- http_server_properties_dict->SetWithoutPathExpansion("quic_servers",
- quic_servers_dict);
+ http_server_properties_dict.SetWithoutPathExpansion("quic_servers",
+ quic_servers_dict);
// Set up the pref.
- pref_service_.SetManagedPref(kTestHttpServerProperties,
- http_server_properties_dict);
+ pref_delegate_->SetPrefs(http_server_properties_dict);
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
@@ -496,25 +522,23 @@ TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
// Set the server preference for www.google.com:80.
base::DictionaryValue* servers_dict = new base::DictionaryValue;
servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict);
- base::DictionaryValue* http_server_properties_dict =
- new base::DictionaryValue;
+ base::DictionaryValue http_server_properties_dict;
if (GetParam() == 4) {
base::ListValue* servers_list = new base::ListValue;
// |servers_list| takes ownership of |servers_dict|.
servers_list->AppendIfNotPresent(servers_dict);
- HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
- http_server_properties_dict->SetWithoutPathExpansion("servers",
- servers_list);
+ HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1);
+ http_server_properties_dict.SetWithoutPathExpansion("servers",
+ servers_list);
} else {
- HttpServerPropertiesManager::SetVersion(http_server_properties_dict,
+ HttpServerPropertiesManager::SetVersion(&http_server_properties_dict,
GetParam());
- http_server_properties_dict->SetWithoutPathExpansion("servers",
- servers_dict);
+ http_server_properties_dict.SetWithoutPathExpansion("servers",
+ servers_dict);
}
// Set up the pref.
- pref_service_.SetManagedPref(kTestHttpServerProperties,
- http_server_properties_dict);
+ pref_delegate_->SetPrefs(http_server_properties_dict);
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
@@ -970,31 +994,29 @@ TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) {
// Set the server preference for mail.google.com:80.
servers_dict->SetWithoutPathExpansion("mail.google.com:80",
server_pref_dict1);
- base::DictionaryValue* http_server_properties_dict =
- new base::DictionaryValue;
+ base::DictionaryValue http_server_properties_dict;
if (GetParam() == 4) {
// |servers_list| takes ownership of |servers_dict|.
servers_list->AppendIfNotPresent(servers_dict);
- HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
- http_server_properties_dict->SetWithoutPathExpansion("servers",
- servers_list);
+ HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1);
+ http_server_properties_dict.SetWithoutPathExpansion("servers",
+ servers_list);
} else {
- HttpServerPropertiesManager::SetVersion(http_server_properties_dict,
+ HttpServerPropertiesManager::SetVersion(&http_server_properties_dict,
GetParam());
- http_server_properties_dict->SetWithoutPathExpansion("servers",
- servers_dict);
+ http_server_properties_dict.SetWithoutPathExpansion("servers",
+ servers_dict);
}
// Set up SupportsQuic for 127.0.0.1
base::DictionaryValue* supports_quic = new base::DictionaryValue;
supports_quic->SetBoolean("used_quic", true);
supports_quic->SetString("address", "127.0.0.1");
- http_server_properties_dict->SetWithoutPathExpansion("supports_quic",
- supports_quic);
+ http_server_properties_dict.SetWithoutPathExpansion("supports_quic",
+ supports_quic);
// Set up the pref.
- pref_service_.SetManagedPref(kTestHttpServerProperties,
- http_server_properties_dict);
+ pref_delegate_->SetPrefs(http_server_properties_dict);
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
@@ -1085,8 +1107,7 @@ TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
"\"version\":4}";
const base::Value* http_server_properties =
- pref_service_.GetUserPref(kTestHttpServerProperties);
- ASSERT_NE(nullptr, http_server_properties);
+ &pref_delegate_->GetServerProperties();
std::string preferences_json;
EXPECT_TRUE(
base::JSONWriter::Write(*http_server_properties, &preferences_json));
@@ -1185,15 +1206,11 @@ TEST_P(HttpServerPropertiesManagerTest,
http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
base::RunLoop().RunUntilIdle();
- const base::Value* pref_value =
- pref_service_.GetUserPref(kTestHttpServerProperties);
- ASSERT_NE(nullptr, pref_value);
-
- const base::DictionaryValue* pref_dict;
- ASSERT_TRUE(pref_value->GetAsDictionary(&pref_dict));
+ const base::DictionaryValue& pref_dict =
+ pref_delegate_->GetServerProperties();
const base::ListValue* servers_list = nullptr;
- ASSERT_TRUE(pref_dict->GetListWithoutPathExpansion("servers", &servers_list));
+ ASSERT_TRUE(pref_dict.GetListWithoutPathExpansion("servers", &servers_list));
base::ListValue::const_iterator it = servers_list->begin();
const base::DictionaryValue* server_pref_dict;
ASSERT_TRUE((*it)->GetAsDictionary(&server_pref_dict));