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

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

Issue 1349613003: [Extensions] Un-refcount PermissionSet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 UpdateExtensionPref(extension_id, pref_key, new_value.ToValue().release()); 549 UpdateExtensionPref(extension_id, pref_key, new_value.ToValue().release());
550 } 550 }
551 551
552 bool ExtensionPrefs::ReadPrefAsBooleanAndReturn( 552 bool ExtensionPrefs::ReadPrefAsBooleanAndReturn(
553 const std::string& extension_id, 553 const std::string& extension_id,
554 const std::string& pref_key) const { 554 const std::string& pref_key) const {
555 bool out_value = false; 555 bool out_value = false;
556 return ReadPrefAsBoolean(extension_id, pref_key, &out_value) && out_value; 556 return ReadPrefAsBoolean(extension_id, pref_key, &out_value) && out_value;
557 } 557 }
558 558
559 scoped_refptr<const PermissionSet> ExtensionPrefs::ReadPrefAsPermissionSet( 559 scoped_ptr<const PermissionSet> ExtensionPrefs::ReadPrefAsPermissionSet(
560 const std::string& extension_id, 560 const std::string& extension_id,
561 const std::string& pref_key) const { 561 const std::string& pref_key) const {
562 if (!GetExtensionPref(extension_id)) 562 if (!GetExtensionPref(extension_id))
563 return nullptr; 563 return nullptr;
564 564
565 // Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet() 565 // Retrieve the API permissions. Please refer SetExtensionPrefPermissionSet()
566 // for api_values format. 566 // for api_values format.
567 APIPermissionSet apis; 567 APIPermissionSet apis;
568 const base::ListValue* api_values = NULL; 568 const base::ListValue* api_values = NULL;
569 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs); 569 std::string api_pref = JoinPrefs(pref_key, kPrefAPIs);
(...skipping 20 matching lines...) Expand all
590 ReadPrefAsURLPatternSet( 590 ReadPrefAsURLPatternSet(
591 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts), 591 extension_id, JoinPrefs(pref_key, kPrefExplicitHosts),
592 &explicit_hosts, Extension::kValidHostPermissionSchemes); 592 &explicit_hosts, Extension::kValidHostPermissionSchemes);
593 593
594 // Retrieve the scriptable host permissions. 594 // Retrieve the scriptable host permissions.
595 URLPatternSet scriptable_hosts; 595 URLPatternSet scriptable_hosts;
596 ReadPrefAsURLPatternSet( 596 ReadPrefAsURLPatternSet(
597 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts), 597 extension_id, JoinPrefs(pref_key, kPrefScriptableHosts),
598 &scriptable_hosts, UserScript::ValidUserScriptSchemes()); 598 &scriptable_hosts, UserScript::ValidUserScriptSchemes());
599 599
600 return make_scoped_refptr(new PermissionSet( 600 return make_scoped_ptr(new PermissionSet(apis, manifest_permissions,
601 apis, manifest_permissions, explicit_hosts, scriptable_hosts)); 601 explicit_hosts, scriptable_hosts));
602 } 602 }
603 603
604 // Set the API or Manifest permissions. 604 // Set the API or Manifest permissions.
605 // The format of api_values is: 605 // The format of api_values is:
606 // [ "permission_name1", // permissions do not support detail. 606 // [ "permission_name1", // permissions do not support detail.
607 // "permission_name2", 607 // "permission_name2",
608 // {"permission_name3": value }, 608 // {"permission_name3": value },
609 // // permission supports detail, permission detail will be stored in value. 609 // // permission supports detail, permission detail will be stored in value.
610 // ... 610 // ...
611 // ] 611 // ]
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 } 1007 }
1008 1008
1009 UpdateExtensionPref(*ext_id, kPrefDisableReasons, 1009 UpdateExtensionPref(*ext_id, kPrefDisableReasons,
1010 new base::FundamentalValue(new_value)); 1010 new base::FundamentalValue(new_value));
1011 // Remove the old disable reason. 1011 // Remove the old disable reason.
1012 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL); 1012 UpdateExtensionPref(*ext_id, kDeprecatedPrefDisableReason, NULL);
1013 } 1013 }
1014 } 1014 }
1015 } 1015 }
1016 1016
1017 scoped_refptr<const PermissionSet> ExtensionPrefs::GetGrantedPermissions( 1017 scoped_ptr<const PermissionSet> ExtensionPrefs::GetGrantedPermissions(
1018 const std::string& extension_id) const { 1018 const std::string& extension_id) const {
1019 CHECK(crx_file::id_util::IdIsValid(extension_id)); 1019 CHECK(crx_file::id_util::IdIsValid(extension_id));
1020 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions); 1020 return ReadPrefAsPermissionSet(extension_id, kPrefGrantedPermissions);
1021 } 1021 }
1022 1022
1023 void ExtensionPrefs::AddGrantedPermissions( 1023 void ExtensionPrefs::AddGrantedPermissions(
1024 const std::string& extension_id, 1024 const std::string& extension_id,
1025 const PermissionSet* permissions) { 1025 const PermissionSet* permissions) {
1026 CHECK(crx_file::id_util::IdIsValid(extension_id)); 1026 CHECK(crx_file::id_util::IdIsValid(extension_id));
1027 DCHECK(permissions); 1027 DCHECK(permissions);
1028 1028
1029 scoped_refptr<const PermissionSet> granted = 1029 scoped_ptr<const PermissionSet> granted = GetGrantedPermissions(extension_id);
1030 GetGrantedPermissions(extension_id); 1030 scoped_ptr<const PermissionSet> union_set;
1031 granted = granted.get() ? PermissionSet::CreateUnion(*permissions, *granted) 1031 if (granted)
1032 : permissions; 1032 union_set = PermissionSet::CreateUnion(*permissions, *granted);
1033 // The new granted permissions are the union of the already granted 1033 // The new granted permissions are the union of the already granted
1034 // permissions and the newly granted permissions. 1034 // permissions and the newly granted permissions.
1035 SetExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions, 1035 SetExtensionPrefPermissionSet(extension_id, kPrefGrantedPermissions,
1036 granted.get()); 1036 union_set ? union_set.get() : permissions);
1037 } 1037 }
1038 1038
1039 void ExtensionPrefs::RemoveGrantedPermissions( 1039 void ExtensionPrefs::RemoveGrantedPermissions(
1040 const std::string& extension_id, 1040 const std::string& extension_id,
1041 const PermissionSet* permissions) { 1041 const PermissionSet* permissions) {
1042 CHECK(crx_file::id_util::IdIsValid(extension_id)); 1042 CHECK(crx_file::id_util::IdIsValid(extension_id));
1043 1043
1044 // The new granted permissions are the difference of the already granted 1044 // The new granted permissions are the difference of the already granted
1045 // permissions and the newly ungranted permissions. 1045 // permissions and the newly ungranted permissions.
1046 SetExtensionPrefPermissionSet( 1046 SetExtensionPrefPermissionSet(
1047 extension_id, kPrefGrantedPermissions, 1047 extension_id, kPrefGrantedPermissions,
1048 PermissionSet::CreateDifference(*GetGrantedPermissions(extension_id), 1048 PermissionSet::CreateDifference(*GetGrantedPermissions(extension_id),
1049 *permissions) 1049 *permissions)
1050 .get()); 1050 .get());
1051 } 1051 }
1052 1052
1053 scoped_refptr<const PermissionSet> ExtensionPrefs::GetActivePermissions( 1053 scoped_ptr<const PermissionSet> ExtensionPrefs::GetActivePermissions(
1054 const std::string& extension_id) const { 1054 const std::string& extension_id) const {
1055 CHECK(crx_file::id_util::IdIsValid(extension_id)); 1055 CHECK(crx_file::id_util::IdIsValid(extension_id));
1056 return ReadPrefAsPermissionSet(extension_id, kPrefActivePermissions); 1056 return ReadPrefAsPermissionSet(extension_id, kPrefActivePermissions);
1057 } 1057 }
1058 1058
1059 void ExtensionPrefs::SetActivePermissions( 1059 void ExtensionPrefs::SetActivePermissions(
1060 const std::string& extension_id, 1060 const std::string& extension_id,
1061 const PermissionSet* permissions) { 1061 const PermissionSet* permissions) {
1062 SetExtensionPrefPermissionSet( 1062 SetExtensionPrefPermissionSet(
1063 extension_id, kPrefActivePermissions, permissions); 1063 extension_id, kPrefActivePermissions, permissions);
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 extension_pref_value_map_->RegisterExtension( 2112 extension_pref_value_map_->RegisterExtension(
2113 extension_id, install_time, is_enabled, is_incognito_enabled); 2113 extension_id, install_time, is_enabled, is_incognito_enabled);
2114 2114
2115 FOR_EACH_OBSERVER( 2115 FOR_EACH_OBSERVER(
2116 ExtensionPrefsObserver, 2116 ExtensionPrefsObserver,
2117 observer_list_, 2117 observer_list_,
2118 OnExtensionRegistered(extension_id, install_time, is_enabled)); 2118 OnExtensionRegistered(extension_id, install_time, is_enabled));
2119 } 2119 }
2120 2120
2121 } // namespace extensions 2121 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698