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 "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
18 #include "webkit/fileapi/file_system_operation_context.h" | 18 #include "webkit/fileapi/file_system_operation_context.h" |
19 #include "webkit/fileapi/file_system_path_manager.h" | 19 #include "webkit/fileapi/file_system_path_manager.h" |
20 #include "webkit/fileapi/file_system_types.h" | 20 #include "webkit/fileapi/file_system_types.h" |
21 #include "webkit/fileapi/file_system_usage_cache.h" | 21 #include "webkit/fileapi/file_system_usage_cache.h" |
22 #include "webkit/fileapi/file_system_util.h" | 22 #include "webkit/fileapi/file_system_util.h" |
23 #include "webkit/fileapi/local_file_system_file_util.h" | 23 #include "webkit/fileapi/local_file_system_file_util.h" |
24 #include "webkit/fileapi/obfuscated_file_system_file_util.h" | 24 #include "webkit/fileapi/obfuscated_file_system_file_util.h" |
25 #include "webkit/fileapi/quota_file_util.h" | 25 #include "webkit/fileapi/quota_file_util.h" |
26 #include "webkit/fileapi/sandbox_mount_point_provider.h" | |
27 #include "webkit/glue/webkit_glue.h" | 26 #include "webkit/glue/webkit_glue.h" |
28 #include "webkit/quota/quota_manager.h" | 27 #include "webkit/quota/quota_manager.h" |
29 | 28 |
30 using quota::QuotaManagerProxy; | 29 using quota::QuotaManagerProxy; |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
34 static const FilePath::CharType kOldFileSystemUniqueNamePrefix[] = | 33 static const FilePath::CharType kOldFileSystemUniqueNamePrefix[] = |
35 FILE_PATH_LITERAL("chrome-"); | 34 FILE_PATH_LITERAL("chrome-"); |
36 static const int kOldFileSystemUniqueLength = 16; | 35 static const int kOldFileSystemUniqueLength = 16; |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 538 |
540 FileSystemOperationContext context(NULL, sandbox_file_util_); | 539 FileSystemOperationContext context(NULL, sandbox_file_util_); |
541 context.set_src_origin_url(origin_url); | 540 context.set_src_origin_url(origin_url); |
542 context.set_src_type(type); | 541 context.set_src_type(type); |
543 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator( | 542 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator( |
544 sandbox_file_util_->CreateFileEnumerator(&context, FilePath())); | 543 sandbox_file_util_->CreateFileEnumerator(&context, FilePath())); |
545 | 544 |
546 FilePath file_path_each; | 545 FilePath file_path_each; |
547 int64 usage = 0; | 546 int64 usage = 0; |
548 | 547 |
549 // TODO(ericu): This could be made much more efficient if the | |
550 // AbstractFileEnumerator also had an interface to tell you the size of the | |
551 // file. ObfuscatedFileSystemFileEnumerator has already looked up the data, | |
552 // and it's a big waste to look it up again. The other implementers could | |
553 // easily add it on-demand, so as not to waste time when it's not needed. | |
554 while (!(file_path_each = enumerator->Next()).empty()) { | 548 while (!(file_path_each = enumerator->Next()).empty()) { |
555 base::PlatformFileInfo file_info; | 549 base::PlatformFileInfo file_info; |
556 FilePath platform_file_path; | 550 FilePath platform_file_path; |
557 if (!enumerator->IsDirectory()) { | 551 usage += enumerator->Size(); |
558 base::PlatformFileError error = sandbox_file_util_->GetFileInfo( | |
559 &context, file_path_each, &file_info, &platform_file_path); | |
560 if (error != base::PLATFORM_FILE_OK) | |
561 NOTREACHED(); | |
562 else | |
563 usage += file_info.size; | |
564 } | |
565 usage += ObfuscatedFileSystemFileUtil::ComputeFilePathCost(file_path_each); | 552 usage += ObfuscatedFileSystemFileUtil::ComputeFilePathCost(file_path_each); |
566 } | 553 } |
567 // This clears the dirty flag too. | 554 // This clears the dirty flag too. |
568 FileSystemUsageCache::UpdateUsage(usage_file_path, usage); | 555 FileSystemUsageCache::UpdateUsage(usage_file_path, usage); |
569 return usage; | 556 return usage; |
570 } | 557 } |
571 | 558 |
572 void SandboxMountPointProvider::NotifyOriginWasAccessedOnIOThread( | 559 void SandboxMountPointProvider::NotifyOriginWasAccessedOnIOThread( |
573 QuotaManagerProxy* proxy, const GURL& origin_url, | 560 QuotaManagerProxy* proxy, const GURL& origin_url, |
574 fileapi::FileSystemType type) { | 561 fileapi::FileSystemType type) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 | 638 |
652 // Creates the root directory. | 639 // Creates the root directory. |
653 root = origin_base_path.Append(OldCreateUniqueDirectoryName(origin_url)); | 640 root = origin_base_path.Append(OldCreateUniqueDirectoryName(origin_url)); |
654 if (!file_util::CreateDirectory(root)) | 641 if (!file_util::CreateDirectory(root)) |
655 return FilePath(); | 642 return FilePath(); |
656 | 643 |
657 return root; | 644 return root; |
658 } | 645 } |
659 | 646 |
660 } // namespace fileapi | 647 } // namespace fileapi |
OLD | NEW |