Chromium Code Reviews| 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 "base/base_paths_posix.h" | 7 #include "base/base_paths_posix.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/i18n/time_formatting.h" | 9 #include "base/i18n/time_formatting.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 const char kMediaGalleriesDeviceIdKey[] = "deviceId"; | 55 const char kMediaGalleriesDeviceIdKey[] = "deviceId"; |
| 56 const char kMediaGalleriesDisplayNameKey[] = "displayName"; | 56 const char kMediaGalleriesDisplayNameKey[] = "displayName"; |
| 57 const char kMediaGalleriesPathKey[] = "path"; | 57 const char kMediaGalleriesPathKey[] = "path"; |
| 58 const char kMediaGalleriesPrefIdKey[] = "prefId"; | 58 const char kMediaGalleriesPrefIdKey[] = "prefId"; |
| 59 const char kMediaGalleriesTypeKey[] = "type"; | 59 const char kMediaGalleriesTypeKey[] = "type"; |
| 60 const char kMediaGalleriesVolumeLabelKey[] = "volumeLabel"; | 60 const char kMediaGalleriesVolumeLabelKey[] = "volumeLabel"; |
| 61 const char kMediaGalleriesVendorNameKey[] = "vendorName"; | 61 const char kMediaGalleriesVendorNameKey[] = "vendorName"; |
| 62 const char kMediaGalleriesModelNameKey[] = "modelName"; | 62 const char kMediaGalleriesModelNameKey[] = "modelName"; |
| 63 const char kMediaGalleriesSizeKey[] = "totalSize"; | 63 const char kMediaGalleriesSizeKey[] = "totalSize"; |
| 64 const char kMediaGalleriesLastAttachTimeKey[] = "lastAttachTime"; | 64 const char kMediaGalleriesLastAttachTimeKey[] = "lastAttachTime"; |
| 65 const char kMediaGalleriesScanImageCountKey[] = "imageCount"; | |
| 66 const char kMediaGalleriesScanMusicCountKey[] = "musicCount"; | |
| 67 const char kMediaGalleriesScanVideoCountKey[] = "videoCount"; | |
| 65 const char kMediaGalleriesPrefsVersionKey[] = "preferencesVersion"; | 68 const char kMediaGalleriesPrefsVersionKey[] = "preferencesVersion"; |
| 66 | 69 |
| 67 const char kMediaGalleriesTypeAutoDetectedValue[] = "autoDetected"; | 70 const char kMediaGalleriesTypeAutoDetectedValue[] = "autoDetected"; |
| 68 const char kMediaGalleriesTypeBlackListedValue[] = "blackListed"; | 71 const char kMediaGalleriesTypeBlackListedValue[] = "blackListed"; |
| 69 const char kMediaGalleriesTypeRemovedScanValue[] = "removedScan"; | 72 const char kMediaGalleriesTypeRemovedScanValue[] = "removedScan"; |
| 70 const char kMediaGalleriesTypeScanResultValue[] = "scanResult"; | 73 const char kMediaGalleriesTypeScanResultValue[] = "scanResult"; |
| 71 const char kMediaGalleriesTypeUserAddedValue[] = "userAdded"; | 74 const char kMediaGalleriesTypeUserAddedValue[] = "userAdded"; |
| 72 | 75 |
| 73 const char kIPhotoGalleryName[] = "iPhoto"; | 76 const char kIPhotoGalleryName[] = "iPhoto"; |
| 74 const char kITunesGalleryName[] = "iTunes"; | 77 const char kITunesGalleryName[] = "iTunes"; |
| 75 const char kPicasaGalleryName[] = "Picasa"; | 78 const char kPicasaGalleryName[] = "Picasa"; |
| 76 | 79 |
| 80 const int kCurrentPrefsVersion = 2; | |
| 81 | |
| 77 int NumberExtensionsUsingMediaGalleries(Profile* profile) { | 82 int NumberExtensionsUsingMediaGalleries(Profile* profile) { |
| 78 int count = 0; | 83 int count = 0; |
| 79 if (!profile) | 84 if (!profile) |
| 80 return count; | 85 return count; |
| 81 ExtensionService* extension_service = | 86 ExtensionService* extension_service = |
| 82 extensions::ExtensionSystem::Get(profile)->extension_service(); | 87 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 83 if (!extension_service) | 88 if (!extension_service) |
| 84 return count; | 89 return count; |
| 85 | 90 |
| 86 const extensions::ExtensionSet* extensions = extension_service->extensions(); | 91 const extensions::ExtensionSet* extensions = extension_service->extensions(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 base::string16 display_name; | 172 base::string16 display_name; |
| 168 std::string device_id; | 173 std::string device_id; |
| 169 base::FilePath::StringType path; | 174 base::FilePath::StringType path; |
| 170 MediaGalleryPrefInfo::Type type = MediaGalleryPrefInfo::kInvalidType; | 175 MediaGalleryPrefInfo::Type type = MediaGalleryPrefInfo::kInvalidType; |
| 171 base::string16 volume_label; | 176 base::string16 volume_label; |
| 172 base::string16 vendor_name; | 177 base::string16 vendor_name; |
| 173 base::string16 model_name; | 178 base::string16 model_name; |
| 174 double total_size_in_bytes = 0.0; | 179 double total_size_in_bytes = 0.0; |
| 175 double last_attach_time = 0.0; | 180 double last_attach_time = 0.0; |
| 176 bool volume_metadata_valid = false; | 181 bool volume_metadata_valid = false; |
| 182 int image_count = 0; | |
| 183 int music_count = 0; | |
| 184 int video_count = 0; | |
| 177 int prefs_version = 0; | 185 int prefs_version = 0; |
| 178 | 186 |
| 179 if (!GetPrefId(dict, &pref_id) || | 187 if (!GetPrefId(dict, &pref_id) || |
| 180 !dict.GetString(kMediaGalleriesDeviceIdKey, &device_id) || | 188 !dict.GetString(kMediaGalleriesDeviceIdKey, &device_id) || |
| 181 !dict.GetString(kMediaGalleriesPathKey, &path) || | 189 !dict.GetString(kMediaGalleriesPathKey, &path) || |
| 182 !GetType(dict, &type)) { | 190 !GetType(dict, &type)) { |
| 183 return false; | 191 return false; |
| 184 } | 192 } |
| 185 | 193 |
| 186 dict.GetString(kMediaGalleriesDisplayNameKey, &display_name); | 194 dict.GetString(kMediaGalleriesDisplayNameKey, &display_name); |
| 187 dict.GetInteger(kMediaGalleriesPrefsVersionKey, &prefs_version); | 195 dict.GetInteger(kMediaGalleriesPrefsVersionKey, &prefs_version); |
| 188 | 196 |
| 189 if (dict.GetString(kMediaGalleriesVolumeLabelKey, &volume_label) && | 197 if (dict.GetString(kMediaGalleriesVolumeLabelKey, &volume_label) && |
| 190 dict.GetString(kMediaGalleriesVendorNameKey, &vendor_name) && | 198 dict.GetString(kMediaGalleriesVendorNameKey, &vendor_name) && |
| 191 dict.GetString(kMediaGalleriesModelNameKey, &model_name) && | 199 dict.GetString(kMediaGalleriesModelNameKey, &model_name) && |
| 192 dict.GetDouble(kMediaGalleriesSizeKey, &total_size_in_bytes) && | 200 dict.GetDouble(kMediaGalleriesSizeKey, &total_size_in_bytes) && |
| 193 dict.GetDouble(kMediaGalleriesLastAttachTimeKey, &last_attach_time)) { | 201 dict.GetDouble(kMediaGalleriesLastAttachTimeKey, &last_attach_time)) { |
| 194 volume_metadata_valid = true; | 202 volume_metadata_valid = true; |
| 195 } | 203 } |
| 196 | 204 |
| 205 if (type == MediaGalleryPrefInfo::kScanResult && | |
| 206 dict.GetInteger(kMediaGalleriesScanImageCountKey, &image_count) && | |
| 207 dict.GetInteger(kMediaGalleriesScanMusicCountKey, &music_count) && | |
| 208 dict.GetInteger(kMediaGalleriesScanVideoCountKey, &video_count)) { | |
| 209 out_gallery_info->image_count = image_count; | |
| 210 out_gallery_info->music_count = music_count; | |
| 211 out_gallery_info->video_count = video_count; | |
| 212 } | |
| 213 | |
| 197 out_gallery_info->pref_id = pref_id; | 214 out_gallery_info->pref_id = pref_id; |
| 198 out_gallery_info->display_name = display_name; | 215 out_gallery_info->display_name = display_name; |
| 199 out_gallery_info->device_id = device_id; | 216 out_gallery_info->device_id = device_id; |
| 200 out_gallery_info->path = base::FilePath(path); | 217 out_gallery_info->path = base::FilePath(path); |
| 201 out_gallery_info->type = type; | 218 out_gallery_info->type = type; |
| 202 out_gallery_info->volume_label = volume_label; | 219 out_gallery_info->volume_label = volume_label; |
| 203 out_gallery_info->vendor_name = vendor_name; | 220 out_gallery_info->vendor_name = vendor_name; |
| 204 out_gallery_info->model_name = model_name; | 221 out_gallery_info->model_name = model_name; |
| 205 out_gallery_info->total_size_in_bytes = total_size_in_bytes; | 222 out_gallery_info->total_size_in_bytes = total_size_in_bytes; |
| 206 out_gallery_info->last_attach_time = | 223 out_gallery_info->last_attach_time = |
| 207 base::Time::FromInternalValue(last_attach_time); | 224 base::Time::FromInternalValue(last_attach_time); |
| 208 out_gallery_info->volume_metadata_valid = volume_metadata_valid; | 225 out_gallery_info->volume_metadata_valid = volume_metadata_valid; |
| 209 out_gallery_info->prefs_version = prefs_version; | 226 out_gallery_info->prefs_version = prefs_version; |
| 210 | 227 |
| 211 return true; | 228 return true; |
| 212 } | 229 } |
| 213 | 230 |
| 214 base::DictionaryValue* CreateGalleryPrefInfoDictionary( | 231 base::DictionaryValue* CreateGalleryPrefInfoDictionary( |
| 215 const MediaGalleryPrefInfo& gallery) { | 232 const MediaGalleryPrefInfo& gallery) { |
| 216 base::DictionaryValue* dict = new base::DictionaryValue(); | 233 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 217 dict->SetString(kMediaGalleriesPrefIdKey, | 234 dict->SetString(kMediaGalleriesPrefIdKey, |
| 218 base::Uint64ToString(gallery.pref_id)); | 235 base::Uint64ToString(gallery.pref_id)); |
| 219 if (!gallery.volume_metadata_valid) | |
| 220 dict->SetString(kMediaGalleriesDisplayNameKey, gallery.display_name); | |
| 221 dict->SetString(kMediaGalleriesDeviceIdKey, gallery.device_id); | 236 dict->SetString(kMediaGalleriesDeviceIdKey, gallery.device_id); |
| 222 dict->SetString(kMediaGalleriesPathKey, gallery.path.value()); | 237 dict->SetString(kMediaGalleriesPathKey, gallery.path.value()); |
| 223 dict->SetString(kMediaGalleriesTypeKey, TypeToStringValue(gallery.type)); | 238 dict->SetString(kMediaGalleriesTypeKey, TypeToStringValue(gallery.type)); |
| 224 | 239 |
| 225 if (gallery.volume_metadata_valid) { | 240 if (gallery.volume_metadata_valid) { |
| 226 dict->SetString(kMediaGalleriesVolumeLabelKey, gallery.volume_label); | 241 dict->SetString(kMediaGalleriesVolumeLabelKey, gallery.volume_label); |
| 227 dict->SetString(kMediaGalleriesVendorNameKey, gallery.vendor_name); | 242 dict->SetString(kMediaGalleriesVendorNameKey, gallery.vendor_name); |
| 228 dict->SetString(kMediaGalleriesModelNameKey, gallery.model_name); | 243 dict->SetString(kMediaGalleriesModelNameKey, gallery.model_name); |
| 229 dict->SetDouble(kMediaGalleriesSizeKey, gallery.total_size_in_bytes); | 244 dict->SetDouble(kMediaGalleriesSizeKey, gallery.total_size_in_bytes); |
| 230 dict->SetDouble(kMediaGalleriesLastAttachTimeKey, | 245 dict->SetDouble(kMediaGalleriesLastAttachTimeKey, |
| 231 gallery.last_attach_time.ToInternalValue()); | 246 gallery.last_attach_time.ToInternalValue()); |
| 247 } else { | |
| 248 dict->SetString(kMediaGalleriesDisplayNameKey, gallery.display_name); | |
| 249 } | |
| 250 | |
| 251 if (gallery.type == MediaGalleryPrefInfo::kScanResult) { | |
| 252 dict->SetInteger(kMediaGalleriesScanImageCountKey, gallery.image_count); | |
| 253 dict->SetInteger(kMediaGalleriesScanMusicCountKey, gallery.music_count); | |
| 254 dict->SetInteger(kMediaGalleriesScanVideoCountKey, gallery.video_count); | |
| 232 } | 255 } |
| 233 | 256 |
| 234 // Version 0 of the prefs format was that the display_name was always | 257 // Version 0 of the prefs format was that the display_name was always |
| 235 // used to show the user-visible name of the gallery. Version 1 means | 258 // used to show the user-visible name of the gallery. Version 1 means |
| 236 // that there is an optional display_name, and when it is present, it | 259 // that there is an optional display_name, and when it is present, it |
| 237 // overrides the name that would be built from the volume metadata, path, | 260 // overrides the name that would be built from the volume metadata, path, |
| 238 // or whatever other data. So if we see a display_name with version 0, it | 261 // or whatever other data. So if we see a display_name with version 0, it |
| 239 // means it may be overwritten simply by getting new volume metadata. | 262 // means it may be overwritten simply by getting new volume metadata. |
| 240 // A display_name with version 1 should not be overwritten. | 263 // A display_name with version 1 should not be overwritten. |
| 241 dict->SetInteger(kMediaGalleriesPrefsVersionKey, gallery.prefs_version); | 264 dict->SetInteger(kMediaGalleriesPrefsVersionKey, gallery.prefs_version); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 return product_name; | 324 return product_name; |
| 302 } | 325 } |
| 303 | 326 |
| 304 } // namespace | 327 } // namespace |
| 305 | 328 |
| 306 MediaGalleryPrefInfo::MediaGalleryPrefInfo() | 329 MediaGalleryPrefInfo::MediaGalleryPrefInfo() |
| 307 : pref_id(kInvalidMediaGalleryPrefId), | 330 : pref_id(kInvalidMediaGalleryPrefId), |
| 308 type(kInvalidType), | 331 type(kInvalidType), |
| 309 total_size_in_bytes(0), | 332 total_size_in_bytes(0), |
| 310 volume_metadata_valid(false), | 333 volume_metadata_valid(false), |
| 334 image_count(0), | |
| 335 music_count(0), | |
| 336 video_count(0), | |
| 311 prefs_version(0) { | 337 prefs_version(0) { |
| 312 } | 338 } |
| 313 | 339 |
| 314 MediaGalleryPrefInfo::~MediaGalleryPrefInfo() {} | 340 MediaGalleryPrefInfo::~MediaGalleryPrefInfo() {} |
| 315 | 341 |
| 316 base::FilePath MediaGalleryPrefInfo::AbsolutePath() const { | 342 base::FilePath MediaGalleryPrefInfo::AbsolutePath() const { |
| 317 base::FilePath base_path = MediaStorageUtil::FindDevicePathById(device_id); | 343 base::FilePath base_path = MediaStorageUtil::FindDevicePathById(device_id); |
| 318 DCHECK(!path.IsAbsolute()); | 344 DCHECK(!path.IsAbsolute()); |
| 319 return base_path.empty() ? base_path : base_path.Append(path); | 345 return base_path.empty() ? base_path : base_path.Append(path); |
| 320 } | 346 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 if (!(StorageInfo::IsMediaDevice(existing_devices[i].device_id()) && | 509 if (!(StorageInfo::IsMediaDevice(existing_devices[i].device_id()) && |
| 484 StorageInfo::IsRemovableDevice(existing_devices[i].device_id()))) | 510 StorageInfo::IsRemovableDevice(existing_devices[i].device_id()))) |
| 485 continue; | 511 continue; |
| 486 AddGallery(existing_devices[i].device_id(), | 512 AddGallery(existing_devices[i].device_id(), |
| 487 base::FilePath(), | 513 base::FilePath(), |
| 488 MediaGalleryPrefInfo::kAutoDetected, | 514 MediaGalleryPrefInfo::kAutoDetected, |
| 489 existing_devices[i].storage_label(), | 515 existing_devices[i].storage_label(), |
| 490 existing_devices[i].vendor_name(), | 516 existing_devices[i].vendor_name(), |
| 491 existing_devices[i].model_name(), | 517 existing_devices[i].model_name(), |
| 492 existing_devices[i].total_size_in_bytes(), | 518 existing_devices[i].total_size_in_bytes(), |
| 493 base::Time::Now()); | 519 base::Time::Now(), 0, 0, 0); |
| 494 } | 520 } |
| 495 | 521 |
| 496 for (std::vector<base::Closure>::iterator iter = | 522 for (std::vector<base::Closure>::iterator iter = |
| 497 on_initialize_callbacks_.begin(); | 523 on_initialize_callbacks_.begin(); |
| 498 iter != on_initialize_callbacks_.end(); | 524 iter != on_initialize_callbacks_.end(); |
| 499 ++iter) { | 525 ++iter) { |
| 500 iter->Run(); | 526 iter->Run(); |
| 501 } | 527 } |
| 502 on_initialize_callbacks_.clear(); | 528 on_initialize_callbacks_.clear(); |
| 503 } | 529 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 514 if (!PathService::Get(kDirectoryKeys[i], &path)) | 540 if (!PathService::Get(kDirectoryKeys[i], &path)) |
| 515 continue; | 541 continue; |
| 516 | 542 |
| 517 base::FilePath relative_path; | 543 base::FilePath relative_path; |
| 518 StorageInfo info; | 544 StorageInfo info; |
| 519 if (MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path)) { | 545 if (MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path)) { |
| 520 AddGalleryInternal(info.device_id(), info.name(), relative_path, | 546 AddGalleryInternal(info.device_id(), info.name(), relative_path, |
| 521 MediaGalleryPrefInfo::kAutoDetected, | 547 MediaGalleryPrefInfo::kAutoDetected, |
| 522 info.storage_label(), info.vendor_name(), | 548 info.storage_label(), info.vendor_name(), |
| 523 info.model_name(), info.total_size_in_bytes(), | 549 info.model_name(), info.total_size_in_bytes(), |
| 524 base::Time(), true, 2); | 550 base::Time(), true, 0, 0, 0, kCurrentPrefsVersion); |
| 525 } | 551 } |
| 526 } | 552 } |
| 527 } | 553 } |
| 528 | 554 |
| 529 bool MediaGalleriesPreferences::UpdateDeviceIDForSingletonType( | 555 bool MediaGalleriesPreferences::UpdateDeviceIDForSingletonType( |
| 530 const std::string& device_id) { | 556 const std::string& device_id) { |
| 531 StorageInfo::Type singleton_type; | 557 StorageInfo::Type singleton_type; |
| 532 if (!StorageInfo::CrackDeviceId(device_id, &singleton_type, NULL)) | 558 if (!StorageInfo::CrackDeviceId(device_id, &singleton_type, NULL)) |
| 533 return false; | 559 return false; |
| 534 | 560 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 else if (StorageInfo::IsITunesDevice(device_id)) | 608 else if (StorageInfo::IsITunesDevice(device_id)) |
| 583 gallery_name = kITunesGalleryName; | 609 gallery_name = kITunesGalleryName; |
| 584 else if (StorageInfo::IsPicasaDevice(device_id)) | 610 else if (StorageInfo::IsPicasaDevice(device_id)) |
| 585 gallery_name = kPicasaGalleryName; | 611 gallery_name = kPicasaGalleryName; |
| 586 else | 612 else |
| 587 NOTREACHED(); | 613 NOTREACHED(); |
| 588 | 614 |
| 589 AddGalleryInternal(device_id, base::ASCIIToUTF16(gallery_name), | 615 AddGalleryInternal(device_id, base::ASCIIToUTF16(gallery_name), |
| 590 base::FilePath(), MediaGalleryPrefInfo::kAutoDetected, | 616 base::FilePath(), MediaGalleryPrefInfo::kAutoDetected, |
| 591 base::string16(), base::string16(), base::string16(), 0, | 617 base::string16(), base::string16(), base::string16(), 0, |
| 592 base::Time(), false, 2); | 618 base::Time(), false, 0, 0, 0, kCurrentPrefsVersion); |
| 593 } | 619 } |
| 594 | 620 |
| 595 OnInitializationCallbackReturned(); | 621 OnInitializationCallbackReturned(); |
| 596 } | 622 } |
| 597 | 623 |
| 598 void MediaGalleriesPreferences::InitFromPrefs() { | 624 void MediaGalleriesPreferences::InitFromPrefs() { |
| 599 known_galleries_.clear(); | 625 known_galleries_.clear(); |
| 600 device_map_.clear(); | 626 device_map_.clear(); |
| 601 | 627 |
| 602 PrefService* prefs = profile_->GetPrefs(); | 628 PrefService* prefs = profile_->GetPrefs(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 633 | 659 |
| 634 void MediaGalleriesPreferences::OnRemovableStorageAttached( | 660 void MediaGalleriesPreferences::OnRemovableStorageAttached( |
| 635 const StorageInfo& info) { | 661 const StorageInfo& info) { |
| 636 DCHECK(IsInitialized()); | 662 DCHECK(IsInitialized()); |
| 637 if (!StorageInfo::IsMediaDevice(info.device_id())) | 663 if (!StorageInfo::IsMediaDevice(info.device_id())) |
| 638 return; | 664 return; |
| 639 | 665 |
| 640 AddGallery(info.device_id(), base::FilePath(), | 666 AddGallery(info.device_id(), base::FilePath(), |
| 641 MediaGalleryPrefInfo::kAutoDetected, info.storage_label(), | 667 MediaGalleryPrefInfo::kAutoDetected, info.storage_label(), |
| 642 info.vendor_name(), info.model_name(), info.total_size_in_bytes(), | 668 info.vendor_name(), info.model_name(), info.total_size_in_bytes(), |
| 643 base::Time::Now()); | 669 base::Time::Now(), 0, 0, 0); |
| 644 } | 670 } |
| 645 | 671 |
| 646 bool MediaGalleriesPreferences::LookUpGalleryByPath( | 672 bool MediaGalleriesPreferences::LookUpGalleryByPath( |
| 647 const base::FilePath& path, | 673 const base::FilePath& path, |
| 648 MediaGalleryPrefInfo* gallery_info) const { | 674 MediaGalleryPrefInfo* gallery_info) const { |
| 649 DCHECK(IsInitialized()); | 675 DCHECK(IsInitialized()); |
| 650 StorageInfo info; | 676 StorageInfo info; |
| 651 base::FilePath relative_path; | 677 base::FilePath relative_path; |
| 652 if (!MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path)) { | 678 if (!MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path)) { |
| 653 if (gallery_info) | 679 if (gallery_info) |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 681 gallery_info->pref_id = kInvalidMediaGalleryPrefId; | 707 gallery_info->pref_id = kInvalidMediaGalleryPrefId; |
| 682 gallery_info->device_id = info.device_id(); | 708 gallery_info->device_id = info.device_id(); |
| 683 gallery_info->path = relative_path; | 709 gallery_info->path = relative_path; |
| 684 gallery_info->type = MediaGalleryPrefInfo::kInvalidType; | 710 gallery_info->type = MediaGalleryPrefInfo::kInvalidType; |
| 685 gallery_info->volume_label = info.storage_label(); | 711 gallery_info->volume_label = info.storage_label(); |
| 686 gallery_info->vendor_name = info.vendor_name(); | 712 gallery_info->vendor_name = info.vendor_name(); |
| 687 gallery_info->model_name = info.model_name(); | 713 gallery_info->model_name = info.model_name(); |
| 688 gallery_info->total_size_in_bytes = info.total_size_in_bytes(); | 714 gallery_info->total_size_in_bytes = info.total_size_in_bytes(); |
| 689 gallery_info->last_attach_time = base::Time::Now(); | 715 gallery_info->last_attach_time = base::Time::Now(); |
| 690 gallery_info->volume_metadata_valid = true; | 716 gallery_info->volume_metadata_valid = true; |
| 691 gallery_info->prefs_version = 2; | 717 gallery_info->prefs_version = kCurrentPrefsVersion; |
| 692 } | 718 } |
| 693 return false; | 719 return false; |
| 694 } | 720 } |
| 695 | 721 |
| 696 MediaGalleryPrefIdSet MediaGalleriesPreferences::LookUpGalleriesByDeviceId( | 722 MediaGalleryPrefIdSet MediaGalleriesPreferences::LookUpGalleriesByDeviceId( |
| 697 const std::string& device_id) const { | 723 const std::string& device_id) const { |
| 698 DeviceIdPrefIdsMap::const_iterator found = device_map_.find(device_id); | 724 DeviceIdPrefIdsMap::const_iterator found = device_map_.find(device_id); |
| 699 if (found == device_map_.end()) | 725 if (found == device_map_.end()) |
| 700 return MediaGalleryPrefIdSet(); | 726 return MediaGalleryPrefIdSet(); |
| 701 return found->second; | 727 return found->second; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 719 } | 745 } |
| 720 | 746 |
| 721 MediaGalleryPrefId MediaGalleriesPreferences::AddGallery( | 747 MediaGalleryPrefId MediaGalleriesPreferences::AddGallery( |
| 722 const std::string& device_id, | 748 const std::string& device_id, |
| 723 const base::FilePath& relative_path, | 749 const base::FilePath& relative_path, |
| 724 MediaGalleryPrefInfo::Type type, | 750 MediaGalleryPrefInfo::Type type, |
| 725 const base::string16& volume_label, | 751 const base::string16& volume_label, |
| 726 const base::string16& vendor_name, | 752 const base::string16& vendor_name, |
| 727 const base::string16& model_name, | 753 const base::string16& model_name, |
| 728 uint64 total_size_in_bytes, | 754 uint64 total_size_in_bytes, |
| 729 base::Time last_attach_time) { | 755 base::Time last_attach_time, |
| 756 int image_count, | |
| 757 int music_count, | |
| 758 int video_count) { | |
| 730 DCHECK(IsInitialized()); | 759 DCHECK(IsInitialized()); |
| 731 return AddGalleryInternal(device_id, base::string16(), relative_path, | 760 return AddGalleryInternal(device_id, base::string16(), relative_path, |
| 732 type, volume_label, vendor_name, model_name, | 761 type, volume_label, vendor_name, model_name, |
| 733 total_size_in_bytes, last_attach_time, true, 2); | 762 total_size_in_bytes, last_attach_time, true, |
| 763 image_count, music_count, video_count, | |
| 764 kCurrentPrefsVersion); | |
| 734 } | 765 } |
| 735 | 766 |
| 736 MediaGalleryPrefId MediaGalleriesPreferences::AddGalleryInternal( | 767 MediaGalleryPrefId MediaGalleriesPreferences::AddGalleryInternal( |
| 737 const std::string& device_id, const base::string16& display_name, | 768 const std::string& device_id, const base::string16& display_name, |
| 738 const base::FilePath& relative_path, MediaGalleryPrefInfo::Type type, | 769 const base::FilePath& relative_path, MediaGalleryPrefInfo::Type type, |
| 739 const base::string16& volume_label, const base::string16& vendor_name, | 770 const base::string16& volume_label, const base::string16& vendor_name, |
| 740 const base::string16& model_name, uint64 total_size_in_bytes, | 771 const base::string16& model_name, uint64 total_size_in_bytes, |
| 741 base::Time last_attach_time, | 772 base::Time last_attach_time, bool volume_metadata_valid, |
| 742 bool volume_metadata_valid, | 773 int image_count, int music_count, int video_count, int prefs_version) { |
| 743 int prefs_version) { | |
| 744 DCHECK(type == MediaGalleryPrefInfo::kUserAdded || | 774 DCHECK(type == MediaGalleryPrefInfo::kUserAdded || |
| 745 type == MediaGalleryPrefInfo::kAutoDetected || | 775 type == MediaGalleryPrefInfo::kAutoDetected || |
| 746 type == MediaGalleryPrefInfo::kScanResult); | 776 type == MediaGalleryPrefInfo::kScanResult); |
| 747 base::FilePath normalized_relative_path = | 777 base::FilePath normalized_relative_path = |
| 748 relative_path.NormalizePathSeparators(); | 778 relative_path.NormalizePathSeparators(); |
| 749 MediaGalleryPrefIdSet galleries_on_device = | 779 MediaGalleryPrefIdSet galleries_on_device = |
| 750 LookUpGalleriesByDeviceId(device_id); | 780 LookUpGalleriesByDeviceId(device_id); |
| 751 for (MediaGalleryPrefIdSet::const_iterator pref_id_it = | 781 for (MediaGalleryPrefIdSet::const_iterator pref_id_it = |
| 752 galleries_on_device.begin(); | 782 galleries_on_device.begin(); |
| 753 pref_id_it != galleries_on_device.end(); | 783 pref_id_it != galleries_on_device.end(); |
| 754 ++pref_id_it) { | 784 ++pref_id_it) { |
| 755 const MediaGalleryPrefInfo& existing = | 785 const MediaGalleryPrefInfo& existing = |
| 756 known_galleries_.find(*pref_id_it)->second; | 786 known_galleries_.find(*pref_id_it)->second; |
| 757 if (existing.path != normalized_relative_path) | 787 if (existing.path != normalized_relative_path) |
| 758 continue; | 788 continue; |
| 759 | 789 |
| 760 bool update_gallery_type = false; | 790 bool update_gallery_type = false; |
| 761 MediaGalleryPrefInfo::Type new_type = existing.type; | 791 MediaGalleryPrefInfo::Type new_type = existing.type; |
| 762 if (type == MediaGalleryPrefInfo::kUserAdded) { | 792 if (type == MediaGalleryPrefInfo::kUserAdded) { |
| 763 if (existing.type == MediaGalleryPrefInfo::kBlackListed) { | 793 if (existing.type == MediaGalleryPrefInfo::kBlackListed) { |
| 764 new_type = MediaGalleryPrefInfo::kAutoDetected; | 794 new_type = MediaGalleryPrefInfo::kAutoDetected; |
| 765 update_gallery_type = true; | 795 update_gallery_type = true; |
| 766 } | 796 } |
| 767 if (existing.type == MediaGalleryPrefInfo::kRemovedScan) { | 797 if (existing.type == MediaGalleryPrefInfo::kRemovedScan) { |
| 768 new_type = type; | 798 new_type = MediaGalleryPrefInfo::kUserAdded; |
| 769 update_gallery_type = true; | 799 update_gallery_type = true; |
| 770 } | 800 } |
| 771 } | 801 } |
| 772 | 802 |
| 773 // Status quo: In M27 and M28, galleries added manually use version 0, | 803 // Status quo: In M27 and M28, galleries added manually use version 0, |
| 774 // and galleries added automatically (including default galleries) use | 804 // and galleries added automatically (including default galleries) use |
| 775 // version 1. The name override is used by default galleries as well | 805 // version 1. The name override is used by default galleries as well |
| 776 // as all device attach events. | 806 // as all device attach events. |
| 777 // We want to upgrade the name if the existing version is < 2. Leave it | 807 // We want to upgrade the name if the existing version is < 2. Leave it |
| 778 // alone if the existing display name is set with version == 2 and the | 808 // alone if the existing display name is set with version == 2 and the |
| 779 // proposed new name is empty. | 809 // proposed new name is empty. |
| 780 bool update_gallery_name = existing.display_name != display_name; | 810 bool update_gallery_name = existing.display_name != display_name; |
| 781 if (existing.prefs_version == 2 && !existing.display_name.empty() && | 811 if (existing.prefs_version == 2 && !existing.display_name.empty() && |
| 782 display_name.empty()) { | 812 display_name.empty()) { |
| 783 update_gallery_name = false; | 813 update_gallery_name = false; |
| 784 } | 814 } |
| 785 bool update_gallery_metadata = volume_metadata_valid && | 815 bool update_gallery_metadata = volume_metadata_valid && |
| 786 ((existing.volume_label != volume_label) || | 816 ((existing.volume_label != volume_label) || |
| 787 (existing.vendor_name != vendor_name) || | 817 (existing.vendor_name != vendor_name) || |
| 788 (existing.model_name != model_name) || | 818 (existing.model_name != model_name) || |
| 789 (existing.total_size_in_bytes != total_size_in_bytes) || | 819 (existing.total_size_in_bytes != total_size_in_bytes) || |
| 790 (existing.last_attach_time != last_attach_time)); | 820 (existing.last_attach_time != last_attach_time)); |
| 791 | 821 |
| 822 bool update_scan_counts = | |
| 823 (new_type == MediaGalleryPrefInfo::kScanResult) && | |
| 824 (image_count > 0 || music_count > 0 || video_count > 0); | |
| 825 | |
| 792 if (!update_gallery_name && !update_gallery_type && | 826 if (!update_gallery_name && !update_gallery_type && |
| 793 !update_gallery_metadata) | 827 !update_gallery_metadata && !update_scan_counts) |
| 794 return *pref_id_it; | 828 return *pref_id_it; |
| 795 | 829 |
| 796 PrefService* prefs = profile_->GetPrefs(); | 830 PrefService* prefs = profile_->GetPrefs(); |
| 797 scoped_ptr<ListPrefUpdate> update( | 831 scoped_ptr<ListPrefUpdate> update( |
| 798 new ListPrefUpdate(prefs, prefs::kMediaGalleriesRememberedGalleries)); | 832 new ListPrefUpdate(prefs, prefs::kMediaGalleriesRememberedGalleries)); |
| 799 base::ListValue* list = update->Get(); | 833 base::ListValue* list = update->Get(); |
| 800 | 834 |
| 801 for (base::ListValue::const_iterator list_iter = list->begin(); | 835 for (base::ListValue::const_iterator list_iter = list->begin(); |
| 802 list_iter != list->end(); | 836 list_iter != list->end(); |
| 803 ++list_iter) { | 837 ++list_iter) { |
| 804 base::DictionaryValue* dict; | 838 base::DictionaryValue* dict; |
| 805 MediaGalleryPrefId iter_id; | 839 MediaGalleryPrefId iter_id; |
| 806 if ((*list_iter)->GetAsDictionary(&dict) && | 840 if ((*list_iter)->GetAsDictionary(&dict) && |
| 807 GetPrefId(*dict, &iter_id) && | 841 GetPrefId(*dict, &iter_id) && |
| 808 *pref_id_it == iter_id) { | 842 *pref_id_it == iter_id) { |
| 809 if (update_gallery_type) | 843 if (update_gallery_type) |
| 810 dict->SetString(kMediaGalleriesTypeKey, TypeToStringValue(new_type)); | 844 dict->SetString(kMediaGalleriesTypeKey, TypeToStringValue(new_type)); |
| 811 if (update_gallery_name) | 845 if (update_gallery_name) |
| 812 dict->SetString(kMediaGalleriesDisplayNameKey, display_name); | 846 dict->SetString(kMediaGalleriesDisplayNameKey, display_name); |
| 813 if (update_gallery_metadata) { | 847 if (update_gallery_metadata) { |
| 814 dict->SetString(kMediaGalleriesVolumeLabelKey, volume_label); | 848 dict->SetString(kMediaGalleriesVolumeLabelKey, volume_label); |
| 815 dict->SetString(kMediaGalleriesVendorNameKey, vendor_name); | 849 dict->SetString(kMediaGalleriesVendorNameKey, vendor_name); |
| 816 dict->SetString(kMediaGalleriesModelNameKey, model_name); | 850 dict->SetString(kMediaGalleriesModelNameKey, model_name); |
| 817 dict->SetDouble(kMediaGalleriesSizeKey, total_size_in_bytes); | 851 dict->SetDouble(kMediaGalleriesSizeKey, total_size_in_bytes); |
| 818 dict->SetDouble(kMediaGalleriesLastAttachTimeKey, | 852 dict->SetDouble(kMediaGalleriesLastAttachTimeKey, |
| 819 last_attach_time.ToInternalValue()); | 853 last_attach_time.ToInternalValue()); |
| 820 } | 854 } |
| 855 if (update_scan_counts) { | |
| 856 dict->SetInteger(kMediaGalleriesScanImageCountKey, image_count); | |
| 857 dict->SetInteger(kMediaGalleriesScanMusicCountKey, music_count); | |
| 858 dict->SetInteger(kMediaGalleriesScanVideoCountKey, video_count); | |
| 859 } | |
| 821 dict->SetInteger(kMediaGalleriesPrefsVersionKey, prefs_version); | 860 dict->SetInteger(kMediaGalleriesPrefsVersionKey, prefs_version); |
| 822 break; | 861 break; |
| 823 } | 862 } |
| 824 } | 863 } |
| 825 | 864 |
| 826 // Commits the prefs update. | 865 // Commits the prefs update. |
| 827 update.reset(); | 866 update.reset(); |
| 828 | 867 |
| 829 if (update_gallery_name || update_gallery_metadata || update_gallery_type) { | 868 InitFromPrefs(); |
| 830 InitFromPrefs(); | 869 FOR_EACH_OBSERVER(GalleryChangeObserver, gallery_change_observers_, |
| 831 FOR_EACH_OBSERVER(GalleryChangeObserver, | 870 OnGalleryInfoUpdated(this, *pref_id_it)); |
| 832 gallery_change_observers_, | |
| 833 OnGalleryInfoUpdated(this, *pref_id_it)); | |
| 834 } | |
| 835 return *pref_id_it; | 871 return *pref_id_it; |
| 836 } | 872 } |
| 837 | 873 |
| 838 PrefService* prefs = profile_->GetPrefs(); | 874 PrefService* prefs = profile_->GetPrefs(); |
| 839 | 875 |
| 840 MediaGalleryPrefInfo gallery_info; | 876 MediaGalleryPrefInfo gallery_info; |
| 841 gallery_info.pref_id = prefs->GetUint64(prefs::kMediaGalleriesUniqueId); | 877 gallery_info.pref_id = prefs->GetUint64(prefs::kMediaGalleriesUniqueId); |
| 842 prefs->SetUint64(prefs::kMediaGalleriesUniqueId, gallery_info.pref_id + 1); | 878 prefs->SetUint64(prefs::kMediaGalleriesUniqueId, gallery_info.pref_id + 1); |
| 843 gallery_info.display_name = display_name; | 879 gallery_info.display_name = display_name; |
| 844 gallery_info.device_id = device_id; | 880 gallery_info.device_id = device_id; |
| 845 gallery_info.path = normalized_relative_path; | 881 gallery_info.path = normalized_relative_path; |
| 846 gallery_info.type = type; | 882 gallery_info.type = type; |
| 847 if (volume_metadata_valid) { | 883 gallery_info.volume_label = volume_label; |
|
Lei Zhang
2014/01/15 22:13:43
Why is this changing?
vandebo (ex-Chrome)
2014/01/15 22:19:44
The thing below this conditionally sets the fields
Lei Zhang
2014/01/15 22:38:23
Right now this change is a no-op because every pla
vandebo (ex-Chrome)
2014/01/15 22:43:05
I don't see that: in CreateGalleryPrefInfoDictiona
| |
| 848 gallery_info.volume_label = volume_label; | 884 gallery_info.vendor_name = vendor_name; |
| 849 gallery_info.vendor_name = vendor_name; | 885 gallery_info.model_name = model_name; |
| 850 gallery_info.model_name = model_name; | 886 gallery_info.total_size_in_bytes = total_size_in_bytes; |
| 851 gallery_info.total_size_in_bytes = total_size_in_bytes; | 887 gallery_info.last_attach_time = last_attach_time; |
| 852 gallery_info.last_attach_time = last_attach_time; | |
| 853 } | |
| 854 gallery_info.volume_metadata_valid = volume_metadata_valid; | 888 gallery_info.volume_metadata_valid = volume_metadata_valid; |
| 889 gallery_info.image_count = image_count; | |
| 890 gallery_info.music_count = music_count; | |
| 891 gallery_info.video_count = video_count; | |
| 855 gallery_info.prefs_version = prefs_version; | 892 gallery_info.prefs_version = prefs_version; |
| 856 | 893 |
| 857 { | 894 { |
| 858 ListPrefUpdate update(prefs, prefs::kMediaGalleriesRememberedGalleries); | 895 ListPrefUpdate update(prefs, prefs::kMediaGalleriesRememberedGalleries); |
| 859 base::ListValue* list = update.Get(); | 896 base::ListValue* list = update.Get(); |
| 860 list->Append(CreateGalleryPrefInfoDictionary(gallery_info)); | 897 list->Append(CreateGalleryPrefInfoDictionary(gallery_info)); |
| 861 } | 898 } |
| 862 InitFromPrefs(); | 899 InitFromPrefs(); |
| 863 FOR_EACH_OBSERVER(GalleryChangeObserver, | 900 FOR_EACH_OBSERVER(GalleryChangeObserver, |
| 864 gallery_change_observers_, | 901 gallery_change_observers_, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 878 return AddGalleryInternal(gallery_info.device_id, | 915 return AddGalleryInternal(gallery_info.device_id, |
| 879 gallery_info.display_name, | 916 gallery_info.display_name, |
| 880 gallery_info.path, | 917 gallery_info.path, |
| 881 type, | 918 type, |
| 882 gallery_info.volume_label, | 919 gallery_info.volume_label, |
| 883 gallery_info.vendor_name, | 920 gallery_info.vendor_name, |
| 884 gallery_info.model_name, | 921 gallery_info.model_name, |
| 885 gallery_info.total_size_in_bytes, | 922 gallery_info.total_size_in_bytes, |
| 886 gallery_info.last_attach_time, | 923 gallery_info.last_attach_time, |
| 887 gallery_info.volume_metadata_valid, | 924 gallery_info.volume_metadata_valid, |
| 888 gallery_info.prefs_version); | 925 0, 0, 0, |
| 926 kCurrentPrefsVersion); | |
| 889 } | 927 } |
| 890 | 928 |
| 891 void MediaGalleriesPreferences::ForgetGalleryById(MediaGalleryPrefId pref_id) { | 929 void MediaGalleriesPreferences::ForgetGalleryById(MediaGalleryPrefId pref_id) { |
| 892 DCHECK(IsInitialized()); | 930 DCHECK(IsInitialized()); |
| 893 PrefService* prefs = profile_->GetPrefs(); | 931 PrefService* prefs = profile_->GetPrefs(); |
| 894 scoped_ptr<ListPrefUpdate> update(new ListPrefUpdate( | 932 scoped_ptr<ListPrefUpdate> update(new ListPrefUpdate( |
| 895 prefs, prefs::kMediaGalleriesRememberedGalleries)); | 933 prefs, prefs::kMediaGalleriesRememberedGalleries)); |
| 896 base::ListValue* list = update->Get(); | 934 base::ListValue* list = update->Get(); |
| 897 | 935 |
| 898 if (!ContainsKey(known_galleries_, pref_id)) | 936 if (!ContainsKey(known_galleries_, pref_id)) |
| 899 return; | 937 return; |
| 900 | 938 |
| 901 for (base::ListValue::iterator iter = list->begin(); | 939 for (base::ListValue::iterator iter = list->begin(); |
| 902 iter != list->end(); ++iter) { | 940 iter != list->end(); ++iter) { |
| 903 base::DictionaryValue* dict; | 941 base::DictionaryValue* dict; |
| 904 MediaGalleryPrefId iter_id; | 942 MediaGalleryPrefId iter_id; |
| 905 if ((*iter)->GetAsDictionary(&dict) && GetPrefId(*dict, &iter_id) && | 943 if ((*iter)->GetAsDictionary(&dict) && GetPrefId(*dict, &iter_id) && |
| 906 pref_id == iter_id) { | 944 pref_id == iter_id) { |
| 907 RemoveGalleryPermissionsFromPrefs(pref_id); | 945 RemoveGalleryPermissionsFromPrefs(pref_id); |
| 908 MediaGalleryPrefInfo::Type type; | 946 MediaGalleryPrefInfo::Type type; |
| 909 if (GetType(*dict, &type) && | 947 if (GetType(*dict, &type) && |
| 910 (type == MediaGalleryPrefInfo::kAutoDetected || | 948 (type == MediaGalleryPrefInfo::kAutoDetected || |
| 911 type == MediaGalleryPrefInfo::kScanResult)) { | 949 type == MediaGalleryPrefInfo::kScanResult)) { |
| 912 if (type == MediaGalleryPrefInfo::kAutoDetected) { | 950 if (type == MediaGalleryPrefInfo::kAutoDetected) { |
| 913 dict->SetString(kMediaGalleriesTypeKey, | 951 dict->SetString(kMediaGalleriesTypeKey, |
| 914 kMediaGalleriesTypeBlackListedValue); | 952 kMediaGalleriesTypeBlackListedValue); |
| 915 } else { | 953 } else { |
| 916 dict->SetString(kMediaGalleriesTypeKey, | 954 dict->SetString(kMediaGalleriesTypeKey, |
| 917 kMediaGalleriesTypeRemovedScanValue); | 955 kMediaGalleriesTypeRemovedScanValue); |
| 956 dict->SetInteger(kMediaGalleriesScanImageCountKey, 0); | |
| 957 dict->SetInteger(kMediaGalleriesScanMusicCountKey, 0); | |
| 958 dict->SetInteger(kMediaGalleriesScanVideoCountKey, 0); | |
| 918 } | 959 } |
| 919 } else { | 960 } else { |
| 920 list->Erase(iter, NULL); | 961 list->Erase(iter, NULL); |
| 921 } | 962 } |
| 922 update.reset(NULL); // commits the update. | 963 update.reset(NULL); // commits the update. |
| 923 | 964 |
| 924 InitFromPrefs(); | 965 InitFromPrefs(); |
| 925 FOR_EACH_OBSERVER(GalleryChangeObserver, | 966 FOR_EACH_OBSERVER(GalleryChangeObserver, |
| 926 gallery_change_observers_, | 967 gallery_change_observers_, |
| 927 OnGalleryRemoved(this, pref_id)); | 968 OnGalleryRemoved(this, pref_id)); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1143 if (extension_prefs_for_testing_) | 1184 if (extension_prefs_for_testing_) |
| 1144 return extension_prefs_for_testing_; | 1185 return extension_prefs_for_testing_; |
| 1145 return extensions::ExtensionPrefs::Get(profile_); | 1186 return extensions::ExtensionPrefs::Get(profile_); |
| 1146 } | 1187 } |
| 1147 | 1188 |
| 1148 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( | 1189 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( |
| 1149 extensions::ExtensionPrefs* extension_prefs) { | 1190 extensions::ExtensionPrefs* extension_prefs) { |
| 1150 DCHECK(IsInitialized()); | 1191 DCHECK(IsInitialized()); |
| 1151 extension_prefs_for_testing_ = extension_prefs; | 1192 extension_prefs_for_testing_ = extension_prefs; |
| 1152 } | 1193 } |
| OLD | NEW |