| 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/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 251 |
| 252 for (size_t i = 0; i < arraysize(kDirectoryKeys); ++i) { | 252 for (size_t i = 0; i < arraysize(kDirectoryKeys); ++i) { |
| 253 base::FilePath path; | 253 base::FilePath path; |
| 254 if (!PathService::Get(kDirectoryKeys[i], &path)) | 254 if (!PathService::Get(kDirectoryKeys[i], &path)) |
| 255 continue; | 255 continue; |
| 256 | 256 |
| 257 base::FilePath relative_path; | 257 base::FilePath relative_path; |
| 258 StorageInfo info; | 258 StorageInfo info; |
| 259 if (MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path)) { | 259 if (MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path)) { |
| 260 // TODO(gbillock): Add in the volume metadata here when available. | 260 // TODO(gbillock): Add in the volume metadata here when available. |
| 261 AddGalleryWithName(info.device_id, info.name, relative_path, | 261 AddGalleryWithName(info.device_id(), info.name(), relative_path, |
| 262 false /*user added*/); | 262 false /*user added*/); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 void MediaGalleriesPreferences::OnITunesDeviceID(const std::string& device_id) { | 267 void MediaGalleriesPreferences::OnITunesDeviceID(const std::string& device_id) { |
| 268 DCHECK(!device_id.empty()); | 268 DCHECK(!device_id.empty()); |
| 269 AddGalleryWithName(device_id, ASCIIToUTF16(kITunesGalleryName), | 269 AddGalleryWithName(device_id, ASCIIToUTF16(kITunesGalleryName), |
| 270 base::FilePath(), false /*not user added*/); | 270 base::FilePath(), false /*not user added*/); |
| 271 } | 271 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 gallery_change_observers_.AddObserver(observer); | 308 gallery_change_observers_.AddObserver(observer); |
| 309 } | 309 } |
| 310 | 310 |
| 311 void MediaGalleriesPreferences::RemoveGalleryChangeObserver( | 311 void MediaGalleriesPreferences::RemoveGalleryChangeObserver( |
| 312 GalleryChangeObserver* observer) { | 312 GalleryChangeObserver* observer) { |
| 313 gallery_change_observers_.RemoveObserver(observer); | 313 gallery_change_observers_.RemoveObserver(observer); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void MediaGalleriesPreferences::OnRemovableStorageAttached( | 316 void MediaGalleriesPreferences::OnRemovableStorageAttached( |
| 317 const StorageInfo& info) { | 317 const StorageInfo& info) { |
| 318 if (!StorageInfo::IsMediaDevice(info.device_id)) | 318 if (!StorageInfo::IsMediaDevice(info.device_id())) |
| 319 return; | 319 return; |
| 320 | 320 |
| 321 if (info.name.empty()) { | 321 if (info.name().empty()) { |
| 322 AddGallery(info.device_id, base::FilePath(), | 322 AddGallery(info.device_id(), |
| 323 base::FilePath(), |
| 323 false /*not user added*/, | 324 false /*not user added*/, |
| 324 info.storage_label, | 325 info.storage_label(), |
| 325 info.vendor_name, | 326 info.vendor_name(), |
| 326 info.model_name, | 327 info.model_name(), |
| 327 info.total_size_in_bytes, | 328 info.total_size_in_bytes(), |
| 328 base::Time::Now()); | 329 base::Time::Now()); |
| 329 } else { | 330 } else { |
| 330 // TODO(gbillock): get rid of this code path. | 331 // TODO(gbillock): get rid of this code path. |
| 331 AddGalleryWithName(info.device_id, info.name, base::FilePath(), false); | 332 AddGalleryWithName(info.device_id(), info.name(), base::FilePath(), false); |
| 332 } | 333 } |
| 333 } | 334 } |
| 334 | 335 |
| 335 bool MediaGalleriesPreferences::LookUpGalleryByPath( | 336 bool MediaGalleriesPreferences::LookUpGalleryByPath( |
| 336 const base::FilePath& path, | 337 const base::FilePath& path, |
| 337 MediaGalleryPrefInfo* gallery_info) const { | 338 MediaGalleryPrefInfo* gallery_info) const { |
| 338 StorageInfo info; | 339 StorageInfo info; |
| 339 base::FilePath relative_path; | 340 base::FilePath relative_path; |
| 340 if (!MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path)) { | 341 if (!MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path)) { |
| 341 if (gallery_info) | 342 if (gallery_info) |
| 342 *gallery_info = MediaGalleryPrefInfo(); | 343 *gallery_info = MediaGalleryPrefInfo(); |
| 343 return false; | 344 return false; |
| 344 } | 345 } |
| 345 | 346 |
| 346 relative_path = relative_path.NormalizePathSeparators(); | 347 relative_path = relative_path.NormalizePathSeparators(); |
| 347 MediaGalleryPrefIdSet galleries_on_device = | 348 MediaGalleryPrefIdSet galleries_on_device = |
| 348 LookUpGalleriesByDeviceId(info.device_id); | 349 LookUpGalleriesByDeviceId(info.device_id()); |
| 349 for (MediaGalleryPrefIdSet::const_iterator it = galleries_on_device.begin(); | 350 for (MediaGalleryPrefIdSet::const_iterator it = galleries_on_device.begin(); |
| 350 it != galleries_on_device.end(); | 351 it != galleries_on_device.end(); |
| 351 ++it) { | 352 ++it) { |
| 352 const MediaGalleryPrefInfo& gallery = known_galleries_.find(*it)->second; | 353 const MediaGalleryPrefInfo& gallery = known_galleries_.find(*it)->second; |
| 353 if (gallery.path != relative_path) | 354 if (gallery.path != relative_path) |
| 354 continue; | 355 continue; |
| 355 | 356 |
| 356 if (gallery_info) | 357 if (gallery_info) |
| 357 *gallery_info = gallery; | 358 *gallery_info = gallery; |
| 358 return true; | 359 return true; |
| 359 } | 360 } |
| 360 | 361 |
| 361 // This method is called by controller::FilesSelected when the user | 362 // This method is called by controller::FilesSelected when the user |
| 362 // adds a new gallery. Control reaches here when the selected gallery is | 363 // adds a new gallery. Control reaches here when the selected gallery is |
| 363 // on a volume we know about, but have no gallery already for. Returns | 364 // on a volume we know about, but have no gallery already for. Returns |
| 364 // hypothetical data to the caller about what the prefs will look like | 365 // hypothetical data to the caller about what the prefs will look like |
| 365 // if the gallery is added. | 366 // if the gallery is added. |
| 366 // TODO(gbillock): split this out into another function so it doesn't | 367 // TODO(gbillock): split this out into another function so it doesn't |
| 367 // conflate LookUp. | 368 // conflate LookUp. |
| 368 if (gallery_info) { | 369 if (gallery_info) { |
| 369 gallery_info->pref_id = kInvalidMediaGalleryPrefId; | 370 gallery_info->pref_id = kInvalidMediaGalleryPrefId; |
| 370 gallery_info->display_name = info.name; | 371 gallery_info->display_name = info.name(); |
| 371 gallery_info->device_id = info.device_id; | 372 gallery_info->device_id = info.device_id(); |
| 372 gallery_info->path = relative_path; | 373 gallery_info->path = relative_path; |
| 373 gallery_info->type = MediaGalleryPrefInfo::kUserAdded; | 374 gallery_info->type = MediaGalleryPrefInfo::kUserAdded; |
| 374 // TODO(gbillock): Need to add volume metadata here from |info|. | 375 // TODO(gbillock): Need to add volume metadata here from |info|. |
| 375 } | 376 } |
| 376 return false; | 377 return false; |
| 377 } | 378 } |
| 378 | 379 |
| 379 MediaGalleryPrefIdSet MediaGalleriesPreferences::LookUpGalleriesByDeviceId( | 380 MediaGalleryPrefIdSet MediaGalleriesPreferences::LookUpGalleriesByDeviceId( |
| 380 const std::string& device_id) const { | 381 const std::string& device_id) const { |
| 381 DeviceIdPrefIdsMap::const_iterator found = device_map_.find(device_id); | 382 DeviceIdPrefIdsMap::const_iterator found = device_map_.find(device_id); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 } | 687 } |
| 687 | 688 |
| 688 extensions::ExtensionPrefs* | 689 extensions::ExtensionPrefs* |
| 689 MediaGalleriesPreferences::GetExtensionPrefs() const { | 690 MediaGalleriesPreferences::GetExtensionPrefs() const { |
| 690 ExtensionService* extension_service = | 691 ExtensionService* extension_service = |
| 691 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 692 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 692 return extension_service->extension_prefs(); | 693 return extension_service->extension_prefs(); |
| 693 } | 694 } |
| 694 | 695 |
| 695 } // namespace chrome | 696 } // namespace chrome |
| OLD | NEW |