OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/fileapi/isolated_context.h" | 5 #include "webkit/fileapi/isolated_context.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 | 36 |
37 // Register the basename -> fullpath map. (We only expose the basename | 37 // Register the basename -> fullpath map. (We only expose the basename |
38 // part to the user scripts) | 38 // part to the user scripts) |
39 FilePath fullpath = iter->NormalizePathSeparators(); | 39 FilePath fullpath = iter->NormalizePathSeparators(); |
40 FilePath basename = iter->BaseName(); | 40 FilePath basename = iter->BaseName(); |
41 // TODO(kinuko): Append a suffix or something if we have multiple pathnames | 41 // TODO(kinuko): Append a suffix or something if we have multiple pathnames |
42 // with the same basename. For now we only register the first one. | 42 // with the same basename. For now we only register the first one. |
43 toplevels.insert(std::make_pair(basename, fullpath)); | 43 toplevels.insert(std::make_pair(basename, fullpath)); |
44 } | 44 } |
45 toplevel_map_[filesystem_id] = toplevels; | 45 toplevel_map_[filesystem_id] = toplevels; |
46 | |
47 // Each file system is created with refcount == 0. | |
48 ref_counts_[filesystem_id] = 0; | |
49 | |
46 return filesystem_id; | 50 return filesystem_id; |
47 } | 51 } |
48 | 52 |
49 // Revoke any registered drag context for the child_id. | 53 void IsolatedContext::AddReference(const std::string& filesystem_id) { |
50 void IsolatedContext::RevokeIsolatedFileSystem( | |
51 const std::string& filesystem_id) { | |
52 base::AutoLock locker(lock_); | 54 base::AutoLock locker(lock_); |
53 toplevel_map_.erase(filesystem_id); | 55 DCHECK(ref_counts_.find(filesystem_id) != ref_counts_.end()); |
54 writable_ids_.erase(filesystem_id); | 56 ref_counts_[filesystem_id]++; |
57 } | |
58 | |
59 void IsolatedContext::RemoveReference(const std::string& filesystem_id) { | |
60 base::AutoLock locker(lock_); | |
tzik
2012/06/21 14:00:35
Could you add DCHECK(ref_counts_.find(filesystem_i
kinuko
2012/06/22 04:53:30
Done. We didn't have similar check in RevokeIsola
| |
61 // Refcount could become <0 if it has never gotten referenced. | |
62 if (--ref_counts_[filesystem_id] <= 0) | |
63 RevokeWithoutLocking(filesystem_id); | |
55 } | 64 } |
56 | 65 |
57 bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path, | 66 bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path, |
58 std::string* filesystem_id, | 67 std::string* filesystem_id, |
59 FilePath* root_path, | 68 FilePath* root_path, |
60 FilePath* platform_path) const { | 69 FilePath* platform_path) const { |
61 DCHECK(filesystem_id); | 70 DCHECK(filesystem_id); |
62 DCHECK(platform_path); | 71 DCHECK(platform_path); |
63 | 72 |
64 // This should not contain any '..' references. | 73 // This should not contain any '..' references. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 full_path = full_path.Append(relative_path); | 149 full_path = full_path.Append(relative_path); |
141 return full_path; | 150 return full_path; |
142 } | 151 } |
143 | 152 |
144 IsolatedContext::IsolatedContext() { | 153 IsolatedContext::IsolatedContext() { |
145 } | 154 } |
146 | 155 |
147 IsolatedContext::~IsolatedContext() { | 156 IsolatedContext::~IsolatedContext() { |
148 } | 157 } |
149 | 158 |
159 void IsolatedContext::RevokeWithoutLocking( | |
160 const std::string& filesystem_id) { | |
161 toplevel_map_.erase(filesystem_id); | |
162 writable_ids_.erase(filesystem_id); | |
163 ref_counts_.erase(filesystem_id); | |
164 } | |
165 | |
150 std::string IsolatedContext::GetNewFileSystemId() const { | 166 std::string IsolatedContext::GetNewFileSystemId() const { |
151 // Returns an arbitrary random string which must be unique in the map. | 167 // Returns an arbitrary random string which must be unique in the map. |
152 uint32 random_data[4]; | 168 uint32 random_data[4]; |
153 std::string id; | 169 std::string id; |
154 do { | 170 do { |
155 base::RandBytes(random_data, sizeof(random_data)); | 171 base::RandBytes(random_data, sizeof(random_data)); |
156 id = base::HexEncode(random_data, sizeof(random_data)); | 172 id = base::HexEncode(random_data, sizeof(random_data)); |
157 } while (toplevel_map_.find(id) != toplevel_map_.end()); | 173 } while (toplevel_map_.find(id) != toplevel_map_.end()); |
158 return id; | 174 return id; |
159 } | 175 } |
160 | 176 |
161 } // namespace fileapi | 177 } // namespace fileapi |
OLD | NEW |