Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: webkit/fileapi/isolated_context.cc

Issue 10837217: Add RevokeFileSystem back to IsolatedContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/fileapi/isolated_context.h ('k') | webkit/fileapi/isolated_context_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_path.h" 7 #include "base/file_path.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 const FileInfoSet& files) { 159 const FileInfoSet& files) {
160 base::AutoLock locker(lock_); 160 base::AutoLock locker(lock_);
161 std::string filesystem_id = GetNewFileSystemId(); 161 std::string filesystem_id = GetNewFileSystemId();
162 instance_map_[filesystem_id] = new Instance( 162 instance_map_[filesystem_id] = new Instance(
163 kFileSystemTypeDragged, files.fileset()); 163 kFileSystemTypeDragged, files.fileset());
164 return filesystem_id; 164 return filesystem_id;
165 } 165 }
166 166
167 std::string IsolatedContext::RegisterFileSystemForPath( 167 std::string IsolatedContext::RegisterFileSystemForPath(
168 FileSystemType type, 168 FileSystemType type,
169 const FilePath& path, 169 const FilePath& path_in,
170 std::string* register_name) { 170 std::string* register_name) {
171 FilePath path(path_in.NormalizePathSeparators());
171 DCHECK(!path.ReferencesParent() && path.IsAbsolute()); 172 DCHECK(!path.ReferencesParent() && path.IsAbsolute());
172 std::string name; 173 std::string name;
173 if (register_name && !register_name->empty()) { 174 if (register_name && !register_name->empty()) {
174 name = *register_name; 175 name = *register_name;
175 } else { 176 } else {
176 name = FilePath(GetRegisterNameForPath(path)).AsUTF8Unsafe(); 177 name = FilePath(GetRegisterNameForPath(path)).AsUTF8Unsafe();
177 if (register_name) 178 if (register_name)
178 register_name->assign(name); 179 register_name->assign(name);
179 } 180 }
180 181
181 base::AutoLock locker(lock_); 182 base::AutoLock locker(lock_);
182 std::string filesystem_id = GetNewFileSystemId(); 183 std::string filesystem_id = GetNewFileSystemId();
183 instance_map_[filesystem_id] = new Instance(type, FileInfo(name, path)); 184 instance_map_[filesystem_id] = new Instance(type, FileInfo(name, path));
184 path_to_id_map_[path].insert(filesystem_id); 185 path_to_id_map_[path].insert(filesystem_id);
185 return filesystem_id; 186 return filesystem_id;
186 } 187 }
187 188
188 void IsolatedContext::RevokeFileSystemByPath(const FilePath& path) { 189 bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) {
189 base::AutoLock locker(lock_); 190 base::AutoLock locker(lock_);
191 return UnregisterFileSystem(filesystem_id);
kinuko 2012/08/13 09:20:26 Changed the mysterious argument name to our usual
192 }
193
194 void IsolatedContext::RevokeFileSystemByPath(const FilePath& path_in) {
195 base::AutoLock locker(lock_);
196 FilePath path(path_in.NormalizePathSeparators());
190 PathToID::iterator ids_iter = path_to_id_map_.find(path); 197 PathToID::iterator ids_iter = path_to_id_map_.find(path);
191 if (ids_iter == path_to_id_map_.end()) 198 if (ids_iter == path_to_id_map_.end())
192 return; 199 return;
193 std::set<std::string>& ids = ids_iter->second; 200 std::set<std::string>& ids = ids_iter->second;
194 for (std::set<std::string>::iterator iter = ids.begin(); 201 for (std::set<std::string>::iterator iter = ids.begin();
195 iter != ids.end(); ++iter) { 202 iter != ids.end(); ++iter) {
196 IDToInstance::iterator found = instance_map_.find(*iter); 203 IDToInstance::iterator found = instance_map_.find(*iter);
197 if (found != instance_map_.end()) { 204 if (found != instance_map_.end()) {
198 delete found->second; 205 delete found->second;
199 instance_map_.erase(found); 206 instance_map_.erase(found);
(...skipping 12 matching lines...) Expand all
212 base::AutoLock locker(lock_); 219 base::AutoLock locker(lock_);
213 // This could get called for non-existent filesystem if it has been 220 // This could get called for non-existent filesystem if it has been
214 // already deleted by RevokeFileSystemByPath. 221 // already deleted by RevokeFileSystemByPath.
215 IDToInstance::iterator found = instance_map_.find(filesystem_id); 222 IDToInstance::iterator found = instance_map_.find(filesystem_id);
216 if (found == instance_map_.end()) 223 if (found == instance_map_.end())
217 return; 224 return;
218 Instance* instance = found->second; 225 Instance* instance = found->second;
219 DCHECK(instance->ref_counts() > 0); 226 DCHECK(instance->ref_counts() > 0);
220 instance->RemoveRef(); 227 instance->RemoveRef();
221 if (instance->ref_counts() == 0) { 228 if (instance->ref_counts() == 0) {
222 if (instance->IsSinglePathInstance()) { 229 bool deleted = UnregisterFileSystem(filesystem_id);
223 PathToID::iterator ids_iter = path_to_id_map_.find( 230 DCHECK(deleted);
224 instance->file_info().path);
225 DCHECK(ids_iter != path_to_id_map_.end());
226 ids_iter->second.erase(filesystem_id);
227 if (ids_iter->second.empty())
228 path_to_id_map_.erase(ids_iter);
229 }
230 delete instance;
231 instance_map_.erase(found);
232 } 231 }
233 } 232 }
234 233
235 bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path, 234 bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path,
236 std::string* filesystem_id, 235 std::string* filesystem_id,
237 FileSystemType* type, 236 FileSystemType* type,
238 FilePath* path) const { 237 FilePath* path) const {
239 DCHECK(filesystem_id); 238 DCHECK(filesystem_id);
240 DCHECK(path); 239 DCHECK(path);
241 240
(...skipping 19 matching lines...) Expand all
261 *type = found_instance->second->type(); 260 *type = found_instance->second->type();
262 if (components.size() == 1) { 261 if (components.size() == 1) {
263 path->clear(); 262 path->clear();
264 return true; 263 return true;
265 } 264 }
266 // components[1] should be a name of the registered paths. 265 // components[1] should be a name of the registered paths.
267 FilePath cracked_path; 266 FilePath cracked_path;
268 std::string name = FilePath(components[1]).AsUTF8Unsafe(); 267 std::string name = FilePath(components[1]).AsUTF8Unsafe();
269 if (!found_instance->second->ResolvePathForName(name, &cracked_path)) 268 if (!found_instance->second->ResolvePathForName(name, &cracked_path))
270 return false; 269 return false;
270
271 for (size_t i = 2; i < components.size(); ++i) 271 for (size_t i = 2; i < components.size(); ++i)
272 cracked_path = cracked_path.Append(components[i]); 272 cracked_path = cracked_path.Append(components[i]);
273 *path = cracked_path; 273 *path = cracked_path;
274 return true; 274 return true;
275 } 275 }
276 276
277 bool IsolatedContext::GetDraggedFileInfo( 277 bool IsolatedContext::GetDraggedFileInfo(
278 const std::string& filesystem_id, std::vector<FileInfo>* files) const { 278 const std::string& filesystem_id, std::vector<FileInfo>* files) const {
279 DCHECK(files); 279 DCHECK(files);
280 base::AutoLock locker(lock_); 280 base::AutoLock locker(lock_);
(...skipping 23 matching lines...) Expand all
304 } 304 }
305 305
306 IsolatedContext::IsolatedContext() { 306 IsolatedContext::IsolatedContext() {
307 } 307 }
308 308
309 IsolatedContext::~IsolatedContext() { 309 IsolatedContext::~IsolatedContext() {
310 STLDeleteContainerPairSecondPointers(instance_map_.begin(), 310 STLDeleteContainerPairSecondPointers(instance_map_.begin(),
311 instance_map_.end()); 311 instance_map_.end());
312 } 312 }
313 313
314 bool IsolatedContext::UnregisterFileSystem(const std::string& filesystem_id) {
315 lock_.AssertAcquired();
316 IDToInstance::iterator found = instance_map_.find(filesystem_id);
317 if (found == instance_map_.end())
318 return false;
319 Instance* instance = found->second;
320 if (instance->IsSinglePathInstance()) {
321 PathToID::iterator ids_iter = path_to_id_map_.find(
322 instance->file_info().path);
323 DCHECK(ids_iter != path_to_id_map_.end());
324 ids_iter->second.erase(filesystem_id);
325 if (ids_iter->second.empty())
326 path_to_id_map_.erase(ids_iter);
327 }
328 delete found->second;
329 instance_map_.erase(found);
330 return true;
331 }
332
314 std::string IsolatedContext::GetNewFileSystemId() const { 333 std::string IsolatedContext::GetNewFileSystemId() const {
315 // Returns an arbitrary random string which must be unique in the map. 334 // Returns an arbitrary random string which must be unique in the map.
335 lock_.AssertAcquired();
316 uint32 random_data[4]; 336 uint32 random_data[4];
317 std::string id; 337 std::string id;
318 do { 338 do {
319 base::RandBytes(random_data, sizeof(random_data)); 339 base::RandBytes(random_data, sizeof(random_data));
320 id = base::HexEncode(random_data, sizeof(random_data)); 340 id = base::HexEncode(random_data, sizeof(random_data));
321 } while (instance_map_.find(id) != instance_map_.end()); 341 } while (instance_map_.find(id) != instance_map_.end());
322 return id; 342 return id;
323 } 343 }
324 344
325 } // namespace fileapi 345 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/isolated_context.h ('k') | webkit/fileapi/isolated_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698