Commit c26afda9 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions Cleanup] Use members in ExtensionPrefs init code

Instead of passing an ExtensionPrefValueMap to
ExtensionPrefs::InitExtensionControlledPrefs(), just use the member
variable directly.

Similarly, instead of passing `this` and the value map to the
anonymous free function LoadExtensionControlledPrefs(), just
make LoadExtensionControlledPrefs() a member function and use
the ExtensionPrefs members directly.

Bug: None

Change-Id: Ifd036983e83a4ecc9b95144cb87c986b68c2fa12
Reviewed-on: https://chromium-review.googlesource.com/996499
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548317}
parent 254ce1be
...@@ -238,28 +238,6 @@ bool IsBlacklistBitSet(const base::DictionaryValue* ext) { ...@@ -238,28 +238,6 @@ bool IsBlacklistBitSet(const base::DictionaryValue* ext) {
return ext->GetBoolean(kPrefBlacklist, &bool_value) && bool_value; return ext->GetBoolean(kPrefBlacklist, &bool_value) && bool_value;
} }
void LoadExtensionControlledPrefs(ExtensionPrefs* prefs,
ExtensionPrefValueMap* value_map,
const std::string& extension_id,
ExtensionPrefsScope scope) {
std::string scope_string;
if (!pref_names::ScopeToPrefName(scope, &scope_string))
return;
std::string key = extension_id + "." + scope_string;
const base::DictionaryValue* source_dict =
prefs->pref_service()->GetDictionary(pref_names::kExtensions);
const base::DictionaryValue* preferences = NULL;
if (!source_dict->GetDictionary(key, &preferences))
return;
for (base::DictionaryValue::Iterator iter(*preferences); !iter.IsAtEnd();
iter.Advance()) {
value_map->SetExtensionPref(
extension_id, iter.key(), scope, iter.value().DeepCopy());
}
}
// Whether SetAlertSystemFirstRun() should always return true, so that alerts // Whether SetAlertSystemFirstRun() should always return true, so that alerts
// are triggered, even in first run. // are triggered, even in first run.
bool g_run_alerts_in_first_run_for_testing = false; bool g_run_alerts_in_first_run_for_testing = false;
...@@ -1597,7 +1575,7 @@ void ExtensionPrefs::InitPrefStore() { ...@@ -1597,7 +1575,7 @@ void ExtensionPrefs::InitPrefStore() {
update.Get(); update.Get();
} }
InitExtensionControlledPrefs(extension_pref_value_map_); InitExtensionControlledPrefs();
extension_pref_value_map_->NotifyInitializationCompleted(); extension_pref_value_map_->NotifyInitializationCompleted();
} }
...@@ -1861,8 +1839,7 @@ void ExtensionPrefs::PopulateExtensionInfoPrefs( ...@@ -1861,8 +1839,7 @@ void ExtensionPrefs::PopulateExtensionInfoPrefs(
extension_dict->Remove(kPrefDoNotSync, NULL); extension_dict->Remove(kPrefDoNotSync, NULL);
} }
void ExtensionPrefs::InitExtensionControlledPrefs( void ExtensionPrefs::InitExtensionControlledPrefs() {
ExtensionPrefValueMap* value_map) {
TRACE_EVENT0("browser,startup", TRACE_EVENT0("browser,startup",
"ExtensionPrefs::InitExtensionControlledPrefs") "ExtensionPrefs::InitExtensionControlledPrefs")
SCOPED_UMA_HISTOGRAM_TIMER("Extensions.InitExtensionControlledPrefsTime"); SCOPED_UMA_HISTOGRAM_TIMER("Extensions.InitExtensionControlledPrefsTime");
...@@ -1876,29 +1853,47 @@ void ExtensionPrefs::InitExtensionControlledPrefs( ...@@ -1876,29 +1853,47 @@ void ExtensionPrefs::InitExtensionControlledPrefs(
base::Time install_time = GetInstallTime(*extension_id); base::Time install_time = GetInstallTime(*extension_id);
bool is_enabled = !IsExtensionDisabled(*extension_id); bool is_enabled = !IsExtensionDisabled(*extension_id);
bool is_incognito_enabled = IsIncognitoEnabled(*extension_id); bool is_incognito_enabled = IsIncognitoEnabled(*extension_id);
value_map->RegisterExtension( extension_pref_value_map_->RegisterExtension(
*extension_id, install_time, is_enabled, is_incognito_enabled); *extension_id, install_time, is_enabled, is_incognito_enabled);
for (auto& observer : observer_list_) for (auto& observer : observer_list_)
observer.OnExtensionRegistered(*extension_id, install_time, is_enabled); observer.OnExtensionRegistered(*extension_id, install_time, is_enabled);
// Set regular extension controlled prefs. // Set regular extension controlled prefs.
LoadExtensionControlledPrefs( LoadExtensionControlledPrefs(*extension_id, kExtensionPrefsScopeRegular);
this, value_map, *extension_id, kExtensionPrefsScopeRegular);
// Set incognito extension controlled prefs. // Set incognito extension controlled prefs.
LoadExtensionControlledPrefs(this, LoadExtensionControlledPrefs(*extension_id,
value_map,
*extension_id,
kExtensionPrefsScopeIncognitoPersistent); kExtensionPrefsScopeIncognitoPersistent);
// Set regular-only extension controlled prefs. // Set regular-only extension controlled prefs.
LoadExtensionControlledPrefs( LoadExtensionControlledPrefs(*extension_id,
this, value_map, *extension_id, kExtensionPrefsScopeRegularOnly); kExtensionPrefsScopeRegularOnly);
for (auto& observer : observer_list_) for (auto& observer : observer_list_)
observer.OnExtensionPrefsLoaded(*extension_id, this); observer.OnExtensionPrefsLoaded(*extension_id, this);
} }
} }
void ExtensionPrefs::LoadExtensionControlledPrefs(
const ExtensionId& extension_id,
ExtensionPrefsScope scope) {
std::string scope_string;
if (!pref_names::ScopeToPrefName(scope, &scope_string))
return;
std::string key = extension_id + "." + scope_string;
const base::DictionaryValue* source_dict =
pref_service()->GetDictionary(pref_names::kExtensions);
const base::DictionaryValue* preferences = NULL;
if (!source_dict->GetDictionary(key, &preferences))
return;
for (base::DictionaryValue::Iterator iter(*preferences); !iter.IsAtEnd();
iter.Advance()) {
extension_pref_value_map_->SetExtensionPref(extension_id, iter.key(), scope,
iter.value().DeepCopy());
}
}
void ExtensionPrefs::FinishExtensionInfoPrefs( void ExtensionPrefs::FinishExtensionInfoPrefs(
const std::string& extension_id, const std::string& extension_id,
const base::Time install_time, const base::Time install_time,
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "components/sync/model/string_ordinal.h" #include "components/sync/model/string_ordinal.h"
#include "extensions/browser/blacklist_state.h" #include "extensions/browser/blacklist_state.h"
#include "extensions/browser/disable_reason.h" #include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_prefs_scope.h"
#include "extensions/browser/install_flag.h" #include "extensions/browser/install_flag.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
...@@ -690,7 +691,11 @@ class ExtensionPrefs : public KeyedService { ...@@ -690,7 +691,11 @@ class ExtensionPrefs : public KeyedService {
const base::Optional<int>& dnr_ruleset_checksum, const base::Optional<int>& dnr_ruleset_checksum,
prefs::DictionaryValueUpdate* extension_dict) const; prefs::DictionaryValueUpdate* extension_dict) const;
void InitExtensionControlledPrefs(ExtensionPrefValueMap* value_map); void InitExtensionControlledPrefs();
// Loads preferences for the given |extension_id| into the pref value map.
void LoadExtensionControlledPrefs(const ExtensionId& extension_id,
ExtensionPrefsScope scope);
// Helper function to complete initialization of the values in // Helper function to complete initialization of the values in
// |extension_dict| for an extension install. Also see // |extension_dict| for an extension install. Also see
......
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