summaryrefslogtreecommitdiffstats
path: root/base/prefs
diff options
context:
space:
mode:
authorrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-11 16:46:36 +0000
committerrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-11 16:46:36 +0000
commitcadac62e5c2b9f5fef59ce0326bb2cd79ffbe622 (patch)
tree7b95f103fce509de887c8c5e643604855b57c0ba /base/prefs
parent9f6e673c7f43f6ee414f72a74585dad8ebaceec3 (diff)
downloadchromium_src-cadac62e5c2b9f5fef59ce0326bb2cd79ffbe622.zip
chromium_src-cadac62e5c2b9f5fef59ce0326bb2cd79ffbe622.tar.gz
chromium_src-cadac62e5c2b9f5fef59ce0326bb2cd79ffbe622.tar.bz2
Call scoped_refptr<T>::get() rather than relying on implicit "operator T*"
This upates calls to bound temporary objects to also use get(). While it has the same semantic equivalence to the existing code, this generally represents a dangerous pattern - indeed, part of the whole motivation for this change is to make this anti-pattern very visible to authors. This change simply updates all of the call sites, to allow the "operator T*" to be removed and preventing new instances. The existing instances will then be reviewed for "suspicious" changes and updated to use/pass scoped_refptr<T> rather than T*, as appropriate. BUG=110610 TBR=darin Review URL: https://codereview.chromium.org/15984016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205560 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/prefs')
-rw-r--r--base/prefs/json_pref_store_unittest.cc22
-rw-r--r--base/prefs/pref_service_builder.cc27
-rw-r--r--base/prefs/testing_pref_service.cc34
-rw-r--r--base/prefs/testing_pref_service.h4
4 files changed, 39 insertions, 48 deletions
diff --git a/base/prefs/json_pref_store_unittest.cc b/base/prefs/json_pref_store_unittest.cc
index 72b9ba4..63b9e02 100644
--- a/base/prefs/json_pref_store_unittest.cc
+++ b/base/prefs/json_pref_store_unittest.cc
@@ -59,9 +59,8 @@ class JsonPrefStoreTest : public testing::Test {
TEST_F(JsonPrefStoreTest, NonExistentFile) {
base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
ASSERT_FALSE(file_util::PathExists(bogus_input_file));
- scoped_refptr<JsonPrefStore> pref_store =
- new JsonPrefStore(
- bogus_input_file, message_loop_.message_loop_proxy());
+ scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
+ bogus_input_file, message_loop_.message_loop_proxy().get());
EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE,
pref_store->ReadPrefs());
EXPECT_FALSE(pref_store->ReadOnly());
@@ -73,8 +72,7 @@ TEST_F(JsonPrefStoreTest, InvalidFile) {
base::FilePath invalid_file = temp_dir_.path().AppendASCII("invalid.json");
ASSERT_TRUE(file_util::CopyFile(invalid_file_original, invalid_file));
scoped_refptr<JsonPrefStore> pref_store =
- new JsonPrefStore(
- invalid_file, message_loop_.message_loop_proxy());
+ new JsonPrefStore(invalid_file, message_loop_.message_loop_proxy().get());
EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE,
pref_store->ReadPrefs());
EXPECT_FALSE(pref_store->ReadOnly());
@@ -161,8 +159,7 @@ TEST_F(JsonPrefStoreTest, Basic) {
base::FilePath input_file = temp_dir_.path().AppendASCII("write.json");
ASSERT_TRUE(file_util::PathExists(input_file));
scoped_refptr<JsonPrefStore> pref_store =
- new JsonPrefStore(
- input_file, message_loop_.message_loop_proxy());
+ new JsonPrefStore(input_file, message_loop_.message_loop_proxy().get());
ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs());
ASSERT_FALSE(pref_store->ReadOnly());
@@ -188,8 +185,7 @@ TEST_F(JsonPrefStoreTest, BasicAsync) {
base::FilePath input_file = temp_dir_.path().AppendASCII("write.json");
ASSERT_TRUE(file_util::PathExists(input_file));
scoped_refptr<JsonPrefStore> pref_store =
- new JsonPrefStore(
- input_file, message_loop_.message_loop_proxy());
+ new JsonPrefStore(input_file, message_loop_.message_loop_proxy().get());
{
MockPrefStoreObserver mock_observer;
@@ -225,9 +221,8 @@ TEST_F(JsonPrefStoreTest, BasicAsync) {
TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) {
base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
ASSERT_FALSE(file_util::PathExists(bogus_input_file));
- scoped_refptr<JsonPrefStore> pref_store =
- new JsonPrefStore(
- bogus_input_file, message_loop_.message_loop_proxy());
+ scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
+ bogus_input_file, message_loop_.message_loop_proxy().get());
MockPrefStoreObserver mock_observer;
pref_store->AddObserver(&mock_observer);
@@ -253,8 +248,7 @@ TEST_F(JsonPrefStoreTest, NeedsEmptyValue) {
// Test that the persistent value can be loaded.
ASSERT_TRUE(file_util::PathExists(pref_file));
scoped_refptr<JsonPrefStore> pref_store =
- new JsonPrefStore(
- pref_file, message_loop_.message_loop_proxy());
+ new JsonPrefStore(pref_file, message_loop_.message_loop_proxy().get());
ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs());
ASSERT_FALSE(pref_store->ReadOnly());
diff --git a/base/prefs/pref_service_builder.cc b/base/prefs/pref_service_builder.cc
index 71d2d5b..b3d3533 100644
--- a/base/prefs/pref_service_builder.cc
+++ b/base/prefs/pref_service_builder.cc
@@ -74,20 +74,19 @@ PrefServiceBuilder& PrefServiceBuilder::WithAsync(bool async) {
PrefService* PrefServiceBuilder::Create(PrefRegistry* pref_registry) {
PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
- PrefService* pref_service = new PrefService(
- pref_notifier,
- new PrefValueStore(
- managed_prefs_.get(),
- extension_prefs_.get(),
- command_line_prefs_.get(),
- user_prefs_.get(),
- recommended_prefs_.get(),
- pref_registry->defaults(),
- pref_notifier),
- user_prefs_.get(),
- pref_registry,
- read_error_callback_,
- async_);
+ PrefService* pref_service =
+ new PrefService(pref_notifier,
+ new PrefValueStore(managed_prefs_.get(),
+ extension_prefs_.get(),
+ command_line_prefs_.get(),
+ user_prefs_.get(),
+ recommended_prefs_.get(),
+ pref_registry->defaults().get(),
+ pref_notifier),
+ user_prefs_.get(),
+ pref_registry,
+ read_error_callback_,
+ async_);
ResetDefaultState();
return pref_service;
}
diff --git a/base/prefs/testing_pref_service.cc b/base/prefs/testing_pref_service.cc
index 22755da..b96268a 100644
--- a/base/prefs/testing_pref_service.cc
+++ b/base/prefs/testing_pref_service.cc
@@ -12,32 +12,30 @@
#include "base/prefs/pref_value_store.h"
#include "testing/gtest/include/gtest/gtest.h"
-template<>
+template <>
TestingPrefServiceBase<PrefService, PrefRegistry>::TestingPrefServiceBase(
TestingPrefStore* managed_prefs,
TestingPrefStore* user_prefs,
TestingPrefStore* recommended_prefs,
PrefRegistry* pref_registry,
PrefNotifierImpl* pref_notifier)
- : PrefService(pref_notifier,
- new PrefValueStore(
- managed_prefs,
- NULL,
- NULL,
- user_prefs,
- recommended_prefs,
- pref_registry->defaults(),
- pref_notifier),
- user_prefs,
- pref_registry,
- base::Bind(
- &TestingPrefServiceBase<
- PrefService, PrefRegistry>::HandleReadError),
- false),
+ : PrefService(
+ pref_notifier,
+ new PrefValueStore(managed_prefs,
+ NULL,
+ NULL,
+ user_prefs,
+ recommended_prefs,
+ pref_registry->defaults().get(),
+ pref_notifier),
+ user_prefs,
+ pref_registry,
+ base::Bind(&TestingPrefServiceBase<PrefService,
+ PrefRegistry>::HandleReadError),
+ false),
managed_prefs_(managed_prefs),
user_prefs_(user_prefs),
- recommended_prefs_(recommended_prefs) {
-}
+ recommended_prefs_(recommended_prefs) {}
TestingPrefServiceSimple::TestingPrefServiceSimple()
: TestingPrefServiceBase<PrefService, PrefRegistry>(
diff --git a/base/prefs/testing_pref_service.h b/base/prefs/testing_pref_service.h
index fee1981..ff15c4d 100644
--- a/base/prefs/testing_pref_service.h
+++ b/base/prefs/testing_pref_service.h
@@ -112,7 +112,7 @@ template<class SuperPrefService, class ConstructionPrefRegistry>
const Value* TestingPrefServiceBase<
SuperPrefService, ConstructionPrefRegistry>::GetManagedPref(
const char* path) const {
- return GetPref(managed_prefs_, path);
+ return GetPref(managed_prefs_.get(), path);
}
template<class SuperPrefService, class ConstructionPrefRegistry>
@@ -133,7 +133,7 @@ template<class SuperPrefService, class ConstructionPrefRegistry>
const Value* TestingPrefServiceBase<
SuperPrefService, ConstructionPrefRegistry>::GetUserPref(
const char* path) const {
- return GetPref(user_prefs_, path);
+ return GetPref(user_prefs_.get(), path);
}
template<class SuperPrefService, class ConstructionPrefRegistry>