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

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

Issue 1136543003: Extensions: Store disable reasons in Sync (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 5 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/extension_prefs.h" 5 #include "extensions/browser/extension_prefs.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 } 532 }
533 533
534 bool ExtensionPrefs::HasPrefForExtension( 534 bool ExtensionPrefs::HasPrefForExtension(
535 const std::string& extension_id) const { 535 const std::string& extension_id) const {
536 return GetExtensionPref(extension_id) != NULL; 536 return GetExtensionPref(extension_id) != NULL;
537 } 537 }
538 538
539 bool ExtensionPrefs::ReadPrefAsURLPatternSet(const std::string& extension_id, 539 bool ExtensionPrefs::ReadPrefAsURLPatternSet(const std::string& extension_id,
540 const std::string& pref_key, 540 const std::string& pref_key,
541 URLPatternSet* result, 541 URLPatternSet* result,
542 int valid_schemes) { 542 int valid_schemes) const {
543 const base::ListValue* value = NULL; 543 const base::ListValue* value = NULL;
544 if (!ReadPrefAsList(extension_id, pref_key, &value)) 544 if (!ReadPrefAsList(extension_id, pref_key, &value))
545 return false; 545 return false;
546 const base::DictionaryValue* extension = GetExtensionPref(extension_id); 546 const base::DictionaryValue* extension = GetExtensionPref(extension_id);
547 if (!extension) 547 if (!extension)
548 return false; 548 return false;
549 int location; 549 int location;
550 if (extension->GetInteger(kPrefLocation, &location) && 550 if (extension->GetInteger(kPrefLocation, &location) &&
551 static_cast<Manifest::Location>(location) == Manifest::COMPONENT) { 551 static_cast<Manifest::Location>(location) == Manifest::COMPONENT) {
552 valid_schemes |= URLPattern::SCHEME_CHROMEUI; 552 valid_schemes |= URLPattern::SCHEME_CHROMEUI;
(...skipping 12 matching lines...) Expand all
565 565
566 bool ExtensionPrefs::ReadPrefAsBooleanAndReturn( 566 bool ExtensionPrefs::ReadPrefAsBooleanAndReturn(
567 const std::string& extension_id, 567 const std::string& extension_id,
568 const std::string& pref_key) const { 568 const std::string& pref_key) const {
569 bool out_value = false; 569 bool out_value = false;
570 return ReadPrefAsBoolean(extension_id, pref_key, &out_value) && out_value; 570 return ReadPrefAsBoolean(extension_id, pref_key, &out_value) && out_value;
571 } 571 }
572 572
573 PermissionSet* ExtensionPrefs::ReadPrefAsPermissionSet( 573 PermissionSet* ExtensionPrefs::ReadPrefAsPermissionSet(
574 const std::string& extension_id, 574 const std::string& extension_id,
575 const std::string& pref_key) { 575 const std::string& pref_key) const {
576 if (!GetExtensionPref(extension_id)) 576 if (!GetExtensionPref(extension_id))
577 return NULL; 577 return NULL;
578 578
579 // Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet() 579 // Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet()
580 // for api_values format. 580 // for api_values format.
581 APIPermissionSet apis; 581 APIPermissionSet apis;
582 const base::ListValue* api_values = NULL; 582 const base::ListValue* api_values = NULL;
583 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); 583 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs);
584 if (ReadPrefAsList(extension_id, api_pref, &api_values)) { 584 if (ReadPrefAsList(extension_id, api_pref, &api_values)) {
585 APIPermissionSet::ParseFromJSON(api_values, 585 APIPermissionSet::ParseFromJSON(api_values,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 const std::string& extension_id) { 675 const std::string& extension_id) {
676 int count = 0; 676 int count = 0;
677 ReadPrefAsInteger(extension_id, kPrefAcknowledgePromptCount, &count); 677 ReadPrefAsInteger(extension_id, kPrefAcknowledgePromptCount, &count);
678 ++count; 678 ++count;
679 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, 679 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount,
680 new base::FundamentalValue(count)); 680 new base::FundamentalValue(count));
681 return count; 681 return count;
682 } 682 }
683 683
684 bool ExtensionPrefs::IsExternalExtensionAcknowledged( 684 bool ExtensionPrefs::IsExternalExtensionAcknowledged(
685 const std::string& extension_id) { 685 const std::string& extension_id) const {
686 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalAcknowledged); 686 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalAcknowledged);
687 } 687 }
688 688
689 void ExtensionPrefs::AcknowledgeExternalExtension( 689 void ExtensionPrefs::AcknowledgeExternalExtension(
690 const std::string& extension_id) { 690 const std::string& extension_id) {
691 DCHECK(crx_file::id_util::IdIsValid(extension_id)); 691 DCHECK(crx_file::id_util::IdIsValid(extension_id));
692 UpdateExtensionPref(extension_id, kPrefExternalAcknowledged, 692 UpdateExtensionPref(extension_id, kPrefExternalAcknowledged,
693 new base::FundamentalValue(true)); 693 new base::FundamentalValue(true));
694 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL); 694 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL);
695 } 695 }
696 696
697 bool ExtensionPrefs::IsBlacklistedExtensionAcknowledged( 697 bool ExtensionPrefs::IsBlacklistedExtensionAcknowledged(
698 const std::string& extension_id) { 698 const std::string& extension_id) const {
699 return ReadPrefAsBooleanAndReturn(extension_id, kPrefBlacklistAcknowledged); 699 return ReadPrefAsBooleanAndReturn(extension_id, kPrefBlacklistAcknowledged);
700 } 700 }
701 701
702 void ExtensionPrefs::AcknowledgeBlacklistedExtension( 702 void ExtensionPrefs::AcknowledgeBlacklistedExtension(
703 const std::string& extension_id) { 703 const std::string& extension_id) {
704 DCHECK(crx_file::id_util::IdIsValid(extension_id)); 704 DCHECK(crx_file::id_util::IdIsValid(extension_id));
705 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, 705 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged,
706 new base::FundamentalValue(true)); 706 new base::FundamentalValue(true));
707 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL); 707 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL);
708 } 708 }
709 709
710 bool ExtensionPrefs::IsExternalInstallFirstRun( 710 bool ExtensionPrefs::IsExternalInstallFirstRun(
711 const std::string& extension_id) { 711 const std::string& extension_id) const {
712 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalInstallFirstRun); 712 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalInstallFirstRun);
713 } 713 }
714 714
715 void ExtensionPrefs::SetExternalInstallFirstRun( 715 void ExtensionPrefs::SetExternalInstallFirstRun(
716 const std::string& extension_id) { 716 const std::string& extension_id) {
717 DCHECK(crx_file::id_util::IdIsValid(extension_id)); 717 DCHECK(crx_file::id_util::IdIsValid(extension_id));
718 UpdateExtensionPref(extension_id, kPrefExternalInstallFirstRun, 718 UpdateExtensionPref(extension_id, kPrefExternalInstallFirstRun,
719 new base::FundamentalValue(true)); 719 new base::FundamentalValue(true));
720 } 720 }
721 721
722 bool ExtensionPrefs::SetAlertSystemFirstRun() { 722 bool ExtensionPrefs::SetAlertSystemFirstRun() {
723 if (prefs_->GetBoolean(pref_names::kAlertsInitialized)) { 723 if (prefs_->GetBoolean(pref_names::kAlertsInitialized)) {
724 return true; 724 return true;
725 } 725 }
726 prefs_->SetBoolean(pref_names::kAlertsInitialized, true); 726 prefs_->SetBoolean(pref_names::kAlertsInitialized, true);
727 return false; 727 return false;
728 } 728 }
729 729
730 bool ExtensionPrefs::DidExtensionEscalatePermissions( 730 bool ExtensionPrefs::DidExtensionEscalatePermissions(
731 const std::string& extension_id) { 731 const std::string& extension_id) const {
732 return ReadPrefAsBooleanAndReturn(extension_id, 732 return ReadPrefAsBooleanAndReturn(extension_id,
733 kExtensionDidEscalatePermissions); 733 kExtensionDidEscalatePermissions);
734 } 734 }
735 735
736 void ExtensionPrefs::SetDidExtensionEscalatePermissions( 736 void ExtensionPrefs::SetDidExtensionEscalatePermissions(
737 const Extension* extension, bool did_escalate) { 737 const Extension* extension, bool did_escalate) {
738 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, 738 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions,
739 new base::FundamentalValue(did_escalate)); 739 new base::FundamentalValue(did_escalate));
740 } 740 }
741 741
(...skipping 10 matching lines...) Expand all
752 const std::string& extension_id, 752 const std::string& extension_id,
753 Extension::DisableReason disable_reason) const { 753 Extension::DisableReason disable_reason) const {
754 return (GetDisableReasons(extension_id) & disable_reason) != 0; 754 return (GetDisableReasons(extension_id) & disable_reason) != 0;
755 } 755 }
756 756
757 void ExtensionPrefs::AddDisableReason(const std::string& extension_id, 757 void ExtensionPrefs::AddDisableReason(const std::string& extension_id,
758 Extension::DisableReason disable_reason) { 758 Extension::DisableReason disable_reason) {
759 ModifyDisableReasons(extension_id, disable_reason, DISABLE_REASON_ADD); 759 ModifyDisableReasons(extension_id, disable_reason, DISABLE_REASON_ADD);
760 } 760 }
761 761
762 void ExtensionPrefs::AddDisableReasons(const std::string& extension_id,
763 int disable_reasons) {
764 ModifyDisableReasons(extension_id, disable_reasons, DISABLE_REASON_ADD);
765 }
766
762 void ExtensionPrefs::RemoveDisableReason( 767 void ExtensionPrefs::RemoveDisableReason(
763 const std::string& extension_id, 768 const std::string& extension_id,
764 Extension::DisableReason disable_reason) { 769 Extension::DisableReason disable_reason) {
765 ModifyDisableReasons(extension_id, disable_reason, DISABLE_REASON_REMOVE); 770 ModifyDisableReasons(extension_id, disable_reason, DISABLE_REASON_REMOVE);
766 } 771 }
767 772
768 void ExtensionPrefs::ClearDisableReasons(const std::string& extension_id) { 773 void ExtensionPrefs::ClearDisableReasons(const std::string& extension_id) {
769 ModifyDisableReasons(extension_id, Extension::DISABLE_NONE, 774 ModifyDisableReasons(extension_id, Extension::DISABLE_NONE,
770 DISABLE_REASON_CLEAR); 775 DISABLE_REASON_CLEAR);
771 } 776 }
(...skipping 24 matching lines...) Expand all
796 UpdateExtensionPref(extension_id, 801 UpdateExtensionPref(extension_id,
797 kPrefDisableReasons, 802 kPrefDisableReasons,
798 new base::FundamentalValue(new_value)); 803 new base::FundamentalValue(new_value));
799 } 804 }
800 805
801 FOR_EACH_OBSERVER(ExtensionPrefsObserver, 806 FOR_EACH_OBSERVER(ExtensionPrefsObserver,
802 observer_list_, 807 observer_list_,
803 OnExtensionDisableReasonsChanged(extension_id, new_value)); 808 OnExtensionDisableReasonsChanged(extension_id, new_value));
804 } 809 }
805 810
806 std::set<std::string> ExtensionPrefs::GetBlacklistedExtensions() { 811 std::set<std::string> ExtensionPrefs::GetBlacklistedExtensions() const {
807 std::set<std::string> ids; 812 std::set<std::string> ids;
808 813
809 const base::DictionaryValue* extensions = 814 const base::DictionaryValue* extensions =
810 prefs_->GetDictionary(pref_names::kExtensions); 815 prefs_->GetDictionary(pref_names::kExtensions);
811 if (!extensions) 816 if (!extensions)
812 return ids; 817 return ids;
813 818
814 for (base::DictionaryValue::Iterator it(*extensions); 819 for (base::DictionaryValue::Iterator it(*extensions);
815 !it.IsAtEnd(); it.Advance()) { 820 !it.IsAtEnd(); it.Advance()) {
816 if (!it.value().IsType(base::Value::TYPE_DICTIONARY)) { 821 if (!it.value().IsType(base::Value::TYPE_DICTIONARY)) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 base::Time ExtensionPrefs::BlacklistLastPingDay() const { 919 base::Time ExtensionPrefs::BlacklistLastPingDay() const {
915 return ReadTime(prefs_->GetDictionary(kExtensionsBlacklistUpdate), 920 return ReadTime(prefs_->GetDictionary(kExtensionsBlacklistUpdate),
916 kLastPingDay); 921 kLastPingDay);
917 } 922 }
918 923
919 void ExtensionPrefs::SetBlacklistLastPingDay(const base::Time& time) { 924 void ExtensionPrefs::SetBlacklistLastPingDay(const base::Time& time) {
920 DictionaryPrefUpdate update(prefs_, kExtensionsBlacklistUpdate); 925 DictionaryPrefUpdate update(prefs_, kExtensionsBlacklistUpdate);
921 SaveTime(update.Get(), kLastPingDay, time); 926 SaveTime(update.Get(), kLastPingDay, time);
922 } 927 }
923 928
924 base::Time ExtensionPrefs::LastActivePingDay(const std::string& extension_id) { 929 base::Time ExtensionPrefs::LastActivePingDay(
930 const std::string& extension_id) const {
925 DCHECK(crx_file::id_util::IdIsValid(extension_id)); 931 DCHECK(crx_file::id_util::IdIsValid(extension_id));
926 return ReadTime(GetExtensionPref(extension_id), kLastActivePingDay); 932 return ReadTime(GetExtensionPref(extension_id), kLastActivePingDay);
927 } 933 }
928 934
929 void ExtensionPrefs::SetLastActivePingDay(const std::string& extension_id, 935 void ExtensionPrefs::SetLastActivePingDay(const std::string& extension_id,
930 const base::Time& time) { 936 const base::Time& time) {
931 DCHECK(crx_file::id_util::IdIsValid(extension_id)); 937 DCHECK(crx_file::id_util::IdIsValid(extension_id));
932 ScopedExtensionPrefUpdate update(prefs_, extension_id); 938 ScopedExtensionPrefUpdate update(prefs_, extension_id);
933 SaveTime(update.Get(), kLastActivePingDay, time); 939 SaveTime(update.Get(), kLastActivePingDay, time);
934 } 940 }
935 941
936 bool ExtensionPrefs::GetActiveBit(const std::string& extension_id) { 942 bool ExtensionPrefs::GetActiveBit(const std::string& extension_id) const {
937 const base::DictionaryValue* dictionary = GetExtensionPref(extension_id); 943 const base::DictionaryValue* dictionary = GetExtensionPref(extension_id);
938 bool result = false; 944 bool result = false;
939 if (dictionary && dictionary->GetBoolean(kActiveBit, &result)) 945 if (dictionary && dictionary->GetBoolean(kActiveBit, &result))
940 return result; 946 return result;
941 return false; 947 return false;
942 } 948 }
943 949
944 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, 950 void ExtensionPrefs::SetActiveBit(const std::string& extension_id,
945 bool active) { 951 bool active) {
946 UpdateExtensionPref(extension_id, kActiveBit, 952 UpdateExtensionPref(extension_id, kActiveBit,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 1025
1020 UpdateExtensionPref(*ext_id, kPrefDisableReasons, 1026 UpdateExtensionPref(*ext_id, kPrefDisableReasons,
1021 new base::FundamentalValue(new_value)); 1027 new base::FundamentalValue(new_value));
1022 // Remove the old disable reason. 1028 // Remove the old disable reason.
1023 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL); 1029 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL);
1024 } 1030 }
1025 } 1031 }
1026 } 1032 }
1027 1033
1028 PermissionSet* ExtensionPrefs::GetGrantedPermissions( 1034 PermissionSet* ExtensionPrefs::GetGrantedPermissions(
1029 const std::string& extension_id) { 1035 const std::string& extension_id) const {
1030 CHECK(crx_file::id_util::IdIsValid(extension_id)); 1036 CHECK(crx_file::id_util::IdIsValid(extension_id));
1031 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions); 1037 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions);
1032 } 1038 }
1033 1039
1034 void ExtensionPrefs::AddGrantedPermissions( 1040 void ExtensionPrefs::AddGrantedPermissions(
1035 const std::string& extension_id, 1041 const std::string& extension_id,
1036 const PermissionSet* permissions) { 1042 const PermissionSet* permissions) {
1037 CHECK(crx_file::id_util::IdIsValid(extension_id)); 1043 CHECK(crx_file::id_util::IdIsValid(extension_id));
1038 1044
1039 scoped_refptr<PermissionSet> granted_permissions( 1045 scoped_refptr<PermissionSet> granted_permissions(
(...skipping 21 matching lines...) Expand all
1061 // permissions and the newly ungranted permissions. 1067 // permissions and the newly ungranted permissions.
1062 scoped_refptr<PermissionSet> new_perms( 1068 scoped_refptr<PermissionSet> new_perms(
1063 PermissionSet::CreateDifference( 1069 PermissionSet::CreateDifference(
1064 granted_permissions.get(), permissions)); 1070 granted_permissions.get(), permissions));
1065 1071
1066 SetExtensionPrefPermissionSet( 1072 SetExtensionPrefPermissionSet(
1067 extension_id, kPrefGrantedPermissions, new_perms.get()); 1073 extension_id, kPrefGrantedPermissions, new_perms.get());
1068 } 1074 }
1069 1075
1070 PermissionSet* ExtensionPrefs::GetActivePermissions( 1076 PermissionSet* ExtensionPrefs::GetActivePermissions(
1071 const std::string& extension_id) { 1077 const std::string& extension_id) const {
1072 CHECK(crx_file::id_util::IdIsValid(extension_id)); 1078 CHECK(crx_file::id_util::IdIsValid(extension_id));
1073 return ReadPrefAsPermissionSet(extension_id, kPrefActivePermissions); 1079 return ReadPrefAsPermissionSet(extension_id, kPrefActivePermissions);
1074 } 1080 }
1075 1081
1076 void ExtensionPrefs::SetActivePermissions( 1082 void ExtensionPrefs::SetActivePermissions(
1077 const std::string& extension_id, 1083 const std::string& extension_id,
1078 const PermissionSet* permissions) { 1084 const PermissionSet* permissions) {
1079 SetExtensionPrefPermissionSet( 1085 SetExtensionPrefPermissionSet(
1080 extension_id, kPrefActivePermissions, permissions); 1086 extension_id, kPrefActivePermissions, permissions);
1081 } 1087 }
1082 1088
1083 void ExtensionPrefs::SetExtensionRunning(const std::string& extension_id, 1089 void ExtensionPrefs::SetExtensionRunning(const std::string& extension_id,
1084 bool is_running) { 1090 bool is_running) {
1085 base::Value* value = new base::FundamentalValue(is_running); 1091 base::Value* value = new base::FundamentalValue(is_running);
1086 UpdateExtensionPref(extension_id, kPrefRunning, value); 1092 UpdateExtensionPref(extension_id, kPrefRunning, value);
1087 } 1093 }
1088 1094
1089 bool ExtensionPrefs::IsExtensionRunning(const std::string& extension_id) { 1095 bool ExtensionPrefs::IsExtensionRunning(const std::string& extension_id) const {
1090 const base::DictionaryValue* extension = GetExtensionPref(extension_id); 1096 const base::DictionaryValue* extension = GetExtensionPref(extension_id);
1091 if (!extension) 1097 if (!extension)
1092 return false; 1098 return false;
1093 bool running = false; 1099 bool running = false;
1094 extension->GetBoolean(kPrefRunning, &running); 1100 extension->GetBoolean(kPrefRunning, &running);
1095 return running; 1101 return running;
1096 } 1102 }
1097 1103
1098 void ExtensionPrefs::SetIsActive(const std::string& extension_id, 1104 void ExtensionPrefs::SetIsActive(const std::string& extension_id,
1099 bool is_active) { 1105 bool is_active) {
1100 base::Value* value = new base::FundamentalValue(is_active); 1106 base::Value* value = new base::FundamentalValue(is_active);
1101 UpdateExtensionPref(extension_id, kIsActive, value); 1107 UpdateExtensionPref(extension_id, kIsActive, value);
1102 } 1108 }
1103 1109
1104 bool ExtensionPrefs::IsActive(const std::string& extension_id) { 1110 bool ExtensionPrefs::IsActive(const std::string& extension_id) const {
1105 const base::DictionaryValue* extension = GetExtensionPref(extension_id); 1111 const base::DictionaryValue* extension = GetExtensionPref(extension_id);
1106 if (!extension) 1112 if (!extension)
1107 return false; 1113 return false;
1108 bool is_active = false; 1114 bool is_active = false;
1109 extension->GetBoolean(kIsActive, &is_active); 1115 extension->GetBoolean(kIsActive, &is_active);
1110 return is_active; 1116 return is_active;
1111 } 1117 }
1112 1118
1113 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) const { 1119 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) const {
1114 return ReadPrefAsBooleanAndReturn(extension_id, kPrefIncognitoEnabled); 1120 return ReadPrefAsBooleanAndReturn(extension_id, kPrefIncognitoEnabled);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 bool ExtensionPrefs::IsExternalExtensionUninstalled( 1161 bool ExtensionPrefs::IsExternalExtensionUninstalled(
1156 const std::string& id) const { 1162 const std::string& id) const {
1157 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); 1163 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED);
1158 } 1164 }
1159 1165
1160 bool ExtensionPrefs::IsExtensionDisabled( 1166 bool ExtensionPrefs::IsExtensionDisabled(
1161 const std::string& id) const { 1167 const std::string& id) const {
1162 return DoesExtensionHaveState(id, Extension::DISABLED); 1168 return DoesExtensionHaveState(id, Extension::DISABLED);
1163 } 1169 }
1164 1170
1165 ExtensionIdList ExtensionPrefs::GetToolbarOrder() { 1171 ExtensionIdList ExtensionPrefs::GetToolbarOrder() const {
1166 ExtensionIdList id_list_out; 1172 ExtensionIdList id_list_out;
1167 GetUserExtensionPrefIntoContainer(pref_names::kToolbar, &id_list_out); 1173 GetUserExtensionPrefIntoContainer(pref_names::kToolbar, &id_list_out);
1168 return id_list_out; 1174 return id_list_out;
1169 } 1175 }
1170 1176
1171 void ExtensionPrefs::SetToolbarOrder(const ExtensionIdList& extension_ids) { 1177 void ExtensionPrefs::SetToolbarOrder(const ExtensionIdList& extension_ids) {
1172 SetExtensionPrefFromContainer(pref_names::kToolbar, extension_ids); 1178 SetExtensionPrefFromContainer(pref_names::kToolbar, extension_ids);
1173 } 1179 }
1174 1180
1175 void ExtensionPrefs::OnExtensionInstalled( 1181 void ExtensionPrefs::OnExtensionInstalled(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 } 1237 }
1232 1238
1233 void ExtensionPrefs::SetExtensionBlacklistState(const std::string& extension_id, 1239 void ExtensionPrefs::SetExtensionBlacklistState(const std::string& extension_id,
1234 BlacklistState state) { 1240 BlacklistState state) {
1235 SetExtensionBlacklisted(extension_id, state == BLACKLISTED_MALWARE); 1241 SetExtensionBlacklisted(extension_id, state == BLACKLISTED_MALWARE);
1236 UpdateExtensionPref(extension_id, kPrefBlacklistState, 1242 UpdateExtensionPref(extension_id, kPrefBlacklistState,
1237 new base::FundamentalValue(state)); 1243 new base::FundamentalValue(state));
1238 } 1244 }
1239 1245
1240 BlacklistState ExtensionPrefs::GetExtensionBlacklistState( 1246 BlacklistState ExtensionPrefs::GetExtensionBlacklistState(
1241 const std::string& extension_id) { 1247 const std::string& extension_id) const {
1242 if (IsExtensionBlacklisted(extension_id)) 1248 if (IsExtensionBlacklisted(extension_id))
1243 return BLACKLISTED_MALWARE; 1249 return BLACKLISTED_MALWARE;
1244 const base::DictionaryValue* ext_prefs = GetExtensionPref(extension_id); 1250 const base::DictionaryValue* ext_prefs = GetExtensionPref(extension_id);
1245 int int_value = 0; 1251 int int_value = 0;
1246 if (ext_prefs && ext_prefs->GetInteger(kPrefBlacklistState, &int_value)) 1252 if (ext_prefs && ext_prefs->GetInteger(kPrefBlacklistState, &int_value))
1247 return static_cast<BlacklistState>(int_value); 1253 return static_cast<BlacklistState>(int_value);
1248 1254
1249 return NOT_BLACKLISTED; 1255 return NOT_BLACKLISTED;
1250 } 1256 }
1251 1257
1252 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { 1258 std::string ExtensionPrefs::GetVersionString(
1259 const std::string& extension_id) const {
1253 const base::DictionaryValue* extension = GetExtensionPref(extension_id); 1260 const base::DictionaryValue* extension = GetExtensionPref(extension_id);
1254 if (!extension) 1261 if (!extension)
1255 return std::string(); 1262 return std::string();
1256 1263
1257 std::string version; 1264 std::string version;
1258 extension->GetString(kPrefVersion, &version); 1265 extension->GetString(kPrefVersion, &version);
1259 1266
1260 return version; 1267 return version;
1261 } 1268 }
1262 1269
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 if (ReadPrefAsInteger(extension_id, kPrefCreationFlags, &creation_flags)) { 1546 if (ReadPrefAsInteger(extension_id, kPrefCreationFlags, &creation_flags)) {
1540 if (creation_flags & Extension::IS_EPHEMERAL) { 1547 if (creation_flags & Extension::IS_EPHEMERAL) {
1541 creation_flags &= ~static_cast<int>(Extension::IS_EPHEMERAL); 1548 creation_flags &= ~static_cast<int>(Extension::IS_EPHEMERAL);
1542 UpdateExtensionPref(extension_id, 1549 UpdateExtensionPref(extension_id,
1543 kPrefCreationFlags, 1550 kPrefCreationFlags,
1544 new base::FundamentalValue(creation_flags)); 1551 new base::FundamentalValue(creation_flags));
1545 } 1552 }
1546 } 1553 }
1547 } 1554 }
1548 1555
1549 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) { 1556 bool ExtensionPrefs::WasAppDraggedByUser(
1557 const std::string& extension_id) const {
1550 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp); 1558 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp);
1551 } 1559 }
1552 1560
1553 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) { 1561 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) {
1554 UpdateExtensionPref(extension_id, kPrefUserDraggedApp, 1562 UpdateExtensionPref(extension_id, kPrefUserDraggedApp,
1555 new base::FundamentalValue(true)); 1563 new base::FundamentalValue(true));
1556 } 1564 }
1557 1565
1558 bool ExtensionPrefs::IsFromWebStore( 1566 bool ExtensionPrefs::IsFromWebStore(
1559 const std::string& extension_id) const { 1567 const std::string& extension_id) const {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 i.Advance()) { 1685 i.Advance()) {
1678 base::DictionaryValue* extension_dict = NULL; 1686 base::DictionaryValue* extension_dict = NULL;
1679 if (!update_dict->GetDictionary(i.key(), &extension_dict)) 1687 if (!update_dict->GetDictionary(i.key(), &extension_dict))
1680 continue; 1688 continue;
1681 1689
1682 if (extension_dict->HasKey(kPrefLastLaunchTime)) 1690 if (extension_dict->HasKey(kPrefLastLaunchTime))
1683 extension_dict->Remove(kPrefLastLaunchTime, NULL); 1691 extension_dict->Remove(kPrefLastLaunchTime, NULL);
1684 } 1692 }
1685 } 1693 }
1686 1694
1687 void ExtensionPrefs::GetExtensions(ExtensionIdList* out) { 1695 void ExtensionPrefs::GetExtensions(ExtensionIdList* out) const {
1688 CHECK(out); 1696 CHECK(out);
1689 1697
1690 scoped_ptr<ExtensionsInfo> extensions_info(GetInstalledExtensionsInfo()); 1698 scoped_ptr<ExtensionsInfo> extensions_info(GetInstalledExtensionsInfo());
1691 1699
1692 for (size_t i = 0; i < extensions_info->size(); ++i) { 1700 for (size_t i = 0; i < extensions_info->size(); ++i) {
1693 ExtensionInfo* info = extensions_info->at(i).get(); 1701 ExtensionInfo* info = extensions_info->at(i).get();
1694 out->push_back(info->extension_id); 1702 out->push_back(info->extension_id);
1695 } 1703 }
1696 } 1704 }
1697 1705
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 FixMissingPrefs(extension_ids); 1784 FixMissingPrefs(extension_ids);
1777 MigratePermissions(extension_ids); 1785 MigratePermissions(extension_ids);
1778 MigrateDisableReasons(extension_ids); 1786 MigrateDisableReasons(extension_ids);
1779 app_sorting_->Initialize(extension_ids); 1787 app_sorting_->Initialize(extension_ids);
1780 1788
1781 InitExtensionControlledPrefs(extension_pref_value_map_); 1789 InitExtensionControlledPrefs(extension_pref_value_map_);
1782 1790
1783 extension_pref_value_map_->NotifyInitializationCompleted(); 1791 extension_pref_value_map_->NotifyInitializationCompleted();
1784 } 1792 }
1785 1793
1786 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) { 1794 bool ExtensionPrefs::HasIncognitoPrefValue(const std::string& pref_key) const {
1787 bool has_incognito_pref_value = false; 1795 bool has_incognito_pref_value = false;
1788 extension_pref_value_map_->GetEffectivePrefValue(pref_key, 1796 extension_pref_value_map_->GetEffectivePrefValue(pref_key,
1789 true, 1797 true,
1790 &has_incognito_pref_value); 1798 &has_incognito_pref_value);
1791 return has_incognito_pref_value; 1799 return has_incognito_pref_value;
1792 } 1800 }
1793 1801
1794 const base::DictionaryValue* ExtensionPrefs::GetGeometryCache( 1802 const base::DictionaryValue* ExtensionPrefs::GetGeometryCache(
1795 const std::string& extension_id) const { 1803 const std::string& extension_id) const {
1796 const base::DictionaryValue* extension_prefs = GetExtensionPref(extension_id); 1804 const base::DictionaryValue* extension_prefs = GetExtensionPref(extension_id);
1797 if (!extension_prefs) 1805 if (!extension_prefs)
1798 return NULL; 1806 return NULL;
1799 1807
1800 const base::DictionaryValue* ext = NULL; 1808 const base::DictionaryValue* ext = NULL;
1801 if (!extension_prefs->GetDictionary(kPrefGeometryCache, &ext)) 1809 if (!extension_prefs->GetDictionary(kPrefGeometryCache, &ext))
1802 return NULL; 1810 return NULL;
1803 1811
1804 return ext; 1812 return ext;
1805 } 1813 }
1806 1814
1807 void ExtensionPrefs::SetGeometryCache( 1815 void ExtensionPrefs::SetGeometryCache(
1808 const std::string& extension_id, 1816 const std::string& extension_id,
1809 scoped_ptr<base::DictionaryValue> cache) { 1817 scoped_ptr<base::DictionaryValue> cache) {
1810 UpdateExtensionPref(extension_id, kPrefGeometryCache, cache.release()); 1818 UpdateExtensionPref(extension_id, kPrefGeometryCache, cache.release());
1811 } 1819 }
1812 1820
1813 const base::DictionaryValue* ExtensionPrefs::GetInstallSignature() { 1821 const base::DictionaryValue* ExtensionPrefs::GetInstallSignature() const {
1814 return prefs_->GetDictionary(kInstallSignature); 1822 return prefs_->GetDictionary(kInstallSignature);
1815 } 1823 }
1816 1824
1817 void ExtensionPrefs::SetInstallSignature( 1825 void ExtensionPrefs::SetInstallSignature(
1818 const base::DictionaryValue* signature) { 1826 const base::DictionaryValue* signature) {
1819 if (signature) { 1827 if (signature) {
1820 prefs_->Set(kInstallSignature, *signature); 1828 prefs_->Set(kInstallSignature, *signature);
1821 DVLOG(1) << "SetInstallSignature - saving"; 1829 DVLOG(1) << "SetInstallSignature - saving";
1822 } else { 1830 } else {
1823 DVLOG(1) << "SetInstallSignature - clearing"; 1831 DVLOG(1) << "SetInstallSignature - clearing";
(...skipping 12 matching lines...) Expand all
1836 return install_parameter; 1844 return install_parameter;
1837 } 1845 }
1838 1846
1839 void ExtensionPrefs::SetInstallParam(const std::string& extension_id, 1847 void ExtensionPrefs::SetInstallParam(const std::string& extension_id,
1840 const std::string& install_parameter) { 1848 const std::string& install_parameter) {
1841 UpdateExtensionPref(extension_id, 1849 UpdateExtensionPref(extension_id,
1842 kPrefInstallParam, 1850 kPrefInstallParam,
1843 new base::StringValue(install_parameter)); 1851 new base::StringValue(install_parameter));
1844 } 1852 }
1845 1853
1846 int ExtensionPrefs::GetCorruptedDisableCount() { 1854 int ExtensionPrefs::GetCorruptedDisableCount() const {
1847 return prefs_->GetInteger(kCorruptedDisableCount); 1855 return prefs_->GetInteger(kCorruptedDisableCount);
1848 } 1856 }
1849 1857
1850 void ExtensionPrefs::IncrementCorruptedDisableCount() { 1858 void ExtensionPrefs::IncrementCorruptedDisableCount() {
1851 int count = prefs_->GetInteger(kCorruptedDisableCount); 1859 int count = prefs_->GetInteger(kCorruptedDisableCount);
1852 prefs_->SetInteger(kCorruptedDisableCount, count + 1); 1860 prefs_->SetInteger(kCorruptedDisableCount, count + 1);
1853 } 1861 }
1854 1862
1855 ExtensionPrefs::ExtensionPrefs( 1863 ExtensionPrefs::ExtensionPrefs(
1856 PrefService* prefs, 1864 PrefService* prefs,
(...skipping 24 matching lines...) Expand all
1881 AddObserver(*iter); 1889 AddObserver(*iter);
1882 } 1890 }
1883 1891
1884 InitPrefStore(); 1892 InitPrefStore();
1885 } 1893 }
1886 1894
1887 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) { 1895 void ExtensionPrefs::SetNeedsStorageGarbageCollection(bool value) {
1888 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value); 1896 prefs_->SetBoolean(pref_names::kStorageGarbageCollect, value);
1889 } 1897 }
1890 1898
1891 bool ExtensionPrefs::NeedsStorageGarbageCollection() { 1899 bool ExtensionPrefs::NeedsStorageGarbageCollection() const {
1892 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect); 1900 return prefs_->GetBoolean(pref_names::kStorageGarbageCollect);
1893 } 1901 }
1894 1902
1895 // static 1903 // static
1896 void ExtensionPrefs::RegisterProfilePrefs( 1904 void ExtensionPrefs::RegisterProfilePrefs(
1897 user_prefs::PrefRegistrySyncable* registry) { 1905 user_prefs::PrefRegistrySyncable* registry) {
1898 registry->RegisterDictionaryPref(pref_names::kExtensions); 1906 registry->RegisterDictionaryPref(pref_names::kExtensions);
1899 registry->RegisterListPref(pref_names::kToolbar, 1907 registry->RegisterListPref(pref_names::kToolbar,
1900 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 1908 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
1901 registry->RegisterIntegerPref(pref_names::kToolbarSize, -1); 1909 registry->RegisterIntegerPref(pref_names::kToolbarSize, -1);
(...skipping 16 matching lines...) Expand all
1918 registry->RegisterIntegerPref(kCorruptedDisableCount, 0); 1926 registry->RegisterIntegerPref(kCorruptedDisableCount, 0);
1919 1927
1920 #if !defined(OS_MACOSX) 1928 #if !defined(OS_MACOSX)
1921 registry->RegisterBooleanPref(pref_names::kAppFullscreenAllowed, true); 1929 registry->RegisterBooleanPref(pref_names::kAppFullscreenAllowed, true);
1922 #endif 1930 #endif
1923 } 1931 }
1924 1932
1925 template <class ExtensionIdContainer> 1933 template <class ExtensionIdContainer>
1926 bool ExtensionPrefs::GetUserExtensionPrefIntoContainer( 1934 bool ExtensionPrefs::GetUserExtensionPrefIntoContainer(
1927 const char* pref, 1935 const char* pref,
1928 ExtensionIdContainer* id_container_out) { 1936 ExtensionIdContainer* id_container_out) const {
1929 DCHECK(id_container_out->empty()); 1937 DCHECK(id_container_out->empty());
1930 1938
1931 const base::Value* user_pref_value = prefs_->GetUserPrefValue(pref); 1939 const base::Value* user_pref_value = prefs_->GetUserPrefValue(pref);
1932 const base::ListValue* user_pref_as_list; 1940 const base::ListValue* user_pref_as_list;
1933 if (!user_pref_value || !user_pref_value->GetAsList(&user_pref_as_list)) 1941 if (!user_pref_value || !user_pref_value->GetAsList(&user_pref_as_list))
1934 return false; 1942 return false;
1935 1943
1936 std::insert_iterator<ExtensionIdContainer> insert_iterator( 1944 std::insert_iterator<ExtensionIdContainer> insert_iterator(
1937 *id_container_out, id_container_out->end()); 1945 *id_container_out, id_container_out->end());
1938 std::string extension_id; 1946 std::string extension_id;
(...skipping 20 matching lines...) Expand all
1959 list_of_values->Append(new base::StringValue(*iter)); 1967 list_of_values->Append(new base::StringValue(*iter));
1960 } 1968 }
1961 } 1969 }
1962 1970
1963 void ExtensionPrefs::PopulateExtensionInfoPrefs( 1971 void ExtensionPrefs::PopulateExtensionInfoPrefs(
1964 const Extension* extension, 1972 const Extension* extension,
1965 const base::Time install_time, 1973 const base::Time install_time,
1966 Extension::State initial_state, 1974 Extension::State initial_state,
1967 int install_flags, 1975 int install_flags,
1968 const std::string& install_parameter, 1976 const std::string& install_parameter,
1969 base::DictionaryValue* extension_dict) { 1977 base::DictionaryValue* extension_dict) const {
1970 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); 1978 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
1971 extension_dict->Set(kPrefLocation, 1979 extension_dict->Set(kPrefLocation,
1972 new base::FundamentalValue(extension->location())); 1980 new base::FundamentalValue(extension->location()));
1973 extension_dict->Set(kPrefCreationFlags, 1981 extension_dict->Set(kPrefCreationFlags,
1974 new base::FundamentalValue(extension->creation_flags())); 1982 new base::FundamentalValue(extension->creation_flags()));
1975 extension_dict->Set(kPrefFromWebStore, 1983 extension_dict->Set(kPrefFromWebStore,
1976 new base::FundamentalValue(extension->from_webstore())); 1984 new base::FundamentalValue(extension->from_webstore()));
1977 extension_dict->Set(kPrefFromBookmark, 1985 extension_dict->Set(kPrefFromBookmark,
1978 new base::FundamentalValue(extension->from_bookmark())); 1986 new base::FundamentalValue(extension->from_bookmark()));
1979 extension_dict->Set( 1987 extension_dict->Set(
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2109 extension_pref_value_map_->RegisterExtension( 2117 extension_pref_value_map_->RegisterExtension(
2110 extension_id, install_time, is_enabled, is_incognito_enabled); 2118 extension_id, install_time, is_enabled, is_incognito_enabled);
2111 2119
2112 FOR_EACH_OBSERVER( 2120 FOR_EACH_OBSERVER(
2113 ExtensionPrefsObserver, 2121 ExtensionPrefsObserver,
2114 observer_list_, 2122 observer_list_,
2115 OnExtensionRegistered(extension_id, install_time, is_enabled)); 2123 OnExtensionRegistered(extension_id, install_time, is_enabled));
2116 } 2124 }
2117 2125
2118 } // namespace extensions 2126 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698