| 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> |
| 8 |
| 7 #include "base/base_paths_posix.h" | 9 #include "base/base_paths_posix.h" |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/i18n/time_formatting.h" | 11 #include "base/i18n/time_formatting.h" |
| 12 #include "base/macros.h" |
| 10 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 11 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 12 #include "base/prefs/scoped_user_pref_update.h" | 15 #include "base/prefs/scoped_user_pref_update.h" |
| 13 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 14 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 15 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "build/build_config.h" |
| 18 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/media_galleries/fileapi/iapps_finder.h" | 23 #include "chrome/browser/media_galleries/fileapi/iapps_finder.h" |
| 20 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" | 24 #include "chrome/browser/media_galleries/fileapi/picasa_finder.h" |
| 21 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" | 25 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" |
| 22 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 26 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 23 #include "chrome/browser/media_galleries/media_galleries_histograms.h" | 27 #include "chrome/browser/media_galleries/media_galleries_histograms.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/grit/generated_resources.h" | 31 #include "chrome/grit/generated_resources.h" |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 return MediaStorageUtil::FindDevicePathById(it->second.device_id); | 838 return MediaStorageUtil::FindDevicePathById(it->second.device_id); |
| 835 } | 839 } |
| 836 | 840 |
| 837 MediaGalleryPrefId MediaGalleriesPreferences::AddGallery( | 841 MediaGalleryPrefId MediaGalleriesPreferences::AddGallery( |
| 838 const std::string& device_id, | 842 const std::string& device_id, |
| 839 const base::FilePath& relative_path, | 843 const base::FilePath& relative_path, |
| 840 MediaGalleryPrefInfo::Type type, | 844 MediaGalleryPrefInfo::Type type, |
| 841 const base::string16& volume_label, | 845 const base::string16& volume_label, |
| 842 const base::string16& vendor_name, | 846 const base::string16& vendor_name, |
| 843 const base::string16& model_name, | 847 const base::string16& model_name, |
| 844 uint64 total_size_in_bytes, | 848 uint64_t total_size_in_bytes, |
| 845 base::Time last_attach_time, | 849 base::Time last_attach_time, |
| 846 int audio_count, | 850 int audio_count, |
| 847 int image_count, | 851 int image_count, |
| 848 int video_count) { | 852 int video_count) { |
| 849 DCHECK(IsInitialized()); | 853 DCHECK(IsInitialized()); |
| 850 return AddOrUpdateGalleryInternal( | 854 return AddOrUpdateGalleryInternal( |
| 851 device_id, | 855 device_id, |
| 852 base::string16(), | 856 base::string16(), |
| 853 relative_path, | 857 relative_path, |
| 854 type, | 858 type, |
| 855 volume_label, | 859 volume_label, |
| 856 vendor_name, | 860 vendor_name, |
| 857 model_name, | 861 model_name, |
| 858 total_size_in_bytes, | 862 total_size_in_bytes, |
| 859 last_attach_time, | 863 last_attach_time, |
| 860 true, | 864 true, |
| 861 audio_count, | 865 audio_count, |
| 862 image_count, | 866 image_count, |
| 863 video_count, | 867 video_count, |
| 864 kCurrentPrefsVersion, | 868 kCurrentPrefsVersion, |
| 865 MediaGalleryPrefInfo::kNotDefault); | 869 MediaGalleryPrefInfo::kNotDefault); |
| 866 } | 870 } |
| 867 | 871 |
| 868 MediaGalleryPrefId MediaGalleriesPreferences::AddOrUpdateGalleryInternal( | 872 MediaGalleryPrefId MediaGalleriesPreferences::AddOrUpdateGalleryInternal( |
| 869 const std::string& device_id, const base::string16& display_name, | 873 const std::string& device_id, |
| 870 const base::FilePath& relative_path, MediaGalleryPrefInfo::Type type, | 874 const base::string16& display_name, |
| 871 const base::string16& volume_label, const base::string16& vendor_name, | 875 const base::FilePath& relative_path, |
| 872 const base::string16& model_name, uint64 total_size_in_bytes, | 876 MediaGalleryPrefInfo::Type type, |
| 873 base::Time last_attach_time, bool volume_metadata_valid, | 877 const base::string16& volume_label, |
| 874 int audio_count, int image_count, int video_count, int prefs_version, | 878 const base::string16& vendor_name, |
| 879 const base::string16& model_name, |
| 880 uint64_t total_size_in_bytes, |
| 881 base::Time last_attach_time, |
| 882 bool volume_metadata_valid, |
| 883 int audio_count, |
| 884 int image_count, |
| 885 int video_count, |
| 886 int prefs_version, |
| 875 MediaGalleryPrefInfo::DefaultGalleryType default_gallery_type) { | 887 MediaGalleryPrefInfo::DefaultGalleryType default_gallery_type) { |
| 876 DCHECK(type == MediaGalleryPrefInfo::kUserAdded || | 888 DCHECK(type == MediaGalleryPrefInfo::kUserAdded || |
| 877 type == MediaGalleryPrefInfo::kAutoDetected || | 889 type == MediaGalleryPrefInfo::kAutoDetected || |
| 878 type == MediaGalleryPrefInfo::kScanResult); | 890 type == MediaGalleryPrefInfo::kScanResult); |
| 879 base::FilePath normalized_relative_path = | 891 base::FilePath normalized_relative_path = |
| 880 relative_path.NormalizePathSeparators(); | 892 relative_path.NormalizePathSeparators(); |
| 881 MediaGalleryPrefIdSet galleries_on_device = | 893 MediaGalleryPrefIdSet galleries_on_device = |
| 882 LookUpGalleriesByDeviceId(device_id); | 894 LookUpGalleriesByDeviceId(device_id); |
| 883 | 895 |
| 884 for (MediaGalleryPrefIdSet::const_iterator pref_id_it = | 896 for (MediaGalleryPrefIdSet::const_iterator pref_id_it = |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 return true; | 1294 return true; |
| 1283 } | 1295 } |
| 1284 | 1296 |
| 1285 const MediaGalleriesPrefInfoMap& MediaGalleriesPreferences::known_galleries() | 1297 const MediaGalleriesPrefInfoMap& MediaGalleriesPreferences::known_galleries() |
| 1286 const { | 1298 const { |
| 1287 DCHECK(IsInitialized()); | 1299 DCHECK(IsInitialized()); |
| 1288 return known_galleries_; | 1300 return known_galleries_; |
| 1289 } | 1301 } |
| 1290 | 1302 |
| 1291 base::Time MediaGalleriesPreferences::GetLastScanCompletionTime() const { | 1303 base::Time MediaGalleriesPreferences::GetLastScanCompletionTime() const { |
| 1292 int64 last_scan_time_internal = | 1304 int64_t last_scan_time_internal = |
| 1293 profile_->GetPrefs()->GetInt64(prefs::kMediaGalleriesLastScanTime); | 1305 profile_->GetPrefs()->GetInt64(prefs::kMediaGalleriesLastScanTime); |
| 1294 return base::Time::FromInternalValue(last_scan_time_internal); | 1306 return base::Time::FromInternalValue(last_scan_time_internal); |
| 1295 } | 1307 } |
| 1296 | 1308 |
| 1297 void MediaGalleriesPreferences::SetLastScanCompletionTime( | 1309 void MediaGalleriesPreferences::SetLastScanCompletionTime( |
| 1298 const base::Time& time) { | 1310 const base::Time& time) { |
| 1299 profile_->GetPrefs()->SetInt64(prefs::kMediaGalleriesLastScanTime, | 1311 profile_->GetPrefs()->SetInt64(prefs::kMediaGalleriesLastScanTime, |
| 1300 time.ToInternalValue()); | 1312 time.ToInternalValue()); |
| 1301 } | 1313 } |
| 1302 | 1314 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 if (extension_prefs_for_testing_) | 1450 if (extension_prefs_for_testing_) |
| 1439 return extension_prefs_for_testing_; | 1451 return extension_prefs_for_testing_; |
| 1440 return extensions::ExtensionPrefs::Get(profile_); | 1452 return extensions::ExtensionPrefs::Get(profile_); |
| 1441 } | 1453 } |
| 1442 | 1454 |
| 1443 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( | 1455 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( |
| 1444 extensions::ExtensionPrefs* extension_prefs) { | 1456 extensions::ExtensionPrefs* extension_prefs) { |
| 1445 DCHECK(IsInitialized()); | 1457 DCHECK(IsInitialized()); |
| 1446 extension_prefs_for_testing_ = extension_prefs; | 1458 extension_prefs_for_testing_ = extension_prefs; |
| 1447 } | 1459 } |
| OLD | NEW |