Chromium Code Reviews

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

Issue 12717014: Launch packaged app with files on Drive on Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « webkit/fileapi/isolated_context.h ('k') | webkit/fileapi/mount_points.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 283 matching lines...)
294 for (; component_iter != components.end(); ++component_iter) 294 for (; component_iter != components.end(); ++component_iter)
295 cracked_path = cracked_path.Append(*component_iter); 295 cracked_path = cracked_path.Append(*component_iter);
296 *path = cracked_path; 296 *path = cracked_path;
297 return true; 297 return true;
298 } 298 }
299 299
300 FileSystemURL IsolatedContext::CrackURL(const GURL& url) const { 300 FileSystemURL IsolatedContext::CrackURL(const GURL& url) const {
301 FileSystemURL filesystem_url = FileSystemURL(url); 301 FileSystemURL filesystem_url = FileSystemURL(url);
302 if (!filesystem_url.is_valid()) 302 if (!filesystem_url.is_valid())
303 return FileSystemURL(); 303 return FileSystemURL();
304 return CreateCrackedFileSystemURL(filesystem_url.origin(), 304 return CrackFileSystemURL(filesystem_url);
305 filesystem_url.mount_type(),
306 filesystem_url.path());
307 } 305 }
308 306
309 FileSystemURL IsolatedContext::CreateCrackedFileSystemURL( 307 FileSystemURL IsolatedContext::CreateCrackedFileSystemURL(
310 const GURL& origin, 308 const GURL& origin,
311 FileSystemType type, 309 FileSystemType type,
312 const base::FilePath& path) const { 310 const base::FilePath& path) const {
313 if (!HandlesFileSystemMountType(type)) 311 return CrackFileSystemURL(FileSystemURL(origin, type, path));
314 return FileSystemURL();
315
316 std::string mount_name;
317 FileSystemType cracked_type;
318 base::FilePath cracked_path;
319 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path))
320 return FileSystemURL();
321
322 return FileSystemURL(origin, type, path,
323 mount_name, cracked_type, cracked_path);
324 } 312 }
325 313
326 void IsolatedContext::RevokeFileSystemByPath(const base::FilePath& path_in) { 314 void IsolatedContext::RevokeFileSystemByPath(const base::FilePath& path_in) {
327 base::AutoLock locker(lock_); 315 base::AutoLock locker(lock_);
328 base::FilePath path(path_in.NormalizePathSeparators()); 316 base::FilePath path(path_in.NormalizePathSeparators());
329 PathToID::iterator ids_iter = path_to_id_map_.find(path); 317 PathToID::iterator ids_iter = path_to_id_map_.find(path);
330 if (ids_iter == path_to_id_map_.end()) 318 if (ids_iter == path_to_id_map_.end())
331 return; 319 return;
332 std::set<std::string>& ids = ids_iter->second; 320 std::set<std::string>& ids = ids_iter->second;
333 for (std::set<std::string>::iterator iter = ids.begin(); 321 for (std::set<std::string>::iterator iter = ids.begin();
(...skipping 49 matching lines...)
383 } 371 }
384 372
385 IsolatedContext::IsolatedContext() { 373 IsolatedContext::IsolatedContext() {
386 } 374 }
387 375
388 IsolatedContext::~IsolatedContext() { 376 IsolatedContext::~IsolatedContext() {
389 STLDeleteContainerPairSecondPointers(instance_map_.begin(), 377 STLDeleteContainerPairSecondPointers(instance_map_.begin(),
390 instance_map_.end()); 378 instance_map_.end());
391 } 379 }
392 380
381 FileSystemURL IsolatedContext::CrackFileSystemURL(
382 const FileSystemURL& url) const {
383 if (!HandlesFileSystemMountType(url.type()))
384 return FileSystemURL();
385
386 std::string mount_name;
387 FileSystemType cracked_type;
388 base::FilePath cracked_path;
389 if (!CrackVirtualPath(url.path(), &mount_name, &cracked_type, &cracked_path))
390 return FileSystemURL();
391
392 return FileSystemURL(
393 url.origin(), url.mount_type(), url.virtual_path(),
394 !url.filesystem_id().empty() ? url.filesystem_id() : mount_name,
395 cracked_type, cracked_path, mount_name);
396 }
397
393 bool IsolatedContext::UnregisterFileSystem(const std::string& filesystem_id) { 398 bool IsolatedContext::UnregisterFileSystem(const std::string& filesystem_id) {
394 lock_.AssertAcquired(); 399 lock_.AssertAcquired();
395 IDToInstance::iterator found = instance_map_.find(filesystem_id); 400 IDToInstance::iterator found = instance_map_.find(filesystem_id);
396 if (found == instance_map_.end()) 401 if (found == instance_map_.end())
397 return false; 402 return false;
398 Instance* instance = found->second; 403 Instance* instance = found->second;
399 if (instance->IsSinglePathInstance()) { 404 if (instance->IsSinglePathInstance()) {
400 PathToID::iterator ids_iter = path_to_id_map_.find( 405 PathToID::iterator ids_iter = path_to_id_map_.find(
401 instance->file_info().path); 406 instance->file_info().path);
402 DCHECK(ids_iter != path_to_id_map_.end()); 407 DCHECK(ids_iter != path_to_id_map_.end());
(...skipping 12 matching lines...)
415 uint32 random_data[4]; 420 uint32 random_data[4];
416 std::string id; 421 std::string id;
417 do { 422 do {
418 base::RandBytes(random_data, sizeof(random_data)); 423 base::RandBytes(random_data, sizeof(random_data));
419 id = base::HexEncode(random_data, sizeof(random_data)); 424 id = base::HexEncode(random_data, sizeof(random_data));
420 } while (instance_map_.find(id) != instance_map_.end()); 425 } while (instance_map_.find(id) != instance_map_.end());
421 return id; 426 return id;
422 } 427 }
423 428
424 } // namespace fileapi 429 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/isolated_context.h ('k') | webkit/fileapi/mount_points.h » ('j') | no next file with comments »

Powered by Google App Engine