Index: chrome/browser/extensions/extension_prefs.cc |
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc |
index 058ede3396ed79a0203d15138dbabcec6a140cac..3fbea883f29b88a199c8f7e7762cf0b53b9d5562 100644 |
--- a/chrome/browser/extensions/extension_prefs.cc |
+++ b/chrome/browser/extensions/extension_prefs.cc |
@@ -14,11 +14,7 @@ using base::Time; |
namespace { |
-// Preferences keys |
- |
-// A preference that keeps track of per-extension settings. This is a dictionary |
-// object read from the Preferences file, keyed off of extension id's. |
-const char kExtensionsPref[] = "extensions.settings"; |
+// Additional preferences keys |
// Where an extension was installed from. (see Extension::Location) |
const char kPrefLocation[] = "location"; |
@@ -79,6 +75,10 @@ const char kPrefAllowFileAccess[] = "allowFileAccess"; |
// purchased apps. |
const char kWebStoreLogin[] = "extensions.webstore_login"; |
+// A preference set by the the NTP to persist the desired launch container type |
+// used for apps. |
+const char kPrefLaunchType[] = "launchType"; |
+ |
} // namespace |
//////////////////////////////////////////////////////////////////////////////// |
@@ -90,7 +90,8 @@ namespace { |
// id. We can remove this in a couple of months. (See http://crbug.com/40017 |
// and http://crbug.com/39745 for more details). |
static void CleanupBadExtensionKeys(PrefService* prefs) { |
- DictionaryValue* dictionary = prefs->GetMutableDictionary(kExtensionsPref); |
+ DictionaryValue* dictionary = |
+ prefs->GetMutableDictionary(ExtensionPrefs::kExtensionsPref); |
std::set<std::string> bad_keys; |
for (DictionaryValue::key_iterator i = dictionary->begin_keys(); |
i != dictionary->end_keys(); ++i) { |
@@ -121,6 +122,9 @@ ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) |
MakePathsRelative(); |
} |
+// static |
+const char ExtensionPrefs::kExtensionsPref[] = "extensions.settings"; |
+ |
static FilePath::StringType MakePathRelative(const FilePath& parent, |
const FilePath& child, |
bool *dirty) { |
@@ -164,7 +168,7 @@ void ExtensionPrefs::MakePathsRelative() { |
} |
} |
if (dirty) |
- prefs_->ScheduleSavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
} |
void ExtensionPrefs::MakePathsAbsolute(DictionaryValue* dict) { |
@@ -233,6 +237,36 @@ bool ExtensionPrefs::ReadExtensionPrefBoolean( |
return ReadBooleanFromPref(ext, pref_key); |
} |
+bool ExtensionPrefs::ReadIntegerFromPref( |
+ DictionaryValue* ext, const std::string& pref_key, int* out_value) { |
+ if (!ext->HasKey(pref_key)) return false; |
+ if (!ext->GetInteger(pref_key, out_value)) { |
+ NOTREACHED() << "Failed to fetch " << pref_key << " flag."; |
+ // In case we could not fetch the flag, we treat it as false. |
+ return false; |
+ } |
+ return out_value != NULL; |
+} |
+ |
+bool ExtensionPrefs::ReadExtensionPrefInteger( |
+ const std::string& extension_id, const std::string& pref_key, |
+ int* out_value) { |
+ const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); |
+ if (!extensions) |
+ return false; |
+ DictionaryValue* ext = NULL; |
+ if (!extensions->GetDictionary(extension_id, &ext)) { |
+ // No such extension yet. |
+ return false; |
+ } |
+ return ReadIntegerFromPref(ext, pref_key, out_value); |
+} |
+ |
+void ExtensionPrefs::SavePrefsAndNotify() { |
+ prefs_->ScheduleSavePersistentPrefs(); |
+ prefs_->pref_notifier()->OnUserPreferenceSet(kExtensionsPref); |
+} |
+ |
bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { |
return ReadBooleanFromPref(ext, kPrefBlacklist); |
} |
@@ -289,7 +323,7 @@ void ExtensionPrefs::SetDidExtensionEscalatePermissions( |
Extension* extension, bool did_escalate) { |
UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, |
Value::CreateBooleanValue(did_escalate)); |
- prefs_->SavePersistentPrefs(); |
+ prefs_->ScheduleSavePersistentPrefs(); |
} |
void ExtensionPrefs::UpdateBlacklist( |
@@ -343,8 +377,7 @@ void ExtensionPrefs::UpdateBlacklist( |
for (unsigned int i = 0; i < remove_pref_ids.size(); ++i) { |
DeleteExtensionPrefs(remove_pref_ids[i]); |
} |
- // Update persistent registry |
- prefs_->ScheduleSavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
return; |
} |
@@ -368,7 +401,7 @@ void ExtensionPrefs::SetLastPingDayImpl(const Time& time, |
} |
std::string value = base::Int64ToString(time.ToInternalValue()); |
dictionary->SetString(kLastPingDay, value); |
- prefs_->ScheduleSavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
} |
Time ExtensionPrefs::LastPingDay(const std::string& extension_id) const { |
@@ -399,7 +432,7 @@ void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, |
bool enabled) { |
UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, |
Value::CreateBooleanValue(enabled)); |
- prefs_->SavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
} |
bool ExtensionPrefs::AllowFileAccess(const std::string& extension_id) { |
@@ -410,7 +443,26 @@ void ExtensionPrefs::SetAllowFileAccess(const std::string& extension_id, |
bool allow) { |
UpdateExtensionPref(extension_id, kPrefAllowFileAccess, |
Value::CreateBooleanValue(allow)); |
- prefs_->SavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
+} |
+ |
+ExtensionPrefs::LaunchType ExtensionPrefs::GetLaunchType( |
+ const std::string& extension_id) { |
+ int value; |
+ if (ReadExtensionPrefInteger(extension_id, kPrefLaunchType, &value) && ( |
+ value == LAUNCH_PINNED || |
+ value == LAUNCH_REGULAR || |
+ value == LAUNCH_FULLSCREEN)) { |
+ return static_cast<LaunchType>(value); |
+ } |
+ return LAUNCH_PINNED; |
+} |
+ |
+void ExtensionPrefs::SetLaunchType(const std::string& extension_id, |
+ LaunchType launch_type) { |
+ UpdateExtensionPref(extension_id, kPrefLaunchType, |
+ Value::CreateIntegerValue(static_cast<int>(launch_type))); |
+ SavePrefsAndNotify(); |
} |
void ExtensionPrefs::GetKilledExtensionIds(std::set<std::string>* killed_ids) { |
@@ -462,7 +514,7 @@ void ExtensionPrefs::SetToolbarOrder( |
iter != extension_ids.end(); ++iter) { |
toolbar_order->Append(new StringValue(*iter)); |
} |
- prefs_->ScheduleSavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
} |
void ExtensionPrefs::OnExtensionInstalled( |
@@ -484,7 +536,7 @@ void ExtensionPrefs::OnExtensionInstalled( |
UpdateExtensionPref(id, kPrefManifest, |
extension->manifest_value()->DeepCopy()); |
} |
- prefs_->SavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
} |
void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, |
@@ -497,7 +549,7 @@ void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, |
if (!external_uninstall && Extension::IsExternalLocation(location)) { |
UpdateExtensionPref(extension_id, kPrefState, |
Value::CreateIntegerValue(Extension::KILLBIT)); |
- prefs_->ScheduleSavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
} else { |
DeleteExtensionPrefs(extension_id); |
} |
@@ -525,7 +577,7 @@ void ExtensionPrefs::SetExtensionState(Extension* extension, |
Extension::State state) { |
UpdateExtensionPref(extension->id(), kPrefState, |
Value::CreateIntegerValue(state)); |
- prefs_->SavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
} |
std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { |
@@ -546,7 +598,7 @@ void ExtensionPrefs::UpdateManifest(Extension* extension) { |
if (extension->location() != Extension::LOAD) { |
UpdateExtensionPref(extension->id(), kPrefManifest, |
extension->manifest_value()->DeepCopy()); |
- prefs_->ScheduleSavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
} |
} |
@@ -577,7 +629,7 @@ void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { |
DictionaryValue* dict = prefs_->GetMutableDictionary(kExtensionsPref); |
if (dict->HasKey(extension_id)) { |
dict->Remove(extension_id, NULL); |
- prefs_->ScheduleSavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
} |
} |
@@ -717,7 +769,7 @@ void ExtensionPrefs::SetIdleInstallInfo(const std::string& extension_id, |
info->SetString(kIdleInstallInfoFetchTime, |
base::Int64ToString(fetch_time.ToInternalValue())); |
extension_prefs->Set(kIdleInstallInfo, info); |
- prefs_->ScheduleSavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
} |
bool ExtensionPrefs::RemoveIdleInstallInfo(const std::string& extension_id) { |
@@ -725,7 +777,7 @@ bool ExtensionPrefs::RemoveIdleInstallInfo(const std::string& extension_id) { |
if (!extension_prefs) |
return false; |
bool result = extension_prefs->Remove(kIdleInstallInfo, NULL); |
- prefs_->ScheduleSavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
return result; |
} |
@@ -807,7 +859,7 @@ bool ExtensionPrefs::GetWebStoreLogin(std::string* result) { |
void ExtensionPrefs::SetWebStoreLogin(const std::string& login) { |
prefs_->SetString(kWebStoreLogin, login); |
- prefs_->ScheduleSavePersistentPrefs(); |
+ SavePrefsAndNotify(); |
} |
// static |