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

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

Issue 10828316: Support multiple disable reasons in ExtensionPerfs (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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
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/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/extensions/admin_policy.h" 10 #include "chrome/browser/extensions/admin_policy.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 const char kPrefAppNotificationDisbaled[] = "app_notif_disabled"; 57 const char kPrefAppNotificationDisbaled[] = "app_notif_disabled";
58 58
59 // Indicates whether the user has acknowledged various types of extensions. 59 // Indicates whether the user has acknowledged various types of extensions.
60 const char kPrefExternalAcknowledged[] = "ack_external"; 60 const char kPrefExternalAcknowledged[] = "ack_external";
61 const char kPrefBlacklistAcknowledged[] = "ack_blacklist"; 61 const char kPrefBlacklistAcknowledged[] = "ack_blacklist";
62 const char kPrefOrphanAcknowledged[] = "ack_orphan"; 62 const char kPrefOrphanAcknowledged[] = "ack_orphan";
63 63
64 // Indicates whether to show an install warning when the user enables. 64 // Indicates whether to show an install warning when the user enables.
65 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable"; 65 const char kExtensionDidEscalatePermissions[] = "install_warning_on_enable";
66 66
67 // DO NOT USE, use kPrefDisableReasons instead.
67 // Indicates whether the extension was updated while it was disabled. 68 // Indicates whether the extension was updated while it was disabled.
68 const char kPrefDisableReason[] = "disable_reason"; 69 const char kDeprecatedPrefDisableReason[] = "disable_reason";
70
71 // A bitmask of all the reasons an extension is disabled.
72 const char kPrefDisableReasons[] = "disable_reasons";
69 73
70 // A preference that tracks browser action toolbar configuration. This is a list 74 // A preference that tracks browser action toolbar configuration. This is a list
71 // object stored in the Preferences file. The extensions are stored by ID. 75 // object stored in the Preferences file. The extensions are stored by ID.
72 const char kExtensionToolbar[] = "extensions.toolbar"; 76 const char kExtensionToolbar[] = "extensions.toolbar";
73 77
74 // A preference that tracks the order of extensions in an action box 78 // A preference that tracks the order of extensions in an action box
75 // (list of extension ids). 79 // (list of extension ids).
76 const char kExtensionActionBox[] = "extensions.action_box_order"; 80 const char kExtensionActionBox[] = "extensions.action_box_order";
77 81
78 // A preference that tracks the order of extensions in a toolbar when 82 // A preference that tracks the order of extensions in a toolbar when
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 return ReadExtensionPrefBoolean(extension_id, 693 return ReadExtensionPrefBoolean(extension_id,
690 kExtensionDidEscalatePermissions); 694 kExtensionDidEscalatePermissions);
691 } 695 }
692 696
693 void ExtensionPrefs::SetDidExtensionEscalatePermissions( 697 void ExtensionPrefs::SetDidExtensionEscalatePermissions(
694 const Extension* extension, bool did_escalate) { 698 const Extension* extension, bool did_escalate) {
695 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, 699 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions,
696 Value::CreateBooleanValue(did_escalate)); 700 Value::CreateBooleanValue(did_escalate));
697 } 701 }
698 702
699 Extension::DisableReason ExtensionPrefs::GetDisableReason( 703 int ExtensionPrefs::GetDisableReasons(const std::string& extension_id) {
700 const std::string& extension_id) {
701 int value = -1; 704 int value = -1;
702 if (ReadExtensionPrefInteger(extension_id, kPrefDisableReason, &value) && 705 if (ReadExtensionPrefInteger(extension_id, kPrefDisableReasons, &value) &&
703 value >= 0 && value < Extension::DISABLE_LAST) { 706 value >= 0) {
704 return static_cast<Extension::DisableReason>(value); 707 return value;
705 } 708 }
706 return Extension::DISABLE_UNKNOWN; 709 return Extension::DISABLE_NONE;
707 } 710 }
708 711
709 void ExtensionPrefs::SetDisableReason(const std::string& extension_id, 712 void ExtensionPrefs::AddDisableReason(const std::string& extension_id,
710 Extension::DisableReason disable_reason) { 713 Extension::DisableReason disable_reason) {
711 UpdateExtensionPref( 714 int new_value = GetDisableReasons(extension_id) |
712 extension_id, kPrefDisableReason, 715 static_cast<int>(disable_reason);
713 Value::CreateIntegerValue(static_cast<int>(disable_reason))); 716 UpdateExtensionPref(extension_id, kPrefDisableReasons,
717 Value::CreateIntegerValue(new_value));
714 } 718 }
715 719
716 void ExtensionPrefs::RemoveDisableReason(const std::string& extension_id) { 720 void ExtensionPrefs::RemoveDisableReason(
717 UpdateExtensionPref(extension_id, kPrefDisableReason, NULL); 721 const std::string& extension_id,
722 Extension::DisableReason disable_reason) {
723 int new_value = GetDisableReasons(extension_id) &
724 ~static_cast<int>(disable_reason);
725 UpdateExtensionPref(extension_id, kPrefDisableReasons,
726 Value::CreateIntegerValue(new_value));
Yoyo Zhou 2012/08/15 00:21:31 This will still store a 0 when there are no disabl
eaugusti 2012/08/15 00:48:50 Ok. Also changing ClearDisableReasons() update wit
727 }
728
729 void ExtensionPrefs::ClearDisableReasons(const std::string& extension_id) {
730 UpdateExtensionPref(
731 extension_id, kPrefDisableReasons,
732 Value::CreateIntegerValue(static_cast<int>(Extension::DISABLE_NONE)));
718 } 733 }
719 734
720 void ExtensionPrefs::UpdateBlacklist( 735 void ExtensionPrefs::UpdateBlacklist(
721 const std::set<std::string>& blacklist_set) { 736 const std::set<std::string>& blacklist_set) {
722 ExtensionIdSet remove_pref_ids; 737 ExtensionIdSet remove_pref_ids;
723 std::set<std::string> used_id_set; 738 std::set<std::string> used_id_set;
724 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 739 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
725 740
726 if (extensions) { 741 if (extensions) {
727 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); 742 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys();
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 if (ext->GetList(kPrefOldGrantedHosts, &hosts)) { 910 if (ext->GetList(kPrefOldGrantedHosts, &hosts)) {
896 UpdateExtensionPref( 911 UpdateExtensionPref(
897 *ext_id, explicit_hosts, hosts->DeepCopy()); 912 *ext_id, explicit_hosts, hosts->DeepCopy());
898 913
899 // We can get rid of the old one by setting it to an empty list. 914 // We can get rid of the old one by setting it to an empty list.
900 UpdateExtensionPref(*ext_id, kPrefOldGrantedHosts, new ListValue()); 915 UpdateExtensionPref(*ext_id, kPrefOldGrantedHosts, new ListValue());
901 } 916 }
902 } 917 }
903 } 918 }
904 919
920 void ExtensionPrefs::MigrateDisableReasons(
921 const ExtensionIdSet& extension_ids) {
922 for (ExtensionIdSet::const_iterator ext_id =
923 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) {
924 int value = -1;
925 if (ReadExtensionPrefInteger(*ext_id, kDeprecatedPrefDisableReason,
926 &value)) {
927 int new_value = Extension::DISABLE_NONE;
928 if (value > Extension::DEPRECATED_DISABLE_UNKNOWN &&
929 value < Extension::DEPRECATED_DISABLE_LAST) {
930 new_value = 1 << (value - 1);
Yoyo Zhou 2012/08/15 00:21:31 This is a little opaque. Why not just have a switc
eaugusti 2012/08/15 00:48:50 Done.
931 }
932
933 UpdateExtensionPref(*ext_id, kPrefDisableReasons,
934 Value::CreateIntegerValue(new_value));
935 // Remove the old disable reason.
936 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL);
937 }
938 }
939 }
940
905 PermissionSet* ExtensionPrefs::GetGrantedPermissions( 941 PermissionSet* ExtensionPrefs::GetGrantedPermissions(
906 const std::string& extension_id) { 942 const std::string& extension_id) {
907 CHECK(Extension::IdIsValid(extension_id)); 943 CHECK(Extension::IdIsValid(extension_id));
908 return ReadExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions); 944 return ReadExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions);
909 } 945 }
910 946
911 void ExtensionPrefs::AddGrantedPermissions( 947 void ExtensionPrefs::AddGrantedPermissions(
912 const std::string& extension_id, 948 const std::string& extension_id,
913 const PermissionSet* permissions) { 949 const PermissionSet* permissions) {
914 CHECK(Extension::IdIsValid(extension_id)); 950 CHECK(Extension::IdIsValid(extension_id));
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 // are pruned when persisting the preferences to disk). 1917 // are pruned when persisting the preferences to disk).
1882 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); 1918 for (ExtensionIdSet::iterator ext_id = extension_ids.begin();
1883 ext_id != extension_ids.end(); ++ext_id) { 1919 ext_id != extension_ids.end(); ++ext_id) {
1884 ScopedExtensionPrefUpdate update(prefs_, *ext_id); 1920 ScopedExtensionPrefUpdate update(prefs_, *ext_id);
1885 // This creates an empty dictionary if none is stored. 1921 // This creates an empty dictionary if none is stored.
1886 update.Get(); 1922 update.Get();
1887 } 1923 }
1888 1924
1889 FixMissingPrefs(extension_ids); 1925 FixMissingPrefs(extension_ids);
1890 MigratePermissions(extension_ids); 1926 MigratePermissions(extension_ids);
1927 MigrateDisableReasons(extension_ids);
1891 extension_sorting_->Initialize(extension_ids); 1928 extension_sorting_->Initialize(extension_ids);
1892 1929
1893 // Store extension controlled preference values in the 1930 // Store extension controlled preference values in the
1894 // |extension_pref_value_map_|, which then informs the subscribers 1931 // |extension_pref_value_map_|, which then informs the subscribers
1895 // (ExtensionPrefStores) about the winning values. 1932 // (ExtensionPrefStores) about the winning values.
1896 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); 1933 for (ExtensionIdSet::iterator ext_id = extension_ids.begin();
1897 ext_id != extension_ids.end(); ++ext_id) { 1934 ext_id != extension_ids.end(); ++ext_id) {
1898 extension_pref_value_map_->RegisterExtension( 1935 extension_pref_value_map_->RegisterExtension(
1899 *ext_id, 1936 *ext_id,
1900 GetInstallTime(*ext_id), 1937 GetInstallTime(*ext_id),
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2098 const ExtensionIdSet& strings) { 2135 const ExtensionIdSet& strings) {
2099 ListPrefUpdate update(prefs_, pref); 2136 ListPrefUpdate update(prefs_, pref);
2100 ListValue* list_of_values = update.Get(); 2137 ListValue* list_of_values = update.Get();
2101 list_of_values->Clear(); 2138 list_of_values->Clear();
2102 for (ExtensionIdSet::const_iterator iter = strings.begin(); 2139 for (ExtensionIdSet::const_iterator iter = strings.begin();
2103 iter != strings.end(); ++iter) 2140 iter != strings.end(); ++iter)
2104 list_of_values->Append(new StringValue(*iter)); 2141 list_of_values->Append(new StringValue(*iter));
2105 } 2142 }
2106 2143
2107 } // namespace extensions 2144 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698