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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
228 bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) { | 229 bool IsolatedContext::RevokeFileSystem(const std::string& filesystem_id) { |
229 base::AutoLock locker(lock_); | 230 base::AutoLock locker(lock_); |
230 return UnregisterFileSystem(filesystem_id); | 231 return UnregisterFileSystem(filesystem_id); |
231 } | 232 } |
232 | 233 |
| 234 bool IsolatedContext::CanHandleURL(const FileSystemURL& url) const { |
| 235 return url.is_valid() && url.type() == kFileSystemTypeIsolated; |
| 236 } |
| 237 |
| 238 FileSystemURL IsolatedContext::CrackFileSystemURL( |
| 239 const FileSystemURL& url) const { |
| 240 if (!CanHandleURL(url)) |
| 241 return FileSystemURL(); |
| 242 |
| 243 std::string mount_name; |
| 244 FileSystemType type; |
| 245 FilePath path; |
| 246 if (!CrackVirtualPath(url.path(), &mount_name, &type, &path)) |
| 247 return FileSystemURL(); |
| 248 |
| 249 return FileSystemURL::CreateForCrackedURL(url, mount_name, type, path); |
| 250 } |
| 251 |
| 252 FileSystemURL IsolatedContext::CrackURL(const GURL& url) const { |
| 253 return CrackFileSystemURL(FileSystemURL(url)); |
| 254 } |
| 255 |
| 256 FileSystemURL IsolatedContext::CreateCrackedFileSystemURL( |
| 257 const GURL& origin, |
| 258 FileSystemType type, |
| 259 const FilePath& path) const { |
| 260 return CrackFileSystemURL(FileSystemURL(origin, type, path)); |
| 261 } |
| 262 |
233 bool IsolatedContext::GetRegisteredPath( | 263 bool IsolatedContext::GetRegisteredPath( |
234 const std::string& filesystem_id, FilePath* path) const { | 264 const std::string& filesystem_id, FilePath* path) const { |
235 DCHECK(path); | 265 DCHECK(path); |
236 base::AutoLock locker(lock_); | 266 base::AutoLock locker(lock_); |
237 IDToInstance::const_iterator found = instance_map_.find(filesystem_id); | 267 IDToInstance::const_iterator found = instance_map_.find(filesystem_id); |
238 if (found == instance_map_.end() || !found->second->IsSinglePathInstance()) | 268 if (found == instance_map_.end() || !found->second->IsSinglePathInstance()) |
239 return false; | 269 return false; |
240 *path = found->second->file_info().path; | 270 *path = found->second->file_info().path; |
241 return true; | 271 return true; |
242 } | 272 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 uint32 random_data[4]; | 414 uint32 random_data[4]; |
385 std::string id; | 415 std::string id; |
386 do { | 416 do { |
387 base::RandBytes(random_data, sizeof(random_data)); | 417 base::RandBytes(random_data, sizeof(random_data)); |
388 id = base::HexEncode(random_data, sizeof(random_data)); | 418 id = base::HexEncode(random_data, sizeof(random_data)); |
389 } while (instance_map_.find(id) != instance_map_.end()); | 419 } while (instance_map_.find(id) != instance_map_.end()); |
390 return id; | 420 return id; |
391 } | 421 } |
392 | 422 |
393 } // namespace fileapi | 423 } // namespace fileapi |
OLD | NEW |