| 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/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" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "webkit/fileapi/file_system_url.h" |
| 15 | 16 |
| 16 namespace fileapi { | 17 namespace fileapi { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 FilePath::StringType GetRegisterNameForPath(const FilePath& path) { | 21 FilePath::StringType GetRegisterNameForPath(const FilePath& path) { |
| 21 // 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. |
| 22 if (path.DirName() != path) | 23 if (path.DirName() != path) |
| 23 return path.BaseName().value(); | 24 return path.BaseName().value(); |
| 24 | 25 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 register_name->assign(name); | 219 register_name->assign(name); |
| 219 } | 220 } |
| 220 | 221 |
| 221 base::AutoLock locker(lock_); | 222 base::AutoLock locker(lock_); |
| 222 std::string filesystem_id = GetNewFileSystemId(); | 223 std::string filesystem_id = GetNewFileSystemId(); |
| 223 instance_map_[filesystem_id] = new Instance(type, MountPointInfo(name, path)); | 224 instance_map_[filesystem_id] = new Instance(type, MountPointInfo(name, path)); |
| 224 path_to_id_map_[path].insert(filesystem_id); | 225 path_to_id_map_[path].insert(filesystem_id); |
| 225 return filesystem_id; | 226 return filesystem_id; |
| 226 } | 227 } |
| 227 | 228 |
| 229 bool IsolatedContext::HandlesFileSystemMountType(FileSystemType type) const { |
| 230 return type == kFileSystemTypeIsolated; |
| 231 } |
| 232 |
| 228 bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) { | 233 bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) { |
| 229 base::AutoLock locker(lock_); | 234 base::AutoLock locker(lock_); |
| 230 return UnregisterFileSystem(filesystem_id); | 235 return UnregisterFileSystem(filesystem_id); |
| 231 } | 236 } |
| 232 | 237 |
| 233 bool IsolatedContext::GetRegisteredPath( | 238 bool IsolatedContext::GetRegisteredPath( |
| 234 const std::string& filesystem_id, FilePath* path) const { | 239 const std::string& filesystem_id, FilePath* path) const { |
| 235 DCHECK(path); | 240 DCHECK(path); |
| 236 base::AutoLock locker(lock_); | 241 base::AutoLock locker(lock_); |
| 237 IDToInstance::const_iterator found = instance_map_.find(filesystem_id); | 242 IDToInstance::const_iterator found = instance_map_.find(filesystem_id); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 if (!instance->ResolvePathForName(name, &cracked_path)) | 290 if (!instance->ResolvePathForName(name, &cracked_path)) |
| 286 return false; | 291 return false; |
| 287 } | 292 } |
| 288 | 293 |
| 289 for (; component_iter != components.end(); ++component_iter) | 294 for (; component_iter != components.end(); ++component_iter) |
| 290 cracked_path = cracked_path.Append(*component_iter); | 295 cracked_path = cracked_path.Append(*component_iter); |
| 291 *path = cracked_path; | 296 *path = cracked_path; |
| 292 return true; | 297 return true; |
| 293 } | 298 } |
| 294 | 299 |
| 300 FileSystemURL IsolatedContext::CrackURL(const GURL& url) const { |
| 301 FileSystemURL filesystem_url = FileSystemURL(url); |
| 302 if (!filesystem_url.is_valid()) |
| 303 return FileSystemURL(); |
| 304 return CreateCrackedFileSystemURL(filesystem_url.origin(), |
| 305 filesystem_url.mount_type(), |
| 306 filesystem_url.path()); |
| 307 } |
| 308 |
| 309 FileSystemURL IsolatedContext::CreateCrackedFileSystemURL( |
| 310 const GURL& origin, |
| 311 FileSystemType type, |
| 312 const FilePath& path) const { |
| 313 if (!HandlesFileSystemMountType(type)) |
| 314 return FileSystemURL(); |
| 315 |
| 316 std::string mount_name; |
| 317 FileSystemType cracked_type; |
| 318 FilePath cracked_path; |
| 319 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path)) |
| 320 return FileSystemURL(); |
| 321 |
| 322 return FileSystemURL(origin, type, path, |
| 323 mount_name, cracked_type, cracked_path); |
| 324 } |
| 325 |
| 295 void IsolatedContext::RevokeFileSystemByPath(const FilePath& path_in) { | 326 void IsolatedContext::RevokeFileSystemByPath(const FilePath& path_in) { |
| 296 base::AutoLock locker(lock_); | 327 base::AutoLock locker(lock_); |
| 297 FilePath path(path_in.NormalizePathSeparators()); | 328 FilePath path(path_in.NormalizePathSeparators()); |
| 298 PathToID::iterator ids_iter = path_to_id_map_.find(path); | 329 PathToID::iterator ids_iter = path_to_id_map_.find(path); |
| 299 if (ids_iter == path_to_id_map_.end()) | 330 if (ids_iter == path_to_id_map_.end()) |
| 300 return; | 331 return; |
| 301 std::set<std::string>& ids = ids_iter->second; | 332 std::set<std::string>& ids = ids_iter->second; |
| 302 for (std::set<std::string>::iterator iter = ids.begin(); | 333 for (std::set<std::string>::iterator iter = ids.begin(); |
| 303 iter != ids.end(); ++iter) { | 334 iter != ids.end(); ++iter) { |
| 304 IDToInstance::iterator found = instance_map_.find(*iter); | 335 IDToInstance::iterator found = instance_map_.find(*iter); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 uint32 random_data[4]; | 415 uint32 random_data[4]; |
| 385 std::string id; | 416 std::string id; |
| 386 do { | 417 do { |
| 387 base::RandBytes(random_data, sizeof(random_data)); | 418 base::RandBytes(random_data, sizeof(random_data)); |
| 388 id = base::HexEncode(random_data, sizeof(random_data)); | 419 id = base::HexEncode(random_data, sizeof(random_data)); |
| 389 } while (instance_map_.find(id) != instance_map_.end()); | 420 } while (instance_map_.find(id) != instance_map_.end()); |
| 390 return id; | 421 return id; |
| 391 } | 422 } |
| 392 | 423 |
| 393 } // namespace fileapi | 424 } // namespace fileapi |
| OLD | NEW |