Index: webkit/fileapi/isolated_context.cc |
diff --git a/webkit/fileapi/isolated_context.cc b/webkit/fileapi/isolated_context.cc |
index 057d508c6f993f5fa584700f9a903f5fbff125b3..8b4394b55010fdf8a6c7e8e24b920958cc90da35 100644 |
--- a/webkit/fileapi/isolated_context.cc |
+++ b/webkit/fileapi/isolated_context.cc |
@@ -62,11 +62,6 @@ bool IsSinglePathIsolatedFileSystem(FileSystemType type) { |
static base::LazyInstance<IsolatedContext>::Leaky g_isolated_context = |
LAZY_INSTANCE_INITIALIZER; |
-IsolatedContext::FileInfo::FileInfo() {} |
-IsolatedContext::FileInfo::FileInfo( |
- const std::string& name, const FilePath& path) |
- : name(name), path(path) {} |
- |
IsolatedContext::FileInfoSet::FileInfoSet() {} |
IsolatedContext::FileInfoSet::~FileInfoSet() {} |
@@ -78,7 +73,8 @@ bool IsolatedContext::FileInfoSet::AddPath( |
FilePath::StringType name = GetRegisterNameForPath(path); |
std::string utf8name = FilePath(name).AsUTF8Unsafe(); |
FilePath normalized_path = path.NormalizePathSeparators(); |
- bool inserted = fileset_.insert(FileInfo(utf8name, normalized_path)).second; |
+ bool inserted = |
+ fileset_.insert(MountPointInfo(utf8name, normalized_path)).second; |
if (!inserted) { |
int suffix = 1; |
std::string basepart = FilePath(name).RemoveExtension().AsUTF8Unsafe(); |
@@ -87,7 +83,8 @@ bool IsolatedContext::FileInfoSet::AddPath( |
utf8name = base::StringPrintf("%s (%d)", basepart.c_str(), suffix++); |
if (!ext.empty()) |
utf8name.append(ext); |
- inserted = fileset_.insert(FileInfo(utf8name, normalized_path)).second; |
+ inserted = |
+ fileset_.insert(MountPointInfo(utf8name, normalized_path)).second; |
} |
} |
if (registered_name) |
@@ -100,34 +97,29 @@ bool IsolatedContext::FileInfoSet::AddPathWithName( |
// The given path should not contain any '..' and should be absolute. |
if (path.ReferencesParent() || !path.IsAbsolute()) |
return false; |
- return fileset_.insert(FileInfo(name, path.NormalizePathSeparators())).second; |
+ return fileset_.insert( |
+ MountPointInfo(name, path.NormalizePathSeparators())).second; |
} |
//-------------------------------------------------------------------------- |
class IsolatedContext::Instance { |
public: |
- typedef FileSystemType MountType; |
- |
// For a single-path isolated file system, which could be registered by |
// IsolatedContext::RegisterFileSystemForPath(). |
// Most of isolated file system contexts should be of this type. |
- Instance(FileSystemType type, const FileInfo& file_info); |
+ Instance(FileSystemType type, const MountPointInfo& file_info); |
// For a multi-paths isolated file system. As of writing only file system |
// type which could have multi-paths is Dragged file system, and |
// could be registered by IsolatedContext::RegisterDraggedFileSystem(). |
- Instance(FileSystemType type, const std::set<FileInfo>& files); |
- |
- // For a single-path external file system. |
- Instance(FileSystemType type, const FilePath& path); |
+ Instance(FileSystemType type, const std::set<MountPointInfo>& files); |
~Instance(); |
- MountType mount_type() const { return mount_type_; } |
FileSystemType type() const { return type_; } |
- const FileInfo& file_info() const { return file_info_; } |
- const std::set<FileInfo>& files() const { return files_; } |
+ const MountPointInfo& file_info() const { return file_info_; } |
+ const std::set<MountPointInfo>& files() const { return files_; } |
int ref_counts() const { return ref_counts_; } |
void AddRef() { ++ref_counts_; } |
@@ -139,14 +131,13 @@ class IsolatedContext::Instance { |
bool IsSinglePathInstance() const; |
private: |
- const MountType mount_type_; |
const FileSystemType type_; |
// For single-path instance. |
- const FileInfo file_info_; |
+ const MountPointInfo file_info_; |
// For multiple-path instance (e.g. dragged file system). |
- const std::set<FileInfo> files_; |
+ const std::set<MountPointInfo> files_; |
// Reference counts. Note that an isolated filesystem is created with ref==0 |
// and will get deleted when the ref count reaches <=0. |
@@ -156,32 +147,21 @@ class IsolatedContext::Instance { |
}; |
IsolatedContext::Instance::Instance(FileSystemType type, |
- const FileInfo& file_info) |
- : mount_type_(kFileSystemTypeIsolated), |
- type_(type), |
+ const MountPointInfo& file_info) |
+ : type_(type), |
file_info_(file_info), |
ref_counts_(0) { |
DCHECK(IsSinglePathIsolatedFileSystem(type_)); |
} |
IsolatedContext::Instance::Instance(FileSystemType type, |
- const std::set<FileInfo>& files) |
- : mount_type_(kFileSystemTypeIsolated), |
- type_(type), |
+ const std::set<MountPointInfo>& files) |
+ : type_(type), |
files_(files), |
ref_counts_(0) { |
DCHECK(!IsSinglePathIsolatedFileSystem(type_)); |
} |
-IsolatedContext::Instance::Instance(FileSystemType type, |
- const FilePath& path) |
- : mount_type_(kFileSystemTypeExternal), |
- type_(type), |
- file_info_(FileInfo("", path)), |
- ref_counts_(0) { |
- DCHECK(IsSinglePathIsolatedFileSystem(type_)); |
-} |
- |
IsolatedContext::Instance::~Instance() {} |
bool IsolatedContext::Instance::ResolvePathForName(const std::string& name, |
@@ -190,8 +170,8 @@ bool IsolatedContext::Instance::ResolvePathForName(const std::string& name, |
*path = file_info_.path; |
return file_info_.name == name; |
} |
- std::set<FileInfo>::const_iterator found = files_.find( |
- FileInfo(name, FilePath())); |
+ std::set<MountPointInfo>::const_iterator found = files_.find( |
+ MountPointInfo(name, FilePath())); |
if (found == files_.end()) |
return false; |
*path = found->path; |
@@ -240,41 +220,11 @@ std::string IsolatedContext::RegisterFileSystemForPath( |
base::AutoLock locker(lock_); |
std::string filesystem_id = GetNewFileSystemId(); |
- instance_map_[filesystem_id] = new Instance(type, FileInfo(name, path)); |
+ instance_map_[filesystem_id] = new Instance(type, MountPointInfo(name, path)); |
path_to_id_map_[path].insert(filesystem_id); |
return filesystem_id; |
} |
-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->mount_type() == kFileSystemTypeExternal) |
- files.push_back(FileInfo(iter->first, iter->second->file_info().path)); |
- } |
- return files; |
-} |
- |
-bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) { |
- base::AutoLock locker(lock_); |
- return UnregisterFileSystem(filesystem_id); |
-} |
- |
void IsolatedContext::RevokeFileSystemByPath(const FilePath& path_in) { |
base::AutoLock locker(lock_); |
FilePath path(path_in.NormalizePathSeparators()); |
@@ -309,8 +259,7 @@ void IsolatedContext::RemoveReference(const std::string& filesystem_id) { |
Instance* instance = found->second; |
DCHECK_GT(instance->ref_counts(), 0); |
instance->RemoveRef(); |
- if (instance->ref_counts() == 0 && |
- instance->mount_type() != kFileSystemTypeExternal) { |
+ if (instance->ref_counts() == 0) { |
bool deleted = UnregisterFileSystem(filesystem_id); |
DCHECK(deleted); |
} |
@@ -348,26 +297,17 @@ bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path, |
const Instance* instance = found_instance->second; |
if (type) |
*type = instance->type(); |
- switch (instance->mount_type()) { |
- case kFileSystemTypeIsolated: { |
- 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 kFileSystemTypeExternal: |
- cracked_path = instance->file_info().path; |
- break; |
- default: |
- NOTREACHED(); |
- break; |
+ |
+ 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; |
} |
for (; component_iter != components.end(); ++component_iter) |
@@ -377,7 +317,8 @@ bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path, |
} |
bool IsolatedContext::GetDraggedFileInfo( |
- const std::string& filesystem_id, std::vector<FileInfo>* files) const { |
+ const std::string& filesystem_id, |
+ std::vector<MountPointInfo>* files) const { |
DCHECK(files); |
base::AutoLock locker(lock_); |
IDToInstance::const_iterator found = instance_map_.find(filesystem_id); |
@@ -389,6 +330,10 @@ bool IsolatedContext::GetDraggedFileInfo( |
return true; |
} |
+bool IsolatedContext::CanCrackMountType(FileSystemType type) const { |
+ return type == kFileSystemTypeIsolated; |
+} |
+ |
bool IsolatedContext::GetRegisteredPath( |
const std::string& filesystem_id, FilePath* path) const { |
DCHECK(path); |
@@ -400,6 +345,12 @@ bool IsolatedContext::GetRegisteredPath( |
return true; |
} |
+bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) { |
+ base::AutoLock locker(lock_); |
kinuko
2013/01/08 12:22:43
nit:indent
tbarzic
2013/01/09 01:26:34
I think indent is fine..
|
+ return UnregisterFileSystem(filesystem_id); |
+} |
+ |
+ |
kinuko
2013/01/08 12:22:43
nit: extra empty line
tbarzic
2013/01/09 01:26:34
Done.
|
FilePath IsolatedContext::CreateVirtualRootPath( |
const std::string& filesystem_id) const { |
return FilePath().AppendASCII(filesystem_id); |
@@ -444,21 +395,4 @@ std::string IsolatedContext::GetNewFileSystemId() const { |
return id; |
} |
-ScopedExternalFileSystem::ScopedExternalFileSystem( |
- const std::string& mount_name, |
- FileSystemType type, |
- const FilePath& path) |
- : mount_name_(mount_name) { |
- IsolatedContext::GetInstance()->RegisterExternalFileSystem( |
- mount_name, type, path); |
-} |
- |
-FilePath ScopedExternalFileSystem::GetVirtualRootPath() const { |
- return IsolatedContext::GetInstance()->CreateVirtualRootPath(mount_name_); |
-} |
- |
-ScopedExternalFileSystem::~ScopedExternalFileSystem() { |
- IsolatedContext::GetInstance()->RevokeFileSystem(mount_name_); |
-} |
- |
} // namespace fileapi |