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

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

Issue 22885002: c/b/extensions, json_schema_compiler: Do not use Value::Create*. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed C-style casts. Created 7 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/prefs/pref_notifier.h" 7 #include "base/prefs/pref_notifier.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 APIPermissionSet apis = new_value->apis(); 574 APIPermissionSet apis = new_value->apis();
575 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); 575 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs);
576 for (APIPermissionSet::const_iterator i = apis.begin(); 576 for (APIPermissionSet::const_iterator i = apis.begin();
577 i != apis.end(); ++i) { 577 i != apis.end(); ++i) {
578 scoped_ptr<Value> detail(i->ToValue()); 578 scoped_ptr<Value> detail(i->ToValue());
579 if (detail) { 579 if (detail) {
580 DictionaryValue* tmp = new DictionaryValue(); 580 DictionaryValue* tmp = new DictionaryValue();
581 tmp->Set(i->name(), detail.release()); 581 tmp->Set(i->name(), detail.release());
582 api_values->Append(tmp); 582 api_values->Append(tmp);
583 } else { 583 } else {
584 api_values->Append(Value::CreateStringValue(i->name())); 584 api_values->Append(new base::StringValue(i->name()));
585 } 585 }
586 } 586 }
587 UpdateExtensionPref(extension_id, api_pref, api_values); 587 UpdateExtensionPref(extension_id, api_pref, api_values);
588 588
589 // Set the explicit host permissions. 589 // Set the explicit host permissions.
590 if (!new_value->explicit_hosts().is_empty()) { 590 if (!new_value->explicit_hosts().is_empty()) {
591 SetExtensionPrefURLPatternSet(extension_id, 591 SetExtensionPrefURLPatternSet(extension_id,
592 JoinPrefs(pref_key, kPrefExplicitHosts), 592 JoinPrefs(pref_key, kPrefExplicitHosts),
593 new_value->explicit_hosts()); 593 new_value->explicit_hosts());
594 } 594 }
595 595
596 // Set the scriptable host permissions. 596 // Set the scriptable host permissions.
597 if (!new_value->scriptable_hosts().is_empty()) { 597 if (!new_value->scriptable_hosts().is_empty()) {
598 SetExtensionPrefURLPatternSet(extension_id, 598 SetExtensionPrefURLPatternSet(extension_id,
599 JoinPrefs(pref_key, kPrefScriptableHosts), 599 JoinPrefs(pref_key, kPrefScriptableHosts),
600 new_value->scriptable_hosts()); 600 new_value->scriptable_hosts());
601 } 601 }
602 } 602 }
603 603
604 int ExtensionPrefs::IncrementAcknowledgePromptCount( 604 int ExtensionPrefs::IncrementAcknowledgePromptCount(
605 const std::string& extension_id) { 605 const std::string& extension_id) {
606 int count = 0; 606 int count = 0;
607 ReadPrefAsInteger(extension_id, kPrefAcknowledgePromptCount, &count); 607 ReadPrefAsInteger(extension_id, kPrefAcknowledgePromptCount, &count);
608 ++count; 608 ++count;
609 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, 609 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount,
610 Value::CreateIntegerValue(count)); 610 new base::FundamentalValue(count));
611 return count; 611 return count;
612 } 612 }
613 613
614 bool ExtensionPrefs::IsExternalExtensionAcknowledged( 614 bool ExtensionPrefs::IsExternalExtensionAcknowledged(
615 const std::string& extension_id) { 615 const std::string& extension_id) {
616 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalAcknowledged); 616 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalAcknowledged);
617 } 617 }
618 618
619 void ExtensionPrefs::AcknowledgeExternalExtension( 619 void ExtensionPrefs::AcknowledgeExternalExtension(
620 const std::string& extension_id) { 620 const std::string& extension_id) {
621 DCHECK(Extension::IdIsValid(extension_id)); 621 DCHECK(Extension::IdIsValid(extension_id));
622 UpdateExtensionPref(extension_id, kPrefExternalAcknowledged, 622 UpdateExtensionPref(extension_id, kPrefExternalAcknowledged,
623 Value::CreateBooleanValue(true)); 623 new base::FundamentalValue(true));
624 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL); 624 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL);
625 } 625 }
626 626
627 bool ExtensionPrefs::IsBlacklistedExtensionAcknowledged( 627 bool ExtensionPrefs::IsBlacklistedExtensionAcknowledged(
628 const std::string& extension_id) { 628 const std::string& extension_id) {
629 return ReadPrefAsBooleanAndReturn(extension_id, kPrefBlacklistAcknowledged); 629 return ReadPrefAsBooleanAndReturn(extension_id, kPrefBlacklistAcknowledged);
630 } 630 }
631 631
632 void ExtensionPrefs::AcknowledgeBlacklistedExtension( 632 void ExtensionPrefs::AcknowledgeBlacklistedExtension(
633 const std::string& extension_id) { 633 const std::string& extension_id) {
634 DCHECK(Extension::IdIsValid(extension_id)); 634 DCHECK(Extension::IdIsValid(extension_id));
635 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, 635 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged,
636 Value::CreateBooleanValue(true)); 636 new base::FundamentalValue(true));
637 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL); 637 UpdateExtensionPref(extension_id, kPrefAcknowledgePromptCount, NULL);
638 } 638 }
639 639
640 bool ExtensionPrefs::IsExternalInstallFirstRun( 640 bool ExtensionPrefs::IsExternalInstallFirstRun(
641 const std::string& extension_id) { 641 const std::string& extension_id) {
642 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalInstallFirstRun); 642 return ReadPrefAsBooleanAndReturn(extension_id, kPrefExternalInstallFirstRun);
643 } 643 }
644 644
645 void ExtensionPrefs::SetExternalInstallFirstRun( 645 void ExtensionPrefs::SetExternalInstallFirstRun(
646 const std::string& extension_id) { 646 const std::string& extension_id) {
647 DCHECK(Extension::IdIsValid(extension_id)); 647 DCHECK(Extension::IdIsValid(extension_id));
648 UpdateExtensionPref(extension_id, kPrefExternalInstallFirstRun, 648 UpdateExtensionPref(extension_id, kPrefExternalInstallFirstRun,
649 Value::CreateBooleanValue(true)); 649 new base::FundamentalValue(true));
650 } 650 }
651 651
652 bool ExtensionPrefs::SetAlertSystemFirstRun() { 652 bool ExtensionPrefs::SetAlertSystemFirstRun() {
653 if (prefs_->GetBoolean(prefs::kExtensionAlertsInitializedPref)) { 653 if (prefs_->GetBoolean(prefs::kExtensionAlertsInitializedPref)) {
654 return true; 654 return true;
655 } 655 }
656 prefs_->SetBoolean(prefs::kExtensionAlertsInitializedPref, true); 656 prefs_->SetBoolean(prefs::kExtensionAlertsInitializedPref, true);
657 return false; 657 return false;
658 } 658 }
659 659
660 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const { 660 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const {
661 return admin_policy::BlacklistedByDefault( 661 return admin_policy::BlacklistedByDefault(
662 prefs_->GetList(prefs::kExtensionInstallDenyList)); 662 prefs_->GetList(prefs::kExtensionInstallDenyList));
663 } 663 }
664 664
665 bool ExtensionPrefs::DidExtensionEscalatePermissions( 665 bool ExtensionPrefs::DidExtensionEscalatePermissions(
666 const std::string& extension_id) { 666 const std::string& extension_id) {
667 return ReadPrefAsBooleanAndReturn(extension_id, 667 return ReadPrefAsBooleanAndReturn(extension_id,
668 kExtensionDidEscalatePermissions); 668 kExtensionDidEscalatePermissions);
669 } 669 }
670 670
671 void ExtensionPrefs::SetDidExtensionEscalatePermissions( 671 void ExtensionPrefs::SetDidExtensionEscalatePermissions(
672 const Extension* extension, bool did_escalate) { 672 const Extension* extension, bool did_escalate) {
673 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions, 673 UpdateExtensionPref(extension->id(), kExtensionDidEscalatePermissions,
674 Value::CreateBooleanValue(did_escalate)); 674 new base::FundamentalValue(did_escalate));
675 } 675 }
676 676
677 int ExtensionPrefs::GetDisableReasons(const std::string& extension_id) { 677 int ExtensionPrefs::GetDisableReasons(const std::string& extension_id) {
678 int value = -1; 678 int value = -1;
679 if (ReadPrefAsInteger(extension_id, kPrefDisableReasons, &value) && 679 if (ReadPrefAsInteger(extension_id, kPrefDisableReasons, &value) &&
680 value >= 0) { 680 value >= 0) {
681 return value; 681 return value;
682 } 682 }
683 return Extension::DISABLE_NONE; 683 return Extension::DISABLE_NONE;
684 } 684 }
685 685
686 void ExtensionPrefs::AddDisableReason(const std::string& extension_id, 686 void ExtensionPrefs::AddDisableReason(const std::string& extension_id,
687 Extension::DisableReason disable_reason) { 687 Extension::DisableReason disable_reason) {
688 int new_value = GetDisableReasons(extension_id) | 688 int new_value = GetDisableReasons(extension_id) |
689 static_cast<int>(disable_reason); 689 static_cast<int>(disable_reason);
690 UpdateExtensionPref(extension_id, kPrefDisableReasons, 690 UpdateExtensionPref(extension_id, kPrefDisableReasons,
691 Value::CreateIntegerValue(new_value)); 691 new base::FundamentalValue(new_value));
692 } 692 }
693 693
694 void ExtensionPrefs::RemoveDisableReason( 694 void ExtensionPrefs::RemoveDisableReason(
695 const std::string& extension_id, 695 const std::string& extension_id,
696 Extension::DisableReason disable_reason) { 696 Extension::DisableReason disable_reason) {
697 int new_value = GetDisableReasons(extension_id) & 697 int new_value = GetDisableReasons(extension_id) &
698 ~static_cast<int>(disable_reason); 698 ~static_cast<int>(disable_reason);
699 if (new_value == Extension::DISABLE_NONE) { 699 if (new_value == Extension::DISABLE_NONE) {
700 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL); 700 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL);
701 } else { 701 } else {
702 UpdateExtensionPref(extension_id, kPrefDisableReasons, 702 UpdateExtensionPref(extension_id, kPrefDisableReasons,
703 Value::CreateIntegerValue(new_value)); 703 new base::FundamentalValue(new_value));
704 } 704 }
705 } 705 }
706 706
707 void ExtensionPrefs::ClearDisableReasons(const std::string& extension_id) { 707 void ExtensionPrefs::ClearDisableReasons(const std::string& extension_id) {
708 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL); 708 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL);
709 } 709 }
710 710
711 std::set<std::string> ExtensionPrefs::GetBlacklistedExtensions() { 711 std::set<std::string> ExtensionPrefs::GetBlacklistedExtensions() {
712 std::set<std::string> ids; 712 std::set<std::string> ids;
713 713
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 const DictionaryValue* dictionary = GetExtensionPref(extension_id); 825 const DictionaryValue* dictionary = GetExtensionPref(extension_id);
826 bool result = false; 826 bool result = false;
827 if (dictionary && dictionary->GetBoolean(kActiveBit, &result)) 827 if (dictionary && dictionary->GetBoolean(kActiveBit, &result))
828 return result; 828 return result;
829 return false; 829 return false;
830 } 830 }
831 831
832 void ExtensionPrefs::SetActiveBit(const std::string& extension_id, 832 void ExtensionPrefs::SetActiveBit(const std::string& extension_id,
833 bool active) { 833 bool active) {
834 UpdateExtensionPref(extension_id, kActiveBit, 834 UpdateExtensionPref(extension_id, kActiveBit,
835 Value::CreateBooleanValue(active)); 835 new base::FundamentalValue(active));
836 } 836 }
837 837
838 void ExtensionPrefs::MigratePermissions(const ExtensionIdList& extension_ids) { 838 void ExtensionPrefs::MigratePermissions(const ExtensionIdList& extension_ids) {
839 PermissionsInfo* info = PermissionsInfo::GetInstance(); 839 PermissionsInfo* info = PermissionsInfo::GetInstance();
840 for (ExtensionIdList::const_iterator ext_id = 840 for (ExtensionIdList::const_iterator ext_id =
841 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) { 841 extension_ids.begin(); ext_id != extension_ids.end(); ++ext_id) {
842 842
843 // An extension's granted permissions need to be migrated if the 843 // An extension's granted permissions need to be migrated if the
844 // full_access bit is present. This bit was always present in the previous 844 // full_access bit is present. This bit was always present in the previous
845 // scheme and is never present now. 845 // scheme and is never present now.
(...skipping 13 matching lines...) Expand all
859 859
860 std::string granted_apis = 860 std::string granted_apis =
861 JoinPrefs(kPrefGrantedPermissions, kPrefAPIs); 861 JoinPrefs(kPrefGrantedPermissions, kPrefAPIs);
862 if (ext->GetList(kPrefOldGrantedAPIs, &apis)) 862 if (ext->GetList(kPrefOldGrantedAPIs, &apis))
863 new_apis = apis->DeepCopy(); 863 new_apis = apis->DeepCopy();
864 else 864 else
865 new_apis = new ListValue(); 865 new_apis = new ListValue();
866 866
867 std::string plugin_name = info->GetByID( 867 std::string plugin_name = info->GetByID(
868 APIPermission::kPlugin)->name(); 868 APIPermission::kPlugin)->name();
869 new_apis->Append(Value::CreateStringValue(plugin_name)); 869 new_apis->Append(new base::StringValue(plugin_name));
870 UpdateExtensionPref(*ext_id, granted_apis, new_apis); 870 UpdateExtensionPref(*ext_id, granted_apis, new_apis);
871 } 871 }
872 872
873 // The granted permissions originally only held the effective hosts, 873 // The granted permissions originally only held the effective hosts,
874 // which are a combination of host and user script host permissions. 874 // which are a combination of host and user script host permissions.
875 // We now maintain these lists separately. For migration purposes, it 875 // We now maintain these lists separately. For migration purposes, it
876 // does not matter how we treat the old effective hosts as long as the 876 // does not matter how we treat the old effective hosts as long as the
877 // new effective hosts will be the same, so we move them to explicit 877 // new effective hosts will be the same, so we move them to explicit
878 // host permissions. 878 // host permissions.
879 const ListValue* hosts = NULL; 879 const ListValue* hosts = NULL;
(...skipping 22 matching lines...) Expand all
902 break; 902 break;
903 case Extension::DEPRECATED_DISABLE_PERMISSIONS_INCREASE: 903 case Extension::DEPRECATED_DISABLE_PERMISSIONS_INCREASE:
904 new_value = Extension::DISABLE_PERMISSIONS_INCREASE; 904 new_value = Extension::DISABLE_PERMISSIONS_INCREASE;
905 break; 905 break;
906 case Extension::DEPRECATED_DISABLE_RELOAD: 906 case Extension::DEPRECATED_DISABLE_RELOAD:
907 new_value = Extension::DISABLE_RELOAD; 907 new_value = Extension::DISABLE_RELOAD;
908 break; 908 break;
909 } 909 }
910 910
911 UpdateExtensionPref(*ext_id, kPrefDisableReasons, 911 UpdateExtensionPref(*ext_id, kPrefDisableReasons,
912 Value::CreateIntegerValue(new_value)); 912 new base::FundamentalValue(new_value));
913 // Remove the old disable reason. 913 // Remove the old disable reason.
914 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL); 914 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL);
915 } 915 }
916 } 916 }
917 } 917 }
918 918
919 PermissionSet* ExtensionPrefs::GetGrantedPermissions( 919 PermissionSet* ExtensionPrefs::GetGrantedPermissions(
920 const std::string& extension_id) { 920 const std::string& extension_id) {
921 CHECK(Extension::IdIsValid(extension_id)); 921 CHECK(Extension::IdIsValid(extension_id));
922 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions); 922 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 966
967 void ExtensionPrefs::SetActivePermissions( 967 void ExtensionPrefs::SetActivePermissions(
968 const std::string& extension_id, 968 const std::string& extension_id,
969 const PermissionSet* permissions) { 969 const PermissionSet* permissions) {
970 SetExtensionPrefPermissionSet( 970 SetExtensionPrefPermissionSet(
971 extension_id, kPrefActivePermissions, permissions); 971 extension_id, kPrefActivePermissions, permissions);
972 } 972 }
973 973
974 void ExtensionPrefs::SetExtensionRunning(const std::string& extension_id, 974 void ExtensionPrefs::SetExtensionRunning(const std::string& extension_id,
975 bool is_running) { 975 bool is_running) {
976 Value* value = Value::CreateBooleanValue(is_running); 976 Value* value = new base::FundamentalValue(is_running);
977 UpdateExtensionPref(extension_id, kPrefRunning, value); 977 UpdateExtensionPref(extension_id, kPrefRunning, value);
978 } 978 }
979 979
980 bool ExtensionPrefs::IsExtensionRunning(const std::string& extension_id) { 980 bool ExtensionPrefs::IsExtensionRunning(const std::string& extension_id) {
981 const DictionaryValue* extension = GetExtensionPref(extension_id); 981 const DictionaryValue* extension = GetExtensionPref(extension_id);
982 if (!extension) 982 if (!extension)
983 return false; 983 return false;
984 bool running = false; 984 bool running = false;
985 extension->GetBoolean(kPrefRunning, &running); 985 extension->GetBoolean(kPrefRunning, &running);
986 return running; 986 return running;
987 } 987 }
988 988
989 void ExtensionPrefs::SetIsActive(const std::string& extension_id, 989 void ExtensionPrefs::SetIsActive(const std::string& extension_id,
990 bool is_active) { 990 bool is_active) {
991 Value* value = Value::CreateBooleanValue(is_active); 991 Value* value = new base::FundamentalValue(is_active);
992 UpdateExtensionPref(extension_id, kIsActive, value); 992 UpdateExtensionPref(extension_id, kIsActive, value);
993 } 993 }
994 994
995 bool ExtensionPrefs::IsActive(const std::string& extension_id) { 995 bool ExtensionPrefs::IsActive(const std::string& extension_id) {
996 const DictionaryValue* extension = GetExtensionPref(extension_id); 996 const DictionaryValue* extension = GetExtensionPref(extension_id);
997 if (!extension) 997 if (!extension)
998 return false; 998 return false;
999 bool is_active = false; 999 bool is_active = false;
1000 extension->GetBoolean(kIsActive, &is_active); 1000 extension->GetBoolean(kIsActive, &is_active);
1001 return is_active; 1001 return is_active;
1002 } 1002 }
1003 1003
1004 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { 1004 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) {
1005 return ReadPrefAsBooleanAndReturn(extension_id, kPrefIncognitoEnabled); 1005 return ReadPrefAsBooleanAndReturn(extension_id, kPrefIncognitoEnabled);
1006 } 1006 }
1007 1007
1008 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, 1008 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id,
1009 bool enabled) { 1009 bool enabled) {
1010 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, 1010 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled,
1011 Value::CreateBooleanValue(enabled)); 1011 new base::FundamentalValue(enabled));
1012 } 1012 }
1013 1013
1014 bool ExtensionPrefs::AllowFileAccess(const std::string& extension_id) { 1014 bool ExtensionPrefs::AllowFileAccess(const std::string& extension_id) {
1015 return ReadPrefAsBooleanAndReturn(extension_id, kPrefAllowFileAccess); 1015 return ReadPrefAsBooleanAndReturn(extension_id, kPrefAllowFileAccess);
1016 } 1016 }
1017 1017
1018 void ExtensionPrefs::SetAllowFileAccess(const std::string& extension_id, 1018 void ExtensionPrefs::SetAllowFileAccess(const std::string& extension_id,
1019 bool allow) { 1019 bool allow) {
1020 UpdateExtensionPref(extension_id, kPrefAllowFileAccess, 1020 UpdateExtensionPref(extension_id, kPrefAllowFileAccess,
1021 Value::CreateBooleanValue(allow)); 1021 new base::FundamentalValue(allow));
1022 } 1022 }
1023 1023
1024 bool ExtensionPrefs::HasAllowFileAccessSetting( 1024 bool ExtensionPrefs::HasAllowFileAccessSetting(
1025 const std::string& extension_id) const { 1025 const std::string& extension_id) const {
1026 const DictionaryValue* ext = GetExtensionPref(extension_id); 1026 const DictionaryValue* ext = GetExtensionPref(extension_id);
1027 return ext && ext->HasKey(kPrefAllowFileAccess); 1027 return ext && ext->HasKey(kPrefAllowFileAccess);
1028 } 1028 }
1029 1029
1030 ExtensionPrefs::LaunchType ExtensionPrefs::GetLaunchType( 1030 ExtensionPrefs::LaunchType ExtensionPrefs::GetLaunchType(
1031 const Extension* extension, 1031 const Extension* extension,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 DLOG(FATAL) << "Failed to set a launch container."; 1117 DLOG(FATAL) << "Failed to set a launch container.";
1118 result = extension_misc::LAUNCH_TAB; 1118 result = extension_misc::LAUNCH_TAB;
1119 } 1119 }
1120 1120
1121 return result; 1121 return result;
1122 } 1122 }
1123 1123
1124 void ExtensionPrefs::SetLaunchType(const std::string& extension_id, 1124 void ExtensionPrefs::SetLaunchType(const std::string& extension_id,
1125 LaunchType launch_type) { 1125 LaunchType launch_type) {
1126 UpdateExtensionPref(extension_id, kPrefLaunchType, 1126 UpdateExtensionPref(extension_id, kPrefLaunchType,
1127 Value::CreateIntegerValue(static_cast<int>(launch_type))); 1127 new base::FundamentalValue(static_cast<int>(launch_type)));
1128 } 1128 }
1129 1129
1130 bool ExtensionPrefs::DoesExtensionHaveState( 1130 bool ExtensionPrefs::DoesExtensionHaveState(
1131 const std::string& id, Extension::State check_state) const { 1131 const std::string& id, Extension::State check_state) const {
1132 const DictionaryValue* extension = GetExtensionPref(id); 1132 const DictionaryValue* extension = GetExtensionPref(id);
1133 int state = -1; 1133 int state = -1;
1134 if (!extension || !extension->GetInteger(kPrefState, &state)) 1134 if (!extension || !extension->GetInteger(kPrefState, &state))
1135 return false; 1135 return false;
1136 1136
1137 if (state < 0 || state >= Extension::NUM_STATES) { 1137 if (state < 0 || state >= Extension::NUM_STATES) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 const Manifest::Location& location, 1179 const Manifest::Location& location,
1180 bool external_uninstall) { 1180 bool external_uninstall) {
1181 extension_sorting_->ClearOrdinals(extension_id); 1181 extension_sorting_->ClearOrdinals(extension_id);
1182 1182
1183 // For external extensions, we save a preference reminding ourself not to try 1183 // For external extensions, we save a preference reminding ourself not to try
1184 // and install the extension anymore (except when |external_uninstall| is 1184 // and install the extension anymore (except when |external_uninstall| is
1185 // true, which signifies that the registry key was deleted or the pref file 1185 // true, which signifies that the registry key was deleted or the pref file
1186 // no longer lists the extension). 1186 // no longer lists the extension).
1187 if (!external_uninstall && Manifest::IsExternalLocation(location)) { 1187 if (!external_uninstall && Manifest::IsExternalLocation(location)) {
1188 UpdateExtensionPref(extension_id, kPrefState, 1188 UpdateExtensionPref(extension_id, kPrefState,
1189 Value::CreateIntegerValue( 1189 new base::FundamentalValue(
1190 Extension::EXTERNAL_EXTENSION_UNINSTALLED)); 1190 Extension::EXTERNAL_EXTENSION_UNINSTALLED));
1191 extension_pref_value_map_->SetExtensionState(extension_id, false); 1191 extension_pref_value_map_->SetExtensionState(extension_id, false);
1192 content_settings_store_->SetExtensionState(extension_id, false); 1192 content_settings_store_->SetExtensionState(extension_id, false);
1193 } else { 1193 } else {
1194 DeleteExtensionPrefs(extension_id); 1194 DeleteExtensionPrefs(extension_id);
1195 } 1195 }
1196 } 1196 }
1197 1197
1198 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, 1198 void ExtensionPrefs::SetExtensionState(const std::string& extension_id,
1199 Extension::State state) { 1199 Extension::State state) {
1200 UpdateExtensionPref(extension_id, kPrefState, 1200 UpdateExtensionPref(extension_id, kPrefState,
1201 Value::CreateIntegerValue(state)); 1201 new base::FundamentalValue(state));
1202 bool enabled = (state == Extension::ENABLED); 1202 bool enabled = (state == Extension::ENABLED);
1203 extension_pref_value_map_->SetExtensionState(extension_id, enabled); 1203 extension_pref_value_map_->SetExtensionState(extension_id, enabled);
1204 content_settings_store_->SetExtensionState(extension_id, enabled); 1204 content_settings_store_->SetExtensionState(extension_id, enabled);
1205 } 1205 }
1206 1206
1207 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { 1207 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) {
1208 const DictionaryValue* extension = GetExtensionPref(extension_id); 1208 const DictionaryValue* extension = GetExtensionPref(extension_id);
1209 if (!extension) 1209 if (!extension)
1210 return std::string(); 1210 return std::string();
1211 1211
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 &serialized_ordinal)) { 1381 &serialized_ordinal)) {
1382 suggested_page_ordinal = syncer::StringOrdinal(serialized_ordinal); 1382 suggested_page_ordinal = syncer::StringOrdinal(serialized_ordinal);
1383 needs_sort_ordinal = true; 1383 needs_sort_ordinal = true;
1384 pending_install_dict->Remove(kPrefSuggestedPageOrdinal, NULL); 1384 pending_install_dict->Remove(kPrefSuggestedPageOrdinal, NULL);
1385 } 1385 }
1386 pending_install_dict->Remove(kDelayedInstallReason, NULL); 1386 pending_install_dict->Remove(kDelayedInstallReason, NULL);
1387 1387
1388 const base::Time install_time = time_provider_->GetCurrentTime(); 1388 const base::Time install_time = time_provider_->GetCurrentTime();
1389 pending_install_dict->Set( 1389 pending_install_dict->Set(
1390 kPrefInstallTime, 1390 kPrefInstallTime,
1391 Value::CreateStringValue( 1391 new base::StringValue(
1392 base::Int64ToString(install_time.ToInternalValue()))); 1392 base::Int64ToString(install_time.ToInternalValue())));
1393 1393
1394 // Commit the delayed install data. 1394 // Commit the delayed install data.
1395 extension_dict->MergeDictionary(pending_install_dict); 1395 extension_dict->MergeDictionary(pending_install_dict);
1396 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal, 1396 FinishExtensionInfoPrefs(extension_id, install_time, needs_sort_ordinal,
1397 suggested_page_ordinal, extension_dict); 1397 suggested_page_ordinal, extension_dict);
1398 return true; 1398 return true;
1399 } 1399 }
1400 1400
1401 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo( 1401 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetDelayedInstallInfo(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 1447
1448 return extensions_info.Pass(); 1448 return extensions_info.Pass();
1449 } 1449 }
1450 1450
1451 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) { 1451 bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) {
1452 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp); 1452 return ReadPrefAsBooleanAndReturn(extension_id, kPrefUserDraggedApp);
1453 } 1453 }
1454 1454
1455 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) { 1455 void ExtensionPrefs::SetAppDraggedByUser(const std::string& extension_id) {
1456 UpdateExtensionPref(extension_id, kPrefUserDraggedApp, 1456 UpdateExtensionPref(extension_id, kPrefUserDraggedApp,
1457 Value::CreateBooleanValue(true)); 1457 new base::FundamentalValue(true));
1458 } 1458 }
1459 1459
1460 bool ExtensionPrefs::IsFromWebStore( 1460 bool ExtensionPrefs::IsFromWebStore(
1461 const std::string& extension_id) const { 1461 const std::string& extension_id) const {
1462 const DictionaryValue* dictionary = GetExtensionPref(extension_id); 1462 const DictionaryValue* dictionary = GetExtensionPref(extension_id);
1463 bool result = false; 1463 bool result = false;
1464 if (dictionary && dictionary->GetBoolean(kPrefFromWebStore, &result)) 1464 if (dictionary && dictionary->GetBoolean(kPrefFromWebStore, &result))
1465 return result; 1465 return result;
1466 return false; 1466 return false;
1467 } 1467 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 for (ExtensionIdList::const_iterator ext_id = extension_ids.begin(); 1569 for (ExtensionIdList::const_iterator ext_id = extension_ids.begin();
1570 ext_id != extension_ids.end(); ++ext_id) { 1570 ext_id != extension_ids.end(); ++ext_id) {
1571 if (GetInstallTime(*ext_id) == base::Time()) { 1571 if (GetInstallTime(*ext_id) == base::Time()) {
1572 LOG(INFO) << "Could not parse installation time of extension " 1572 LOG(INFO) << "Could not parse installation time of extension "
1573 << *ext_id << ". It was probably installed before setting " 1573 << *ext_id << ". It was probably installed before setting "
1574 << kPrefInstallTime << " was introduced. Updating " 1574 << kPrefInstallTime << " was introduced. Updating "
1575 << kPrefInstallTime << " to the current time."; 1575 << kPrefInstallTime << " to the current time.";
1576 const base::Time install_time = time_provider_->GetCurrentTime(); 1576 const base::Time install_time = time_provider_->GetCurrentTime();
1577 UpdateExtensionPref(*ext_id, 1577 UpdateExtensionPref(*ext_id,
1578 kPrefInstallTime, 1578 kPrefInstallTime,
1579 Value::CreateStringValue(base::Int64ToString( 1579 new base::StringValue(base::Int64ToString(
1580 install_time.ToInternalValue()))); 1580 install_time.ToInternalValue())));
1581 } 1581 }
1582 } 1582 }
1583 } 1583 }
1584 1584
1585 void ExtensionPrefs::InitPrefStore() { 1585 void ExtensionPrefs::InitPrefStore() {
1586 if (extensions_disabled_) { 1586 if (extensions_disabled_) {
1587 extension_pref_value_map_->NotifyInitializationCompleted(); 1587 extension_pref_value_map_->NotifyInitializationCompleted();
1588 return; 1588 return;
1589 } 1589 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 } 1754 }
1755 1755
1756 void ExtensionPrefs::SetExtensionPrefFromVector( 1756 void ExtensionPrefs::SetExtensionPrefFromVector(
1757 const char* pref, 1757 const char* pref,
1758 const ExtensionIdList& strings) { 1758 const ExtensionIdList& strings) {
1759 ListPrefUpdate update(prefs_, pref); 1759 ListPrefUpdate update(prefs_, pref);
1760 ListValue* list_of_values = update.Get(); 1760 ListValue* list_of_values = update.Get();
1761 list_of_values->Clear(); 1761 list_of_values->Clear();
1762 for (ExtensionIdList::const_iterator iter = strings.begin(); 1762 for (ExtensionIdList::const_iterator iter = strings.begin();
1763 iter != strings.end(); ++iter) 1763 iter != strings.end(); ++iter)
1764 list_of_values->Append(new StringValue(*iter)); 1764 list_of_values->Append(new base::StringValue(*iter));
1765 } 1765 }
1766 1766
1767 void ExtensionPrefs::PopulateExtensionInfoPrefs( 1767 void ExtensionPrefs::PopulateExtensionInfoPrefs(
1768 const Extension* extension, 1768 const Extension* extension,
1769 const base::Time install_time, 1769 const base::Time install_time,
1770 Extension::State initial_state, 1770 Extension::State initial_state,
1771 Blacklist::BlacklistState blacklist_state, 1771 Blacklist::BlacklistState blacklist_state,
1772 DictionaryValue* extension_dict) { 1772 DictionaryValue* extension_dict) {
1773 // Leave the state blank for component extensions so that old chrome versions 1773 // Leave the state blank for component extensions so that old chrome versions
1774 // loading new profiles do not fail in GetInstalledExtensionInfo. Older 1774 // loading new profiles do not fail in GetInstalledExtensionInfo. Older
1775 // Chrome versions would only check for an omitted state. 1775 // Chrome versions would only check for an omitted state.
1776 if (initial_state != Extension::ENABLED_COMPONENT) 1776 if (initial_state != Extension::ENABLED_COMPONENT)
1777 extension_dict->Set(kPrefState, Value::CreateIntegerValue(initial_state)); 1777 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
1778 1778
1779 extension_dict->Set(kPrefLocation, 1779 extension_dict->Set(kPrefLocation,
1780 Value::CreateIntegerValue(extension->location())); 1780 new base::FundamentalValue(extension->location()));
1781 extension_dict->Set(kPrefCreationFlags, 1781 extension_dict->Set(kPrefCreationFlags,
1782 Value::CreateIntegerValue(extension->creation_flags())); 1782 new base::FundamentalValue(extension->creation_flags()));
1783 extension_dict->Set(kPrefFromWebStore, 1783 extension_dict->Set(kPrefFromWebStore,
1784 Value::CreateBooleanValue(extension->from_webstore())); 1784 new base::FundamentalValue(extension->from_webstore()));
1785 extension_dict->Set(kPrefFromBookmark, 1785 extension_dict->Set(kPrefFromBookmark,
1786 Value::CreateBooleanValue(extension->from_bookmark())); 1786 new base::FundamentalValue(extension->from_bookmark()));
1787 extension_dict->Set( 1787 extension_dict->Set(
1788 kPrefWasInstalledByDefault, 1788 kPrefWasInstalledByDefault,
1789 Value::CreateBooleanValue(extension->was_installed_by_default())); 1789 new base::FundamentalValue(extension->was_installed_by_default()));
1790 extension_dict->Set(kPrefInstallTime, 1790 extension_dict->Set(kPrefInstallTime,
1791 Value::CreateStringValue( 1791 new base::StringValue(
1792 base::Int64ToString(install_time.ToInternalValue()))); 1792 base::Int64ToString(install_time.ToInternalValue())));
1793 if (blacklist_state == Blacklist::BLACKLISTED) 1793 if (blacklist_state == Blacklist::BLACKLISTED)
1794 extension_dict->Set(kPrefBlacklist, Value::CreateBooleanValue(true)); 1794 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true));
1795 1795
1796 base::FilePath::StringType path = MakePathRelative(install_directory_, 1796 base::FilePath::StringType path = MakePathRelative(install_directory_,
1797 extension->path()); 1797 extension->path());
1798 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); 1798 extension_dict->Set(kPrefPath, new base::StringValue(path));
1799 // We store prefs about LOAD extensions, but don't cache their manifest 1799 // We store prefs about LOAD extensions, but don't cache their manifest
1800 // since it may change on disk. 1800 // since it may change on disk.
1801 if (!Manifest::IsUnpackedLocation(extension->location())) { 1801 if (!Manifest::IsUnpackedLocation(extension->location())) {
1802 extension_dict->Set(kPrefManifest, 1802 extension_dict->Set(kPrefManifest,
1803 extension->manifest()->value()->DeepCopy()); 1803 extension->manifest()->value()->DeepCopy());
1804 } 1804 }
1805 } 1805 }
1806 1806
1807 void ExtensionPrefs::FinishExtensionInfoPrefs( 1807 void ExtensionPrefs::FinishExtensionInfoPrefs(
1808 const std::string& extension_id, 1808 const std::string& extension_id,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1842 is_enabled = initial_state == Extension::ENABLED; 1842 is_enabled = initial_state == Extension::ENABLED;
1843 } 1843 }
1844 1844
1845 extension_pref_value_map_->RegisterExtension(extension_id, install_time, 1845 extension_pref_value_map_->RegisterExtension(extension_id, install_time,
1846 is_enabled); 1846 is_enabled);
1847 content_settings_store_->RegisterExtension(extension_id, install_time, 1847 content_settings_store_->RegisterExtension(extension_id, install_time,
1848 is_enabled); 1848 is_enabled);
1849 } 1849 }
1850 1850
1851 } // namespace extensions 1851 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_pref_value_map_unittest.cc ('k') | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698