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

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

Issue 12258021: Fix filesystem API file_handlers to work for drive on ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 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/files/file_path.h" 7 #include "base/files/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"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 std::string mount_name; 237 std::string mount_name;
238 FileSystemType cracked_type; 238 FileSystemType cracked_type;
239 base::FilePath cracked_path; 239 base::FilePath cracked_path;
240 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path)) 240 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path))
241 return FileSystemURL(); 241 return FileSystemURL();
242 242
243 return FileSystemURL(origin, type, path, 243 return FileSystemURL(origin, type, path,
244 mount_name, cracked_type, cracked_path); 244 mount_name, cracked_type, cracked_path);
245 } 245 }
246 246
247 RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy( 247 RemoteFileSystemProxyInterface*
248 const std::string& mount_name) const { 248 ExternalMountPoints::GetRemoteFileSystemProxyForPath(
249 const base::FilePath& full_path) const {
249 base::AutoLock locker(lock_); 250 base::AutoLock locker(lock_);
250 NameToInstance::const_iterator found = instance_map_.find(mount_name); 251
252 std::string mount_point;
253 if (!GetMountPointForPath(full_path, &mount_point, NULL))
254 return NULL;
255
256 // Get mount point instance.
257 NameToInstance::const_iterator found = instance_map_.find(mount_point);
251 if (found == instance_map_.end()) 258 if (found == instance_map_.end())
252 return NULL; 259 return NULL;
260
253 return found->second->remote_proxy(); 261 return found->second->remote_proxy();
254 } 262 }
255 263
256 void ExternalMountPoints::AddMountPointInfosTo( 264 void ExternalMountPoints::AddMountPointInfosTo(
257 std::vector<MountPointInfo>* mount_points) const { 265 std::vector<MountPointInfo>* mount_points) const {
258 base::AutoLock locker(lock_); 266 base::AutoLock locker(lock_);
259 DCHECK(mount_points); 267 DCHECK(mount_points);
260 for (NameToInstance::const_iterator iter = instance_map_.begin(); 268 for (NameToInstance::const_iterator iter = instance_map_.begin();
261 iter != instance_map_.end(); ++iter) { 269 iter != instance_map_.end(); ++iter) {
262 mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); 270 mount_points->push_back(MountPointInfo(iter->first, iter->second->path()));
263 } 271 }
264 } 272 }
265 273
266 bool ExternalMountPoints::GetVirtualPath(const base::FilePath& path_in, 274 bool ExternalMountPoints::GetVirtualPath(const base::FilePath& path,
267 base::FilePath* virtual_path) { 275 base::FilePath* virtual_path) {
268 DCHECK(virtual_path); 276 DCHECK(virtual_path);
269 277
270 base::AutoLock locker(lock_); 278 base::AutoLock locker(lock_);
271 279
272 base::FilePath path = NormalizeFilePath(path_in); 280 std::string mount_point_name;
273 std::map<base::FilePath, std::string>::reverse_iterator iter( 281 base::FilePath mount_point_root;
274 path_to_name_map_.upper_bound(path)); 282 if (!GetMountPointForPath(path, &mount_point_name, &mount_point_root))
275 if (iter == path_to_name_map_.rend())
276 return false; 283 return false;
277 284
278 *virtual_path = CreateVirtualRootPath(iter->second); 285 *virtual_path = CreateVirtualRootPath(mount_point_name);
279 if (iter->first == path) 286 if (mount_point_root == path)
280 return true; 287 return true;
281 return iter->first.AppendRelativePath(path, virtual_path); 288 return mount_point_root.AppendRelativePath(path, virtual_path);
282 } 289 }
283 290
284 base::FilePath ExternalMountPoints::CreateVirtualRootPath( 291 base::FilePath ExternalMountPoints::CreateVirtualRootPath(
285 const std::string& mount_name) const { 292 const std::string& mount_name) const {
286 return base::FilePath().AppendASCII(mount_name); 293 return base::FilePath().AppendASCII(mount_name);
287 } 294 }
288 295
289 ExternalMountPoints::ExternalMountPoints() {} 296 ExternalMountPoints::ExternalMountPoints() {}
290 297
291 ExternalMountPoints::~ExternalMountPoints() { 298 ExternalMountPoints::~ExternalMountPoints() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 332 }
326 333
327 std::map<base::FilePath, std::string>::iterator potential_child = 334 std::map<base::FilePath, std::string>::iterator potential_child =
328 path_to_name_map_.upper_bound(path); 335 path_to_name_map_.upper_bound(path);
329 if (potential_child == path_to_name_map_.end()) 336 if (potential_child == path_to_name_map_.end())
330 return true; 337 return true;
331 return !(potential_child->first == path) && 338 return !(potential_child->first == path) &&
332 !path.IsParent(potential_child->first); 339 !path.IsParent(potential_child->first);
333 } 340 }
334 341
342 bool ExternalMountPoints::GetMountPointForPath(
343 const base::FilePath& path,
344 std::string* mount_point_name,
345 base::FilePath* mount_point_root) const {
346 DCHECK(mount_point_name);
347
348 // Get mount point the path belongs to. It is the path whose value is smaller
349 // than normalized path, but also parents the normalized_path. Note that
350 // ExternalMountPoints are constrained so there cannot be a root path x for
351 // which the following holds: root_path(path) < x < path.
352 base::FilePath normalized_path = NormalizeFilePath(path);
353 std::map<base::FilePath, std::string>::const_reverse_iterator iter(
354 path_to_name_map_.upper_bound(normalized_path));
355 if (iter == path_to_name_map_.rend() ||
356 (iter->first != normalized_path &&
357 !iter->first.IsParent(normalized_path))) {
358 return false;
359 }
360
361 *mount_point_name = iter->second;
362 if (mount_point_root)
363 *mount_point_root = iter->first;
364 return true;
365 }
366
335 ScopedExternalFileSystem::ScopedExternalFileSystem( 367 ScopedExternalFileSystem::ScopedExternalFileSystem(
336 const std::string& mount_name, 368 const std::string& mount_name,
337 FileSystemType type, 369 FileSystemType type,
338 const base::FilePath& path) 370 const base::FilePath& path)
339 : mount_name_(mount_name) { 371 : mount_name_(mount_name) {
340 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( 372 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem(
341 mount_name, type, path); 373 mount_name, type, path);
342 } 374 }
343 375
344 base::FilePath ScopedExternalFileSystem::GetVirtualRootPath() const { 376 base::FilePath ScopedExternalFileSystem::GetVirtualRootPath() const {
345 return ExternalMountPoints::GetSystemInstance()-> 377 return ExternalMountPoints::GetSystemInstance()->
346 CreateVirtualRootPath(mount_name_); 378 CreateVirtualRootPath(mount_name_);
347 } 379 }
348 380
349 ScopedExternalFileSystem::~ScopedExternalFileSystem() { 381 ScopedExternalFileSystem::~ScopedExternalFileSystem() {
350 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); 382 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_);
351 } 383 }
352 384
353 } // namespace fileapi 385 } // namespace fileapi
354 386
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698