OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/file_system_context.h" | 5 #include "webkit/fileapi/file_system_context.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "googleurl/src/gurl.h" |
9 #include "webkit/fileapi/file_system_path_manager.h" | 10 #include "webkit/fileapi/file_system_path_manager.h" |
10 #include "webkit/fileapi/file_system_quota_manager.h" | |
11 #include "webkit/fileapi/file_system_usage_tracker.h" | 11 #include "webkit/fileapi/file_system_usage_tracker.h" |
12 | 12 |
13 namespace fileapi { | 13 namespace fileapi { |
14 | 14 |
15 FileSystemContext::FileSystemContext( | 15 FileSystemContext::FileSystemContext( |
16 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 16 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
17 scoped_refptr<base::MessageLoopProxy> io_message_loop, | 17 scoped_refptr<base::MessageLoopProxy> io_message_loop, |
18 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 18 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
19 const FilePath& profile_path, | 19 const FilePath& profile_path, |
20 bool is_incognito, | 20 bool is_incognito, |
21 bool allow_file_access, | 21 bool allow_file_access, |
22 bool unlimited_quota) | 22 bool unlimited_quota) |
23 : file_message_loop_(file_message_loop), | 23 : file_message_loop_(file_message_loop), |
24 io_message_loop_(io_message_loop), | 24 io_message_loop_(io_message_loop), |
| 25 special_storage_policy_(special_storage_policy), |
| 26 allow_file_access_from_files_(allow_file_access), |
| 27 unlimited_quota_(unlimited_quota), |
25 path_manager_(new FileSystemPathManager( | 28 path_manager_(new FileSystemPathManager( |
26 file_message_loop, profile_path, is_incognito, allow_file_access)), | 29 file_message_loop, profile_path, is_incognito, allow_file_access)), |
27 quota_manager_(new FileSystemQuotaManager( | |
28 allow_file_access, unlimited_quota, special_storage_policy)), | |
29 usage_tracker_(new FileSystemUsageTracker( | 30 usage_tracker_(new FileSystemUsageTracker( |
30 file_message_loop, profile_path, is_incognito)) { | 31 file_message_loop, profile_path, is_incognito)) { |
31 } | 32 } |
32 | 33 |
33 FileSystemContext::~FileSystemContext() { | 34 FileSystemContext::~FileSystemContext() { |
34 } | 35 } |
35 | 36 |
| 37 bool FileSystemContext::IsStorageUnlimited(const GURL& origin) { |
| 38 // If allow-file-access-from-files flag is explicitly given and the scheme |
| 39 // is file, or if unlimited quota for this process was explicitly requested, |
| 40 // return true. |
| 41 return unlimited_quota_ || |
| 42 (allow_file_access_from_files_ && origin.SchemeIsFile()) || |
| 43 (special_storage_policy_.get() && |
| 44 special_storage_policy_->IsStorageUnlimited(origin)); |
| 45 } |
| 46 |
36 void FileSystemContext::DeleteDataForOriginOnFileThread( | 47 void FileSystemContext::DeleteDataForOriginOnFileThread( |
37 const GURL& origin_url) { | 48 const GURL& origin_url) { |
38 DCHECK(path_manager_.get()); | 49 DCHECK(path_manager_.get()); |
39 DCHECK(file_message_loop_->BelongsToCurrentThread()); | 50 DCHECK(file_message_loop_->BelongsToCurrentThread()); |
40 | 51 |
41 std::string origin_identifier = | 52 std::string origin_identifier = |
42 FileSystemPathManager::GetOriginIdentifierFromURL(origin_url); | 53 FileSystemPathManager::GetOriginIdentifierFromURL(origin_url); |
43 FilePath path_for_origin = path_manager_->base_path().AppendASCII( | 54 FilePath path_for_origin = path_manager_->base_path().AppendASCII( |
44 origin_identifier); | 55 origin_identifier); |
45 | 56 |
46 file_util::Delete(path_for_origin, true /* recursive */); | 57 file_util::Delete(path_for_origin, true /* recursive */); |
47 } | 58 } |
48 | 59 |
49 void FileSystemContext::DeleteOnCorrectThread() const { | 60 void FileSystemContext::DeleteOnCorrectThread() const { |
50 if (!io_message_loop_->BelongsToCurrentThread()) { | 61 if (!io_message_loop_->BelongsToCurrentThread()) { |
51 io_message_loop_->DeleteSoon(FROM_HERE, this); | 62 io_message_loop_->DeleteSoon(FROM_HERE, this); |
52 return; | 63 return; |
53 } | 64 } |
54 delete this; | 65 delete this; |
55 } | 66 } |
56 | 67 |
57 } // namespace fileapi | 68 } // namespace fileapi |
OLD | NEW |