summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/isolated_context.cc
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-26 05:05:18 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-26 05:05:18 +0000
commitd16ef66b6fac08e893265ba581bb0db270dbe5ef (patch)
tree6c17424b2209fc96229c812ceed0ef4410d9aa87 /webkit/fileapi/isolated_context.cc
parent9de7d5d2bcc3e87801b7b0982a5c3331710636dc (diff)
downloadchromium_src-d16ef66b6fac08e893265ba581bb0db270dbe5ef.zip
chromium_src-d16ef66b6fac08e893265ba581bb0db270dbe5ef.tar.gz
chromium_src-d16ef66b6fac08e893265ba581bb0db270dbe5ef.tar.bz2
Manage IsolatedContext with reference counts
to make it possible to be shared by multiple children. This patch itself should have no side effect. BUG=none TEST=existing tests should pass Review URL: https://chromiumcodereview.appspot.com/10536200 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144115 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/isolated_context.cc')
-rw-r--r--webkit/fileapi/isolated_context.cc38
1 files changed, 31 insertions, 7 deletions
diff --git a/webkit/fileapi/isolated_context.cc b/webkit/fileapi/isolated_context.cc
index e8b52ae..a7386fb0 100644
--- a/webkit/fileapi/isolated_context.cc
+++ b/webkit/fileapi/isolated_context.cc
@@ -29,10 +29,8 @@ std::string IsolatedContext::RegisterIsolatedFileSystem(
PathMap toplevels;
for (std::set<FilePath>::const_iterator iter = files.begin();
iter != files.end(); ++iter) {
- // If the given path contains any '..' or is not an absolute path,
- // return an empty (invalid) id.
- if (iter->ReferencesParent() || !iter->IsAbsolute())
- return std::string();
+ // The given path should not contain any '..' and must be an absolute path.
+ DCHECK(!iter->ReferencesParent() && iter->IsAbsolute());
// Register the basename -> fullpath map. (We only expose the basename
// part to the user scripts)
@@ -43,15 +41,34 @@ std::string IsolatedContext::RegisterIsolatedFileSystem(
toplevels.insert(std::make_pair(basename, fullpath));
}
toplevel_map_[filesystem_id] = toplevels;
+
+ // Each file system is created with refcount == 0.
+ ref_counts_[filesystem_id] = 0;
+
return filesystem_id;
}
-// Revoke any registered drag context for the child_id.
void IsolatedContext::RevokeIsolatedFileSystem(
const std::string& filesystem_id) {
base::AutoLock locker(lock_);
- toplevel_map_.erase(filesystem_id);
- writable_ids_.erase(filesystem_id);
+ RevokeWithoutLocking(filesystem_id);
+}
+
+void IsolatedContext::AddReference(const std::string& filesystem_id) {
+ base::AutoLock locker(lock_);
+ DCHECK(ref_counts_.find(filesystem_id) != ref_counts_.end());
+ ref_counts_[filesystem_id]++;
+}
+
+void IsolatedContext::RemoveReference(const std::string& filesystem_id) {
+ base::AutoLock locker(lock_);
+ // This could get called for non-existent filesystem if it has been
+ // already deleted by RevokeIsolatedFileSystem.
+ if (ref_counts_.find(filesystem_id) == ref_counts_.end())
+ return;
+ DCHECK(ref_counts_[filesystem_id] > 0);
+ if (--ref_counts_[filesystem_id] == 0)
+ RevokeWithoutLocking(filesystem_id);
}
bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path,
@@ -147,6 +164,13 @@ IsolatedContext::IsolatedContext() {
IsolatedContext::~IsolatedContext() {
}
+void IsolatedContext::RevokeWithoutLocking(
+ const std::string& filesystem_id) {
+ toplevel_map_.erase(filesystem_id);
+ writable_ids_.erase(filesystem_id);
+ ref_counts_.erase(filesystem_id);
+}
+
std::string IsolatedContext::GetNewFileSystemId() const {
// Returns an arbitrary random string which must be unique in the map.
uint32 random_data[4];