diff options
Diffstat (limited to 'webkit/chromeos')
-rw-r--r-- | webkit/chromeos/fileapi/cros_mount_point_provider.cc | 147 | ||||
-rw-r--r-- | webkit/chromeos/fileapi/cros_mount_point_provider.h | 46 | ||||
-rw-r--r-- | webkit/chromeos/fileapi/remote_file_system_operation.cc | 167 | ||||
-rw-r--r-- | webkit/chromeos/fileapi/remote_file_system_operation.h | 108 | ||||
-rw-r--r-- | webkit/chromeos/fileapi/remote_file_system_proxy.h | 31 |
5 files changed, 451 insertions, 48 deletions
diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.cc b/webkit/chromeos/fileapi/cros_mount_point_provider.cc index 07ab125..def95f8 100644 --- a/webkit/chromeos/fileapi/cros_mount_point_provider.cc +++ b/webkit/chromeos/fileapi/cros_mount_point_provider.cc @@ -16,67 +16,80 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSystem.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" #include "webkit/chromeos/fileapi/file_access_permissions.h" +#include "webkit/chromeos/fileapi/remote_file_system_operation.h" #include "webkit/fileapi/file_system_operation.h" #include "webkit/fileapi/file_system_util.h" #include "webkit/fileapi/native_file_util.h" #include "webkit/glue/webkit_glue.h" -namespace chromeos { - -typedef struct { - const char* local_root_path; - const char* web_root_path; -} FixedExposedPaths; +namespace { const char kChromeUIScheme[] = "chrome"; // Top level file system elements exposed in FileAPI in ChromeOS: -FixedExposedPaths fixed_exposed_paths[] = { - {"/home/chronos/user/", "Downloads"}, - {"/media", "archive"}, - {"/media", "removable"}, - {"/special", "gdata"}, +// TODO(zelidrag): Move fixed mount path initialization out of webkit layer. +struct LocalMountPointInfo { + const char* const web_root_path; + const char* const local_root_path; + chromeos::CrosMountPointProvider::FileSystemLocation location; }; +const LocalMountPointInfo kFixedExposedPaths[] = { + {"Downloads", + "/home/chronos/user/", + chromeos::CrosMountPointProvider::LOCAL}, + {"archive", + "/media", + chromeos::CrosMountPointProvider::LOCAL}, + {"removable", + "/media", + chromeos::CrosMountPointProvider::LOCAL}, +}; + +} + +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() { +} + 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(new fileapi::NativeFileUtil())) { - for (size_t i = 0; i < arraysize(fixed_exposed_paths); i++) { - mount_point_map_.insert(std::pair<std::string, FilePath>( - std::string(fixed_exposed_paths[i].web_root_path), - FilePath(std::string(fixed_exposed_paths[i].local_root_path)))); + for (size_t i = 0; i < arraysize(kFixedExposedPaths); i++) { + mount_point_map_.insert(std::make_pair( + std::string(kFixedExposedPaths[i].web_root_path), + MountPoint( + FilePath(std::string(kFixedExposedPaths[i].web_root_path)), + FilePath(std::string(kFixedExposedPaths[i].local_root_path)), + kFixedExposedPaths[i].location, + NULL))); } } CrosMountPointProvider::~CrosMountPointProvider() { } -// TODO(zelidrag) share with SandboxMountPointProvider impl. -std::string GetOriginIdentifierFromURL( - const GURL& url) { - WebKit::WebSecurityOrigin web_security_origin = - WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); - return web_security_origin.databaseIdentifier().utf8(); -} - bool CrosMountPointProvider::GetRootForVirtualPath( const FilePath& virtual_path, FilePath* root_path) { - std::vector<FilePath::StringType> components; - virtual_path.GetComponents(&components); - if (components.size() < 1) { + const MountPoint* mount_point = GetMountPoint(virtual_path); + if (!mount_point) return false; - } - base::AutoLock locker(lock_); - // Check if this root mount point is exposed by this provider. - MountPointMap::iterator iter = mount_point_map_.find(components[0]); - if (iter == mount_point_map_.end()) { - return false; - } - *root_path = iter->second; + DCHECK(root_path); + *root_path = mount_point->local_root_path; return true; } @@ -127,15 +140,42 @@ bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const { return false; } -void CrosMountPointProvider::AddMountPoint(FilePath mount_point) { - base::AutoLock locker(lock_); +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(); +} + +void CrosMountPointProvider::AddLocalMountPoint(const FilePath& 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))); +} + +void CrosMountPointProvider::AddRemoteMountPoint( + const FilePath& mount_point, + fileapi::RemoteFileSystemProxyInterface* remote_proxy) { + DCHECK(remote_proxy); + base::AutoLock locker(mount_point_map_lock_); mount_point_map_.erase(mount_point.BaseName().value()); - mount_point_map_.insert(std::pair<std::string, FilePath>( - mount_point.BaseName().value(), mount_point.DirName())); + mount_point_map_.insert(std::make_pair( + mount_point.BaseName().value(), + MountPoint(mount_point.BaseName(), + mount_point.DirName(), + REMOTE, + remote_proxy))); } -void CrosMountPointProvider::RemoveMountPoint(FilePath mount_point) { - base::AutoLock locker(lock_); +void CrosMountPointProvider::RemoveMountPoint(const FilePath& mount_point) { + base::AutoLock locker(mount_point_map_lock_); mount_point_map_.erase(mount_point.BaseName().value()); } @@ -170,7 +210,7 @@ std::vector<FilePath> CrosMountPointProvider::GetRootDirectories() const { for (MountPointMap::const_iterator iter = mount_point_map_.begin(); iter != mount_point_map_.end(); ++iter) { - root_dirs.push_back(iter->second.Append(iter->first)); + root_dirs.push_back(iter->second.local_root_path.Append(iter->first)); } return root_dirs; } @@ -179,6 +219,23 @@ fileapi::FileSystemFileUtil* CrosMountPointProvider::GetFileUtil() { return local_file_util_.get(); } +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); +} + fileapi::FileSystemOperationInterface* CrosMountPointProvider::CreateFileSystemOperation( const GURL& origin_url, @@ -186,8 +243,10 @@ CrosMountPointProvider::CreateFileSystemOperation( const FilePath& virtual_path, base::MessageLoopProxy* file_proxy, fileapi::FileSystemContext* context) const { - // TODO(satorux,zel): instantiate appropriate FileSystemOperation that - // implements async/remote operations. + const MountPoint* mount_point = GetMountPoint(virtual_path); + if (mount_point && mount_point->location == REMOTE) + return new chromeos::RemoteFileSystemOperation(mount_point->remote_proxy); + return new fileapi::FileSystemOperation(file_proxy, context); } @@ -196,7 +255,7 @@ bool CrosMountPointProvider::GetVirtualPath(const FilePath& filesystem_path, for (MountPointMap::const_iterator iter = mount_point_map_.begin(); iter != mount_point_map_.end(); ++iter) { - FilePath mount_prefix = iter->second.Append(iter->first); + FilePath mount_prefix = iter->second.local_root_path.Append(iter->first); *virtual_path = FilePath(iter->first); if (mount_prefix == filesystem_path) { return true; diff --git a/webkit/chromeos/fileapi/cros_mount_point_provider.h b/webkit/chromeos/fileapi/cros_mount_point_provider.h index 1ebdab8..86991a4 100644 --- a/webkit/chromeos/fileapi/cros_mount_point_provider.h +++ b/webkit/chromeos/fileapi/cros_mount_point_provider.h @@ -28,6 +28,14 @@ class FileAccessPermissions; class CrosMountPointProvider : public fileapi::ExternalFileSystemMountPointProvider { public: + // 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, + }; + typedef fileapi::FileSystemMountPointProvider::ValidateFileSystemCallback ValidateFileSystemCallback; @@ -67,20 +75,50 @@ class CrosMountPointProvider const std::string& extension_id, const FilePath& virtual_path) OVERRIDE; virtual void RevokeAccessForExtension( const std::string& extension_id) OVERRIDE; - virtual void AddMountPoint(FilePath mount_point) OVERRIDE; - virtual void RemoveMountPoint(FilePath mount_point) OVERRIDE; + virtual bool HasMountPoint(const FilePath& mount_point) OVERRIDE; + virtual void AddLocalMountPoint(const FilePath& mount_point) OVERRIDE; + virtual void AddRemoteMountPoint( + const FilePath& mount_point, + fileapi::RemoteFileSystemProxyInterface* remote_proxy) OVERRIDE; + virtual void RemoveMountPoint(const FilePath& mount_point) OVERRIDE; virtual bool GetVirtualPath(const FilePath& filesystem_path, FilePath* virtual_path) OVERRIDE; private: class GetFileSystemRootPathTask; - typedef std::map<std::string, FilePath> MountPointMap; + + // 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 filesytem 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 lock_; // Synchronize all access to path_map_. + base::Lock mount_point_map_lock_; MountPointMap mount_point_map_; scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; scoped_ptr<FileAccessPermissions> file_access_permissions_; diff --git a/webkit/chromeos/fileapi/remote_file_system_operation.cc b/webkit/chromeos/fileapi/remote_file_system_operation.cc new file mode 100644 index 0000000..3db3915 --- /dev/null +++ b/webkit/chromeos/fileapi/remote_file_system_operation.cc @@ -0,0 +1,167 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/chromeos/fileapi/remote_file_system_operation.h" + +#include "base/bind.h" +#include "base/utf_string_conversions.h" +#include "base/platform_file.h" +#include "base/values.h" +#include "webkit/fileapi/file_system_callback_dispatcher.h" + +namespace chromeos { + +RemoteFileSystemOperation::RemoteFileSystemOperation( + scoped_refptr<fileapi::RemoteFileSystemProxyInterface> remote_proxy) + : remote_proxy_(remote_proxy), + pending_operation_(kOperationNone) { +} + +RemoteFileSystemOperation::~RemoteFileSystemOperation() { +} + +void RemoteFileSystemOperation::GetMetadata(const GURL& path, + const GetMetadataCallback& callback) { + DCHECK(SetPendingOperationType(kOperationGetMetadata)); + remote_proxy_->GetFileInfo(path, + base::Bind(&RemoteFileSystemOperation::DidGetMetadata, + base::Owned(this), callback)); +} + +void RemoteFileSystemOperation::DirectoryExists(const GURL& path, + const StatusCallback& callback) { + DCHECK(SetPendingOperationType(kOperationDirectoryExists)); + remote_proxy_->GetFileInfo(path, + base::Bind(&RemoteFileSystemOperation::DidDirectoryExists, + base::Owned(this), callback)); +} + +void RemoteFileSystemOperation::FileExists(const GURL& path, + const StatusCallback& callback) { + DCHECK(SetPendingOperationType(kOperationFileExists)); + remote_proxy_->GetFileInfo(path, + base::Bind(base::Bind(&RemoteFileSystemOperation::DidFileExists, + base::Owned(this), callback))); +} + +void RemoteFileSystemOperation::ReadDirectory(const GURL& path, + const ReadDirectoryCallback& callback) { + DCHECK(SetPendingOperationType(kOperationReadDirectory)); + remote_proxy_->ReadDirectory(path, + base::Bind(&RemoteFileSystemOperation::DidReadDirectory, + base::Owned(this), callback)); +} + +void RemoteFileSystemOperation::CreateFile(const GURL& path, + bool exclusive, + const StatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void RemoteFileSystemOperation::CreateDirectory( + const GURL& path, bool exclusive, bool recursive, + const StatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void RemoteFileSystemOperation::Copy(const GURL& src_path, + const GURL& dest_path, + const StatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void RemoteFileSystemOperation::Move(const GURL& src_path, + const GURL& dest_path, + const StatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void RemoteFileSystemOperation::Remove(const GURL& path, bool recursive, + const StatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void RemoteFileSystemOperation::Write( + const net::URLRequestContext* url_request_context, + const GURL& path, + const GURL& blob_url, + int64 offset, + const WriteCallback& callback) { + NOTIMPLEMENTED(); +} + +void RemoteFileSystemOperation::Truncate(const GURL& path, + int64 length, + const StatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void RemoteFileSystemOperation::Cancel(const StatusCallback& cancel_callback) { + NOTIMPLEMENTED(); +} + +void RemoteFileSystemOperation::TouchFile(const GURL& path, + const base::Time& last_access_time, + const base::Time& last_modified_time, + const StatusCallback& callback) { + NOTIMPLEMENTED(); +} + +void RemoteFileSystemOperation::OpenFile(const GURL& path, + int file_flags, + base::ProcessHandle peer_handle, + const OpenFileCallback& callback) { + NOTIMPLEMENTED(); +} + +fileapi::FileSystemOperation* +RemoteFileSystemOperation::AsFileSystemOperation() { + NOTIMPLEMENTED(); + return NULL; +} + +bool RemoteFileSystemOperation::SetPendingOperationType(OperationType type) { + if (pending_operation_ != kOperationNone) + return false; + pending_operation_ = type; + return true; +} + +void RemoteFileSystemOperation::DidDirectoryExists( + const StatusCallback& callback, + base::PlatformFileError rv, + const base::PlatformFileInfo& file_info, + const FilePath& unused) { + if (rv == base::PLATFORM_FILE_OK && !file_info.is_directory) + rv = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; + callback.Run(rv); +} + +void RemoteFileSystemOperation::DidFileExists( + const StatusCallback& callback, + base::PlatformFileError rv, + const base::PlatformFileInfo& file_info, + const FilePath& unused) { + if (rv == base::PLATFORM_FILE_OK && file_info.is_directory) + rv = base::PLATFORM_FILE_ERROR_NOT_A_FILE; + callback.Run(rv); +} + +void RemoteFileSystemOperation::DidGetMetadata( + const GetMetadataCallback& callback, + base::PlatformFileError rv, + const base::PlatformFileInfo& file_info, + const FilePath& platform_path) { + callback.Run(rv, file_info, platform_path); +} + +void RemoteFileSystemOperation::DidReadDirectory( + const ReadDirectoryCallback& callback, + base::PlatformFileError rv, + const std::vector<base::FileUtilProxy::Entry>& entries, + bool has_more) { + callback.Run(rv, entries, has_more /* has_more */); +} + +} // namespace chromeos diff --git a/webkit/chromeos/fileapi/remote_file_system_operation.h b/webkit/chromeos/fileapi/remote_file_system_operation.h new file mode 100644 index 0000000..0cf542f --- /dev/null +++ b/webkit/chromeos/fileapi/remote_file_system_operation.h @@ -0,0 +1,108 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_SYSTEM_OPERATION_H_ +#define WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_SYSTEM_OPERATION_H_ + +#include "webkit/chromeos/fileapi/remote_file_system_proxy.h" +#include "webkit/fileapi/file_system_operation_interface.h" + +namespace base { +class Value; +} + +namespace fileapi { +class FileSystemOperation; +} + +namespace chromeos { + +// FileSystemOperation implementation for local file systems. +class RemoteFileSystemOperation : public fileapi::FileSystemOperationInterface { + public: + virtual ~RemoteFileSystemOperation(); + + // FileSystemOperationInterface overrides. + virtual void CreateFile(const GURL& path, + bool exclusive, + const StatusCallback& callback) OVERRIDE; + virtual void CreateDirectory(const GURL& path, + bool exclusive, + bool recursive, + const StatusCallback& callback) OVERRIDE; + virtual void Copy(const GURL& src_path, + const GURL& dest_path, + const StatusCallback& callback) OVERRIDE; + virtual void Move(const GURL& src_path, + const GURL& dest_path, + const StatusCallback& callback) OVERRIDE; + virtual void DirectoryExists(const GURL& path, + const StatusCallback& callback) OVERRIDE; + virtual void FileExists(const GURL& path, + const StatusCallback& callback) OVERRIDE; + virtual void GetMetadata(const GURL& path, + const GetMetadataCallback& callback) OVERRIDE; + virtual void ReadDirectory(const GURL& path, + const ReadDirectoryCallback& callback) OVERRIDE; + virtual void Remove(const GURL& path, bool recursive, + const StatusCallback& callback) OVERRIDE; + virtual void Write(const net::URLRequestContext* url_request_context, + const GURL& path, + const GURL& blob_url, + int64 offset, + const WriteCallback& callback) OVERRIDE; + virtual void Truncate(const GURL& path, int64 length, + const StatusCallback& callback) OVERRIDE; + virtual void Cancel(const StatusCallback& cancel_callback) OVERRIDE; + virtual void TouchFile(const GURL& path, + const base::Time& last_access_time, + const base::Time& last_modified_time, + const StatusCallback& callback) OVERRIDE; + virtual void OpenFile( + const GURL& path, + int file_flags, + base::ProcessHandle peer_handle, + const OpenFileCallback& callback) OVERRIDE; + + virtual fileapi::FileSystemOperation* AsFileSystemOperation() OVERRIDE; + + private: + friend class CrosMountPointProvider; + + RemoteFileSystemOperation( + scoped_refptr<fileapi::RemoteFileSystemProxyInterface> remote_proxy); + + // Used only for internal assertions. + // Returns false if there's another inflight pending operation. + bool SetPendingOperationType(OperationType type); + + // Generic callback that translates platform errors to WebKit error codes. + void DidDirectoryExists(const StatusCallback& callback, + base::PlatformFileError rv, + const base::PlatformFileInfo& file_info, + const FilePath& unused); + void DidFileExists(const StatusCallback& callback, + base::PlatformFileError rv, + const base::PlatformFileInfo& file_info, + const FilePath& unused); + void DidGetMetadata(const GetMetadataCallback& callback, + base::PlatformFileError rv, + const base::PlatformFileInfo& file_info, + const FilePath& platform_path); + void DidReadDirectory( + const ReadDirectoryCallback& callback, + base::PlatformFileError rv, + const std::vector<base::FileUtilProxy::Entry>& entries, + bool has_more); + + scoped_refptr<fileapi::RemoteFileSystemProxyInterface> remote_proxy_; + // A flag to make sure we call operation only once per instance. + OperationType pending_operation_; + + DISALLOW_COPY_AND_ASSIGN(RemoteFileSystemOperation); +}; + +} // namespace chromeos + +#endif // WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_SYSTEM_OPERATION_H_ diff --git a/webkit/chromeos/fileapi/remote_file_system_proxy.h b/webkit/chromeos/fileapi/remote_file_system_proxy.h new file mode 100644 index 0000000..c6dae7f --- /dev/null +++ b/webkit/chromeos/fileapi/remote_file_system_proxy.h @@ -0,0 +1,31 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_SYSTEM_PROXY_H_ +#define WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_SYSTEM_PROXY_H_ + +#include "base/callback.h" +#include "base/memory/ref_counted.h" +#include "webkit/fileapi/file_system_operation_interface.h" + +class GURL; + +namespace fileapi { + +// The interface class for remote file system proxy. +class RemoteFileSystemProxyInterface : + public base::RefCountedThreadSafe<RemoteFileSystemProxyInterface> { + public: + virtual ~RemoteFileSystemProxyInterface() {} + + virtual void GetFileInfo(const GURL& path, + const FileSystemOperationInterface::GetMetadataCallback& callback) = 0; + virtual void ReadDirectory(const GURL& path, + const FileSystemOperationInterface::ReadDirectoryCallback& callback) = 0; + // TODO(zelidrag): More methods to follow as we implement other parts of FSO. +}; + +} // namespace chromeos + +#endif // WEBKIT_CHROMEOS_FILEAPI_REMOTE_FILE_SYSTEM_PROXY_H_ |