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

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: fix test on Win 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 FilePath path = NormalizeFilePath(path_in); 148 FilePath path = NormalizeFilePath(path_in);
148 if (!ValidateNewMountPoint(mount_name, path)) 149 if (!ValidateNewMountPoint(mount_name, path))
149 return false; 150 return false;
150 151
151 instance_map_[mount_name] = new Instance(type, path, remote_proxy); 152 instance_map_[mount_name] = new Instance(type, path, remote_proxy);
152 if (!path.empty()) 153 if (!path.empty())
153 path_to_name_map_.insert(std::make_pair(path, mount_name)); 154 path_to_name_map_.insert(std::make_pair(path, mount_name));
154 return true; 155 return true;
155 } 156 }
156 157
158 bool ExternalMountPoints::HandlesFileSystemMountType(
159 FileSystemType type) const {
160 return type == kFileSystemTypeExternal;
161 }
162
157 bool ExternalMountPoints::RevokeFileSystem(const std::string& mount_name) { 163 bool ExternalMountPoints::RevokeFileSystem(const std::string& mount_name) {
158 base::AutoLock locker(lock_); 164 base::AutoLock locker(lock_);
159 NameToInstance::iterator found = instance_map_.find(mount_name); 165 NameToInstance::iterator found = instance_map_.find(mount_name);
160 if (found == instance_map_.end()) 166 if (found == instance_map_.end())
161 return false; 167 return false;
162 Instance* instance = found->second; 168 Instance* instance = found->second;
163 path_to_name_map_.erase(NormalizeFilePath(instance->path())); 169 path_to_name_map_.erase(NormalizeFilePath(instance->path()));
164 delete found->second; 170 delete found->second;
165 instance_map_.erase(found); 171 instance_map_.erase(found);
166 return true; 172 return true;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 *type = instance->type(); 220 *type = instance->type();
215 cracked_path = instance->path(); 221 cracked_path = instance->path();
216 } 222 }
217 223
218 for (; component_iter != components.end(); ++component_iter) 224 for (; component_iter != components.end(); ++component_iter)
219 cracked_path = cracked_path.Append(*component_iter); 225 cracked_path = cracked_path.Append(*component_iter);
220 *path = cracked_path; 226 *path = cracked_path;
221 return true; 227 return true;
222 } 228 }
223 229
230 FileSystemURL ExternalMountPoints::CrackURL(const GURL& url) const {
231 FileSystemURL filesystem_url = FileSystemURL(url);
232 if (!filesystem_url.is_valid())
233 return FileSystemURL();
234 return CreateCrackedFileSystemURL(filesystem_url.origin(),
235 filesystem_url.mount_type(),
236 filesystem_url.path());
237 }
238
239 FileSystemURL ExternalMountPoints::CreateCrackedFileSystemURL(
240 const GURL& origin,
241 FileSystemType type,
242 const FilePath& path) const {
243 if (!HandlesFileSystemMountType(type))
244 return FileSystemURL();
245
246 std::string mount_name;
247 FileSystemType cracked_type;
248 FilePath cracked_path;
249 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path))
250 return FileSystemURL();
251
252 return FileSystemURL(origin, type, path,
253 mount_name, cracked_type, cracked_path);
254 }
255
224 RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy( 256 RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy(
225 const std::string& mount_name) const { 257 const std::string& mount_name) const {
226 base::AutoLock locker(lock_); 258 base::AutoLock locker(lock_);
227 NameToInstance::const_iterator found = instance_map_.find(mount_name); 259 NameToInstance::const_iterator found = instance_map_.find(mount_name);
228 if (found == instance_map_.end()) 260 if (found == instance_map_.end())
229 return NULL; 261 return NULL;
230 return found->second->remote_proxy(); 262 return found->second->remote_proxy();
231 } 263 }
232 264
233 void ExternalMountPoints::AddMountPointInfosTo( 265 void ExternalMountPoints::AddMountPointInfosTo(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 return ExternalMountPoints::GetSystemInstance()-> 354 return ExternalMountPoints::GetSystemInstance()->
323 CreateVirtualRootPath(mount_name_); 355 CreateVirtualRootPath(mount_name_);
324 } 356 }
325 357
326 ScopedExternalFileSystem::~ScopedExternalFileSystem() { 358 ScopedExternalFileSystem::~ScopedExternalFileSystem() {
327 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); 359 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_);
328 } 360 }
329 361
330 } // namespace fileapi 362 } // namespace fileapi
331 363
OLDNEW
« no previous file with comments | « webkit/fileapi/external_mount_points.h ('k') | webkit/fileapi/external_mount_points_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698