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

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

Issue 10821077: Add gallery permissions to Media Galleries Preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_prefs.h" 5 #include "chrome/browser/extensions/extension_prefs.h"
6 6
7 #include "base/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 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 void ExtensionPrefs::SetLaunchType(const std::string& extension_id, 1157 void ExtensionPrefs::SetLaunchType(const std::string& extension_id,
1158 LaunchType launch_type) { 1158 LaunchType launch_type) {
1159 UpdateExtensionPref(extension_id, kPrefLaunchType, 1159 UpdateExtensionPref(extension_id, kPrefLaunchType,
1160 Value::CreateIntegerValue(static_cast<int>(launch_type))); 1160 Value::CreateIntegerValue(static_cast<int>(launch_type)));
1161 } 1161 }
1162 1162
1163 namespace { 1163 namespace {
1164 1164
1165 bool GetMediaGalleryPermissionFromDictionary( 1165 bool GetMediaGalleryPermissionFromDictionary(
1166 const DictionaryValue* dict, 1166 const DictionaryValue* dict,
1167 MediaGalleryPermission* out_permission) { 1167 chrome::MediaGalleryPermission* out_permission) {
1168 std::string string_id; 1168 std::string string_id;
1169 if (dict->GetString(kMediaGalleryIdKey, &string_id) && 1169 if (dict->GetString(kMediaGalleryIdKey, &string_id) &&
1170 base::StringToUint64(string_id, &out_permission->pref_id) && 1170 base::StringToUint64(string_id, &out_permission->pref_id) &&
1171 dict->GetBoolean(kMediaGalleryHasPermissionKey, 1171 dict->GetBoolean(kMediaGalleryHasPermissionKey,
1172 &out_permission->has_permission)) { 1172 &out_permission->has_permission)) {
1173 return true; 1173 return true;
1174 } 1174 }
1175 NOTREACHED(); 1175 NOTREACHED();
1176 return false; 1176 return false;
1177 } 1177 }
1178 1178
1179 void RemoveMediaGalleryPermissionsFromExtension(PrefService* prefs, 1179 void RemoveMediaGalleryPermissionsFromExtension(
1180 const std::string& extension_id, 1180 PrefService* prefs,
1181 MediaGalleryPrefId gallery_id) { 1181 const std::string& extension_id,
1182 chrome::MediaGalleryPrefId gallery_id) {
1182 ScopedExtensionPrefUpdate update(prefs, extension_id); 1183 ScopedExtensionPrefUpdate update(prefs, extension_id);
1183 DictionaryValue* extension_dict = update.Get(); 1184 DictionaryValue* extension_dict = update.Get();
1184 ListValue* permissions = NULL; 1185 ListValue* permissions = NULL;
1185 if (!extension_dict->GetList(kMediaGalleriesPermissions, &permissions)) 1186 if (!extension_dict->GetList(kMediaGalleriesPermissions, &permissions))
1186 return; 1187 return;
1187 1188
1188 for (ListValue::iterator it = permissions->begin(); 1189 for (ListValue::iterator it = permissions->begin();
1189 it != permissions->end(); 1190 it != permissions->end();
1190 ++it) { 1191 ++it) {
1191 const DictionaryValue* dict = NULL; 1192 const DictionaryValue* dict = NULL;
1192 if (!(*it)->GetAsDictionary(&dict)) 1193 if (!(*it)->GetAsDictionary(&dict))
1193 continue; 1194 continue;
1194 MediaGalleryPermission perm; 1195 chrome::MediaGalleryPermission perm;
1195 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm)) 1196 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm))
1196 continue; 1197 continue;
1197 if (perm.pref_id == gallery_id) { 1198 if (perm.pref_id == gallery_id) {
1198 permissions->Erase(it, NULL); 1199 permissions->Erase(it, NULL);
1199 return; 1200 return;
1200 } 1201 }
1201 } 1202 }
1202 } 1203 }
1203 1204
1204 } // namespace 1205 } // namespace
1205 1206
1206 void ExtensionPrefs::SetMediaGalleryPermission(const std::string& extension_id, 1207 void ExtensionPrefs::SetMediaGalleryPermission(
1207 MediaGalleryPrefId gallery, 1208 const std::string& extension_id,
1208 bool has_access) { 1209 chrome::MediaGalleryPrefId gallery,
1210 bool has_access) {
1209 ScopedExtensionPrefUpdate update(prefs_, extension_id); 1211 ScopedExtensionPrefUpdate update(prefs_, extension_id);
1210 DictionaryValue* extension_dict = update.Get(); 1212 DictionaryValue* extension_dict = update.Get();
1211 ListValue* permissions = NULL; 1213 ListValue* permissions = NULL;
1212 if (!extension_dict->GetList(kMediaGalleriesPermissions, &permissions)) { 1214 if (!extension_dict->GetList(kMediaGalleriesPermissions, &permissions)) {
1213 permissions = new ListValue; 1215 permissions = new ListValue;
1214 extension_dict->Set(kMediaGalleriesPermissions, permissions); 1216 extension_dict->Set(kMediaGalleriesPermissions, permissions);
1215 } else { 1217 } else {
1216 // If the gallery is already in the list, update the permission. 1218 // If the gallery is already in the list, update the permission.
1217 for (ListValue::const_iterator it = permissions->begin(); 1219 for (ListValue::const_iterator it = permissions->begin();
1218 it != permissions->end(); 1220 it != permissions->end();
1219 ++it) { 1221 ++it) {
1220 DictionaryValue* dict = NULL; 1222 DictionaryValue* dict = NULL;
1221 if (!(*it)->GetAsDictionary(&dict)) 1223 if (!(*it)->GetAsDictionary(&dict))
1222 continue; 1224 continue;
1223 MediaGalleryPermission perm; 1225 chrome::MediaGalleryPermission perm;
1224 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm)) 1226 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm))
1225 continue; 1227 continue;
1226 if (perm.pref_id == gallery) { 1228 if (perm.pref_id == gallery) {
1227 dict->SetBoolean(kMediaGalleryHasPermissionKey, has_access); 1229 dict->SetBoolean(kMediaGalleryHasPermissionKey, has_access);
1228 return; 1230 return;
1229 } 1231 }
1230 } 1232 }
1231 } 1233 }
1232 1234
1233 DictionaryValue* dict = new DictionaryValue; 1235 DictionaryValue* dict = new DictionaryValue;
1234 dict->SetString(kMediaGalleryIdKey, base::Uint64ToString(gallery)); 1236 dict->SetString(kMediaGalleryIdKey, base::Uint64ToString(gallery));
1235 dict->SetBoolean(kMediaGalleryHasPermissionKey, has_access); 1237 dict->SetBoolean(kMediaGalleryHasPermissionKey, has_access);
1236 permissions->Append(dict); 1238 permissions->Append(dict);
1237 } 1239 }
1238 1240
1239 std::vector<MediaGalleryPermission> ExtensionPrefs::GetMediaGalleryPermissions( 1241 void ExtensionPrefs::UnsetMediaGalleryPermission(
1240 const std::string& extension_id) { 1242 const std::string& extension_id,
1241 std::vector<MediaGalleryPermission> result; 1243 chrome::MediaGalleryPrefId gallery) {
1244 RemoveMediaGalleryPermissionsFromExtension(prefs_, extension_id, gallery);
1245 }
1246
1247 std::vector<chrome::MediaGalleryPermission>
1248 ExtensionPrefs::GetMediaGalleryPermissions(const std::string& extension_id) {
1249 std::vector<chrome::MediaGalleryPermission> result;
1242 const ListValue* permissions = NULL; 1250 const ListValue* permissions = NULL;
1243 if (ReadExtensionPrefList(extension_id, kMediaGalleriesPermissions, 1251 if (ReadExtensionPrefList(extension_id, kMediaGalleriesPermissions,
1244 &permissions)) { 1252 &permissions)) {
1245 for (ListValue::const_iterator it = permissions->begin(); 1253 for (ListValue::const_iterator it = permissions->begin();
1246 it != permissions->end(); 1254 it != permissions->end();
1247 ++it) { 1255 ++it) {
1248 DictionaryValue* dict = NULL; 1256 DictionaryValue* dict = NULL;
1249 if (!(*it)->GetAsDictionary(&dict)) 1257 if (!(*it)->GetAsDictionary(&dict))
1250 continue; 1258 continue;
1251 MediaGalleryPermission perm; 1259 chrome::MediaGalleryPermission perm;
1252 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm)) 1260 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm))
1253 continue; 1261 continue;
1254 result.push_back(perm); 1262 result.push_back(perm);
1255 } 1263 }
1256 } 1264 }
1257 return result; 1265 return result;
1258 } 1266 }
1259 1267
1260 void ExtensionPrefs::RemoveMediaGalleryPermissions( 1268 void ExtensionPrefs::RemoveMediaGalleryPermissions(
1261 MediaGalleryPrefId gallery_id) { 1269 chrome::MediaGalleryPrefId gallery_id) {
1262 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 1270 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1263 if (!extensions) 1271 if (!extensions)
1264 return; 1272 return;
1265 1273
1266 for (DictionaryValue::key_iterator it = extensions->begin_keys(); 1274 for (DictionaryValue::key_iterator it = extensions->begin_keys();
1267 it != extensions->end_keys(); 1275 it != extensions->end_keys();
1268 ++it) { 1276 ++it) {
1269 const std::string& id(*it); 1277 const std::string& id(*it);
1270 if (!Extension::IdIsValid(id)) { 1278 if (!Extension::IdIsValid(id)) {
1271 NOTREACHED(); 1279 NOTREACHED();
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
2059 0, // default value 2067 0, // default value
2060 PrefService::UNSYNCABLE_PREF); 2068 PrefService::UNSYNCABLE_PREF);
2061 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, 2069 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck,
2062 0, // default value 2070 0, // default value
2063 PrefService::UNSYNCABLE_PREF); 2071 PrefService::UNSYNCABLE_PREF);
2064 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, 2072 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
2065 PrefService::UNSYNCABLE_PREF); 2073 PrefService::UNSYNCABLE_PREF);
2066 } 2074 }
2067 2075
2068 } // namespace extensions 2076 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698