| OLD | NEW |
| 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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 635 if (device_type == singleton_type) { | 635 if (device_type == singleton_type) { |
| 636 dict->SetString(kMediaGalleriesDeviceIdKey, device_id); | 636 dict->SetString(kMediaGalleriesDeviceIdKey, device_id); |
| 637 update.reset(); // commits the update. | 637 update.reset(); // commits the update. |
| 638 InitFromPrefs(); | 638 InitFromPrefs(); |
| 639 MediaGalleryPrefId pref_id; | 639 MediaGalleryPrefId pref_id; |
| 640 if (GetPrefId(*dict, &pref_id)) { | 640 if (GetPrefId(*dict, &pref_id)) { |
| 641 FOR_EACH_OBSERVER(GalleryChangeObserver, | 641 for (auto& observer : gallery_change_observers_) |
| 642 gallery_change_observers_, | 642 observer.OnGalleryInfoUpdated(this, pref_id); |
| 643 OnGalleryInfoUpdated(this, pref_id)); | |
| 644 } | 643 } |
| 645 return true; | 644 return true; |
| 646 } | 645 } |
| 647 } | 646 } |
| 648 return false; | 647 return false; |
| 649 } | 648 } |
| 650 | 649 |
| 651 void MediaGalleriesPreferences::OnStorageMonitorInit( | 650 void MediaGalleriesPreferences::OnStorageMonitorInit( |
| 652 bool api_has_been_used) { | 651 bool api_has_been_used) { |
| 653 if (api_has_been_used) | 652 if (api_has_been_used) |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 } | 989 } |
| 991 dict->SetInteger(kMediaGalleriesPrefsVersionKey, prefs_version); | 990 dict->SetInteger(kMediaGalleriesPrefsVersionKey, prefs_version); |
| 992 break; | 991 break; |
| 993 } | 992 } |
| 994 } | 993 } |
| 995 | 994 |
| 996 // Commits the prefs update. | 995 // Commits the prefs update. |
| 997 update.reset(); | 996 update.reset(); |
| 998 | 997 |
| 999 InitFromPrefs(); | 998 InitFromPrefs(); |
| 1000 FOR_EACH_OBSERVER(GalleryChangeObserver, gallery_change_observers_, | 999 for (auto& observer : gallery_change_observers_) |
| 1001 OnGalleryInfoUpdated(this, *pref_id_it)); | 1000 observer.OnGalleryInfoUpdated(this, *pref_id_it); |
| 1002 return *pref_id_it; | 1001 return *pref_id_it; |
| 1003 } | 1002 } |
| 1004 | 1003 |
| 1005 PrefService* prefs = profile_->GetPrefs(); | 1004 PrefService* prefs = profile_->GetPrefs(); |
| 1006 | 1005 |
| 1007 MediaGalleryPrefInfo gallery_info; | 1006 MediaGalleryPrefInfo gallery_info; |
| 1008 gallery_info.pref_id = prefs->GetUint64(prefs::kMediaGalleriesUniqueId); | 1007 gallery_info.pref_id = prefs->GetUint64(prefs::kMediaGalleriesUniqueId); |
| 1009 prefs->SetUint64(prefs::kMediaGalleriesUniqueId, gallery_info.pref_id + 1); | 1008 prefs->SetUint64(prefs::kMediaGalleriesUniqueId, gallery_info.pref_id + 1); |
| 1010 gallery_info.display_name = display_name; | 1009 gallery_info.display_name = display_name; |
| 1011 gallery_info.device_id = device_id; | 1010 gallery_info.device_id = device_id; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1022 gallery_info.video_count = video_count; | 1021 gallery_info.video_count = video_count; |
| 1023 gallery_info.prefs_version = prefs_version; | 1022 gallery_info.prefs_version = prefs_version; |
| 1024 gallery_info.default_gallery_type = default_gallery_type; | 1023 gallery_info.default_gallery_type = default_gallery_type; |
| 1025 | 1024 |
| 1026 { | 1025 { |
| 1027 ListPrefUpdate update(prefs, prefs::kMediaGalleriesRememberedGalleries); | 1026 ListPrefUpdate update(prefs, prefs::kMediaGalleriesRememberedGalleries); |
| 1028 base::ListValue* list = update.Get(); | 1027 base::ListValue* list = update.Get(); |
| 1029 list->Append(CreateGalleryPrefInfoDictionary(gallery_info)); | 1028 list->Append(CreateGalleryPrefInfoDictionary(gallery_info)); |
| 1030 } | 1029 } |
| 1031 InitFromPrefs(); | 1030 InitFromPrefs(); |
| 1032 FOR_EACH_OBSERVER(GalleryChangeObserver, | 1031 for (auto& observer : gallery_change_observers_) |
| 1033 gallery_change_observers_, | 1032 observer.OnGalleryAdded(this, gallery_info.pref_id); |
| 1034 OnGalleryAdded(this, gallery_info.pref_id)); | |
| 1035 | 1033 |
| 1036 return gallery_info.pref_id; | 1034 return gallery_info.pref_id; |
| 1037 } | 1035 } |
| 1038 | 1036 |
| 1039 | 1037 |
| 1040 void MediaGalleriesPreferences::UpdateDefaultGalleriesPaths() { | 1038 void MediaGalleriesPreferences::UpdateDefaultGalleriesPaths() { |
| 1041 base::FilePath music_path; | 1039 base::FilePath music_path; |
| 1042 base::FilePath pictures_path; | 1040 base::FilePath pictures_path; |
| 1043 base::FilePath videos_path; | 1041 base::FilePath videos_path; |
| 1044 bool got_music_path = PathService::Get(chrome::DIR_USER_MUSIC, &music_path); | 1042 bool got_music_path = PathService::Get(chrome::DIR_USER_MUSIC, &music_path); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 pref_ids.push_back(pref_id); | 1096 pref_ids.push_back(pref_id); |
| 1099 } | 1097 } |
| 1100 | 1098 |
| 1101 // Commit the prefs update. | 1099 // Commit the prefs update. |
| 1102 update.reset(); | 1100 update.reset(); |
| 1103 InitFromPrefs(); | 1101 InitFromPrefs(); |
| 1104 | 1102 |
| 1105 for (std::vector<MediaGalleryPrefId>::iterator iter = pref_ids.begin(); | 1103 for (std::vector<MediaGalleryPrefId>::iterator iter = pref_ids.begin(); |
| 1106 iter != pref_ids.end(); | 1104 iter != pref_ids.end(); |
| 1107 ++iter) { | 1105 ++iter) { |
| 1108 FOR_EACH_OBSERVER(GalleryChangeObserver, | 1106 for (auto& observer : gallery_change_observers_) |
| 1109 gallery_change_observers_, | 1107 observer.OnGalleryInfoUpdated(this, *iter); |
| 1110 OnGalleryInfoUpdated(this, *iter)); | |
| 1111 } | 1108 } |
| 1112 } | 1109 } |
| 1113 | 1110 |
| 1114 | 1111 |
| 1115 MediaGalleryPrefId MediaGalleriesPreferences::AddGalleryByPath( | 1112 MediaGalleryPrefId MediaGalleriesPreferences::AddGalleryByPath( |
| 1116 const base::FilePath& path, MediaGalleryPrefInfo::Type type) { | 1113 const base::FilePath& path, MediaGalleryPrefInfo::Type type) { |
| 1117 DCHECK(IsInitialized()); | 1114 DCHECK(IsInitialized()); |
| 1118 MediaGalleryPrefInfo gallery_info; | 1115 MediaGalleryPrefInfo gallery_info; |
| 1119 if (LookUpGalleryByPath(path, &gallery_info) && | 1116 if (LookUpGalleryByPath(path, &gallery_info) && |
| 1120 !gallery_info.IsBlackListedType()) { | 1117 !gallery_info.IsBlackListedType()) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 dict->SetInteger(kMediaGalleriesScanAudioCountKey, 0); | 1171 dict->SetInteger(kMediaGalleriesScanAudioCountKey, 0); |
| 1175 dict->SetInteger(kMediaGalleriesScanImageCountKey, 0); | 1172 dict->SetInteger(kMediaGalleriesScanImageCountKey, 0); |
| 1176 dict->SetInteger(kMediaGalleriesScanVideoCountKey, 0); | 1173 dict->SetInteger(kMediaGalleriesScanVideoCountKey, 0); |
| 1177 } | 1174 } |
| 1178 } else { | 1175 } else { |
| 1179 list->Erase(iter, NULL); | 1176 list->Erase(iter, NULL); |
| 1180 } | 1177 } |
| 1181 update.reset(NULL); // commits the update. | 1178 update.reset(NULL); // commits the update. |
| 1182 | 1179 |
| 1183 InitFromPrefs(); | 1180 InitFromPrefs(); |
| 1184 FOR_EACH_OBSERVER(GalleryChangeObserver, | 1181 for (auto& observer : gallery_change_observers_) |
| 1185 gallery_change_observers_, | 1182 observer.OnGalleryRemoved(this, id); |
| 1186 OnGalleryRemoved(this, id)); | |
| 1187 return; | 1183 return; |
| 1188 } | 1184 } |
| 1189 } | 1185 } |
| 1190 } | 1186 } |
| 1191 | 1187 |
| 1192 bool MediaGalleriesPreferences::NonAutoGalleryHasPermission( | 1188 bool MediaGalleriesPreferences::NonAutoGalleryHasPermission( |
| 1193 MediaGalleryPrefId id) const { | 1189 MediaGalleryPrefId id) const { |
| 1194 DCHECK(IsInitialized()); | 1190 DCHECK(IsInitialized()); |
| 1195 DCHECK(!base::ContainsKey(known_galleries_, id) || | 1191 DCHECK(!base::ContainsKey(known_galleries_, id) || |
| 1196 known_galleries_.find(id)->second.type != | 1192 known_galleries_.find(id)->second.type != |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 default_permission = HasAutoDetectedGalleryPermission(extension); | 1274 default_permission = HasAutoDetectedGalleryPermission(extension); |
| 1279 // When the permission matches the default, we don't need to remember it. | 1275 // When the permission matches the default, we don't need to remember it. |
| 1280 if (has_permission == default_permission) { | 1276 if (has_permission == default_permission) { |
| 1281 if (!UnsetGalleryPermissionInPrefs(extension.id(), pref_id)) | 1277 if (!UnsetGalleryPermissionInPrefs(extension.id(), pref_id)) |
| 1282 // If permission wasn't set, assume nothing has changed. | 1278 // If permission wasn't set, assume nothing has changed. |
| 1283 return false; | 1279 return false; |
| 1284 } else { | 1280 } else { |
| 1285 if (!SetGalleryPermissionInPrefs(extension.id(), pref_id, has_permission)) | 1281 if (!SetGalleryPermissionInPrefs(extension.id(), pref_id, has_permission)) |
| 1286 return false; | 1282 return false; |
| 1287 } | 1283 } |
| 1288 if (has_permission) | 1284 if (has_permission) { |
| 1289 FOR_EACH_OBSERVER(GalleryChangeObserver, | 1285 for (auto& observer : gallery_change_observers_) |
| 1290 gallery_change_observers_, | 1286 observer.OnPermissionAdded(this, extension.id(), pref_id); |
| 1291 OnPermissionAdded(this, extension.id(), pref_id)); | 1287 } else { |
| 1292 else | 1288 for (auto& observer : gallery_change_observers_) |
| 1293 FOR_EACH_OBSERVER(GalleryChangeObserver, | 1289 observer.OnPermissionRemoved(this, extension.id(), pref_id); |
| 1294 gallery_change_observers_, | 1290 } |
| 1295 OnPermissionRemoved(this, extension.id(), pref_id)); | |
| 1296 return true; | 1291 return true; |
| 1297 } | 1292 } |
| 1298 | 1293 |
| 1299 const MediaGalleriesPrefInfoMap& MediaGalleriesPreferences::known_galleries() | 1294 const MediaGalleriesPrefInfoMap& MediaGalleriesPreferences::known_galleries() |
| 1300 const { | 1295 const { |
| 1301 DCHECK(IsInitialized()); | 1296 DCHECK(IsInitialized()); |
| 1302 return known_galleries_; | 1297 return known_galleries_; |
| 1303 } | 1298 } |
| 1304 | 1299 |
| 1305 void MediaGalleriesPreferences::Shutdown() { | 1300 void MediaGalleriesPreferences::Shutdown() { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 if (extension_prefs_for_testing_) | 1433 if (extension_prefs_for_testing_) |
| 1439 return extension_prefs_for_testing_; | 1434 return extension_prefs_for_testing_; |
| 1440 return extensions::ExtensionPrefs::Get(profile_); | 1435 return extensions::ExtensionPrefs::Get(profile_); |
| 1441 } | 1436 } |
| 1442 | 1437 |
| 1443 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( | 1438 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( |
| 1444 extensions::ExtensionPrefs* extension_prefs) { | 1439 extensions::ExtensionPrefs* extension_prefs) { |
| 1445 DCHECK(IsInitialized()); | 1440 DCHECK(IsInitialized()); |
| 1446 extension_prefs_for_testing_ = extension_prefs; | 1441 extension_prefs_for_testing_ = extension_prefs; |
| 1447 } | 1442 } |
| OLD | NEW |