Index: chrome/browser/media_gallery/media_file_system_registry.cc |
diff --git a/chrome/browser/media_gallery/media_file_system_registry.cc b/chrome/browser/media_gallery/media_file_system_registry.cc |
index ebeca1a5bb4e959de449d0b218c6d4c1ce1af0a5..3d689fd6ced814f73ffc5943dbac58d8c5514e1d 100644 |
--- a/chrome/browser/media_gallery/media_file_system_registry.cc |
+++ b/chrome/browser/media_gallery/media_file_system_registry.cc |
@@ -21,6 +21,13 @@ |
#include "content/public/browser/render_process_host.h" |
#include "webkit/fileapi/file_system_types.h" |
#include "webkit/fileapi/isolated_context.h" |
+#include "webkit/fileapi/media/media_file_system_config.h" |
+ |
+#if defined(SUPPORT_MEDIA_FILESYSTEM) |
+#include "webkit/fileapi/media/media_device_map_service.h" |
+ |
+using fileapi::MediaDeviceMapService; |
+#endif |
namespace chrome { |
@@ -76,7 +83,8 @@ MediaFileSystemRegistry::GetMediaFileSystemsForExtension( |
if (PathService::Get(chrome::DIR_USER_PICTURES, &pictures_path) && |
IsGalleryPermittedForExtension(extension, SystemMonitor::TYPE_PATH, |
pictures_path.value())) { |
- std::string fsid = RegisterPathAsFileSystem(pictures_path); |
+ std::string fsid = RegisterPathAsFileSystem(SystemMonitor::TYPE_PATH, |
+ pictures_path); |
child_it->second.insert(std::make_pair(pictures_path, fsid)); |
} |
} |
@@ -89,9 +97,11 @@ MediaFileSystemRegistry::GetMediaFileSystemsForExtension( |
if (media_devices[i].type == SystemMonitor::TYPE_PATH && |
IsGalleryPermittedForExtension(extension, media_devices[i].type, |
media_devices[i].location)) { |
+ device_id_map_.insert(std::make_pair(media_devices[i].unique_id, |
+ media_devices[i])); |
FilePath path(media_devices[i].location); |
- device_id_map_.insert(std::make_pair(media_devices[i].unique_id, path)); |
- const std::string fsid = RegisterPathAsFileSystem(path); |
+ const std::string fsid = RegisterPathAsFileSystem(media_devices[i].type, |
+ path); |
child_it->second.insert(std::make_pair(path, fsid)); |
} |
} |
@@ -113,10 +123,12 @@ MediaFileSystemRegistry::GetMediaFileSystemsForExtension( |
void MediaFileSystemRegistry::OnMediaDeviceDetached(const std::string& id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- DeviceIdToMediaPathMap::iterator it = device_id_map_.find(id); |
+ DeviceIdToInfoMap::iterator it = device_id_map_.find(id); |
if (it == device_id_map_.end()) |
return; |
- RevokeMediaFileSystem(it->second); |
+ |
+ FilePath path(it->second.location); |
+ RevokeMediaFileSystem(it->second.type, path); |
device_id_map_.erase(it); |
} |
@@ -165,24 +177,36 @@ void MediaFileSystemRegistry::UnregisterForRPHGoneNotifications( |
} |
std::string MediaFileSystemRegistry::RegisterPathAsFileSystem( |
- const FilePath& path) { |
+ const SystemMonitor::MediaDeviceType& device_type, const FilePath& path) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
// Sanity checks for |path|. |
CHECK(path.IsAbsolute()); |
CHECK(!path.ReferencesParent()); |
+ fileapi::FileSystemType type; |
kinuko
2012/08/02 20:33:44
nit: Please initialize this to kFileSystemTypeUnkn
kmadhusu
2012/08/02 22:05:39
Done.
|
+ switch (device_type) { |
+ case SystemMonitor::TYPE_MTP: |
+ type = fileapi::kFileSystemTypeDeviceMedia; |
+ break; |
+ case SystemMonitor::TYPE_PATH: |
+ // TODO(kmadhusu): This should be kFileSystemTypeNativeMedia. |
+ type = fileapi::kFileSystemTypeIsolated; |
kinuko
2012/08/02 20:33:44
I believe now you can use kFileSystemTypeNativeMed
kmadhusu
2012/08/02 22:05:39
Done.
|
+ break; |
+ } |
+ |
// The directory name is not exposed to the js layer and we simply use |
// a fixed name (as we only register a single directory per file system). |
std::string register_name(extension_misc::kMediaFileSystemPathPart); |
const std::string fsid = |
IsolatedContext::GetInstance()->RegisterFileSystemForPath( |
- fileapi::kFileSystemTypeIsolated, path, ®ister_name); |
+ type, path, ®ister_name); |
CHECK(!fsid.empty()); |
return fsid; |
} |
-void MediaFileSystemRegistry::RevokeMediaFileSystem(const FilePath& path) { |
+void MediaFileSystemRegistry::RevokeMediaFileSystem( |
+ const SystemMonitor::MediaDeviceType& device_type, const FilePath& path) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
IsolatedContext* isolated_context = IsolatedContext::GetInstance(); |
@@ -193,7 +217,21 @@ void MediaFileSystemRegistry::RevokeMediaFileSystem(const FilePath& path) { |
MediaPathToFSIDMap::iterator media_path_it = child_map.find(path); |
if (media_path_it == child_map.end()) |
continue; |
- isolated_context->RevokeFileSystem(media_path_it->second); |
+ |
+ // Always revoke the file sytem and then do the clean up operation. |
Lei Zhang
2012/08/02 20:54:50
nit: indentation is off here.
kmadhusu
2012/08/02 22:05:39
Done.
|
+ isolated_context->RevokeFileSystem(media_path_it->second); |
+ |
+ // Do the clean up tasks related to the file system. |
+ switch (device_type) { |
+ case SystemMonitor::TYPE_MTP: |
+#if defined(SUPPORT_MEDIA_FILESYSTEM) |
+ MediaDeviceMapService::GetInstance()->RemoveMediaDevice(path.value()); |
+#endif |
+ break; |
+ case SystemMonitor::TYPE_PATH: |
+ break; |
+ } |
+ |
child_map.erase(media_path_it); |
} |
} |