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/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 "googleurl/src/gurl.h" |
10 #include "webkit/fileapi/file_system_path_manager.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste
m.h" |
| 11 #include "webkit/fileapi/file_system_file_util.h" |
| 12 #include "webkit/fileapi/file_system_options.h" |
| 13 #include "webkit/fileapi/file_system_quota_client.h" |
11 #include "webkit/fileapi/file_system_util.h" | 14 #include "webkit/fileapi/file_system_util.h" |
12 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 15 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
13 #include "webkit/fileapi/file_system_quota_client.h" | |
14 #include "webkit/quota/quota_manager.h" | 16 #include "webkit/quota/quota_manager.h" |
| 17 #include "webkit/quota/special_storage_policy.h" |
| 18 |
| 19 #if defined(OS_CHROMEOS) |
| 20 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
| 21 #endif |
15 | 22 |
16 using quota::QuotaClient; | 23 using quota::QuotaClient; |
17 | 24 |
18 namespace fileapi { | 25 namespace fileapi { |
19 | 26 |
20 namespace { | 27 namespace { |
| 28 |
21 QuotaClient* CreateQuotaClient( | 29 QuotaClient* CreateQuotaClient( |
22 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 30 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
23 FileSystemContext* context, | 31 FileSystemContext* context, |
24 bool is_incognito) { | 32 bool is_incognito) { |
25 return new FileSystemQuotaClient(file_message_loop, context, is_incognito); | 33 return new FileSystemQuotaClient(file_message_loop, context, is_incognito); |
26 } | 34 } |
| 35 |
27 } // anonymous namespace | 36 } // anonymous namespace |
28 | 37 |
29 FileSystemContext::FileSystemContext( | 38 FileSystemContext::FileSystemContext( |
30 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 39 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
31 scoped_refptr<base::MessageLoopProxy> io_message_loop, | 40 scoped_refptr<base::MessageLoopProxy> io_message_loop, |
32 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, | 41 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
33 quota::QuotaManagerProxy* quota_manager_proxy, | 42 quota::QuotaManagerProxy* quota_manager_proxy, |
34 const FilePath& profile_path, | 43 const FilePath& profile_path, |
35 bool is_incognito, | 44 const FileSystemOptions& options) |
36 bool allow_file_access_from_files, | |
37 FileSystemPathManager* path_manager) | |
38 : file_message_loop_(file_message_loop), | 45 : file_message_loop_(file_message_loop), |
39 io_message_loop_(io_message_loop), | 46 io_message_loop_(io_message_loop), |
40 quota_manager_proxy_(quota_manager_proxy), | 47 quota_manager_proxy_(quota_manager_proxy), |
41 path_manager_(path_manager) { | 48 sandbox_provider_( |
42 if (!path_manager) { | 49 new SandboxMountPointProvider( |
43 path_manager_.reset(new FileSystemPathManager( | 50 file_message_loop, |
44 file_message_loop, profile_path, special_storage_policy, | 51 profile_path, |
45 is_incognito, allow_file_access_from_files)); | 52 options)) { |
46 } | |
47 if (quota_manager_proxy) { | 53 if (quota_manager_proxy) { |
48 quota_manager_proxy->RegisterClient(CreateQuotaClient( | 54 quota_manager_proxy->RegisterClient(CreateQuotaClient( |
49 file_message_loop, this, is_incognito)); | 55 file_message_loop, this, options.is_incognito())); |
50 } | 56 } |
| 57 #if defined(OS_CHROMEOS) |
| 58 external_provider_.reset( |
| 59 new chromeos::CrosMountPointProvider(special_storage_policy)); |
| 60 #endif |
51 } | 61 } |
52 | 62 |
53 FileSystemContext::~FileSystemContext() { | 63 FileSystemContext::~FileSystemContext() { |
54 } | 64 } |
55 | 65 |
56 bool FileSystemContext::DeleteDataForOriginOnFileThread( | 66 bool FileSystemContext::DeleteDataForOriginOnFileThread( |
57 const GURL& origin_url) { | 67 const GURL& origin_url) { |
58 DCHECK(file_message_loop_->BelongsToCurrentThread()); | 68 DCHECK(file_message_loop_->BelongsToCurrentThread()); |
59 DCHECK(sandbox_provider()); | 69 DCHECK(sandbox_provider()); |
60 | 70 |
(...skipping 20 matching lines...) Expand all Loading... |
81 FileSystemQuotaUtil* | 91 FileSystemQuotaUtil* |
82 FileSystemContext::GetQuotaUtil(FileSystemType type) const { | 92 FileSystemContext::GetQuotaUtil(FileSystemType type) const { |
83 if (type == fileapi::kFileSystemTypeTemporary || | 93 if (type == fileapi::kFileSystemTypeTemporary || |
84 type == fileapi::kFileSystemTypePersistent) { | 94 type == fileapi::kFileSystemTypePersistent) { |
85 DCHECK(sandbox_provider()); | 95 DCHECK(sandbox_provider()); |
86 return sandbox_provider()->quota_util(); | 96 return sandbox_provider()->quota_util(); |
87 } | 97 } |
88 return NULL; | 98 return NULL; |
89 } | 99 } |
90 | 100 |
| 101 FileSystemFileUtil* FileSystemContext::GetFileUtil( |
| 102 FileSystemType type) const { |
| 103 FileSystemMountPointProvider* mount_point_provider = |
| 104 GetMountPointProvider(type); |
| 105 if (!mount_point_provider) |
| 106 return NULL; |
| 107 return mount_point_provider->GetFileUtil(); |
| 108 } |
| 109 |
| 110 FileSystemMountPointProvider* FileSystemContext::GetMountPointProvider( |
| 111 FileSystemType type) const { |
| 112 switch (type) { |
| 113 case kFileSystemTypeTemporary: |
| 114 case kFileSystemTypePersistent: |
| 115 return sandbox_provider_.get(); |
| 116 case kFileSystemTypeExternal: |
| 117 return external_provider_.get(); |
| 118 case kFileSystemTypeUnknown: |
| 119 default: |
| 120 NOTREACHED(); |
| 121 return NULL; |
| 122 } |
| 123 } |
| 124 |
| 125 SandboxMountPointProvider* |
| 126 FileSystemContext::sandbox_provider() const { |
| 127 return sandbox_provider_.get(); |
| 128 } |
| 129 |
| 130 ExternalFileSystemMountPointProvider* |
| 131 FileSystemContext::external_provider() const { |
| 132 return external_provider_.get(); |
| 133 } |
| 134 |
91 void FileSystemContext::DeleteOnCorrectThread() const { | 135 void FileSystemContext::DeleteOnCorrectThread() const { |
92 if (!io_message_loop_->BelongsToCurrentThread()) { | 136 if (!io_message_loop_->BelongsToCurrentThread()) { |
93 io_message_loop_->DeleteSoon(FROM_HERE, this); | 137 io_message_loop_->DeleteSoon(FROM_HERE, this); |
94 return; | 138 return; |
95 } | 139 } |
96 delete this; | 140 delete this; |
97 } | 141 } |
98 | 142 |
99 SandboxMountPointProvider* FileSystemContext::sandbox_provider() const { | 143 } // namespace fileapi |
100 return path_manager_->sandbox_provider(); | |
101 } | |
102 | 144 |
103 } // namespace fileapi | 145 COMPILE_ASSERT(int(WebKit::WebFileSystem::TypeTemporary) == \ |
| 146 int(fileapi::kFileSystemTypeTemporary), mismatching_enums); |
| 147 COMPILE_ASSERT(int(WebKit::WebFileSystem::TypePersistent) == \ |
| 148 int(fileapi::kFileSystemTypePersistent), mismatching_enums); |
| 149 COMPILE_ASSERT(int(WebKit::WebFileSystem::TypeExternal) == \ |
| 150 int(fileapi::kFileSystemTypeExternal), mismatching_enums); |
OLD | NEW |