diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-21 14:55:37 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-21 14:55:37 +0000 |
commit | 9fb9294aab92e35d9584df40d853be5e7ca25ea0 (patch) | |
tree | dcb89bceb4352859ca54fe7995a1c1d66190369c /webkit/chromeos | |
parent | 262a1f2968e0cb860f4eec37fa07cd51aba48fba (diff) | |
download | chromium_src-9fb9294aab92e35d9584df40d853be5e7ca25ea0.zip chromium_src-9fb9294aab92e35d9584df40d853be5e7ca25ea0.tar.gz chromium_src-9fb9294aab92e35d9584df40d853be5e7ca25ea0.tar.bz2 |
Integrate external mount points to IsolatedContext
* To support MTP/Media filesystems in CrOS's FileBrowser
* To eventually support external, persistent mount points in sans-CrOS chrome (currently ifdef'ed only for cros since we need http://crbug.com/142289 to do the same in chrome)
* To introduce more finer-grained filesystem types
* To reduce duplicated code
What this patch actually does:
- Add external mount point support in IsolatedContext
- Introduce new filesystem types, NativeLocal and GData, to represent file systems supported by CrOS
- Replace CrOSMountPointProvider's internal mount map with IsolatedContext
BUG=139223
TEST=manually tested
TEST=existing tests
Review URL: https://chromiumcodereview.appspot.com/10823273
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152559 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/chromeos')
-rw-r--r-- | webkit/chromeos/fileapi/cros_mount_point_provider.cc | 190 | ||||
-rw-r--r-- | webkit/chromeos/fileapi/cros_mount_point_provider.h | 66 |
2 files changed, 110 insertions, 146 deletions
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/chromeos/fileapi/cros_mount_point_provider.cc index fcb71ce..20c1c52 100644 --- a/webkit/chromeos/fileapi/cros_mount_point_provider.cc +++ b/webkit/chromeos/fileapi/cros_mount_point_provider.cc @@ -23,6 +23,8 @@ #include "webkit/fileapi/file_system_operation_context.h" #include "webkit/fileapi/file_system_url.h" #include "webkit/fileapi/file_system_util.h" +#include "webkit/fileapi/isolated_context.h" +#include "webkit/fileapi/isolated_file_util.h" #include "webkit/fileapi/local_file_stream_writer.h" #include "webkit/fileapi/local_file_system_operation.h" #include "webkit/glue/webkit_glue.h" @@ -35,23 +37,19 @@ const char kChromeUIScheme[] = "chrome"; namespace chromeos { -CrosMountPointProvider::MountPoint::MountPoint( - const FilePath& in_web_root_path, - const FilePath& in_local_root_path, - FileSystemLocation in_location, - fileapi::RemoteFileSystemProxyInterface* in_proxy) - : web_root_path(in_web_root_path), local_root_path(in_local_root_path), - location(in_location), remote_proxy(in_proxy) { -} - -CrosMountPointProvider::MountPoint::~MountPoint() { +// static +bool CrosMountPointProvider::CanHandleURL(const fileapi::FileSystemURL& url) { + if (!url.is_valid()) + return false; + return url.type() == fileapi::kFileSystemTypeNativeLocal || + url.type() == fileapi::kFileSystemTypeDrive; } CrosMountPointProvider::CrosMountPointProvider( scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) : special_storage_policy_(special_storage_policy), file_access_permissions_(new FileAccessPermissions()), - local_file_util_(new fileapi::LocalFileUtil()) { + local_file_util_(new fileapi::IsolatedFileUtil()) { FilePath home_path; if (PathService::Get(base::DIR_HOME, &home_path)) AddLocalMountPoint(home_path.AppendASCII("Downloads")); @@ -62,17 +60,6 @@ CrosMountPointProvider::CrosMountPointProvider( CrosMountPointProvider::~CrosMountPointProvider() { } -bool CrosMountPointProvider::GetRootForVirtualPath( - const FilePath& virtual_path, FilePath* root_path) { - const MountPoint* mount_point = GetMountPoint(virtual_path); - if (!mount_point) - return false; - - DCHECK(root_path); - *root_path = mount_point->local_root_path; - return true; -} - void CrosMountPointProvider::ValidateFileSystemRoot( const GURL& origin_url, fileapi::FileSystemType type, @@ -89,17 +76,24 @@ FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( const FilePath& virtual_path, bool create) { DCHECK(type == fileapi::kFileSystemTypeExternal); + fileapi::FileSystemURL url(origin_url, type, virtual_path); + if (!url.is_valid()) + return FilePath(); + FilePath root_path; - if (!GetRootForVirtualPath(virtual_path, &root_path)) + if (!isolated_context()->GetRegisteredPath(url.filesystem_id(), &root_path)) return FilePath(); - return root_path; + return root_path.DirName(); } bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url, fileapi::FileSystemType type, const FilePath& virtual_path) { - if (type != fileapi::kFileSystemTypeExternal) + // TODO(kinuko): this should call CanHandleURL() once + // http://crbug.com/142267 is fixed. + if (type != fileapi::kFileSystemTypeNativeLocal && + type != fileapi::kFileSystemTypeDrive) return false; // Permit access to mount points from internal WebUI. @@ -135,42 +129,43 @@ void CrosMountPointProvider::DeleteFileSystem( } bool CrosMountPointProvider::HasMountPoint(const FilePath& mount_point) { - base::AutoLock locker(mount_point_map_lock_); - MountPointMap::const_iterator iter = mount_point_map_.find( - mount_point.BaseName().value()); - DCHECK(iter == mount_point_map_.end() || - iter->second.local_root_path == mount_point.DirName()); - return iter != mount_point_map_.end(); + std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); + FilePath path; + const bool valid = isolated_context()->GetRegisteredPath(mount_name, &path); + return valid && path == mount_point; } void CrosMountPointProvider::AddLocalMountPoint(const FilePath& mount_point) { + std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); + isolated_context()->RevokeFileSystem(mount_name); + isolated_context()->RegisterExternalFileSystem( + mount_name, + fileapi::kFileSystemTypeNativeLocal, + mount_point); base::AutoLock locker(mount_point_map_lock_); - mount_point_map_.erase(mount_point.BaseName().value()); - mount_point_map_.insert(std::make_pair( - mount_point.BaseName().value(), - MountPoint(mount_point.BaseName(), - mount_point.DirName(), - LOCAL, - NULL))); + local_to_virtual_map_[mount_point] = mount_point.BaseName(); } void CrosMountPointProvider::AddRemoteMountPoint( const FilePath& mount_point, fileapi::RemoteFileSystemProxyInterface* remote_proxy) { DCHECK(remote_proxy); + std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); + isolated_context()->RevokeFileSystem(mount_name); + isolated_context()->RegisterExternalFileSystem(mount_name, + fileapi::kFileSystemTypeDrive, + mount_point); base::AutoLock locker(mount_point_map_lock_); - mount_point_map_.erase(mount_point.BaseName().value()); - mount_point_map_.insert(std::make_pair( - mount_point.BaseName().value(), - MountPoint(mount_point.BaseName(), - mount_point.DirName(), - REMOTE, - remote_proxy))); + remote_proxy_map_[mount_name] = remote_proxy; + local_to_virtual_map_[mount_point] = mount_point.BaseName(); } void CrosMountPointProvider::RemoveMountPoint(const FilePath& mount_point) { + std::string mount_name = mount_point.BaseName().AsUTF8Unsafe(); + isolated_context()->RevokeFileSystem(mount_name); base::AutoLock locker(mount_point_map_lock_); - mount_point_map_.erase(mount_point.BaseName().value()); + remote_proxy_map_.erase(mount_name); + local_to_virtual_map_.erase(mount_point); } void CrosMountPointProvider::GrantFullAccessToExtension( @@ -178,10 +173,11 @@ void CrosMountPointProvider::GrantFullAccessToExtension( DCHECK(special_storage_policy_->IsFileHandler(extension_id)); if (!special_storage_policy_->IsFileHandler(extension_id)) return; - for (MountPointMap::const_iterator iter = mount_point_map_.begin(); - iter != mount_point_map_.end(); - ++iter) { - GrantFileAccessToExtension(extension_id, FilePath(iter->first)); + std::vector<fileapi::IsolatedContext::FileInfo> files = + isolated_context()->GetExternalMountPoints(); + for (size_t i = 0; i < files.size(); ++i) { + GrantFileAccessToExtension(extension_id, + FilePath::FromUTF8Unsafe(files[i].name)); } } @@ -200,56 +196,41 @@ void CrosMountPointProvider::RevokeAccessForExtension( } std::vector<FilePath> CrosMountPointProvider::GetRootDirectories() const { + std::vector<fileapi::IsolatedContext::FileInfo> files = + isolated_context()->GetExternalMountPoints(); std::vector<FilePath> root_dirs; - for (MountPointMap::const_iterator iter = mount_point_map_.begin(); - iter != mount_point_map_.end(); - ++iter) { - root_dirs.push_back(iter->second.local_root_path.Append(iter->first)); - } + for (size_t i = 0; i < files.size(); ++i) + root_dirs.push_back(files[i].path); return root_dirs; } fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil( fileapi::FileSystemType type) { + DCHECK(type == fileapi::kFileSystemTypeNativeLocal); return local_file_util_.get(); } FilePath CrosMountPointProvider::GetPathForPermissionsCheck( const FilePath& virtual_path) const { - const MountPoint* mount_point = GetMountPoint(virtual_path); - if (!mount_point) - return FilePath(); - - FilePath root_path = mount_point->local_root_path; - - return root_path.Append(virtual_path); -} - -const CrosMountPointProvider::MountPoint* -CrosMountPointProvider::GetMountPoint(const FilePath& virtual_path) const { - std::vector<FilePath::StringType> components; - virtual_path.GetComponents(&components); - if (components.empty()) - return NULL; - - base::AutoLock locker( - const_cast<CrosMountPointProvider*>(this)->mount_point_map_lock_); - // Check if this root mount point is exposed by this provider. - MountPointMap::const_iterator iter = mount_point_map_.find(components[0]); - if (iter == mount_point_map_.end()) - return NULL; - - return &(iter->second); + return virtual_path; } fileapi::FileSystemOperationInterface* CrosMountPointProvider::CreateFileSystemOperation( const fileapi::FileSystemURL& url, fileapi::FileSystemContext* context) const { - const MountPoint* mount_point = GetMountPoint(url.path()); - if (mount_point && mount_point->location == REMOTE) - return new chromeos::RemoteFileSystemOperation(mount_point->remote_proxy); + if (url.type() == fileapi::kFileSystemTypeDrive) { + base::AutoLock locker(mount_point_map_lock_); + RemoteProxyMap::const_iterator found = remote_proxy_map_.find( + url.filesystem_id()); + // TODO(kinuko): we should handle not-found case gracefully. + // http://crbug.com/141617 + if (found != remote_proxy_map_.end()) { + return new chromeos::RemoteFileSystemOperation(found->second); + } + } + DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); scoped_ptr<fileapi::FileSystemOperationContext> operation_context( new fileapi::FileSystemOperationContext(context)); return new fileapi::LocalFileSystemOperation(context, @@ -272,33 +253,36 @@ fileapi::FileStreamWriter* CrosMountPointProvider::CreateFileStreamWriter( fileapi::FileSystemContext* context) const { if (!url.is_valid()) return NULL; - const MountPoint* mount_point = GetMountPoint(url.path()); - if (!mount_point) - return NULL; - if (mount_point->location == REMOTE) { - return new fileapi::RemoteFileStreamWriter(mount_point->remote_proxy, - url, - offset); + if (url.type() == fileapi::kFileSystemTypeDrive) { + base::AutoLock locker(mount_point_map_lock_); + RemoteProxyMap::const_iterator found = remote_proxy_map_.find( + url.filesystem_id()); + if (found == remote_proxy_map_.end()) + return NULL; + return new fileapi::RemoteFileStreamWriter(found->second, url, offset); } - FilePath root_path = mount_point->local_root_path; - return new fileapi::LocalFileStreamWriter( - root_path.Append(url.path()), offset); + + DCHECK(url.type() == fileapi::kFileSystemTypeNativeLocal); + return new fileapi::LocalFileStreamWriter(url.path(), offset); } bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path, FilePath* virtual_path) { - for (MountPointMap::const_iterator iter = mount_point_map_.begin(); - iter != mount_point_map_.end(); - ++iter) { - FilePath mount_prefix = iter->second.local_root_path.Append(iter->first); - *virtual_path = FilePath(iter->first); - if (mount_prefix == filesystem_path) { - return true; - } else if (mount_prefix.AppendRelativePath(filesystem_path, virtual_path)) { - return true; - } + base::AutoLock locker(mount_point_map_lock_); + std::map<FilePath, FilePath>::reverse_iterator iter( + local_to_virtual_map_.upper_bound(filesystem_path)); + if (iter == local_to_virtual_map_.rend()) + return false; + if (iter->first == filesystem_path) { + *virtual_path = iter->second; + return true; } - return false; + return iter->first.DirName().AppendRelativePath( + filesystem_path, virtual_path); +} + +fileapi::IsolatedContext* CrosMountPointProvider::isolated_context() const { + return fileapi::IsolatedContext::GetInstance(); } } // namespace chromeos diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.h b/webkit/chromeos/fileapi/cros_mount_point_provider.h index a7c410b..a9e0650 100644 --- a/webkit/chromeos/fileapi/cros_mount_point_provider.h +++ b/webkit/chromeos/fileapi/cros_mount_point_provider.h @@ -11,13 +11,16 @@ #include "base/compiler_specific.h" #include "base/file_path.h" +#include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" #include "webkit/fileapi/file_system_mount_point_provider.h" -#include "webkit/fileapi/local_file_util.h" +#include "webkit/fileapi/fileapi_export.h" #include "webkit/quota/special_storage_policy.h" namespace fileapi { class FileSystemFileUtil; +class IsolatedContext; +class LocalFileUtil; } namespace chromeos { @@ -25,24 +28,21 @@ namespace chromeos { class FileAccessPermissions; // An interface to provide local filesystem paths. -class CrosMountPointProvider +class FILEAPI_EXPORT CrosMountPointProvider : public fileapi::ExternalFileSystemMountPointProvider { public: using fileapi::FileSystemMountPointProvider::ValidateFileSystemCallback; using fileapi::FileSystemMountPointProvider::DeleteFileSystemCallback; - // Mount point file system location enum. - enum FileSystemLocation { - // File system that is locally mounted by the underlying OS. - LOCAL, - // File system that is remotely hosted on the net. - REMOTE, - }; - CrosMountPointProvider( scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy); virtual ~CrosMountPointProvider(); + // Returns true if CrosMountpointProvider can handle |url|, i.e. its + // file system type matches with what this provider supports. + // This could be called on any threads. + static bool CanHandleURL(const fileapi::FileSystemURL& url); + // fileapi::FileSystemMountPointProvider overrides. virtual void ValidateFileSystemRoot( const GURL& origin_url, @@ -99,39 +99,19 @@ class CrosMountPointProvider FilePath* virtual_path) OVERRIDE; private: - // Representation of a mount point exposed by this external mount point - // provider. - struct MountPoint { - MountPoint(const FilePath& web_path, - const FilePath& local_path, - FileSystemLocation loc, - fileapi::RemoteFileSystemProxyInterface* proxy); - virtual ~MountPoint(); - // Virtual web path, relative to external root in filesystem URLs. - // For example, in "filesystem://.../external/foo/bar/" this path would - // map to "foo/bar/". - const FilePath web_root_path; - // Parent directory for the exposed file system path. For example, - // mount point that exposes "/media/removable" would have this - // root path as "/media". - const FilePath local_root_path; - // File system location. - const FileSystemLocation location; - // Remote file system proxy for remote mount points. - scoped_refptr<fileapi::RemoteFileSystemProxyInterface> remote_proxy; - }; - - typedef std::map<std::string, MountPoint> MountPointMap; - - // Gives the real file system's |root_path| for given |virtual_path|. Returns - // false when |virtual_path| cannot be mapped to the real file system. - bool GetRootForVirtualPath(const FilePath& virtual_path, FilePath* root_path); - // Returns mount point info for a given |virtual_path|, NULL if the path is - // not part of the mounted file systems exposed through this provider. - const MountPoint* GetMountPoint(const FilePath& virtual_path) const; - - base::Lock mount_point_map_lock_; - MountPointMap mount_point_map_; + typedef scoped_refptr<fileapi::RemoteFileSystemProxyInterface> RemoteProxy; + typedef std::map<FilePath::StringType, RemoteProxy> RemoteProxyMap; + + fileapi::IsolatedContext* isolated_context() const; + + // Represents a map from mount point name to a remote proxy. + RemoteProxyMap remote_proxy_map_; + + // Reverse map for GetVirtualPath. + std::map<FilePath, FilePath> local_to_virtual_map_; + + mutable base::Lock mount_point_map_lock_; + scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; scoped_ptr<FileAccessPermissions> file_access_permissions_; scoped_ptr<fileapi::LocalFileUtil> local_file_util_; |