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 // MediaFileSystemRegistry implementation. | 5 // MediaFileSystemRegistry implementation. |
6 | 6 |
7 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 7 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
19 #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" | |
19 #include "chrome/browser/media_galleries/media_file_system_context.h" | 20 #include "chrome/browser/media_galleries/media_file_system_context.h" |
20 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" | 21 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" |
21 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.h" | 22 #include "chrome/browser/media_galleries/media_galleries_preferences_factory.h" |
22 #include "chrome/browser/media_galleries/scoped_mtp_device_map_entry.h" | 23 #include "chrome/browser/media_galleries/scoped_mtp_device_map_entry.h" |
23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/storage_monitor/media_storage_util.h" | 25 #include "chrome/browser/storage_monitor/media_storage_util.h" |
25 #include "chrome/browser/storage_monitor/storage_monitor.h" | 26 #include "chrome/browser/storage_monitor/storage_monitor.h" |
26 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
27 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/extensions/extension.h" | 29 #include "chrome/common/extensions/extension.h" |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 | 324 |
324 base::FilePath path = gallery_info.AbsolutePath(); | 325 base::FilePath path = gallery_info.AbsolutePath(); |
325 if (!MediaStorageUtil::CanCreateFileSystem(device_id, path)) | 326 if (!MediaStorageUtil::CanCreateFileSystem(device_id, path)) |
326 continue; | 327 continue; |
327 | 328 |
328 std::string fsid; | 329 std::string fsid; |
329 if (StorageInfo::IsMassStorageDevice(device_id)) { | 330 if (StorageInfo::IsMassStorageDevice(device_id)) { |
330 fsid = file_system_context_->RegisterFileSystemForMassStorage( | 331 fsid = file_system_context_->RegisterFileSystemForMassStorage( |
331 device_id, path); | 332 device_id, path); |
332 } else { | 333 } else { |
333 scoped_refptr<ScopedMTPDeviceMapEntry> mtp_device_host; | 334 StorageInfo::Type type; |
334 fsid = file_system_context_->RegisterFileSystemForMTPDevice( | 335 if (!StorageInfo::CrackDeviceId(device_id, &type, NULL)) |
335 device_id, path, &mtp_device_host); | 336 continue; |
336 DCHECK(mtp_device_host.get()); | 337 |
337 media_device_map_references_[pref_id] = mtp_device_host; | 338 switch (type) { |
vandebo (ex-Chrome)
2013/05/22 15:05:49
I'd prefer to do this switch in MediaFileSystemCon
tommycli
2013/05/22 18:03:09
Done.
| |
339 case StorageInfo::MTP_OR_PTP: | |
340 case StorageInfo::MAC_IMAGE_CAPTURE: { | |
341 scoped_refptr<ScopedMTPDeviceMapEntry> mtp_device_host; | |
342 fsid = file_system_context_->RegisterFileSystemForMTPDevice( | |
343 device_id, path, &mtp_device_host); | |
344 DCHECK(mtp_device_host.get()); | |
345 media_device_map_references_[pref_id] = mtp_device_host; | |
346 break; | |
347 } | |
348 case StorageInfo::ITUNES: { | |
349 NOTIMPLEMENTED(); | |
350 break; | |
351 } | |
352 case StorageInfo::PICASA: { | |
353 fsid = file_system_context_->RegisterFileSystemForPicasa( | |
354 device_id, path); | |
355 break; | |
356 } | |
357 default: { | |
358 NOTREACHED(); | |
359 } | |
360 } | |
338 } | 361 } |
339 DCHECK(!fsid.empty()); | 362 DCHECK(!fsid.empty()); |
340 | 363 |
341 MediaFileSystemInfo new_entry( | 364 MediaFileSystemInfo new_entry( |
342 MediaGalleriesDialogController::GetGalleryDisplayNameNoAttachment( | 365 MediaGalleriesDialogController::GetGalleryDisplayNameNoAttachment( |
343 gallery_info), | 366 gallery_info), |
344 path, | 367 path, |
345 fsid, | 368 fsid, |
346 pref_id, | 369 pref_id, |
347 GetTransientIdForRemovableDeviceId(device_id), | 370 GetTransientIdForRemovableDeviceId(device_id), |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 std::string fs_name(extension_misc::kMediaFileSystemPathPart); | 617 std::string fs_name(extension_misc::kMediaFileSystemPathPart); |
595 const std::string fsid = | 618 const std::string fsid = |
596 IsolatedContext::GetInstance()->RegisterFileSystemForPath( | 619 IsolatedContext::GetInstance()->RegisterFileSystemForPath( |
597 fileapi::kFileSystemTypeDeviceMedia, path, &fs_name); | 620 fileapi::kFileSystemTypeDeviceMedia, path, &fs_name); |
598 CHECK(!fsid.empty()); | 621 CHECK(!fsid.empty()); |
599 DCHECK(entry); | 622 DCHECK(entry); |
600 *entry = registry_->GetOrCreateScopedMTPDeviceMapEntry(path.value()); | 623 *entry = registry_->GetOrCreateScopedMTPDeviceMapEntry(path.value()); |
601 return fsid; | 624 return fsid; |
602 } | 625 } |
603 | 626 |
627 virtual std::string RegisterFileSystemForPicasa( | |
628 const std::string& device_id, const base::FilePath& path) OVERRIDE { | |
629 return | |
630 ImportedMediaGalleryRegistry::RegisterPicasaFilesystemOnUIThread(path); | |
631 } | |
632 | |
604 virtual void RevokeFileSystem(const std::string& fsid) OVERRIDE { | 633 virtual void RevokeFileSystem(const std::string& fsid) OVERRIDE { |
605 IsolatedContext::GetInstance()->RevokeFileSystem(fsid); | 634 IsolatedContext::GetInstance()->RevokeFileSystem(fsid); |
606 } | 635 } |
607 | 636 |
608 virtual MediaFileSystemRegistry* GetMediaFileSystemRegistry() OVERRIDE { | 637 virtual MediaFileSystemRegistry* GetMediaFileSystemRegistry() OVERRIDE { |
609 return registry_; | 638 return registry_; |
610 } | 639 } |
611 | 640 |
612 private: | 641 private: |
642 | |
vandebo (ex-Chrome)
2013/05/22 15:05:49
nit: extra line.
tommycli
2013/05/22 18:03:09
Done.
| |
613 MediaFileSystemRegistry* registry_; | 643 MediaFileSystemRegistry* registry_; |
614 | 644 |
615 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemContextImpl); | 645 DISALLOW_COPY_AND_ASSIGN(MediaFileSystemContextImpl); |
616 }; | 646 }; |
617 | 647 |
618 MediaFileSystemRegistry::MediaFileSystemRegistry() | 648 MediaFileSystemRegistry::MediaFileSystemRegistry() |
619 : file_system_context_(new MediaFileSystemContextImpl(this)) { | 649 : file_system_context_(new MediaFileSystemContextImpl(this)) { |
620 // StorageMonitor may be NULL in unit tests. | 650 // StorageMonitor may be NULL in unit tests. |
621 StorageMonitor* monitor = StorageMonitor::GetInstance(); | 651 StorageMonitor* monitor = StorageMonitor::GetInstance(); |
622 if (monitor) | 652 if (monitor) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
720 // previously used. | 750 // previously used. |
721 PrefChangeRegistrarMap::iterator pref_it = | 751 PrefChangeRegistrarMap::iterator pref_it = |
722 pref_change_registrar_map_.find(profile); | 752 pref_change_registrar_map_.find(profile); |
723 DCHECK(pref_it != pref_change_registrar_map_.end()); | 753 DCHECK(pref_it != pref_change_registrar_map_.end()); |
724 delete pref_it->second; | 754 delete pref_it->second; |
725 pref_change_registrar_map_.erase(pref_it); | 755 pref_change_registrar_map_.erase(pref_it); |
726 } | 756 } |
727 } | 757 } |
728 | 758 |
729 } // namespace chrome | 759 } // namespace chrome |
OLD | NEW |