Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(932)

Side by Side Diff: chrome/browser/extensions/extension_prefs.cc

Issue 10977048: Fix bug in disabling sync for default apps (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fix browser and integration tests, which got broken Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_prefs.h" 5 #include "chrome/browser/extensions/extension_prefs.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 const char kPrefScriptableHosts[] = "scriptable_host"; 155 const char kPrefScriptableHosts[] = "scriptable_host";
156 156
157 // The preference names for the old granted permissions scheme. 157 // The preference names for the old granted permissions scheme.
158 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full"; 158 const char kPrefOldGrantedFullAccess[] = "granted_permissions.full";
159 const char kPrefOldGrantedHosts[] = "granted_permissions.host"; 159 const char kPrefOldGrantedHosts[] = "granted_permissions.host";
160 const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; 160 const char kPrefOldGrantedAPIs[] = "granted_permissions.api";
161 161
162 // A preference that indicates when an extension was installed. 162 // A preference that indicates when an extension was installed.
163 const char kPrefInstallTime[] = "install_time"; 163 const char kPrefInstallTime[] = "install_time";
164 164
165 // A preference which saves the creation flags for extensions.
166 const char kPrefCreationFlags[] = "creation_flags";
167
165 // A preference that indicates whether the extension was installed from the 168 // A preference that indicates whether the extension was installed from the
166 // Chrome Web Store. 169 // Chrome Web Store.
167 const char kPrefFromWebStore[] = "from_webstore"; 170 const char kPrefFromWebStore[] = "from_webstore";
168 171
169 // A preference that indicates whether the extension was installed from a 172 // A preference that indicates whether the extension was installed from a
170 // mock App created from a bookmark. 173 // mock App created from a bookmark.
171 const char kPrefFromBookmark[] = "from_bookmark"; 174 const char kPrefFromBookmark[] = "from_bookmark";
172 175
173 // A prefrence that indicates whethere the extension was installed as 176 // A prefrence that indicates whethere the extension was installed as
174 // default apps. 177 // default apps.
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 return GetExtensionPrefAsVector(kExtensionActionBox); 1438 return GetExtensionPrefAsVector(kExtensionActionBox);
1436 } 1439 }
1437 1440
1438 void ExtensionPrefs::SetActionBoxOrder(const ExtensionIdList& extension_ids) { 1441 void ExtensionPrefs::SetActionBoxOrder(const ExtensionIdList& extension_ids) {
1439 SetExtensionPrefFromVector(kExtensionActionBox, extension_ids); 1442 SetExtensionPrefFromVector(kExtensionActionBox, extension_ids);
1440 } 1443 }
1441 1444
1442 void ExtensionPrefs::OnExtensionInstalled( 1445 void ExtensionPrefs::OnExtensionInstalled(
1443 const Extension* extension, 1446 const Extension* extension,
1444 Extension::State initial_state, 1447 Extension::State initial_state,
1445 bool from_webstore,
1446 const syncer::StringOrdinal& page_ordinal) { 1448 const syncer::StringOrdinal& page_ordinal) {
1447 const std::string& id = extension->id(); 1449 const std::string& id = extension->id();
1448 CHECK(Extension::IdIsValid(id)); 1450 CHECK(Extension::IdIsValid(id));
1449 ScopedExtensionPrefUpdate update(prefs_, id); 1451 ScopedExtensionPrefUpdate update(prefs_, id);
1450 DictionaryValue* extension_dict = update.Get(); 1452 DictionaryValue* extension_dict = update.Get();
1451 const base::Time install_time = GetCurrentTime(); 1453 const base::Time install_time = GetCurrentTime();
1452 extension_dict->Set(kPrefState, Value::CreateIntegerValue(initial_state)); 1454 extension_dict->Set(kPrefState, Value::CreateIntegerValue(initial_state));
1453 extension_dict->Set(kPrefLocation, 1455 extension_dict->Set(kPrefLocation,
1454 Value::CreateIntegerValue(extension->location())); 1456 Value::CreateIntegerValue(extension->location()));
1457 extension_dict->Set(kPrefCreationFlags,
1458 Value::CreateIntegerValue(extension->creation_flags()));
1455 extension_dict->Set(kPrefFromWebStore, 1459 extension_dict->Set(kPrefFromWebStore,
1456 Value::CreateBooleanValue(from_webstore)); 1460 Value::CreateBooleanValue(extension->from_webstore()));
1457 extension_dict->Set(kPrefFromBookmark, 1461 extension_dict->Set(kPrefFromBookmark,
1458 Value::CreateBooleanValue(extension->from_bookmark())); 1462 Value::CreateBooleanValue(extension->from_bookmark()));
1459 extension_dict->Set(kPrefWasInstalledByDefault, 1463 extension_dict->Set(kPrefWasInstalledByDefault,
1460 Value::CreateBooleanValue(extension->was_installed_by_default())); 1464 Value::CreateBooleanValue(extension->was_installed_by_default()));
1461 extension_dict->Set(kPrefInstallTime, 1465 extension_dict->Set(kPrefInstallTime,
1462 Value::CreateStringValue( 1466 Value::CreateStringValue(
1463 base::Int64ToString(install_time.ToInternalValue()))); 1467 base::Int64ToString(install_time.ToInternalValue())));
1464 extension_dict->Set(kPrefPreferences, new DictionaryValue()); 1468 extension_dict->Set(kPrefPreferences, new DictionaryValue());
1465 extension_dict->Set(kPrefIncognitoPreferences, new DictionaryValue()); 1469 extension_dict->Set(kPrefIncognitoPreferences, new DictionaryValue());
1466 extension_dict->Set(kPrefRegularOnlyPreferences, new DictionaryValue()); 1470 extension_dict->Set(kPrefRegularOnlyPreferences, new DictionaryValue());
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 1862
1859 bool ExtensionPrefs::IsFromBookmark( 1863 bool ExtensionPrefs::IsFromBookmark(
1860 const std::string& extension_id) const { 1864 const std::string& extension_id) const {
1861 const DictionaryValue* dictionary = GetExtensionPref(extension_id); 1865 const DictionaryValue* dictionary = GetExtensionPref(extension_id);
1862 bool result = false; 1866 bool result = false;
1863 if (dictionary && dictionary->GetBoolean(kPrefFromBookmark, &result)) 1867 if (dictionary && dictionary->GetBoolean(kPrefFromBookmark, &result))
1864 return result; 1868 return result;
1865 return false; 1869 return false;
1866 } 1870 }
1867 1871
1872 int ExtensionPrefs::GetCreationFlags(const std::string& extension_id) const {
1873 int creation_flags = Extension::NO_FLAGS;
1874 if (!ReadExtensionPrefInteger(extension_id, kPrefCreationFlags,
1875 &creation_flags)) {
1876 // Since kPrefCreationFlags was added later, it will be missing for
1877 // previously installed extensions.
1878 if (IsFromBookmark(extension_id))
1879 creation_flags |= Extension::FROM_BOOKMARK;
1880 if (IsFromWebStore(extension_id))
1881 creation_flags |= Extension::FROM_WEBSTORE;
1882 if (WasInstalledByDefault(extension_id))
1883 creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT;
1884 }
1885 return creation_flags;
1886 }
1887
1868 bool ExtensionPrefs::WasInstalledByDefault( 1888 bool ExtensionPrefs::WasInstalledByDefault(
1869 const std::string& extension_id) const { 1889 const std::string& extension_id) const {
1870 const DictionaryValue* dictionary = GetExtensionPref(extension_id); 1890 const DictionaryValue* dictionary = GetExtensionPref(extension_id);
1871 bool result = false; 1891 bool result = false;
1872 if (dictionary && 1892 if (dictionary &&
1873 dictionary->GetBoolean(kPrefWasInstalledByDefault, &result)) 1893 dictionary->GetBoolean(kPrefWasInstalledByDefault, &result))
1874 return result; 1894 return result;
1875 return false; 1895 return false;
1876 } 1896 }
1877 1897
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 const ExtensionIdList& strings) { 2220 const ExtensionIdList& strings) {
2201 ListPrefUpdate update(prefs_, pref); 2221 ListPrefUpdate update(prefs_, pref);
2202 ListValue* list_of_values = update.Get(); 2222 ListValue* list_of_values = update.Get();
2203 list_of_values->Clear(); 2223 list_of_values->Clear();
2204 for (ExtensionIdList::const_iterator iter = strings.begin(); 2224 for (ExtensionIdList::const_iterator iter = strings.begin();
2205 iter != strings.end(); ++iter) 2225 iter != strings.end(); ++iter)
2206 list_of_values->Append(new StringValue(*iter)); 2226 list_of_values->Append(new StringValue(*iter));
2207 } 2227 }
2208 2228
2209 } // namespace extensions 2229 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698