OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "android_webview/native/aw_quota_manager_bridge_impl.h" | 5 #include "android_webview/native/aw_quota_manager_bridge_impl.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "android_webview/browser/aw_browser_context.h" | 9 #include "android_webview/browser/aw_browser_context.h" |
10 #include "android_webview/browser/aw_content_browser_client.h" | 10 #include "android_webview/browser/aw_content_browser_client.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 173 } |
174 | 174 |
175 AwQuotaManagerBridgeImpl::AwQuotaManagerBridgeImpl( | 175 AwQuotaManagerBridgeImpl::AwQuotaManagerBridgeImpl( |
176 AwBrowserContext* browser_context) | 176 AwBrowserContext* browser_context) |
177 : browser_context_(browser_context), | 177 : browser_context_(browser_context), |
178 weak_factory_(this) { | 178 weak_factory_(this) { |
179 } | 179 } |
180 | 180 |
181 AwQuotaManagerBridgeImpl::~AwQuotaManagerBridgeImpl() {} | 181 AwQuotaManagerBridgeImpl::~AwQuotaManagerBridgeImpl() {} |
182 | 182 |
183 void AwQuotaManagerBridgeImpl::Init(JNIEnv* env, jobject object) { | 183 void AwQuotaManagerBridgeImpl::Init(JNIEnv* env, |
| 184 const JavaParamRef<jobject>& object) { |
184 java_ref_ = JavaObjectWeakGlobalRef(env, object); | 185 java_ref_ = JavaObjectWeakGlobalRef(env, object); |
185 } | 186 } |
186 | 187 |
187 StoragePartition* AwQuotaManagerBridgeImpl::GetStoragePartition() const { | 188 StoragePartition* AwQuotaManagerBridgeImpl::GetStoragePartition() const { |
188 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 189 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
189 | 190 |
190 // AndroidWebview does not use per-site storage partitions. | 191 // AndroidWebview does not use per-site storage partitions. |
191 StoragePartition* storage_partition = | 192 StoragePartition* storage_partition = |
192 content::BrowserContext::GetDefaultStoragePartition(browser_context_); | 193 content::BrowserContext::GetDefaultStoragePartition(browser_context_); |
193 DCHECK(storage_partition); | 194 DCHECK(storage_partition); |
194 return storage_partition; | 195 return storage_partition; |
195 } | 196 } |
196 | 197 |
197 QuotaManager* AwQuotaManagerBridgeImpl::GetQuotaManager() const { | 198 QuotaManager* AwQuotaManagerBridgeImpl::GetQuotaManager() const { |
198 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 199 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
199 | 200 |
200 QuotaManager* quota_manager = GetStoragePartition()->GetQuotaManager(); | 201 QuotaManager* quota_manager = GetStoragePartition()->GetQuotaManager(); |
201 DCHECK(quota_manager); | 202 DCHECK(quota_manager); |
202 return quota_manager; | 203 return quota_manager; |
203 } | 204 } |
204 | 205 |
205 void AwQuotaManagerBridgeImpl::DeleteAllData(JNIEnv* env, jobject object) { | 206 void AwQuotaManagerBridgeImpl::DeleteAllData( |
| 207 JNIEnv* env, |
| 208 const JavaParamRef<jobject>& object) { |
206 RunOnUIThread(base::Bind(&AwQuotaManagerBridgeImpl::DeleteAllDataOnUiThread, | 209 RunOnUIThread(base::Bind(&AwQuotaManagerBridgeImpl::DeleteAllDataOnUiThread, |
207 this)); | 210 this)); |
208 } | 211 } |
209 | 212 |
210 void AwQuotaManagerBridgeImpl::DeleteAllDataOnUiThread() { | 213 void AwQuotaManagerBridgeImpl::DeleteAllDataOnUiThread() { |
211 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 214 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
212 GetStoragePartition()->ClearData( | 215 GetStoragePartition()->ClearData( |
213 // Clear all web storage data except cookies. | 216 // Clear all web storage data except cookies. |
214 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | 217 StoragePartition::REMOVE_DATA_MASK_APPCACHE | |
215 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | 218 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | |
216 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | | 219 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | |
217 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE | | 220 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE | |
218 StoragePartition::REMOVE_DATA_MASK_WEBSQL, | 221 StoragePartition::REMOVE_DATA_MASK_WEBSQL, |
219 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY, | 222 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY, |
220 GURL(), StoragePartition::OriginMatcherFunction(), | 223 GURL(), StoragePartition::OriginMatcherFunction(), |
221 base::Time(), base::Time::Max(), base::Bind(&base::DoNothing)); | 224 base::Time(), base::Time::Max(), base::Bind(&base::DoNothing)); |
222 } | 225 } |
223 | 226 |
224 void AwQuotaManagerBridgeImpl::DeleteOrigin( | 227 void AwQuotaManagerBridgeImpl::DeleteOrigin( |
225 JNIEnv* env, jobject object, jstring origin) { | 228 JNIEnv* env, |
| 229 const JavaParamRef<jobject>& object, |
| 230 const JavaParamRef<jstring>& origin) { |
226 base::string16 origin_string( | 231 base::string16 origin_string( |
227 base::android::ConvertJavaStringToUTF16(env, origin)); | 232 base::android::ConvertJavaStringToUTF16(env, origin)); |
228 RunOnUIThread(base::Bind(&AwQuotaManagerBridgeImpl::DeleteOriginOnUiThread, | 233 RunOnUIThread(base::Bind(&AwQuotaManagerBridgeImpl::DeleteOriginOnUiThread, |
229 this, | 234 this, |
230 origin_string)); | 235 origin_string)); |
231 } | 236 } |
232 | 237 |
233 void AwQuotaManagerBridgeImpl::DeleteOriginOnUiThread( | 238 void AwQuotaManagerBridgeImpl::DeleteOriginOnUiThread( |
234 const base::string16& origin) { | 239 const base::string16& origin) { |
235 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 240 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
236 StoragePartition* storage_partition = GetStoragePartition(); | 241 StoragePartition* storage_partition = GetStoragePartition(); |
237 storage_partition->ClearDataForOrigin( | 242 storage_partition->ClearDataForOrigin( |
238 // All (temporary) QuotaClient types. | 243 // All (temporary) QuotaClient types. |
239 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | 244 StoragePartition::REMOVE_DATA_MASK_APPCACHE | |
240 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | 245 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | |
241 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | | 246 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | |
242 StoragePartition::REMOVE_DATA_MASK_WEBSQL, | 247 StoragePartition::REMOVE_DATA_MASK_WEBSQL, |
243 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY, | 248 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY, |
244 GURL(origin), | 249 GURL(origin), |
245 storage_partition->GetURLRequestContext(), | 250 storage_partition->GetURLRequestContext(), |
246 base::Bind(&base::DoNothing)); | 251 base::Bind(&base::DoNothing)); |
247 } | 252 } |
248 | 253 |
249 void AwQuotaManagerBridgeImpl::GetOrigins( | 254 void AwQuotaManagerBridgeImpl::GetOrigins(JNIEnv* env, |
250 JNIEnv* env, jobject object, jint callback_id) { | 255 const JavaParamRef<jobject>& object, |
| 256 jint callback_id) { |
251 RunOnUIThread(base::Bind(&AwQuotaManagerBridgeImpl::GetOriginsOnUiThread, | 257 RunOnUIThread(base::Bind(&AwQuotaManagerBridgeImpl::GetOriginsOnUiThread, |
252 this, | 258 this, |
253 callback_id)); | 259 callback_id)); |
254 } | 260 } |
255 | 261 |
256 void AwQuotaManagerBridgeImpl::GetOriginsOnUiThread(jint callback_id) { | 262 void AwQuotaManagerBridgeImpl::GetOriginsOnUiThread(jint callback_id) { |
257 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 263 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
258 | 264 |
259 const GetOriginsCallback ui_callback = base::Bind( | 265 const GetOriginsCallback ui_callback = base::Bind( |
260 &AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl, | 266 &AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 304 } |
299 BrowserThread::PostTask( | 305 BrowserThread::PostTask( |
300 BrowserThread::UI, | 306 BrowserThread::UI, |
301 FROM_HERE, | 307 FROM_HERE, |
302 base::Bind(ui_callback, usage, quota)); | 308 base::Bind(ui_callback, usage, quota)); |
303 } | 309 } |
304 | 310 |
305 } // namespace | 311 } // namespace |
306 | 312 |
307 void AwQuotaManagerBridgeImpl::GetUsageAndQuotaForOrigin( | 313 void AwQuotaManagerBridgeImpl::GetUsageAndQuotaForOrigin( |
308 JNIEnv* env, jobject object, | 314 JNIEnv* env, |
309 jstring origin, | 315 const JavaParamRef<jobject>& object, |
| 316 const JavaParamRef<jstring>& origin, |
310 jint callback_id, | 317 jint callback_id, |
311 bool is_quota) { | 318 bool is_quota) { |
312 base::string16 origin_string( | 319 base::string16 origin_string( |
313 base::android::ConvertJavaStringToUTF16(env, origin)); | 320 base::android::ConvertJavaStringToUTF16(env, origin)); |
314 RunOnUIThread(base::Bind( | 321 RunOnUIThread(base::Bind( |
315 &AwQuotaManagerBridgeImpl::GetUsageAndQuotaForOriginOnUiThread, | 322 &AwQuotaManagerBridgeImpl::GetUsageAndQuotaForOriginOnUiThread, |
316 this, | 323 this, |
317 origin_string, | 324 origin_string, |
318 callback_id, | 325 callback_id, |
319 is_quota)); | 326 is_quota)); |
(...skipping 30 matching lines...) Expand all Loading... |
350 | 357 |
351 Java_AwQuotaManagerBridge_onGetUsageAndQuotaForOriginCallback( | 358 Java_AwQuotaManagerBridge_onGetUsageAndQuotaForOriginCallback( |
352 env, obj.obj(), jcallback_id, is_quota, usage, quota); | 359 env, obj.obj(), jcallback_id, is_quota, usage, quota); |
353 } | 360 } |
354 | 361 |
355 bool RegisterAwQuotaManagerBridge(JNIEnv* env) { | 362 bool RegisterAwQuotaManagerBridge(JNIEnv* env) { |
356 return RegisterNativesImpl(env); | 363 return RegisterNativesImpl(env); |
357 } | 364 } |
358 | 365 |
359 } // namespace android_webview | 366 } // namespace android_webview |
OLD | NEW |