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

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

Issue 11787028: New FileSystemURL cracking (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 11 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/external_mount_points.h" 5 #include "webkit/fileapi/external_mount_points.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "webkit/fileapi/file_system_url.h"
11 #include "webkit/fileapi/remote_file_system_proxy.h" 12 #include "webkit/fileapi/remote_file_system_proxy.h"
12 13
13 namespace { 14 namespace {
14 15
15 // Normalizes file path so it has normalized separators and ends with exactly 16 // Normalizes file path so it has normalized separators and ends with exactly
16 // one separator. Paths have to be normalized this way for use in 17 // one separator. Paths have to be normalized this way for use in
17 // GetVirtualPath method. Separators cannot be completely stripped, or 18 // GetVirtualPath method. Separators cannot be completely stripped, or
18 // GetVirtualPath could not working in some edge cases. 19 // GetVirtualPath could not working in some edge cases.
19 // For example, /a/b/c(1)/d would be erroneously resolved as c/d if the 20 // For example, /a/b/c(1)/d would be erroneously resolved as c/d if the
20 // following mount points were registered: "/a/b/c", "/a/b/c(1)". (Note: 21 // following mount points were registered: "/a/b/c", "/a/b/c(1)". (Note:
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 void ExternalMountPoints::AddMountPointInfosTo( 234 void ExternalMountPoints::AddMountPointInfosTo(
234 std::vector<MountPointInfo>* mount_points) const { 235 std::vector<MountPointInfo>* mount_points) const {
235 base::AutoLock locker(lock_); 236 base::AutoLock locker(lock_);
236 DCHECK(mount_points); 237 DCHECK(mount_points);
237 for (NameToInstance::const_iterator iter = instance_map_.begin(); 238 for (NameToInstance::const_iterator iter = instance_map_.begin();
238 iter != instance_map_.end(); ++iter) { 239 iter != instance_map_.end(); ++iter) {
239 mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); 240 mount_points->push_back(MountPointInfo(iter->first, iter->second->path()));
240 } 241 }
241 } 242 }
242 243
244 bool ExternalMountPoints::CanHandleURL(const FileSystemURL& url) const {
245 return url.is_valid() && url.type() == kFileSystemTypeExternal;
246 }
247
248 FileSystemURL ExternalMountPoints::CrackURL(const FileSystemURL& url) const {
249 if (!CanHandleURL(url))
250 return FileSystemURL();
251
252 DCHECK(!url.is_cracked());
253
254 std::string mount_name;
255 FileSystemType type;
256 FilePath path;
257 if (!CrackVirtualPath(url.path(), &mount_name, &type, &path))
258 return FileSystemURL();
259
260 return FileSystemURL::CreateForCrackedURL(url, mount_name, type, path);
261 }
262
243 bool ExternalMountPoints::GetVirtualPath(const FilePath& path_in, 263 bool ExternalMountPoints::GetVirtualPath(const FilePath& path_in,
244 FilePath* virtual_path) { 264 FilePath* virtual_path) {
245 DCHECK(virtual_path); 265 DCHECK(virtual_path);
246 266
247 base::AutoLock locker(lock_); 267 base::AutoLock locker(lock_);
248 268
249 FilePath path = NormalizeFilePath(path_in); 269 FilePath path = NormalizeFilePath(path_in);
250 std::map<FilePath, std::string>::reverse_iterator iter( 270 std::map<FilePath, std::string>::reverse_iterator iter(
251 path_to_name_map_.upper_bound(path)); 271 path_to_name_map_.upper_bound(path));
252 if (iter == path_to_name_map_.rend()) 272 if (iter == path_to_name_map_.rend())
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return ExternalMountPoints::GetSystemInstance()-> 342 return ExternalMountPoints::GetSystemInstance()->
323 CreateVirtualRootPath(mount_name_); 343 CreateVirtualRootPath(mount_name_);
324 } 344 }
325 345
326 ScopedExternalFileSystem::~ScopedExternalFileSystem() { 346 ScopedExternalFileSystem::~ScopedExternalFileSystem() {
327 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); 347 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_);
328 } 348 }
329 349
330 } // namespace fileapi 350 } // namespace fileapi
331 351
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698