| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sandbox_mount_point_provider.h" | 5 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_callback_factory.h" | 9 #include "base/memory/scoped_callback_factory.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/utf_string_conversions.h" | |
| 17 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 18 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" | |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | |
| 22 #include "webkit/fileapi/file_system_path_manager.h" | 18 #include "webkit/fileapi/file_system_path_manager.h" |
| 23 #include "webkit/fileapi/file_system_types.h" | 19 #include "webkit/fileapi/file_system_types.h" |
| 24 #include "webkit/fileapi/file_system_usage_cache.h" | 20 #include "webkit/fileapi/file_system_usage_cache.h" |
| 25 #include "webkit/fileapi/file_system_util.h" | 21 #include "webkit/fileapi/file_system_util.h" |
| 26 #include "webkit/fileapi/local_file_system_file_util.h" | 22 #include "webkit/fileapi/local_file_system_file_util.h" |
| 27 #include "webkit/fileapi/obfuscated_file_system_file_util.h" | 23 #include "webkit/fileapi/obfuscated_file_system_file_util.h" |
| 28 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 24 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 29 #include "webkit/glue/webkit_glue.h" | 25 #include "webkit/glue/webkit_glue.h" |
| 30 #include "webkit/quota/quota_manager.h" | 26 #include "webkit/quota/quota_manager.h" |
| 31 | 27 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 56 | 52 |
| 57 inline std::string FilePathStringToASCII( | 53 inline std::string FilePathStringToASCII( |
| 58 const FilePath::StringType& path_string) { | 54 const FilePath::StringType& path_string) { |
| 59 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| 60 return WideToASCII(path_string); | 56 return WideToASCII(path_string); |
| 61 #elif defined(OS_POSIX) | 57 #elif defined(OS_POSIX) |
| 62 return path_string; | 58 return path_string; |
| 63 #endif | 59 #endif |
| 64 } | 60 } |
| 65 | 61 |
| 66 // TODO(kinuko): Merge these two methods (conversion methods between | |
| 67 // origin url <==> identifier) with the ones in the database module. | |
| 68 std::string GetOriginIdentifierFromURL(const GURL& url) { | |
| 69 WebKit::WebSecurityOrigin web_security_origin = | |
| 70 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); | |
| 71 return web_security_origin.databaseIdentifier().utf8(); | |
| 72 } | |
| 73 | |
| 74 GURL GetOriginURLFromIdentifier(const std::string& origin_identifier) { | |
| 75 WebKit::WebSecurityOrigin web_security_origin = | |
| 76 WebKit::WebSecurityOrigin::createFromDatabaseIdentifier( | |
| 77 UTF8ToUTF16(origin_identifier)); | |
| 78 GURL origin_url(web_security_origin.toString()); | |
| 79 | |
| 80 // We need this work-around for file:/// URIs as | |
| 81 // createFromDatabaseIdentifier returns empty origin_url for them. | |
| 82 if (origin_url.spec().empty() && | |
| 83 origin_identifier.find("file__") == 0) | |
| 84 return GURL("file:///"); | |
| 85 return origin_url; | |
| 86 } | |
| 87 | |
| 88 FilePath::StringType CreateUniqueDirectoryName(const GURL& origin_url) { | 62 FilePath::StringType CreateUniqueDirectoryName(const GURL& origin_url) { |
| 89 // This can be anything but need to be unpredictable. | 63 // This can be anything but need to be unpredictable. |
| 90 static const FilePath::CharType letters[] = FILE_PATH_LITERAL( | 64 static const FilePath::CharType letters[] = FILE_PATH_LITERAL( |
| 91 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); | 65 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); |
| 92 FilePath::StringType unique(kFileSystemUniqueNamePrefix); | 66 FilePath::StringType unique(kFileSystemUniqueNamePrefix); |
| 93 for (int i = 0; i < kFileSystemUniqueLength; ++i) | 67 for (int i = 0; i < kFileSystemUniqueLength; ++i) |
| 94 unique += letters[base::RandInt(0, arraysize(letters) - 2)]; | 68 unique += letters[base::RandInt(0, arraysize(letters) - 2)]; |
| 95 return unique; | 69 return unique; |
| 96 } | 70 } |
| 97 | 71 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 return FilePath(); | 105 return FilePath(); |
| 132 | 106 |
| 133 // Creates the root directory. | 107 // Creates the root directory. |
| 134 root = origin_base_path.Append(CreateUniqueDirectoryName(origin_url)); | 108 root = origin_base_path.Append(CreateUniqueDirectoryName(origin_url)); |
| 135 if (!file_util::CreateDirectory(root)) | 109 if (!file_util::CreateDirectory(root)) |
| 136 return FilePath(); | 110 return FilePath(); |
| 137 | 111 |
| 138 return root; | 112 return root; |
| 139 } | 113 } |
| 140 | 114 |
| 115 class ObfuscatedOriginEnumerator |
| 116 : public fileapi::SandboxMountPointProvider::OriginEnumerator { |
| 117 public: |
| 118 explicit ObfuscatedOriginEnumerator( |
| 119 fileapi::ObfuscatedFileSystemFileUtil* file_util) { |
| 120 enum_.reset(file_util->CreateOriginEnumerator()); |
| 121 } |
| 122 virtual ~ObfuscatedOriginEnumerator() {} |
| 123 |
| 124 virtual GURL Next() OVERRIDE { |
| 125 return enum_->Next(); |
| 126 } |
| 127 |
| 128 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { |
| 129 return enum_->HasFileSystemType(type); |
| 130 } |
| 131 |
| 132 private: |
| 133 scoped_ptr<fileapi::ObfuscatedFileSystemFileUtil::AbstractOriginEnumerator> |
| 134 enum_; |
| 135 }; |
| 136 |
| 141 class SandboxOriginEnumerator | 137 class SandboxOriginEnumerator |
| 142 : public fileapi::SandboxMountPointProvider::OriginEnumerator { | 138 : public fileapi::SandboxMountPointProvider::OriginEnumerator { |
| 143 public: | 139 public: |
| 144 explicit SandboxOriginEnumerator(const FilePath& base_path) | 140 explicit SandboxOriginEnumerator(const FilePath& base_path) |
| 145 : enumerator_(base_path, false /* recursive */, | 141 : enumerator_(base_path, false /* recursive */, |
| 146 file_util::FileEnumerator::DIRECTORIES) {} | 142 file_util::FileEnumerator::DIRECTORIES) {} |
| 147 virtual ~SandboxOriginEnumerator() {} | 143 virtual ~SandboxOriginEnumerator() {} |
| 148 | 144 |
| 149 virtual GURL Next() OVERRIDE { | 145 virtual GURL Next() OVERRIDE { |
| 150 current_ = enumerator_.Next(); | 146 current_ = enumerator_.Next(); |
| 151 if (current_.empty()) | 147 if (current_.empty()) |
| 152 return GURL(); | 148 return GURL(); |
| 153 return GetOriginURLFromIdentifier( | 149 return fileapi::GetOriginURLFromIdentifier( |
| 154 FilePathStringToASCII(current_.BaseName().value())); | 150 FilePathStringToASCII(current_.BaseName().value())); |
| 155 } | 151 } |
| 156 | 152 |
| 157 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { | 153 virtual bool HasFileSystemType(fileapi::FileSystemType type) const OVERRIDE { |
| 158 if (current_.empty()) | 154 if (current_.empty()) |
| 159 return false; | 155 return false; |
| 160 std::string directory = | 156 std::string directory = |
| 161 fileapi::FileSystemPathManager::GetFileSystemTypeString(type); | 157 fileapi::FileSystemPathManager::GetFileSystemTypeString(type); |
| 162 DCHECK(!directory.empty()); | 158 DCHECK(!directory.empty()); |
| 163 return file_util::DirectoryExists(current_.AppendASCII(directory)); | 159 return file_util::DirectoryExists(current_.AppendASCII(directory)); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 254 |
| 259 scoped_refptr<base::MessageLoopProxy> file_message_loop_; | 255 scoped_refptr<base::MessageLoopProxy> file_message_loop_; |
| 260 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; | 256 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; |
| 261 GURL origin_url_; | 257 GURL origin_url_; |
| 262 FilePath origin_base_path_; | 258 FilePath origin_base_path_; |
| 263 FileSystemType type_; | 259 FileSystemType type_; |
| 264 scoped_refptr<ObfuscatedFileSystemFileUtil> file_util_; | 260 scoped_refptr<ObfuscatedFileSystemFileUtil> file_util_; |
| 265 scoped_ptr<FileSystemPathManager::GetRootPathCallback> callback_; | 261 scoped_ptr<FileSystemPathManager::GetRootPathCallback> callback_; |
| 266 }; | 262 }; |
| 267 | 263 |
| 268 FilePath SandboxMountPointProvider::GetFileSystemRootPathOnFileThread( | |
| 269 const GURL& origin_url, FileSystemType type, bool create) { | |
| 270 if (CommandLine::ForCurrentProcess()->HasSwitch(kObfuscationFlag)) | |
| 271 return sandbox_file_util_->GetDirectoryForOriginAndType( | |
| 272 origin_url, type, create); | |
| 273 | |
| 274 std::string name; | |
| 275 FilePath origin_base_path; | |
| 276 if (!GetOriginBasePathAndName(origin_url, &origin_base_path, type, &name)) | |
| 277 return FilePath(); | |
| 278 | |
| 279 return GetFileSystemRootPathOnFileThreadHelper( | |
| 280 origin_url, origin_base_path, create); | |
| 281 } | |
| 282 | |
| 283 bool SandboxMountPointProvider::IsRestrictedFileName(const FilePath& filename) | 264 bool SandboxMountPointProvider::IsRestrictedFileName(const FilePath& filename) |
| 284 const { | 265 const { |
| 285 if (filename.value().empty()) | 266 if (filename.value().empty()) |
| 286 return false; | 267 return false; |
| 287 | 268 |
| 288 if (IsWhitespace(filename.value()[filename.value().size() - 1]) || | 269 if (IsWhitespace(filename.value()[filename.value().size() - 1]) || |
| 289 filename.value()[filename.value().size() - 1] == '.') | 270 filename.value()[filename.value().size() - 1] == '.') |
| 290 return true; | 271 return true; |
| 291 | 272 |
| 292 std::string filename_lower = StringToLowerASCII( | 273 std::string filename_lower = StringToLowerASCII( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 313 std::vector<FilePath> SandboxMountPointProvider::GetRootDirectories() const { | 294 std::vector<FilePath> SandboxMountPointProvider::GetRootDirectories() const { |
| 314 NOTREACHED(); | 295 NOTREACHED(); |
| 315 // TODO(ericu): Implement this method and check for access permissions as | 296 // TODO(ericu): Implement this method and check for access permissions as |
| 316 // fileBrowserPrivate extension API does. We currently have another mechanism, | 297 // fileBrowserPrivate extension API does. We currently have another mechanism, |
| 317 // but we should switch over. | 298 // but we should switch over. |
| 318 return std::vector<FilePath>(); | 299 return std::vector<FilePath>(); |
| 319 } | 300 } |
| 320 | 301 |
| 321 SandboxMountPointProvider::OriginEnumerator* | 302 SandboxMountPointProvider::OriginEnumerator* |
| 322 SandboxMountPointProvider::CreateOriginEnumerator() const { | 303 SandboxMountPointProvider::CreateOriginEnumerator() const { |
| 304 if (CommandLine::ForCurrentProcess()->HasSwitch(kObfuscationFlag)) |
| 305 return new ObfuscatedOriginEnumerator(sandbox_file_util_.get()); |
| 323 return new SandboxOriginEnumerator(base_path_); | 306 return new SandboxOriginEnumerator(base_path_); |
| 324 } | 307 } |
| 325 | 308 |
| 326 void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( | 309 void SandboxMountPointProvider::ValidateFileSystemRootAndGetURL( |
| 327 const GURL& origin_url, fileapi::FileSystemType type, | 310 const GURL& origin_url, fileapi::FileSystemType type, |
| 328 bool create, FileSystemPathManager::GetRootPathCallback* callback_ptr) { | 311 bool create, FileSystemPathManager::GetRootPathCallback* callback_ptr) { |
| 329 scoped_ptr<FileSystemPathManager::GetRootPathCallback> callback(callback_ptr); | 312 scoped_ptr<FileSystemPathManager::GetRootPathCallback> callback(callback_ptr); |
| 330 ObfuscatedFileSystemFileUtil* file_util = NULL; | 313 ObfuscatedFileSystemFileUtil* file_util = NULL; |
| 331 FilePath origin_base_path; | 314 FilePath origin_base_path; |
| 315 |
| 316 if (path_manager_->is_incognito()) { |
| 317 // TODO(kinuko): return an isolated temporary directory. |
| 318 callback->Run(false, FilePath(), std::string()); |
| 319 return; |
| 320 } |
| 321 |
| 322 if (!path_manager_->IsAllowedScheme(origin_url)) { |
| 323 callback->Run(false, FilePath(), std::string()); |
| 324 return; |
| 325 } |
| 326 |
| 332 if (CommandLine::ForCurrentProcess()->HasSwitch(kObfuscationFlag)) { | 327 if (CommandLine::ForCurrentProcess()->HasSwitch(kObfuscationFlag)) { |
| 333 file_util = sandbox_file_util_.get(); | 328 file_util = sandbox_file_util_.get(); |
| 334 } else { | 329 } else { |
| 335 std::string name; | 330 std::string name; |
| 336 if (!GetOriginBasePathAndName(origin_url, &origin_base_path, type, &name)) { | 331 if (!GetOriginBasePathAndName(origin_url, &origin_base_path, type, &name)) { |
| 337 callback->Run(false, FilePath(), std::string()); | 332 callback->Run(false, FilePath(), std::string()); |
| 338 return; | 333 return; |
| 339 } | 334 } |
| 340 } | 335 } |
| 341 | 336 |
| 342 scoped_refptr<GetFileSystemRootPathTask> task( | 337 scoped_refptr<GetFileSystemRootPathTask> task( |
| 343 new GetFileSystemRootPathTask(file_message_loop_, | 338 new GetFileSystemRootPathTask(file_message_loop_, |
| 344 origin_url, | 339 origin_url, |
| 345 origin_base_path, | 340 origin_base_path, |
| 346 type, | 341 type, |
| 347 file_util, | 342 file_util, |
| 348 callback.release())); | 343 callback.release())); |
| 349 task->Start(create); | 344 task->Start(create); |
| 350 }; | 345 }; |
| 351 | 346 |
| 352 FilePath | 347 FilePath |
| 353 SandboxMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread( | 348 SandboxMountPointProvider::ValidateFileSystemRootAndGetPathOnFileThread( |
| 354 const GURL& origin_url, FileSystemType type, const FilePath& unused, | 349 const GURL& origin_url, FileSystemType type, const FilePath& unused, |
| 355 bool create) { | 350 bool create) { |
| 356 return GetFileSystemRootPathOnFileThread(origin_url, type, create); | 351 if (path_manager_->is_incognito()) |
| 352 // TODO(kinuko): return an isolated temporary directory. |
| 353 return FilePath(); |
| 354 |
| 355 if (!path_manager_->IsAllowedScheme(origin_url)) |
| 356 return FilePath(); |
| 357 |
| 358 if (CommandLine::ForCurrentProcess()->HasSwitch(kObfuscationFlag)) |
| 359 return sandbox_file_util_->GetDirectoryForOriginAndType( |
| 360 origin_url, type, create); |
| 361 |
| 362 std::string name; |
| 363 FilePath origin_base_path; |
| 364 if (!GetOriginBasePathAndName(origin_url, &origin_base_path, type, &name)) |
| 365 return FilePath(); |
| 366 |
| 367 return GetFileSystemRootPathOnFileThreadHelper( |
| 368 origin_url, origin_base_path, create); |
| 357 } | 369 } |
| 358 | 370 |
| 359 FilePath SandboxMountPointProvider::GetBaseDirectoryForOrigin( | 371 FilePath SandboxMountPointProvider::GetBaseDirectoryForOrigin( |
| 360 const GURL& origin_url) const { | 372 const GURL& origin_url, bool create) const { |
| 373 if (CommandLine::ForCurrentProcess()->HasSwitch(kObfuscationFlag)) |
| 374 return sandbox_file_util_->GetDirectoryForOrigin( |
| 375 origin_url, create); |
| 361 return base_path_.AppendASCII(GetOriginIdentifierFromURL(origin_url)); | 376 return base_path_.AppendASCII(GetOriginIdentifierFromURL(origin_url)); |
| 362 } | 377 } |
| 363 | 378 |
| 364 // Needed for the old way of doing things. | 379 // Needed for the old way of doing things. |
| 365 FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType( | 380 FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType( |
| 366 const GURL& origin_url, fileapi::FileSystemType type) const { | 381 const GURL& origin_url, fileapi::FileSystemType type, bool create) const { |
| 382 if (CommandLine::ForCurrentProcess()->HasSwitch(kObfuscationFlag)) |
| 383 return sandbox_file_util_->GetDirectoryForOriginAndType( |
| 384 origin_url, type, create); |
| 367 std::string type_string = | 385 std::string type_string = |
| 368 FileSystemPathManager::GetFileSystemTypeString(type); | 386 FileSystemPathManager::GetFileSystemTypeString(type); |
| 369 if (type_string.empty()) { | 387 if (type_string.empty()) { |
| 370 LOG(WARNING) << "Unknown filesystem type is requested:" << type; | 388 LOG(WARNING) << "Unknown filesystem type is requested:" << type; |
| 371 return FilePath(); | 389 return FilePath(); |
| 372 } | 390 } |
| 373 return GetBaseDirectoryForOrigin(origin_url).AppendASCII(type_string); | 391 return GetBaseDirectoryForOrigin(origin_url, create).AppendASCII(type_string); |
| 374 } | 392 } |
| 375 | 393 |
| 376 bool SandboxMountPointProvider::DeleteOriginDataOnFileThread( | 394 bool SandboxMountPointProvider::DeleteOriginDataOnFileThread( |
| 377 QuotaManagerProxy* proxy, const GURL& origin_url, | 395 QuotaManagerProxy* proxy, const GURL& origin_url, |
| 378 fileapi::FileSystemType type) { | 396 fileapi::FileSystemType type) { |
| 379 FilePath path_for_origin = GetBaseDirectoryForOriginAndType(origin_url, | 397 FilePath path_for_origin = |
| 380 type); | 398 GetBaseDirectoryForOriginAndType(origin_url, type, false); |
| 381 if (!file_util::PathExists(path_for_origin)) | 399 if (!file_util::PathExists(path_for_origin)) |
| 382 return true; | 400 return true; |
| 383 | 401 |
| 384 int64 usage = GetOriginUsageOnFileThread(origin_url, type); | 402 int64 usage = GetOriginUsageOnFileThread(origin_url, type); |
| 385 bool result = file_util::Delete(path_for_origin, true /* recursive */); | 403 bool result = file_util::Delete(path_for_origin, true /* recursive */); |
| 386 if (result && proxy) { | 404 if (result && proxy) { |
| 387 proxy->NotifyStorageModified( | 405 proxy->NotifyStorageModified( |
| 388 quota::QuotaClient::kFileSystem, | 406 quota::QuotaClient::kFileSystem, |
| 389 origin_url, | 407 origin_url, |
| 390 FileSystemTypeToQuotaStorageType(type), | 408 FileSystemTypeToQuotaStorageType(type), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 418 if (host == net::GetHostOrSpecFromURL(origin) && | 436 if (host == net::GetHostOrSpecFromURL(origin) && |
| 419 enumerator->HasFileSystemType(type)) | 437 enumerator->HasFileSystemType(type)) |
| 420 origins->insert(origin); | 438 origins->insert(origin); |
| 421 } | 439 } |
| 422 } | 440 } |
| 423 | 441 |
| 424 int64 SandboxMountPointProvider::GetOriginUsageOnFileThread( | 442 int64 SandboxMountPointProvider::GetOriginUsageOnFileThread( |
| 425 const GURL& origin_url, fileapi::FileSystemType type) { | 443 const GURL& origin_url, fileapi::FileSystemType type) { |
| 426 DCHECK(type == fileapi::kFileSystemTypeTemporary || | 444 DCHECK(type == fileapi::kFileSystemTypeTemporary || |
| 427 type == fileapi::kFileSystemTypePersistent); | 445 type == fileapi::kFileSystemTypePersistent); |
| 428 FilePath base_path = GetBaseDirectoryForOriginAndType(origin_url, type); | 446 FilePath base_path = |
| 447 GetBaseDirectoryForOriginAndType(origin_url, type, false); |
| 429 if (!file_util::DirectoryExists(base_path)) | 448 if (!file_util::DirectoryExists(base_path)) |
| 430 return 0; | 449 return 0; |
| 431 | 450 |
| 432 FilePath usage_file_path = base_path.AppendASCII( | 451 FilePath usage_file_path = base_path.AppendASCII( |
| 433 FileSystemUsageCache::kUsageFileName); | 452 FileSystemUsageCache::kUsageFileName); |
| 434 int32 dirty_status = FileSystemUsageCache::GetDirty(usage_file_path); | 453 int32 dirty_status = FileSystemUsageCache::GetDirty(usage_file_path); |
| 435 bool visited = (visited_origins_.find(origin_url) != visited_origins_.end()); | 454 bool visited = (visited_origins_.find(origin_url) != visited_origins_.end()); |
| 436 visited_origins_.insert(origin_url); | 455 visited_origins_.insert(origin_url); |
| 437 if (dirty_status == 0 || (dirty_status > 0 && visited)) { | 456 if (dirty_status == 0 || (dirty_status > 0 && visited)) { |
| 438 // The usage cache is clean (dirty == 0) or the origin is already | 457 // The usage cache is clean (dirty == 0) or the origin is already |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 return LocalFileSystemFileUtil::GetInstance(); | 524 return LocalFileSystemFileUtil::GetInstance(); |
| 506 } | 525 } |
| 507 | 526 |
| 508 // Needed for the old way of doing things. | 527 // Needed for the old way of doing things. |
| 509 bool SandboxMountPointProvider::GetOriginBasePathAndName( | 528 bool SandboxMountPointProvider::GetOriginBasePathAndName( |
| 510 const GURL& origin_url, | 529 const GURL& origin_url, |
| 511 FilePath* origin_base_path, | 530 FilePath* origin_base_path, |
| 512 FileSystemType type, | 531 FileSystemType type, |
| 513 std::string* name) { | 532 std::string* name) { |
| 514 | 533 |
| 515 // TODO(ericu): Put the incognito and allowed scheme checks somewhere in the | 534 *origin_base_path = GetBaseDirectoryForOriginAndType(origin_url, type, false); |
| 516 // obfuscated code as well. | |
| 517 if (path_manager_->is_incognito()) | |
| 518 // TODO(kinuko): return an isolated temporary directory. | |
| 519 return false; | |
| 520 | |
| 521 if (!path_manager_->IsAllowedScheme(origin_url)) | |
| 522 return false; | |
| 523 | |
| 524 *origin_base_path = GetBaseDirectoryForOriginAndType(origin_url, type); | |
| 525 if (origin_base_path->empty()) | 535 if (origin_base_path->empty()) |
| 526 return false; | 536 return false; |
| 527 | 537 |
| 528 std::string origin_identifier = GetOriginIdentifierFromURL(origin_url); | 538 std::string origin_identifier = GetOriginIdentifierFromURL(origin_url); |
| 529 std::string type_string = | 539 std::string type_string = |
| 530 FileSystemPathManager::GetFileSystemTypeString(type); | 540 FileSystemPathManager::GetFileSystemTypeString(type); |
| 531 DCHECK(!type_string.empty()); | 541 DCHECK(!type_string.empty()); |
| 532 if (name) | 542 if (name) |
| 533 *name = origin_identifier + ":" + type_string; | 543 *name = origin_identifier + ":" + type_string; |
| 534 return true; | 544 return true; |
| 535 } | 545 } |
| 536 | 546 |
| 537 FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( | 547 FilePath SandboxMountPointProvider::GetUsageCachePathForOriginAndType( |
| 538 const GURL& origin_url, fileapi::FileSystemType type) const { | 548 const GURL& origin_url, fileapi::FileSystemType type) const { |
| 539 FilePath base_path = GetBaseDirectoryForOriginAndType(origin_url, type); | 549 FilePath base_path = |
| 550 GetBaseDirectoryForOriginAndType(origin_url, type, false); |
| 540 return base_path.AppendASCII(FileSystemUsageCache::kUsageFileName); | 551 return base_path.AppendASCII(FileSystemUsageCache::kUsageFileName); |
| 541 } | 552 } |
| 542 | 553 |
| 543 } // namespace fileapi | 554 } // namespace fileapi |
| OLD | NEW |