Commit 0aa36d96 authored by François Degros's avatar François Degros Committed by Commit Bot

Simple code cleanup.

Passed PrefRegistry and PrefRegistrySyncable by raw pointer instead of reference
to scoped_ptr. PrefRegistry and PrefRegistrySyncable have an internal reference
count. There is no need to use a double indirection when passing them around.

Used base::MakeRefCounted instead of naked 'new' operator.

Change-Id: I53a0fdfc99b7ef3dd32b191664520659c2585fa5
Reviewed-on: https://chromium-review.googlesource.com/892582Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: François Degros <fdegros@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533087}
parent 23267b86
...@@ -1035,7 +1035,7 @@ void BrowserProcessImpl::CreateLocalState() { ...@@ -1035,7 +1035,7 @@ void BrowserProcessImpl::CreateLocalState() {
base::FilePath local_state_path; base::FilePath local_state_path;
CHECK(PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path)); CHECK(PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path));
auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>(); const auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
// Register local state preferences. // Register local state preferences.
RegisterLocalState(pref_registry.get()); RegisterLocalState(pref_registry.get());
...@@ -1044,7 +1044,7 @@ void BrowserProcessImpl::CreateLocalState() { ...@@ -1044,7 +1044,7 @@ void BrowserProcessImpl::CreateLocalState() {
delegate->InitPrefRegistry(pref_registry.get()); delegate->InitPrefRegistry(pref_registry.get());
local_state_ = chrome_prefs::CreateLocalState( local_state_ = chrome_prefs::CreateLocalState(
local_state_path, local_state_task_runner_.get(), policy_service(), local_state_path, local_state_task_runner_.get(), policy_service(),
pref_registry, false, std::move(delegate)); pref_registry.get(), false, std::move(delegate));
DCHECK(local_state_); DCHECK(local_state_);
pref_change_registrar_.Init(local_state_.get()); pref_change_registrar_.Init(local_state_.get());
......
...@@ -390,11 +390,12 @@ PrefService* InitializeLocalState( ...@@ -390,11 +390,12 @@ PrefService* InitializeLocalState(
if (!local_state_file_exists) { if (!local_state_file_exists) {
base::FilePath parent_profile = base::FilePath parent_profile =
parsed_command_line.GetSwitchValuePath(switches::kParentProfile); parsed_command_line.GetSwitchValuePath(switches::kParentProfile);
scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple(); const auto registry = base::MakeRefCounted<PrefRegistrySimple>();
std::unique_ptr<PrefService> parent_local_state( std::unique_ptr<PrefService> parent_local_state(
chrome_prefs::CreateLocalState( chrome_prefs::CreateLocalState(parent_profile,
parent_profile, local_state_task_runner, local_state_task_runner,
g_browser_process->policy_service(), registry, false, nullptr)); g_browser_process->policy_service(),
registry.get(), false, nullptr));
registry->RegisterStringPref(prefs::kApplicationLocale, std::string()); registry->RegisterStringPref(prefs::kApplicationLocale, std::string());
// Right now, we only inherit the locale setting from the parent profile. // Right now, we only inherit the locale setting from the parent profile.
local_state->SetString( local_state->SetString(
......
...@@ -440,7 +440,7 @@ std::unique_ptr<PrefService> CreateLocalState( ...@@ -440,7 +440,7 @@ std::unique_ptr<PrefService> CreateLocalState(
const base::FilePath& pref_filename, const base::FilePath& pref_filename,
base::SequencedTaskRunner* pref_io_task_runner, base::SequencedTaskRunner* pref_io_task_runner,
policy::PolicyService* policy_service, policy::PolicyService* policy_service,
const scoped_refptr<PrefRegistry>& pref_registry, PrefRegistry* pref_registry,
bool async, bool async,
std::unique_ptr<PrefValueStore::Delegate> delegate) { std::unique_ptr<PrefValueStore::Delegate> delegate) {
sync_preferences::PrefServiceSyncableFactory factory; sync_preferences::PrefServiceSyncableFactory factory;
...@@ -450,7 +450,7 @@ std::unique_ptr<PrefService> CreateLocalState( ...@@ -450,7 +450,7 @@ std::unique_ptr<PrefService> CreateLocalState(
std::unique_ptr<PrefFilter>()), std::unique_ptr<PrefFilter>()),
NULL, // extension_prefs NULL, // extension_prefs
async); async);
return factory.Create(pref_registry.get(), std::move(delegate)); return factory.Create(pref_registry, std::move(delegate));
} }
std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs( std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs(
...@@ -459,7 +459,7 @@ std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs( ...@@ -459,7 +459,7 @@ std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs(
policy::PolicyService* policy_service, policy::PolicyService* policy_service,
SupervisedUserSettingsService* supervised_user_settings, SupervisedUserSettingsService* supervised_user_settings,
const scoped_refptr<PrefStore>& extension_prefs, const scoped_refptr<PrefStore>& extension_prefs,
const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry, user_prefs::PrefRegistrySyncable* pref_registry,
bool async, bool async,
scoped_refptr<base::SequencedTaskRunner> io_task_runner, scoped_refptr<base::SequencedTaskRunner> io_task_runner,
std::unique_ptr<PrefValueStore::Delegate> delegate) { std::unique_ptr<PrefValueStore::Delegate> delegate) {
...@@ -471,19 +471,16 @@ std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs( ...@@ -471,19 +471,16 @@ std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs(
base::MakeUnique<ResetOnLoadObserverImpl>(profile_path), base::MakeUnique<ResetOnLoadObserverImpl>(profile_path),
mojo::MakeRequest(&reset_on_load_observer)); mojo::MakeRequest(&reset_on_load_observer));
sync_preferences::PrefServiceSyncableFactory factory; sync_preferences::PrefServiceSyncableFactory factory;
scoped_refptr<PersistentPrefStore> user_pref_store( const scoped_refptr<PersistentPrefStore> user_pref_store =
CreateProfilePrefStoreManager(profile_path) CreateProfilePrefStoreManager(profile_path)
->CreateProfilePrefStore( ->CreateProfilePrefStore(
GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount, GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount,
std::move(io_task_runner), std::move(reset_on_load_observer), std::move(io_task_runner), std::move(reset_on_load_observer),
std::move(validation_delegate))); std::move(validation_delegate));
PrepareFactory(&factory, profile_path, policy_service, PrepareFactory(&factory, profile_path, policy_service,
supervised_user_settings, user_pref_store, extension_prefs, supervised_user_settings, user_pref_store, extension_prefs,
async); async);
std::unique_ptr<sync_preferences::PrefServiceSyncable> pref_service = return factory.CreateSyncable(pref_registry, std::move(delegate));
factory.CreateSyncable(pref_registry.get(), std::move(delegate));
return pref_service;
} }
void DisableDomainCheckForTesting() { void DisableDomainCheckForTesting() {
......
...@@ -68,7 +68,7 @@ std::unique_ptr<PrefService> CreateLocalState( ...@@ -68,7 +68,7 @@ std::unique_ptr<PrefService> CreateLocalState(
const base::FilePath& pref_filename, const base::FilePath& pref_filename,
base::SequencedTaskRunner* pref_io_task_runner, base::SequencedTaskRunner* pref_io_task_runner,
policy::PolicyService* policy_service, policy::PolicyService* policy_service,
const scoped_refptr<PrefRegistry>& pref_registry, PrefRegistry* pref_registry,
bool async, bool async,
std::unique_ptr<PrefValueStore::Delegate> delegate); std::unique_ptr<PrefValueStore::Delegate> delegate);
...@@ -78,7 +78,7 @@ std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs( ...@@ -78,7 +78,7 @@ std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs(
policy::PolicyService* policy_service, policy::PolicyService* policy_service,
SupervisedUserSettingsService* supervised_user_settings, SupervisedUserSettingsService* supervised_user_settings,
const scoped_refptr<PrefStore>& extension_prefs, const scoped_refptr<PrefStore>& extension_prefs,
const scoped_refptr<user_prefs::PrefRegistrySyncable>& pref_registry, user_prefs::PrefRegistrySyncable* pref_registry,
bool async, bool async,
scoped_refptr<base::SequencedTaskRunner> io_task_runner, scoped_refptr<base::SequencedTaskRunner> io_task_runner,
std::unique_ptr<PrefValueStore::Delegate> delegate); std::unique_ptr<PrefValueStore::Delegate> delegate);
......
...@@ -393,7 +393,7 @@ ProfileImpl::ProfileImpl( ...@@ -393,7 +393,7 @@ ProfileImpl::ProfileImpl(
scoped_refptr<base::SequencedTaskRunner> io_task_runner) scoped_refptr<base::SequencedTaskRunner> io_task_runner)
: path_(path), : path_(path),
io_task_runner_(std::move(io_task_runner)), io_task_runner_(std::move(io_task_runner)),
pref_registry_(new user_prefs::PrefRegistrySyncable), pref_registry_(base::MakeRefCounted<user_prefs::PrefRegistrySyncable>()),
io_data_(this), io_data_(this),
last_session_exit_type_(EXIT_NORMAL), last_session_exit_type_(EXIT_NORMAL),
start_time_(base::Time::Now()), start_time_(base::Time::Now()),
...@@ -502,8 +502,8 @@ ProfileImpl::ProfileImpl( ...@@ -502,8 +502,8 @@ ProfileImpl::ProfileImpl(
prefs_ = chrome_prefs::CreateProfilePrefs( prefs_ = chrome_prefs::CreateProfilePrefs(
path_, std::move(pref_validation_delegate), path_, std::move(pref_validation_delegate),
profile_policy_connector_->policy_service(), supervised_user_settings, profile_policy_connector_->policy_service(), supervised_user_settings,
CreateExtensionPrefStore(this, false), pref_registry_, async_prefs, CreateExtensionPrefStore(this, false), pref_registry_.get(),
GetIOTaskRunner(), std::move(delegate)); async_prefs, GetIOTaskRunner(), std::move(delegate));
// Register on BrowserContext. // Register on BrowserContext.
user_prefs::UserPrefs::Set(this, prefs_.get()); user_prefs::UserPrefs::Set(this, prefs_.get());
} }
......
...@@ -228,7 +228,7 @@ class ProfileImpl : public Profile { ...@@ -228,7 +228,7 @@ class ProfileImpl : public Profile {
// Keep |prefs_| on top for destruction order because |extension_prefs_|, // Keep |prefs_| on top for destruction order because |extension_prefs_|,
// |io_data_| and others store pointers to |prefs_| and shall be destructed // |io_data_| and others store pointers to |prefs_| and shall be destructed
// first. // first.
scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_; const scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry_;
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_; std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_;
// See comment in GetOffTheRecordPrefs. Field exists so something owns the // See comment in GetOffTheRecordPrefs. Field exists so something owns the
// dummy. // dummy.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment