OLD | NEW |
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/browser/fileapi/file_system_quota_client.h" | 5 #include "webkit/browser/fileapi/file_system_quota_client.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "webkit/browser/fileapi/file_system_usage_cache.h" | 23 #include "webkit/browser/fileapi/file_system_usage_cache.h" |
24 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" | 24 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" |
25 #include "webkit/common/fileapi/file_system_util.h" | 25 #include "webkit/common/fileapi/file_system_util.h" |
26 | 26 |
27 using quota::StorageType; | 27 using quota::StorageType; |
28 | 28 |
29 namespace fileapi { | 29 namespace fileapi { |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 void GetOriginsForTypeOnFileThread( | 33 void GetOriginsForTypeOnFileTaskRunner( |
34 FileSystemContext* context, | 34 FileSystemContext* context, |
35 StorageType storage_type, | 35 StorageType storage_type, |
36 std::set<GURL>* origins_ptr) { | 36 std::set<GURL>* origins_ptr) { |
37 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 37 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
38 DCHECK(type != kFileSystemTypeUnknown); | 38 DCHECK(type != kFileSystemTypeUnknown); |
39 | 39 |
40 FileSystemQuotaUtil* quota_util = context->GetQuotaUtil(type); | 40 FileSystemQuotaUtil* quota_util = context->GetQuotaUtil(type); |
41 if (!quota_util) | 41 if (!quota_util) |
42 return; | 42 return; |
43 quota_util->GetOriginsForTypeOnFileThread(type, origins_ptr); | 43 quota_util->GetOriginsForTypeOnFileTaskRunner(type, origins_ptr); |
44 } | 44 } |
45 | 45 |
46 void GetOriginsForHostOnFileThread( | 46 void GetOriginsForHostOnFileTaskRunner( |
47 FileSystemContext* context, | 47 FileSystemContext* context, |
48 StorageType storage_type, | 48 StorageType storage_type, |
49 const std::string& host, | 49 const std::string& host, |
50 std::set<GURL>* origins_ptr) { | 50 std::set<GURL>* origins_ptr) { |
51 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 51 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
52 DCHECK(type != kFileSystemTypeUnknown); | 52 DCHECK(type != kFileSystemTypeUnknown); |
53 | 53 |
54 FileSystemQuotaUtil* quota_util = context->GetQuotaUtil(type); | 54 FileSystemQuotaUtil* quota_util = context->GetQuotaUtil(type); |
55 if (!quota_util) | 55 if (!quota_util) |
56 return; | 56 return; |
57 quota_util->GetOriginsForHostOnFileThread(type, host, origins_ptr); | 57 quota_util->GetOriginsForHostOnFileTaskRunner(type, host, origins_ptr); |
58 } | 58 } |
59 | 59 |
60 void DidGetOrigins( | 60 void DidGetOrigins( |
61 const quota::QuotaClient::GetOriginsCallback& callback, | 61 const quota::QuotaClient::GetOriginsCallback& callback, |
62 std::set<GURL>* origins_ptr) { | 62 std::set<GURL>* origins_ptr) { |
63 callback.Run(*origins_ptr); | 63 callback.Run(*origins_ptr); |
64 } | 64 } |
65 | 65 |
66 quota::QuotaStatusCode DeleteOriginOnFileThread( | 66 quota::QuotaStatusCode DeleteOriginOnFileTaskRunner( |
67 FileSystemContext* context, | 67 FileSystemContext* context, |
68 const GURL& origin, | 68 const GURL& origin, |
69 FileSystemType type) { | 69 FileSystemType type) { |
70 FileSystemBackend* provider = context->GetFileSystemBackend(type); | 70 FileSystemBackend* provider = context->GetFileSystemBackend(type); |
71 if (!provider || !provider->GetQuotaUtil()) | 71 if (!provider || !provider->GetQuotaUtil()) |
72 return quota::kQuotaErrorNotSupported; | 72 return quota::kQuotaErrorNotSupported; |
73 base::PlatformFileError result = | 73 base::PlatformFileError result = |
74 provider->GetQuotaUtil()->DeleteOriginDataOnFileThread( | 74 provider->GetQuotaUtil()->DeleteOriginDataOnFileTaskRunner( |
75 context, context->quota_manager_proxy(), origin, type); | 75 context, context->quota_manager_proxy(), origin, type); |
76 if (result == base::PLATFORM_FILE_OK) | 76 if (result == base::PLATFORM_FILE_OK) |
77 return quota::kQuotaStatusOk; | 77 return quota::kQuotaStatusOk; |
78 return quota::kQuotaErrorInvalidModification; | 78 return quota::kQuotaErrorInvalidModification; |
79 } | 79 } |
80 | 80 |
81 } // namespace | 81 } // namespace |
82 | 82 |
83 FileSystemQuotaClient::FileSystemQuotaClient( | 83 FileSystemQuotaClient::FileSystemQuotaClient( |
84 FileSystemContext* file_system_context, | 84 FileSystemContext* file_system_context, |
(...skipping 30 matching lines...) Expand all Loading... |
115 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type); | 115 FileSystemQuotaUtil* quota_util = file_system_context_->GetQuotaUtil(type); |
116 if (!quota_util) { | 116 if (!quota_util) { |
117 callback.Run(0); | 117 callback.Run(0); |
118 return; | 118 return; |
119 } | 119 } |
120 | 120 |
121 base::PostTaskAndReplyWithResult( | 121 base::PostTaskAndReplyWithResult( |
122 file_task_runner(), | 122 file_task_runner(), |
123 FROM_HERE, | 123 FROM_HERE, |
124 // It is safe to pass Unretained(quota_util) since context owns it. | 124 // It is safe to pass Unretained(quota_util) since context owns it. |
125 base::Bind(&FileSystemQuotaUtil::GetOriginUsageOnFileThread, | 125 base::Bind(&FileSystemQuotaUtil::GetOriginUsageOnFileTaskRunner, |
126 base::Unretained(quota_util), | 126 base::Unretained(quota_util), |
127 file_system_context_, | 127 file_system_context_, |
128 origin_url, | 128 origin_url, |
129 type), | 129 type), |
130 callback); | 130 callback); |
131 } | 131 } |
132 | 132 |
133 void FileSystemQuotaClient::GetOriginsForType( | 133 void FileSystemQuotaClient::GetOriginsForType( |
134 StorageType storage_type, | 134 StorageType storage_type, |
135 const GetOriginsCallback& callback) { | 135 const GetOriginsCallback& callback) { |
136 DCHECK(!callback.is_null()); | 136 DCHECK(!callback.is_null()); |
137 | 137 |
138 if (is_incognito_) { | 138 if (is_incognito_) { |
139 // We don't support FileSystem in incognito mode yet. | 139 // We don't support FileSystem in incognito mode yet. |
140 std::set<GURL> origins; | 140 std::set<GURL> origins; |
141 callback.Run(origins); | 141 callback.Run(origins); |
142 return; | 142 return; |
143 } | 143 } |
144 | 144 |
145 std::set<GURL>* origins_ptr = new std::set<GURL>(); | 145 std::set<GURL>* origins_ptr = new std::set<GURL>(); |
146 file_task_runner()->PostTaskAndReply( | 146 file_task_runner()->PostTaskAndReply( |
147 FROM_HERE, | 147 FROM_HERE, |
148 base::Bind(&GetOriginsForTypeOnFileThread, | 148 base::Bind(&GetOriginsForTypeOnFileTaskRunner, |
149 file_system_context_, | 149 file_system_context_, |
150 storage_type, | 150 storage_type, |
151 base::Unretained(origins_ptr)), | 151 base::Unretained(origins_ptr)), |
152 base::Bind(&DidGetOrigins, | 152 base::Bind(&DidGetOrigins, |
153 callback, | 153 callback, |
154 base::Owned(origins_ptr))); | 154 base::Owned(origins_ptr))); |
155 } | 155 } |
156 | 156 |
157 void FileSystemQuotaClient::GetOriginsForHost( | 157 void FileSystemQuotaClient::GetOriginsForHost( |
158 StorageType storage_type, | 158 StorageType storage_type, |
159 const std::string& host, | 159 const std::string& host, |
160 const GetOriginsCallback& callback) { | 160 const GetOriginsCallback& callback) { |
161 DCHECK(!callback.is_null()); | 161 DCHECK(!callback.is_null()); |
162 | 162 |
163 if (is_incognito_) { | 163 if (is_incognito_) { |
164 // We don't support FileSystem in incognito mode yet. | 164 // We don't support FileSystem in incognito mode yet. |
165 std::set<GURL> origins; | 165 std::set<GURL> origins; |
166 callback.Run(origins); | 166 callback.Run(origins); |
167 return; | 167 return; |
168 } | 168 } |
169 | 169 |
170 std::set<GURL>* origins_ptr = new std::set<GURL>(); | 170 std::set<GURL>* origins_ptr = new std::set<GURL>(); |
171 file_task_runner()->PostTaskAndReply( | 171 file_task_runner()->PostTaskAndReply( |
172 FROM_HERE, | 172 FROM_HERE, |
173 base::Bind(&GetOriginsForHostOnFileThread, | 173 base::Bind(&GetOriginsForHostOnFileTaskRunner, |
174 file_system_context_, | 174 file_system_context_, |
175 storage_type, | 175 storage_type, |
176 host, | 176 host, |
177 base::Unretained(origins_ptr)), | 177 base::Unretained(origins_ptr)), |
178 base::Bind(&DidGetOrigins, | 178 base::Bind(&DidGetOrigins, |
179 callback, | 179 callback, |
180 base::Owned(origins_ptr))); | 180 base::Owned(origins_ptr))); |
181 } | 181 } |
182 | 182 |
183 void FileSystemQuotaClient::DeleteOriginData( | 183 void FileSystemQuotaClient::DeleteOriginData( |
184 const GURL& origin, | 184 const GURL& origin, |
185 StorageType type, | 185 StorageType type, |
186 const DeletionCallback& callback) { | 186 const DeletionCallback& callback) { |
187 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); | 187 FileSystemType fs_type = QuotaStorageTypeToFileSystemType(type); |
188 DCHECK(fs_type != kFileSystemTypeUnknown); | 188 DCHECK(fs_type != kFileSystemTypeUnknown); |
189 | 189 |
190 base::PostTaskAndReplyWithResult( | 190 base::PostTaskAndReplyWithResult( |
191 file_task_runner(), | 191 file_task_runner(), |
192 FROM_HERE, | 192 FROM_HERE, |
193 base::Bind(&DeleteOriginOnFileThread, | 193 base::Bind(&DeleteOriginOnFileTaskRunner, |
194 file_system_context_, | 194 file_system_context_, |
195 origin, | 195 origin, |
196 fs_type), | 196 fs_type), |
197 callback); | 197 callback); |
198 } | 198 } |
199 | 199 |
200 bool FileSystemQuotaClient::DoesSupport(quota::StorageType storage_type) const { | 200 bool FileSystemQuotaClient::DoesSupport(quota::StorageType storage_type) const { |
201 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); | 201 FileSystemType type = QuotaStorageTypeToFileSystemType(storage_type); |
202 DCHECK(type != kFileSystemTypeUnknown); | 202 DCHECK(type != kFileSystemTypeUnknown); |
203 return file_system_context_->IsSandboxFileSystem(type); | 203 return file_system_context_->IsSandboxFileSystem(type); |
204 } | 204 } |
205 | 205 |
206 base::SequencedTaskRunner* FileSystemQuotaClient::file_task_runner() const { | 206 base::SequencedTaskRunner* FileSystemQuotaClient::file_task_runner() const { |
207 return file_system_context_->default_file_task_runner(); | 207 return file_system_context_->default_file_task_runner(); |
208 } | 208 } |
209 | 209 |
210 } // namespace fileapi | 210 } // namespace fileapi |
OLD | NEW |