Chromium Code Reviews| Index: chrome/browser/extensions/extension_prefs.cc |
| diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc |
| index dbbbf8d4115408fe03d568fca98e441d763afe32..1c35cf17b0eda2c0e155833795609c5a49ba7fcb 100644 |
| --- a/chrome/browser/extensions/extension_prefs.cc |
| +++ b/chrome/browser/extensions/extension_prefs.cc |
| @@ -70,6 +70,15 @@ const char kPrefDisableReason[] = "disable_reason"; |
| // object stored in the Preferences file. The extensions are stored by ID. |
| const char kExtensionToolbar[] = "extensions.toolbar"; |
| +// A preference that tracks order of extensions in an action box |
|
msw
2012/07/24 23:41:55
grammar nit: "the order".
yefimt
2012/07/25 21:09:21
Done.
|
| +// (list of extension ids). |
| +const char kExtensionActionBox[] = "extensions.action_box_order"; |
| + |
| +// A preference that tracks order of extensions in an toolbar when |
|
msw
2012/07/24 23:41:55
grammar nits: "the order", "a toolbar", and "is en
yefimt
2012/07/25 21:09:21
Done.
msw
2012/07/25 23:02:03
Almost, please change "an toolbar" to "a toolbar".
yefimt
2012/07/31 00:10:11
Done.
|
| +// action box enabled (list of extension ids). |
| +const char kExtensionActionBoxBar[] = |
| + "extensions.toolbar_order_with_action_box"; |
| + |
| // The key for a serialized Time value indicating the start of the day (from the |
| // server's perspective) an extension last included a "ping" parameter during |
| // its update check. |
| @@ -700,7 +709,7 @@ void ExtensionPrefs::RemoveDisableReason(const std::string& extension_id) { |
| void ExtensionPrefs::UpdateBlacklist( |
| const std::set<std::string>& blacklist_set) { |
| - std::vector<std::string> remove_pref_ids; |
| + ExtensionIdSet remove_pref_ids; |
| std::set<std::string> used_id_set; |
| const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
| @@ -747,7 +756,7 @@ void ExtensionPrefs::UpdateBlacklist( |
| Value::CreateBooleanValue(true)); |
| } |
| } |
| - for (unsigned int i = 0; i < remove_pref_ids.size(); ++i) { |
| + for (size_t i = 0; i < remove_pref_ids.size(); ++i) { |
| DeleteExtensionPrefs(remove_pref_ids[i]); |
| } |
| } |
| @@ -1175,28 +1184,25 @@ bool ExtensionPrefs::IsExtensionDisabled( |
| return DoesExtensionHaveState(id, Extension::DISABLED); |
| } |
| -std::vector<std::string> ExtensionPrefs::GetToolbarOrder() { |
| - ExtensionIdSet extension_ids; |
| - const ListValue* toolbar_order = prefs_->GetList(kExtensionToolbar); |
| - if (toolbar_order) { |
| - for (size_t i = 0; i < toolbar_order->GetSize(); ++i) { |
| - std::string extension_id; |
| - if (toolbar_order->GetString(i, &extension_id)) |
| - extension_ids.push_back(extension_id); |
| - } |
| - } |
| - return extension_ids; |
| +ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetToolbarOrder() { |
| + bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); |
| + return GetExtensionPrefAsVector( |
| + action_box_enabled ? kExtensionActionBoxBar : kExtensionToolbar); |
| } |
| -void ExtensionPrefs::SetToolbarOrder( |
| - const std::vector<std::string>& extension_ids) { |
| - ListPrefUpdate update(prefs_, kExtensionToolbar); |
| - ListValue* toolbar_order = update.Get(); |
| - toolbar_order->Clear(); |
| - for (std::vector<std::string>::const_iterator iter = extension_ids.begin(); |
| - iter != extension_ids.end(); ++iter) { |
| - toolbar_order->Append(new StringValue(*iter)); |
| - } |
| +void ExtensionPrefs::SetToolbarOrder(const ExtensionIdSet& extension_ids) { |
| + bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); |
| + SetExtensionPrefFromVector( |
| + action_box_enabled ? kExtensionActionBoxBar : kExtensionToolbar, |
| + extension_ids); |
| +} |
| + |
| +ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetActionBoxOrder() { |
| + return GetExtensionPrefAsVector(kExtensionActionBox); |
| +} |
| + |
| +void ExtensionPrefs::SetActionBoxOrder(const ExtensionIdSet& extension_ids) { |
| + SetExtensionPrefFromVector(kExtensionActionBox, extension_ids); |
| } |
| void ExtensionPrefs::OnExtensionInstalled( |
| @@ -1913,6 +1919,8 @@ URLPatternSet ExtensionPrefs::GetAllowedInstallSites() { |
| void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
| prefs->RegisterDictionaryPref(kExtensionsPref, PrefService::UNSYNCABLE_PREF); |
| prefs->RegisterListPref(kExtensionToolbar, PrefService::UNSYNCABLE_PREF); |
| + prefs->RegisterListPref(kExtensionActionBox, PrefService::UNSYNCABLE_PREF); |
| + prefs->RegisterListPref(kExtensionActionBoxBar, PrefService::UNSYNCABLE_PREF); |
| prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, |
| -1, // default value |
| PrefService::UNSYNCABLE_PREF); |
| @@ -1940,4 +1948,29 @@ void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
| PrefService::UNSYNCABLE_PREF); |
| } |
| +ExtensionPrefs::ExtensionIdSet ExtensionPrefs::GetExtensionPrefAsVector( |
| + const char* pref) { |
| + ExtensionIdSet extension_ids; |
| + const ListValue* list_of_values = prefs_->GetList(pref); |
| + if (!list_of_values) |
| + return extension_ids; |
| + |
| + for (size_t i = 0; i < list_of_values->GetSize(); ++i) { |
| + std::string extension_id; |
|
msw
2012/07/24 23:41:55
nit: move string decl out of loop.
yefimt
2012/07/25 21:09:21
Done.
|
| + if (list_of_values->GetString(i, &extension_id)) |
| + extension_ids.push_back(extension_id); |
| + } |
| + return extension_ids; |
| +} |
| + |
| +void ExtensionPrefs::SetExtensionPrefFromVector(const char* pref, |
| + const ExtensionIdSet& strings) { |
| + ListPrefUpdate update(prefs_, pref); |
| + ListValue* list_of_values = update.Get(); |
| + list_of_values->Clear(); |
| + for (ExtensionIdSet::const_iterator iter = strings.begin(); |
| + iter != strings.end(); ++iter) |
| + list_of_values->Append(new StringValue(*iter)); |
| +} |
| + |
| } // namespace extensions |