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

Side by Side Diff: chrome/browser/media_galleries/media_galleries_preferences.cc

Issue 2816513002: Revert of Change base::Value::ListStorage to std::vector<base::Value> (Closed)
Patch Set: Created 3 years, 8 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/media_galleries/media_galleries_preferences.h" 5 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 return false; 614 return false;
615 615
616 PrefService* prefs = profile_->GetPrefs(); 616 PrefService* prefs = profile_->GetPrefs();
617 std::unique_ptr<ListPrefUpdate> update( 617 std::unique_ptr<ListPrefUpdate> update(
618 new ListPrefUpdate(prefs, prefs::kMediaGalleriesRememberedGalleries)); 618 new ListPrefUpdate(prefs, prefs::kMediaGalleriesRememberedGalleries));
619 base::ListValue* list = update->Get(); 619 base::ListValue* list = update->Get();
620 for (base::ListValue::iterator iter = list->begin(); 620 for (base::ListValue::iterator iter = list->begin();
621 iter != list->end(); ++iter) { 621 iter != list->end(); ++iter) {
622 // All of these calls should succeed, but preferences file can be corrupt. 622 // All of these calls should succeed, but preferences file can be corrupt.
623 base::DictionaryValue* dict; 623 base::DictionaryValue* dict;
624 if (!iter->GetAsDictionary(&dict)) 624 if (!(*iter)->GetAsDictionary(&dict))
625 continue; 625 continue;
626 std::string this_device_id; 626 std::string this_device_id;
627 if (!dict->GetString(kMediaGalleriesDeviceIdKey, &this_device_id)) 627 if (!dict->GetString(kMediaGalleriesDeviceIdKey, &this_device_id))
628 continue; 628 continue;
629 if (this_device_id == device_id) 629 if (this_device_id == device_id)
630 return true; // No update is necessary. 630 return true; // No update is necessary.
631 StorageInfo::Type device_type; 631 StorageInfo::Type device_type;
632 if (!StorageInfo::CrackDeviceId(this_device_id, &device_type, NULL)) 632 if (!StorageInfo::CrackDeviceId(this_device_id, &device_type, NULL))
633 continue; 633 continue;
634 634
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 known_galleries_.clear(); 706 known_galleries_.clear();
707 device_map_.clear(); 707 device_map_.clear();
708 708
709 PrefService* prefs = profile_->GetPrefs(); 709 PrefService* prefs = profile_->GetPrefs();
710 const base::ListValue* list = prefs->GetList( 710 const base::ListValue* list = prefs->GetList(
711 prefs::kMediaGalleriesRememberedGalleries); 711 prefs::kMediaGalleriesRememberedGalleries);
712 if (list) { 712 if (list) {
713 for (base::ListValue::const_iterator it = list->begin(); 713 for (base::ListValue::const_iterator it = list->begin();
714 it != list->end(); ++it) { 714 it != list->end(); ++it) {
715 const base::DictionaryValue* dict = NULL; 715 const base::DictionaryValue* dict = NULL;
716 if (!it->GetAsDictionary(&dict)) 716 if (!(*it)->GetAsDictionary(&dict))
717 continue; 717 continue;
718 718
719 MediaGalleryPrefInfo gallery_info; 719 MediaGalleryPrefInfo gallery_info;
720 if (!PopulateGalleryPrefInfoFromDictionary(*dict, &gallery_info)) 720 if (!PopulateGalleryPrefInfoFromDictionary(*dict, &gallery_info))
721 continue; 721 continue;
722 722
723 known_galleries_[gallery_info.pref_id] = gallery_info; 723 known_galleries_[gallery_info.pref_id] = gallery_info;
724 device_map_[gallery_info.device_id].insert(gallery_info.pref_id); 724 device_map_[gallery_info.device_id].insert(gallery_info.pref_id);
725 } 725 }
726 } 726 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 if (!update_gallery_name && !update_gallery_type && 950 if (!update_gallery_name && !update_gallery_type &&
951 !update_gallery_metadata && !update_scan_counts && 951 !update_gallery_metadata && !update_scan_counts &&
952 !update_default_gallery_type) 952 !update_default_gallery_type)
953 return *pref_id_it; 953 return *pref_id_it;
954 954
955 PrefService* prefs = profile_->GetPrefs(); 955 PrefService* prefs = profile_->GetPrefs();
956 std::unique_ptr<ListPrefUpdate> update( 956 std::unique_ptr<ListPrefUpdate> update(
957 new ListPrefUpdate(prefs, prefs::kMediaGalleriesRememberedGalleries)); 957 new ListPrefUpdate(prefs, prefs::kMediaGalleriesRememberedGalleries));
958 base::ListValue* list = update->Get(); 958 base::ListValue* list = update->Get();
959 959
960 for (base::ListValue::iterator list_iter = list->begin(); 960 for (base::ListValue::const_iterator list_iter = list->begin();
961 list_iter != list->end(); ++list_iter) { 961 list_iter != list->end();
962 ++list_iter) {
962 base::DictionaryValue* dict; 963 base::DictionaryValue* dict;
963 MediaGalleryPrefId iter_id; 964 MediaGalleryPrefId iter_id;
964 if (list_iter->GetAsDictionary(&dict) && GetPrefId(*dict, &iter_id) && 965 if ((*list_iter)->GetAsDictionary(&dict) &&
966 GetPrefId(*dict, &iter_id) &&
965 *pref_id_it == iter_id) { 967 *pref_id_it == iter_id) {
966 if (update_gallery_type) 968 if (update_gallery_type)
967 dict->SetString(kMediaGalleriesTypeKey, TypeToStringValue(new_type)); 969 dict->SetString(kMediaGalleriesTypeKey, TypeToStringValue(new_type));
968 if (update_gallery_name) 970 if (update_gallery_name)
969 dict->SetString(kMediaGalleriesDisplayNameKey, display_name); 971 dict->SetString(kMediaGalleriesDisplayNameKey, display_name);
970 if (update_gallery_metadata) { 972 if (update_gallery_metadata) {
971 dict->SetString(kMediaGalleriesVolumeLabelKey, volume_label); 973 dict->SetString(kMediaGalleriesVolumeLabelKey, volume_label);
972 dict->SetString(kMediaGalleriesVendorNameKey, vendor_name); 974 dict->SetString(kMediaGalleriesVendorNameKey, vendor_name);
973 dict->SetString(kMediaGalleriesModelNameKey, model_name); 975 dict->SetString(kMediaGalleriesModelNameKey, model_name);
974 dict->SetDouble(kMediaGalleriesSizeKey, total_size_in_bytes); 976 dict->SetDouble(kMediaGalleriesSizeKey, total_size_in_bytes);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 base::ListValue* list = update->Get(); 1051 base::ListValue* list = update->Get();
1050 1052
1051 std::vector<MediaGalleryPrefId> pref_ids; 1053 std::vector<MediaGalleryPrefId> pref_ids;
1052 1054
1053 for (base::ListValue::iterator iter = list->begin(); 1055 for (base::ListValue::iterator iter = list->begin();
1054 iter != list->end(); 1056 iter != list->end();
1055 ++iter) { 1057 ++iter) {
1056 base::DictionaryValue* dict; 1058 base::DictionaryValue* dict;
1057 MediaGalleryPrefId pref_id; 1059 MediaGalleryPrefId pref_id;
1058 1060
1059 if (!(iter->GetAsDictionary(&dict) && GetPrefId(*dict, &pref_id))) 1061 if (!((*iter)->GetAsDictionary(&dict) && GetPrefId(*dict, &pref_id)))
1060 continue; 1062 continue;
1061 1063
1062 std::string default_gallery_type_string; 1064 std::string default_gallery_type_string;
1063 1065
1064 // If the "default gallery type" key is set, just update the paths in place. 1066 // If the "default gallery type" key is set, just update the paths in place.
1065 // If it's not set, then AddOrUpdateGalleryInternal will take care of 1067 // If it's not set, then AddOrUpdateGalleryInternal will take care of
1066 // setting it as part of migration to prefs version 3. 1068 // setting it as part of migration to prefs version 3.
1067 if (dict->GetString(kMediaGalleriesDefaultGalleryTypeKey, 1069 if (dict->GetString(kMediaGalleriesDefaultGalleryTypeKey,
1068 &default_gallery_type_string)) { 1070 &default_gallery_type_string)) {
1069 std::string device_id; 1071 std::string device_id;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 new ListPrefUpdate(prefs, prefs::kMediaGalleriesRememberedGalleries)); 1148 new ListPrefUpdate(prefs, prefs::kMediaGalleriesRememberedGalleries));
1147 base::ListValue* list = update->Get(); 1149 base::ListValue* list = update->Get();
1148 1150
1149 if (!base::ContainsKey(known_galleries_, id)) 1151 if (!base::ContainsKey(known_galleries_, id))
1150 return; 1152 return;
1151 1153
1152 for (base::ListValue::iterator iter = list->begin(); 1154 for (base::ListValue::iterator iter = list->begin();
1153 iter != list->end(); ++iter) { 1155 iter != list->end(); ++iter) {
1154 base::DictionaryValue* dict; 1156 base::DictionaryValue* dict;
1155 MediaGalleryPrefId iter_id; 1157 MediaGalleryPrefId iter_id;
1156 if (iter->GetAsDictionary(&dict) && GetPrefId(*dict, &iter_id) && 1158 if ((*iter)->GetAsDictionary(&dict) && GetPrefId(*dict, &iter_id) &&
1157 id == iter_id) { 1159 id == iter_id) {
1158 RemoveGalleryPermissionsFromPrefs(id); 1160 RemoveGalleryPermissionsFromPrefs(id);
1159 MediaGalleryPrefInfo::Type type; 1161 MediaGalleryPrefInfo::Type type;
1160 if (!erase && GetType(*dict, &type) && 1162 if (!erase && GetType(*dict, &type) &&
1161 (type == MediaGalleryPrefInfo::kAutoDetected || 1163 (type == MediaGalleryPrefInfo::kAutoDetected ||
1162 type == MediaGalleryPrefInfo::kScanResult)) { 1164 type == MediaGalleryPrefInfo::kScanResult)) {
1163 if (type == MediaGalleryPrefInfo::kAutoDetected) { 1165 if (type == MediaGalleryPrefInfo::kAutoDetected) {
1164 dict->SetString(kMediaGalleriesTypeKey, 1166 dict->SetString(kMediaGalleriesTypeKey,
1165 kMediaGalleriesTypeBlackListedValue); 1167 kMediaGalleriesTypeBlackListedValue);
1166 } else { 1168 } else {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 extension_id, 1326 extension_id,
1325 kMediaGalleriesPermissions); 1327 kMediaGalleriesPermissions);
1326 base::ListValue* permissions = update.Get(); 1328 base::ListValue* permissions = update.Get();
1327 if (!permissions) { 1329 if (!permissions) {
1328 permissions = update.Create(); 1330 permissions = update.Create();
1329 } else { 1331 } else {
1330 // If the gallery is already in the list, update the permission... 1332 // If the gallery is already in the list, update the permission...
1331 for (base::ListValue::iterator iter = permissions->begin(); 1333 for (base::ListValue::iterator iter = permissions->begin();
1332 iter != permissions->end(); ++iter) { 1334 iter != permissions->end(); ++iter) {
1333 base::DictionaryValue* dict = NULL; 1335 base::DictionaryValue* dict = NULL;
1334 if (!iter->GetAsDictionary(&dict)) 1336 if (!(*iter)->GetAsDictionary(&dict))
1335 continue; 1337 continue;
1336 MediaGalleryPermission perm; 1338 MediaGalleryPermission perm;
1337 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm)) 1339 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm))
1338 continue; 1340 continue;
1339 if (perm.pref_id == gallery_id) { 1341 if (perm.pref_id == gallery_id) {
1340 if (has_access != perm.has_permission) { 1342 if (has_access != perm.has_permission) {
1341 dict->SetBoolean(kMediaGalleryHasPermissionKey, has_access); 1343 dict->SetBoolean(kMediaGalleryHasPermissionKey, has_access);
1342 return true; 1344 return true;
1343 } else { 1345 } else {
1344 return false; 1346 return false;
(...skipping 16 matching lines...) Expand all
1361 ExtensionPrefs::ScopedListUpdate update(GetExtensionPrefs(), 1363 ExtensionPrefs::ScopedListUpdate update(GetExtensionPrefs(),
1362 extension_id, 1364 extension_id,
1363 kMediaGalleriesPermissions); 1365 kMediaGalleriesPermissions);
1364 base::ListValue* permissions = update.Get(); 1366 base::ListValue* permissions = update.Get();
1365 if (!permissions) 1367 if (!permissions)
1366 return false; 1368 return false;
1367 1369
1368 for (base::ListValue::iterator iter = permissions->begin(); 1370 for (base::ListValue::iterator iter = permissions->begin();
1369 iter != permissions->end(); ++iter) { 1371 iter != permissions->end(); ++iter) {
1370 const base::DictionaryValue* dict = NULL; 1372 const base::DictionaryValue* dict = NULL;
1371 if (!iter->GetAsDictionary(&dict)) 1373 if (!(*iter)->GetAsDictionary(&dict))
1372 continue; 1374 continue;
1373 MediaGalleryPermission perm; 1375 MediaGalleryPermission perm;
1374 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm)) 1376 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm))
1375 continue; 1377 continue;
1376 if (perm.pref_id == gallery_id) { 1378 if (perm.pref_id == gallery_id) {
1377 permissions->Erase(iter, NULL); 1379 permissions->Erase(iter, NULL);
1378 return true; 1380 return true;
1379 } 1381 }
1380 } 1382 }
1381 return false; 1383 return false;
1382 } 1384 }
1383 1385
1384 std::vector<MediaGalleryPermission> 1386 std::vector<MediaGalleryPermission>
1385 MediaGalleriesPreferences::GetGalleryPermissionsFromPrefs( 1387 MediaGalleriesPreferences::GetGalleryPermissionsFromPrefs(
1386 const std::string& extension_id) const { 1388 const std::string& extension_id) const {
1387 DCHECK(IsInitialized()); 1389 DCHECK(IsInitialized());
1388 std::vector<MediaGalleryPermission> result; 1390 std::vector<MediaGalleryPermission> result;
1389 const base::ListValue* permissions; 1391 const base::ListValue* permissions;
1390 if (!GetExtensionPrefs()->ReadPrefAsList(extension_id, 1392 if (!GetExtensionPrefs()->ReadPrefAsList(extension_id,
1391 kMediaGalleriesPermissions, 1393 kMediaGalleriesPermissions,
1392 &permissions)) { 1394 &permissions)) {
1393 return result; 1395 return result;
1394 } 1396 }
1395 1397
1396 for (base::ListValue::const_iterator iter = permissions->begin(); 1398 for (base::ListValue::const_iterator iter = permissions->begin();
1397 iter != permissions->end(); ++iter) { 1399 iter != permissions->end(); ++iter) {
1398 const base::DictionaryValue* dict = NULL; 1400 base::DictionaryValue* dict = NULL;
1399 if (!iter->GetAsDictionary(&dict)) 1401 if (!(*iter)->GetAsDictionary(&dict))
1400 continue; 1402 continue;
1401 MediaGalleryPermission perm; 1403 MediaGalleryPermission perm;
1402 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm)) 1404 if (!GetMediaGalleryPermissionFromDictionary(dict, &perm))
1403 continue; 1405 continue;
1404 result.push_back(perm); 1406 result.push_back(perm);
1405 } 1407 }
1406 1408
1407 return result; 1409 return result;
1408 } 1410 }
1409 1411
(...skipping 21 matching lines...) Expand all
1431 if (extension_prefs_for_testing_) 1433 if (extension_prefs_for_testing_)
1432 return extension_prefs_for_testing_; 1434 return extension_prefs_for_testing_;
1433 return extensions::ExtensionPrefs::Get(profile_); 1435 return extensions::ExtensionPrefs::Get(profile_);
1434 } 1436 }
1435 1437
1436 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( 1438 void MediaGalleriesPreferences::SetExtensionPrefsForTesting(
1437 extensions::ExtensionPrefs* extension_prefs) { 1439 extensions::ExtensionPrefs* extension_prefs) {
1438 DCHECK(IsInitialized()); 1440 DCHECK(IsInitialized());
1439 extension_prefs_for_testing_ = extension_prefs; 1441 extension_prefs_for_testing_ = extension_prefs;
1440 } 1442 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698