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

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: Couple of nits I noticed 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
kinuko 2013/01/21 06:57:33 nit: extra empty line
245 bool ExternalMountPoints::CanHandleURL(const FileSystemURL& url) const {
246 return url.is_valid() && url.type() == kFileSystemTypeExternal;
247 }
248
249 FileSystemURL ExternalMountPoints::CrackFileSystemURL(
250 const FileSystemURL& url) const {
251 if (!CanHandleURL(url))
252 return FileSystemURL();
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
263 FileSystemURL ExternalMountPoints::CrackURL(const GURL& url) const {
264 return CrackFileSystemURL(FileSystemURL(url));
265 }
266
267 FileSystemURL ExternalMountPoints::CreateCrackedFileSystemURL(
268 const GURL& origin,
269 FileSystemType type,
270 const FilePath& path) const {
271 return CrackFileSystemURL(FileSystemURL(origin, type, path));
272 }
273
243 bool ExternalMountPoints::GetVirtualPath(const FilePath& path_in, 274 bool ExternalMountPoints::GetVirtualPath(const FilePath& path_in,
244 FilePath* virtual_path) { 275 FilePath* virtual_path) {
245 DCHECK(virtual_path); 276 DCHECK(virtual_path);
246 277
247 base::AutoLock locker(lock_); 278 base::AutoLock locker(lock_);
248 279
249 FilePath path = NormalizeFilePath(path_in); 280 FilePath path = NormalizeFilePath(path_in);
250 std::map<FilePath, std::string>::reverse_iterator iter( 281 std::map<FilePath, std::string>::reverse_iterator iter(
251 path_to_name_map_.upper_bound(path)); 282 path_to_name_map_.upper_bound(path));
252 if (iter == path_to_name_map_.rend()) 283 if (iter == path_to_name_map_.rend())
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return ExternalMountPoints::GetSystemInstance()-> 353 return ExternalMountPoints::GetSystemInstance()->
323 CreateVirtualRootPath(mount_name_); 354 CreateVirtualRootPath(mount_name_);
324 } 355 }
325 356
326 ScopedExternalFileSystem::~ScopedExternalFileSystem() { 357 ScopedExternalFileSystem::~ScopedExternalFileSystem() {
327 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); 358 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_);
328 } 359 }
329 360
330 } // namespace fileapi 361 } // namespace fileapi
331 362
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698