| Index: webkit/fileapi/isolated_context.cc
|
| diff --git a/webkit/fileapi/isolated_context.cc b/webkit/fileapi/isolated_context.cc
|
| index 6398e42ea336db68c8c0b0898a7f66d41eafc05d..ef7f01b2cf5b1d7f45c1e827d8bc78b67da4d276 100644
|
| --- a/webkit/fileapi/isolated_context.cc
|
| +++ b/webkit/fileapi/isolated_context.cc
|
| @@ -53,6 +53,8 @@ bool IsSinglePathIsolatedFileSystem(FileSystemType type) {
|
| case kFileSystemTypeTemporary:
|
| case kFileSystemTypePersistent:
|
| case kFileSystemTypeExternal:
|
| + case kFileSystemTypeNativeLocal:
|
| + case kFileSystemTypeGData:
|
| case kFileSystemTypeTest:
|
| return true;
|
|
|
| @@ -114,7 +116,8 @@ bool IsolatedContext::FileInfoSet::AddPathWithName(
|
|
|
| IsolatedContext::Instance::Instance(FileSystemType type,
|
| const FileInfo& file_info)
|
| - : type_(type),
|
| + : instance_type_(ISOLATED),
|
| + type_(type),
|
| file_info_(file_info),
|
| ref_counts_(0) {
|
| DCHECK(IsSinglePathIsolatedFileSystem(type_));
|
| @@ -122,12 +125,22 @@ IsolatedContext::Instance::Instance(FileSystemType type,
|
|
|
| IsolatedContext::Instance::Instance(FileSystemType type,
|
| const std::set<FileInfo>& files)
|
| - : type_(type),
|
| + : instance_type_(ISOLATED),
|
| + type_(type),
|
| files_(files),
|
| ref_counts_(0) {
|
| DCHECK(!IsSinglePathIsolatedFileSystem(type_));
|
| }
|
|
|
| +IsolatedContext::Instance::Instance(FileSystemType type,
|
| + const FilePath& path)
|
| + : instance_type_(EXTERNAL),
|
| + type_(type),
|
| + file_info_(FileInfo("", path)),
|
| + ref_counts_(0) {
|
| + DCHECK(IsSinglePathIsolatedFileSystem(type_));
|
| +}
|
| +
|
| IsolatedContext::Instance::~Instance() {}
|
|
|
| bool IsolatedContext::Instance::ResolvePathForName(const std::string& name,
|
| @@ -155,6 +168,11 @@ IsolatedContext* IsolatedContext::GetInstance() {
|
| return g_isolated_context.Pointer();
|
| }
|
|
|
| +// static
|
| +bool IsolatedContext::IsIsolatedType(FileSystemType type) {
|
| + return type == kFileSystemTypeIsolated || type == kFileSystemTypeExternal;
|
| +}
|
| +
|
| std::string IsolatedContext::RegisterDraggedFileSystem(
|
| const FileInfoSet& files) {
|
| base::AutoLock locker(lock_);
|
| @@ -186,6 +204,33 @@ std::string IsolatedContext::RegisterFileSystemForPath(
|
| return filesystem_id;
|
| }
|
|
|
| +#if defined(OS_CHROMEOS)
|
| +bool IsolatedContext::RegisterExternalFileSystem(const std::string& mount_name,
|
| + FileSystemType type,
|
| + const FilePath& path) {
|
| + base::AutoLock locker(lock_);
|
| + IDToInstance::iterator found = instance_map_.find(mount_name);
|
| + if (found != instance_map_.end())
|
| + return false;
|
| + instance_map_[mount_name] = new Instance(type, path);
|
| + path_to_id_map_[path].insert(mount_name);
|
| + return true;
|
| +}
|
| +
|
| +std::vector<IsolatedContext::FileInfo>
|
| +IsolatedContext::GetExternalMountPoints() const {
|
| + base::AutoLock locker(lock_);
|
| + std::vector<FileInfo> files;
|
| + for (IDToInstance::const_iterator iter = instance_map_.begin();
|
| + iter != instance_map_.end();
|
| + ++iter) {
|
| + if (iter->second->instance_type() == Instance::EXTERNAL)
|
| + files.push_back(FileInfo(iter->first, iter->second->file_info().path));
|
| + }
|
| + return files;
|
| +}
|
| +#endif
|
| +
|
| bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) {
|
| base::AutoLock locker(lock_);
|
| return UnregisterFileSystem(filesystem_id);
|
| @@ -225,51 +270,66 @@ void IsolatedContext::RemoveReference(const std::string& filesystem_id) {
|
| Instance* instance = found->second;
|
| DCHECK(instance->ref_counts() > 0);
|
| instance->RemoveRef();
|
| - if (instance->ref_counts() == 0) {
|
| + if (instance->ref_counts() == 0 &&
|
| + instance->instance_type() != Instance::EXTERNAL) {
|
| bool deleted = UnregisterFileSystem(filesystem_id);
|
| DCHECK(deleted);
|
| }
|
| }
|
|
|
| bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path,
|
| - std::string* filesystem_id,
|
| + std::string* id_or_name,
|
| FileSystemType* type,
|
| FilePath* path) const {
|
| - DCHECK(filesystem_id);
|
| + DCHECK(id_or_name);
|
| DCHECK(path);
|
|
|
| // This should not contain any '..' references.
|
| if (virtual_path.ReferencesParent())
|
| return false;
|
|
|
| - // The virtual_path should comprise <filesystem_id> and <relative_path> parts.
|
| + // The virtual_path should comprise <id_or_name> and <relative_path> parts.
|
| std::vector<FilePath::StringType> components;
|
| virtual_path.GetComponents(&components);
|
| if (components.size() < 1)
|
| return false;
|
| -
|
| - base::AutoLock locker(lock_);
|
| - std::string fsid = FilePath(components[0]).MaybeAsASCII();
|
| + std::vector<FilePath::StringType>::iterator component_iter =
|
| + components.begin();
|
| + std::string fsid = FilePath(*component_iter++).MaybeAsASCII();
|
| if (fsid.empty())
|
| return false;
|
| - IDToInstance::const_iterator found_instance = instance_map_.find(fsid);
|
| - if (found_instance == instance_map_.end())
|
| - return false;
|
| - *filesystem_id = fsid;
|
| - if (type)
|
| - *type = found_instance->second->type();
|
| - if (components.size() == 1) {
|
| - path->clear();
|
| - return true;
|
| - }
|
| - // components[1] should be a name of the registered paths.
|
| +
|
| FilePath cracked_path;
|
| - std::string name = FilePath(components[1]).AsUTF8Unsafe();
|
| - if (!found_instance->second->ResolvePathForName(name, &cracked_path))
|
| - return false;
|
| + {
|
| + base::AutoLock locker(lock_);
|
| + IDToInstance::const_iterator found_instance = instance_map_.find(fsid);
|
| + if (found_instance == instance_map_.end())
|
| + return false;
|
| + *id_or_name = fsid;
|
| + const Instance* instance = found_instance->second;
|
| + if (type)
|
| + *type = instance->type();
|
| + switch (instance->instance_type()) {
|
| + case Instance::ISOLATED: {
|
| + if (component_iter == components.end()) {
|
| + // The virtual root case.
|
| + path->clear();
|
| + return true;
|
| + }
|
| + // *component_iter should be a name of the registered path.
|
| + std::string name = FilePath(*component_iter++).AsUTF8Unsafe();
|
| + if (!instance->ResolvePathForName(name, &cracked_path))
|
| + return false;
|
| + break;
|
| + }
|
| + case Instance::EXTERNAL:
|
| + cracked_path = instance->file_info().path;
|
| + break;
|
| + }
|
| + }
|
|
|
| - for (size_t i = 2; i < components.size(); ++i)
|
| - cracked_path = cracked_path.Append(components[i]);
|
| + for (; component_iter != components.end(); ++component_iter)
|
| + cracked_path = cracked_path.Append(*component_iter);
|
| *path = cracked_path;
|
| return true;
|
| }
|
|
|