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/browser/fileapi/isolated_context.h" | 5 #include "storage/browser/fileapi/isolated_context.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "webkit/browser/fileapi/file_system_url.h" | 15 #include "storage/browser/fileapi/file_system_url.h" |
16 | 16 |
17 namespace fileapi { | 17 namespace storage { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 base::FilePath::StringType GetRegisterNameForPath(const base::FilePath& path) { | 21 base::FilePath::StringType GetRegisterNameForPath(const base::FilePath& path) { |
22 // If it's not a root path simply return a base name. | 22 // If it's not a root path simply return a base name. |
23 if (path.DirName() != path) | 23 if (path.DirName() != path) |
24 return path.BaseName().value(); | 24 return path.BaseName().value(); |
25 | 25 |
26 #if defined(FILE_PATH_USES_DRIVE_LETTERS) | 26 #if defined(FILE_PATH_USES_DRIVE_LETTERS) |
27 base::FilePath::StringType name; | 27 base::FilePath::StringType name; |
(...skipping 17 matching lines...) Expand all Loading... |
45 // As of writing dragged file system is the only filesystem which could have | 45 // As of writing dragged file system is the only filesystem which could have |
46 // multiple top-level paths. | 46 // multiple top-level paths. |
47 return type != kFileSystemTypeDragged; | 47 return type != kFileSystemTypeDragged; |
48 } | 48 } |
49 | 49 |
50 static base::LazyInstance<IsolatedContext>::Leaky g_isolated_context = | 50 static base::LazyInstance<IsolatedContext>::Leaky g_isolated_context = |
51 LAZY_INSTANCE_INITIALIZER; | 51 LAZY_INSTANCE_INITIALIZER; |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 IsolatedContext::FileInfoSet::FileInfoSet() {} | 55 IsolatedContext::FileInfoSet::FileInfoSet() { |
56 IsolatedContext::FileInfoSet::~FileInfoSet() {} | 56 } |
| 57 IsolatedContext::FileInfoSet::~FileInfoSet() { |
| 58 } |
57 | 59 |
58 bool IsolatedContext::FileInfoSet::AddPath( | 60 bool IsolatedContext::FileInfoSet::AddPath(const base::FilePath& path, |
59 const base::FilePath& path, std::string* registered_name) { | 61 std::string* registered_name) { |
60 // The given path should not contain any '..' and should be absolute. | 62 // The given path should not contain any '..' and should be absolute. |
61 if (path.ReferencesParent() || !path.IsAbsolute()) | 63 if (path.ReferencesParent() || !path.IsAbsolute()) |
62 return false; | 64 return false; |
63 base::FilePath::StringType name = GetRegisterNameForPath(path); | 65 base::FilePath::StringType name = GetRegisterNameForPath(path); |
64 std::string utf8name = base::FilePath(name).AsUTF8Unsafe(); | 66 std::string utf8name = base::FilePath(name).AsUTF8Unsafe(); |
65 base::FilePath normalized_path = path.NormalizePathSeparators(); | 67 base::FilePath normalized_path = path.NormalizePathSeparators(); |
66 bool inserted = | 68 bool inserted = |
67 fileset_.insert(MountPointInfo(utf8name, normalized_path)).second; | 69 fileset_.insert(MountPointInfo(utf8name, normalized_path)).second; |
68 if (!inserted) { | 70 if (!inserted) { |
69 int suffix = 1; | 71 int suffix = 1; |
70 std::string basepart = | 72 std::string basepart = |
71 base::FilePath(name).RemoveExtension().AsUTF8Unsafe(); | 73 base::FilePath(name).RemoveExtension().AsUTF8Unsafe(); |
72 std::string ext = | 74 std::string ext = |
73 base::FilePath(base::FilePath(name).Extension()).AsUTF8Unsafe(); | 75 base::FilePath(base::FilePath(name).Extension()).AsUTF8Unsafe(); |
74 while (!inserted) { | 76 while (!inserted) { |
75 utf8name = base::StringPrintf("%s (%d)", basepart.c_str(), suffix++); | 77 utf8name = base::StringPrintf("%s (%d)", basepart.c_str(), suffix++); |
76 if (!ext.empty()) | 78 if (!ext.empty()) |
77 utf8name.append(ext); | 79 utf8name.append(ext); |
78 inserted = | 80 inserted = |
79 fileset_.insert(MountPointInfo(utf8name, normalized_path)).second; | 81 fileset_.insert(MountPointInfo(utf8name, normalized_path)).second; |
80 } | 82 } |
81 } | 83 } |
82 if (registered_name) | 84 if (registered_name) |
83 *registered_name = utf8name; | 85 *registered_name = utf8name; |
84 return true; | 86 return true; |
85 } | 87 } |
86 | 88 |
87 bool IsolatedContext::FileInfoSet::AddPathWithName( | 89 bool IsolatedContext::FileInfoSet::AddPathWithName(const base::FilePath& path, |
88 const base::FilePath& path, const std::string& name) { | 90 const std::string& name) { |
89 // The given path should not contain any '..' and should be absolute. | 91 // The given path should not contain any '..' and should be absolute. |
90 if (path.ReferencesParent() || !path.IsAbsolute()) | 92 if (path.ReferencesParent() || !path.IsAbsolute()) |
91 return false; | 93 return false; |
92 return fileset_.insert( | 94 return fileset_.insert(MountPointInfo(name, path.NormalizePathSeparators())) |
93 MountPointInfo(name, path.NormalizePathSeparators())).second; | 95 .second; |
94 } | 96 } |
95 | 97 |
96 //-------------------------------------------------------------------------- | 98 //-------------------------------------------------------------------------- |
97 | 99 |
98 class IsolatedContext::Instance { | 100 class IsolatedContext::Instance { |
99 public: | 101 public: |
100 enum PathType { | 102 enum PathType { PLATFORM_PATH, VIRTUAL_PATH }; |
101 PLATFORM_PATH, | |
102 VIRTUAL_PATH | |
103 }; | |
104 | 103 |
105 // For a single-path isolated file system, which could be registered by | 104 // For a single-path isolated file system, which could be registered by |
106 // IsolatedContext::RegisterFileSystemForPath() or | 105 // IsolatedContext::RegisterFileSystemForPath() or |
107 // IsolatedContext::RegisterFileSystemForVirtualPath(). | 106 // IsolatedContext::RegisterFileSystemForVirtualPath(). |
108 // Most of isolated file system contexts should be of this type. | 107 // Most of isolated file system contexts should be of this type. |
109 Instance(FileSystemType type, | 108 Instance(FileSystemType type, |
110 const std::string& filesystem_id, | 109 const std::string& filesystem_id, |
111 const MountPointInfo& file_info, | 110 const MountPointInfo& file_info, |
112 PathType path_type); | 111 PathType path_type); |
113 | 112 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 : type_(type), | 156 : type_(type), |
158 filesystem_id_(filesystem_id), | 157 filesystem_id_(filesystem_id), |
159 file_info_(file_info), | 158 file_info_(file_info), |
160 path_type_(path_type), | 159 path_type_(path_type), |
161 ref_counts_(0) { | 160 ref_counts_(0) { |
162 DCHECK(IsSinglePathIsolatedFileSystem(type_)); | 161 DCHECK(IsSinglePathIsolatedFileSystem(type_)); |
163 } | 162 } |
164 | 163 |
165 IsolatedContext::Instance::Instance(FileSystemType type, | 164 IsolatedContext::Instance::Instance(FileSystemType type, |
166 const std::set<MountPointInfo>& files) | 165 const std::set<MountPointInfo>& files) |
167 : type_(type), | 166 : type_(type), path_type_(PLATFORM_PATH), files_(files), ref_counts_(0) { |
168 path_type_(PLATFORM_PATH), | |
169 files_(files), | |
170 ref_counts_(0) { | |
171 DCHECK(!IsSinglePathIsolatedFileSystem(type_)); | 167 DCHECK(!IsSinglePathIsolatedFileSystem(type_)); |
172 } | 168 } |
173 | 169 |
174 IsolatedContext::Instance::~Instance() {} | 170 IsolatedContext::Instance::~Instance() { |
| 171 } |
175 | 172 |
176 bool IsolatedContext::Instance::ResolvePathForName(const std::string& name, | 173 bool IsolatedContext::Instance::ResolvePathForName(const std::string& name, |
177 base::FilePath* path) const { | 174 base::FilePath* path) const { |
178 if (IsSinglePathIsolatedFileSystem(type_)) { | 175 if (IsSinglePathIsolatedFileSystem(type_)) { |
179 switch (path_type_) { | 176 switch (path_type_) { |
180 case PLATFORM_PATH: | 177 case PLATFORM_PATH: |
181 *path = file_info_.path; | 178 *path = file_info_.path; |
182 break; | 179 break; |
183 case VIRTUAL_PATH: | 180 case VIRTUAL_PATH: |
184 *path = base::FilePath(); | 181 *path = base::FilePath(); |
185 break; | 182 break; |
186 default: | 183 default: |
187 NOTREACHED(); | 184 NOTREACHED(); |
188 } | 185 } |
189 | 186 |
190 return file_info_.name == name; | 187 return file_info_.name == name; |
191 } | 188 } |
192 std::set<MountPointInfo>::const_iterator found = files_.find( | 189 std::set<MountPointInfo>::const_iterator found = |
193 MountPointInfo(name, base::FilePath())); | 190 files_.find(MountPointInfo(name, base::FilePath())); |
194 if (found == files_.end()) | 191 if (found == files_.end()) |
195 return false; | 192 return false; |
196 *path = found->path; | 193 *path = found->path; |
197 return true; | 194 return true; |
198 } | 195 } |
199 | 196 |
200 bool IsolatedContext::Instance::IsSinglePathInstance() const { | 197 bool IsolatedContext::Instance::IsSinglePathInstance() const { |
201 return IsSinglePathIsolatedFileSystem(type_); | 198 return IsSinglePathIsolatedFileSystem(type_); |
202 } | 199 } |
203 | 200 |
204 //-------------------------------------------------------------------------- | 201 //-------------------------------------------------------------------------- |
205 | 202 |
206 // static | 203 // static |
207 IsolatedContext* IsolatedContext::GetInstance() { | 204 IsolatedContext* IsolatedContext::GetInstance() { |
208 return g_isolated_context.Pointer(); | 205 return g_isolated_context.Pointer(); |
209 } | 206 } |
210 | 207 |
211 // static | 208 // static |
212 bool IsolatedContext::IsIsolatedType(FileSystemType type) { | 209 bool IsolatedContext::IsIsolatedType(FileSystemType type) { |
213 return type == kFileSystemTypeIsolated || type == kFileSystemTypeExternal; | 210 return type == kFileSystemTypeIsolated || type == kFileSystemTypeExternal; |
214 } | 211 } |
215 | 212 |
216 std::string IsolatedContext::RegisterDraggedFileSystem( | 213 std::string IsolatedContext::RegisterDraggedFileSystem( |
217 const FileInfoSet& files) { | 214 const FileInfoSet& files) { |
218 base::AutoLock locker(lock_); | 215 base::AutoLock locker(lock_); |
219 std::string filesystem_id = GetNewFileSystemId(); | 216 std::string filesystem_id = GetNewFileSystemId(); |
220 instance_map_[filesystem_id] = new Instance( | 217 instance_map_[filesystem_id] = |
221 kFileSystemTypeDragged, files.fileset()); | 218 new Instance(kFileSystemTypeDragged, files.fileset()); |
222 return filesystem_id; | 219 return filesystem_id; |
223 } | 220 } |
224 | 221 |
225 std::string IsolatedContext::RegisterFileSystemForPath( | 222 std::string IsolatedContext::RegisterFileSystemForPath( |
226 FileSystemType type, | 223 FileSystemType type, |
227 const std::string& filesystem_id, | 224 const std::string& filesystem_id, |
228 const base::FilePath& path_in, | 225 const base::FilePath& path_in, |
229 std::string* register_name) { | 226 std::string* register_name) { |
230 base::FilePath path(path_in.NormalizePathSeparators()); | 227 base::FilePath path(path_in.NormalizePathSeparators()); |
231 if (path.ReferencesParent() || !path.IsAbsolute()) | 228 if (path.ReferencesParent() || !path.IsAbsolute()) |
232 return std::string(); | 229 return std::string(); |
233 std::string name; | 230 std::string name; |
234 if (register_name && !register_name->empty()) { | 231 if (register_name && !register_name->empty()) { |
235 name = *register_name; | 232 name = *register_name; |
236 } else { | 233 } else { |
237 name = base::FilePath(GetRegisterNameForPath(path)).AsUTF8Unsafe(); | 234 name = base::FilePath(GetRegisterNameForPath(path)).AsUTF8Unsafe(); |
238 if (register_name) | 235 if (register_name) |
239 register_name->assign(name); | 236 register_name->assign(name); |
240 } | 237 } |
241 | 238 |
242 base::AutoLock locker(lock_); | 239 base::AutoLock locker(lock_); |
243 std::string new_id = GetNewFileSystemId(); | 240 std::string new_id = GetNewFileSystemId(); |
244 instance_map_[new_id] = new Instance(type, filesystem_id, | 241 instance_map_[new_id] = new Instance( |
245 MountPointInfo(name, path), | 242 type, filesystem_id, MountPointInfo(name, path), Instance::PLATFORM_PATH); |
246 Instance::PLATFORM_PATH); | |
247 path_to_id_map_[path].insert(new_id); | 243 path_to_id_map_[path].insert(new_id); |
248 return new_id; | 244 return new_id; |
249 } | 245 } |
250 | 246 |
251 std::string IsolatedContext::RegisterFileSystemForVirtualPath( | 247 std::string IsolatedContext::RegisterFileSystemForVirtualPath( |
252 FileSystemType type, | 248 FileSystemType type, |
253 const std::string& register_name, | 249 const std::string& register_name, |
254 const base::FilePath& cracked_path_prefix) { | 250 const base::FilePath& cracked_path_prefix) { |
255 base::AutoLock locker(lock_); | 251 base::AutoLock locker(lock_); |
256 base::FilePath path(cracked_path_prefix.NormalizePathSeparators()); | 252 base::FilePath path(cracked_path_prefix.NormalizePathSeparators()); |
257 if (path.ReferencesParent()) | 253 if (path.ReferencesParent()) |
258 return std::string(); | 254 return std::string(); |
259 std::string filesystem_id = GetNewFileSystemId(); | 255 std::string filesystem_id = GetNewFileSystemId(); |
260 instance_map_[filesystem_id] = new Instance( | 256 instance_map_[filesystem_id] = |
261 type, | 257 new Instance(type, |
262 std::string(), // filesystem_id | 258 std::string(), // filesystem_id |
263 MountPointInfo(register_name, cracked_path_prefix), | 259 MountPointInfo(register_name, cracked_path_prefix), |
264 Instance::VIRTUAL_PATH); | 260 Instance::VIRTUAL_PATH); |
265 path_to_id_map_[path].insert(filesystem_id); | 261 path_to_id_map_[path].insert(filesystem_id); |
266 return filesystem_id; | 262 return filesystem_id; |
267 } | 263 } |
268 | 264 |
269 bool IsolatedContext::HandlesFileSystemMountType(FileSystemType type) const { | 265 bool IsolatedContext::HandlesFileSystemMountType(FileSystemType type) const { |
270 return type == kFileSystemTypeIsolated; | 266 return type == kFileSystemTypeIsolated; |
271 } | 267 } |
272 | 268 |
273 bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) { | 269 bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) { |
274 base::AutoLock locker(lock_); | 270 base::AutoLock locker(lock_); |
275 return UnregisterFileSystem(filesystem_id); | 271 return UnregisterFileSystem(filesystem_id); |
276 } | 272 } |
277 | 273 |
278 bool IsolatedContext::GetRegisteredPath( | 274 bool IsolatedContext::GetRegisteredPath(const std::string& filesystem_id, |
279 const std::string& filesystem_id, base::FilePath* path) const { | 275 base::FilePath* path) const { |
280 DCHECK(path); | 276 DCHECK(path); |
281 base::AutoLock locker(lock_); | 277 base::AutoLock locker(lock_); |
282 IDToInstance::const_iterator found = instance_map_.find(filesystem_id); | 278 IDToInstance::const_iterator found = instance_map_.find(filesystem_id); |
283 if (found == instance_map_.end() || !found->second->IsSinglePathInstance()) | 279 if (found == instance_map_.end() || !found->second->IsSinglePathInstance()) |
284 return false; | 280 return false; |
285 *path = found->second->file_info().path; | 281 *path = found->second->file_info().path; |
286 return true; | 282 return true; |
287 } | 283 } |
288 | 284 |
289 bool IsolatedContext::CrackVirtualPath( | 285 bool IsolatedContext::CrackVirtualPath( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 return CrackFileSystemURL(FileSystemURL(origin, type, path)); | 355 return CrackFileSystemURL(FileSystemURL(origin, type, path)); |
360 } | 356 } |
361 | 357 |
362 void IsolatedContext::RevokeFileSystemByPath(const base::FilePath& path_in) { | 358 void IsolatedContext::RevokeFileSystemByPath(const base::FilePath& path_in) { |
363 base::AutoLock locker(lock_); | 359 base::AutoLock locker(lock_); |
364 base::FilePath path(path_in.NormalizePathSeparators()); | 360 base::FilePath path(path_in.NormalizePathSeparators()); |
365 PathToID::iterator ids_iter = path_to_id_map_.find(path); | 361 PathToID::iterator ids_iter = path_to_id_map_.find(path); |
366 if (ids_iter == path_to_id_map_.end()) | 362 if (ids_iter == path_to_id_map_.end()) |
367 return; | 363 return; |
368 std::set<std::string>& ids = ids_iter->second; | 364 std::set<std::string>& ids = ids_iter->second; |
369 for (std::set<std::string>::iterator iter = ids.begin(); | 365 for (std::set<std::string>::iterator iter = ids.begin(); iter != ids.end(); |
370 iter != ids.end(); ++iter) { | 366 ++iter) { |
371 IDToInstance::iterator found = instance_map_.find(*iter); | 367 IDToInstance::iterator found = instance_map_.find(*iter); |
372 if (found != instance_map_.end()) { | 368 if (found != instance_map_.end()) { |
373 delete found->second; | 369 delete found->second; |
374 instance_map_.erase(found); | 370 instance_map_.erase(found); |
375 } | 371 } |
376 } | 372 } |
377 path_to_id_map_.erase(ids_iter); | 373 path_to_id_map_.erase(ids_iter); |
378 } | 374 } |
379 | 375 |
380 void IsolatedContext::AddReference(const std::string& filesystem_id) { | 376 void IsolatedContext::AddReference(const std::string& filesystem_id) { |
(...skipping 20 matching lines...) Expand all Loading... |
401 | 397 |
402 bool IsolatedContext::GetDraggedFileInfo( | 398 bool IsolatedContext::GetDraggedFileInfo( |
403 const std::string& filesystem_id, | 399 const std::string& filesystem_id, |
404 std::vector<MountPointInfo>* files) const { | 400 std::vector<MountPointInfo>* files) const { |
405 DCHECK(files); | 401 DCHECK(files); |
406 base::AutoLock locker(lock_); | 402 base::AutoLock locker(lock_); |
407 IDToInstance::const_iterator found = instance_map_.find(filesystem_id); | 403 IDToInstance::const_iterator found = instance_map_.find(filesystem_id); |
408 if (found == instance_map_.end() || | 404 if (found == instance_map_.end() || |
409 found->second->type() != kFileSystemTypeDragged) | 405 found->second->type() != kFileSystemTypeDragged) |
410 return false; | 406 return false; |
411 files->assign(found->second->files().begin(), | 407 files->assign(found->second->files().begin(), found->second->files().end()); |
412 found->second->files().end()); | |
413 return true; | 408 return true; |
414 } | 409 } |
415 | 410 |
416 base::FilePath IsolatedContext::CreateVirtualRootPath( | 411 base::FilePath IsolatedContext::CreateVirtualRootPath( |
417 const std::string& filesystem_id) const { | 412 const std::string& filesystem_id) const { |
418 return base::FilePath().AppendASCII(filesystem_id); | 413 return base::FilePath().AppendASCII(filesystem_id); |
419 } | 414 } |
420 | 415 |
421 IsolatedContext::IsolatedContext() { | 416 IsolatedContext::IsolatedContext() { |
422 } | 417 } |
423 | 418 |
424 IsolatedContext::~IsolatedContext() { | 419 IsolatedContext::~IsolatedContext() { |
425 STLDeleteContainerPairSecondPointers(instance_map_.begin(), | 420 STLDeleteContainerPairSecondPointers(instance_map_.begin(), |
426 instance_map_.end()); | 421 instance_map_.end()); |
427 } | 422 } |
428 | 423 |
429 FileSystemURL IsolatedContext::CrackFileSystemURL( | 424 FileSystemURL IsolatedContext::CrackFileSystemURL( |
430 const FileSystemURL& url) const { | 425 const FileSystemURL& url) const { |
431 if (!HandlesFileSystemMountType(url.type())) | 426 if (!HandlesFileSystemMountType(url.type())) |
432 return FileSystemURL(); | 427 return FileSystemURL(); |
433 | 428 |
434 std::string mount_name; | 429 std::string mount_name; |
435 std::string cracked_mount_name; | 430 std::string cracked_mount_name; |
436 FileSystemType cracked_type; | 431 FileSystemType cracked_type; |
437 base::FilePath cracked_path; | 432 base::FilePath cracked_path; |
438 FileSystemMountOption cracked_mount_option; | 433 FileSystemMountOption cracked_mount_option; |
439 if (!CrackVirtualPath(url.path(), &mount_name, &cracked_type, | 434 if (!CrackVirtualPath(url.path(), |
440 &cracked_mount_name, &cracked_path, | 435 &mount_name, |
| 436 &cracked_type, |
| 437 &cracked_mount_name, |
| 438 &cracked_path, |
441 &cracked_mount_option)) { | 439 &cracked_mount_option)) { |
442 return FileSystemURL(); | 440 return FileSystemURL(); |
443 } | 441 } |
444 | 442 |
445 return FileSystemURL( | 443 return FileSystemURL( |
446 url.origin(), url.mount_type(), url.virtual_path(), | 444 url.origin(), |
| 445 url.mount_type(), |
| 446 url.virtual_path(), |
447 !url.filesystem_id().empty() ? url.filesystem_id() : mount_name, | 447 !url.filesystem_id().empty() ? url.filesystem_id() : mount_name, |
448 cracked_type, cracked_path, | 448 cracked_type, |
| 449 cracked_path, |
449 cracked_mount_name.empty() ? mount_name : cracked_mount_name, | 450 cracked_mount_name.empty() ? mount_name : cracked_mount_name, |
450 cracked_mount_option); | 451 cracked_mount_option); |
451 } | 452 } |
452 | 453 |
453 bool IsolatedContext::UnregisterFileSystem(const std::string& filesystem_id) { | 454 bool IsolatedContext::UnregisterFileSystem(const std::string& filesystem_id) { |
454 lock_.AssertAcquired(); | 455 lock_.AssertAcquired(); |
455 IDToInstance::iterator found = instance_map_.find(filesystem_id); | 456 IDToInstance::iterator found = instance_map_.find(filesystem_id); |
456 if (found == instance_map_.end()) | 457 if (found == instance_map_.end()) |
457 return false; | 458 return false; |
458 Instance* instance = found->second; | 459 Instance* instance = found->second; |
459 if (instance->IsSinglePathInstance()) { | 460 if (instance->IsSinglePathInstance()) { |
460 PathToID::iterator ids_iter = path_to_id_map_.find( | 461 PathToID::iterator ids_iter = |
461 instance->file_info().path); | 462 path_to_id_map_.find(instance->file_info().path); |
462 DCHECK(ids_iter != path_to_id_map_.end()); | 463 DCHECK(ids_iter != path_to_id_map_.end()); |
463 ids_iter->second.erase(filesystem_id); | 464 ids_iter->second.erase(filesystem_id); |
464 if (ids_iter->second.empty()) | 465 if (ids_iter->second.empty()) |
465 path_to_id_map_.erase(ids_iter); | 466 path_to_id_map_.erase(ids_iter); |
466 } | 467 } |
467 delete found->second; | 468 delete found->second; |
468 instance_map_.erase(found); | 469 instance_map_.erase(found); |
469 return true; | 470 return true; |
470 } | 471 } |
471 | 472 |
472 std::string IsolatedContext::GetNewFileSystemId() const { | 473 std::string IsolatedContext::GetNewFileSystemId() const { |
473 // Returns an arbitrary random string which must be unique in the map. | 474 // Returns an arbitrary random string which must be unique in the map. |
474 lock_.AssertAcquired(); | 475 lock_.AssertAcquired(); |
475 uint32 random_data[4]; | 476 uint32 random_data[4]; |
476 std::string id; | 477 std::string id; |
477 do { | 478 do { |
478 base::RandBytes(random_data, sizeof(random_data)); | 479 base::RandBytes(random_data, sizeof(random_data)); |
479 id = base::HexEncode(random_data, sizeof(random_data)); | 480 id = base::HexEncode(random_data, sizeof(random_data)); |
480 } while (instance_map_.find(id) != instance_map_.end()); | 481 } while (instance_map_.find(id) != instance_map_.end()); |
481 return id; | 482 return id; |
482 } | 483 } |
483 | 484 |
484 } // namespace fileapi | 485 } // namespace storage |
OLD | NEW |