| 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" |
| 11 #include "base/android/jni_array.h" | 11 #include "base/android/jni_array.h" |
| 12 #include "base/android/jni_string.h" | 12 #include "base/android/jni_string.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/storage_partition.h" | 15 #include "content/public/browser/storage_partition.h" |
| 16 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 17 #include "jni/AwQuotaManagerBridge_jni.h" | 17 #include "jni/AwQuotaManagerBridge_jni.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 #include "webkit/browser/quota/quota_manager.h" | 19 #include "webkit/browser/quota/quota_manager.h" |
| 20 #include "webkit/common/quota/quota_types.h" | 20 #include "webkit/common/quota/quota_types.h" |
| 21 | 21 |
| 22 using base::android::AttachCurrentThread; | 22 using base::android::AttachCurrentThread; |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 using content::StoragePartition; | 24 using content::StoragePartition; |
| 25 using quota::QuotaClient; | 25 using storage::QuotaClient; |
| 26 using quota::QuotaManager; | 26 using storage::QuotaManager; |
| 27 | 27 |
| 28 namespace android_webview { | 28 namespace android_webview { |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // This object lives on UI and IO threads. Care need to be taken to make sure | 32 // This object lives on UI and IO threads. Care need to be taken to make sure |
| 33 // there are no concurrent accesses to instance variables. Also this object | 33 // there are no concurrent accesses to instance variables. Also this object |
| 34 // is refcounted in the various callbacks, and is destroyed when all callbacks | 34 // is refcounted in the various callbacks, and is destroyed when all callbacks |
| 35 // are destroyed at the end of DoneOnUIThread. | 35 // are destroyed at the end of DoneOnUIThread. |
| 36 class GetOriginsTask : public base::RefCountedThreadSafe<GetOriginsTask> { | 36 class GetOriginsTask : public base::RefCountedThreadSafe<GetOriginsTask> { |
| 37 public: | 37 public: |
| 38 GetOriginsTask( | 38 GetOriginsTask( |
| 39 const AwQuotaManagerBridgeImpl::GetOriginsCallback& callback, | 39 const AwQuotaManagerBridgeImpl::GetOriginsCallback& callback, |
| 40 QuotaManager* quota_manager); | 40 QuotaManager* quota_manager); |
| 41 | 41 |
| 42 void Run(); | 42 void Run(); |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 friend class base::RefCountedThreadSafe<GetOriginsTask>; | 45 friend class base::RefCountedThreadSafe<GetOriginsTask>; |
| 46 ~GetOriginsTask(); | 46 ~GetOriginsTask(); |
| 47 | 47 |
| 48 void OnOriginsObtained(const std::set<GURL>& origins, | 48 void OnOriginsObtained(const std::set<GURL>& origins, |
| 49 quota::StorageType type); | 49 storage::StorageType type); |
| 50 | 50 |
| 51 void OnUsageAndQuotaObtained(const GURL& origin, | 51 void OnUsageAndQuotaObtained(const GURL& origin, |
| 52 quota::QuotaStatusCode status_code, | 52 storage::QuotaStatusCode status_code, |
| 53 int64 usage, | 53 int64 usage, |
| 54 int64 quota); | 54 int64 quota); |
| 55 | 55 |
| 56 void CheckDone(); | 56 void CheckDone(); |
| 57 void DoneOnUIThread(); | 57 void DoneOnUIThread(); |
| 58 | 58 |
| 59 AwQuotaManagerBridgeImpl::GetOriginsCallback ui_callback_; | 59 AwQuotaManagerBridgeImpl::GetOriginsCallback ui_callback_; |
| 60 scoped_refptr<QuotaManager> quota_manager_; | 60 scoped_refptr<QuotaManager> quota_manager_; |
| 61 | 61 |
| 62 std::vector<std::string> origin_; | 62 std::vector<std::string> origin_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 79 | 79 |
| 80 GetOriginsTask::~GetOriginsTask() {} | 80 GetOriginsTask::~GetOriginsTask() {} |
| 81 | 81 |
| 82 void GetOriginsTask::Run() { | 82 void GetOriginsTask::Run() { |
| 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 84 BrowserThread::PostTask( | 84 BrowserThread::PostTask( |
| 85 BrowserThread::IO, | 85 BrowserThread::IO, |
| 86 FROM_HERE, | 86 FROM_HERE, |
| 87 base::Bind(&QuotaManager::GetOriginsModifiedSince, | 87 base::Bind(&QuotaManager::GetOriginsModifiedSince, |
| 88 quota_manager_, | 88 quota_manager_, |
| 89 quota::kStorageTypeTemporary, | 89 storage::kStorageTypeTemporary, |
| 90 base::Time() /* Since beginning of time. */, | 90 base::Time() /* Since beginning of time. */, |
| 91 base::Bind(&GetOriginsTask::OnOriginsObtained, this))); | 91 base::Bind(&GetOriginsTask::OnOriginsObtained, this))); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void GetOriginsTask::OnOriginsObtained( | 94 void GetOriginsTask::OnOriginsObtained(const std::set<GURL>& origins, |
| 95 const std::set<GURL>& origins, quota::StorageType type) { | 95 storage::StorageType type) { |
| 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 97 num_callbacks_to_wait_ = origins.size(); | 97 num_callbacks_to_wait_ = origins.size(); |
| 98 num_callbacks_received_ = 0u; | 98 num_callbacks_received_ = 0u; |
| 99 | 99 |
| 100 for (std::set<GURL>::const_iterator origin = origins.begin(); | 100 for (std::set<GURL>::const_iterator origin = origins.begin(); |
| 101 origin != origins.end(); | 101 origin != origins.end(); |
| 102 ++origin) { | 102 ++origin) { |
| 103 quota_manager_->GetUsageAndQuota( | 103 quota_manager_->GetUsageAndQuota( |
| 104 *origin, | 104 *origin, |
| 105 type, | 105 type, |
| 106 base::Bind(&GetOriginsTask::OnUsageAndQuotaObtained, this, *origin)); | 106 base::Bind(&GetOriginsTask::OnUsageAndQuotaObtained, this, *origin)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 CheckDone(); | 109 CheckDone(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void GetOriginsTask::OnUsageAndQuotaObtained(const GURL& origin, | 112 void GetOriginsTask::OnUsageAndQuotaObtained( |
| 113 quota::QuotaStatusCode status_code, | 113 const GURL& origin, |
| 114 int64 usage, | 114 storage::QuotaStatusCode status_code, |
| 115 int64 quota) { | 115 int64 usage, |
| 116 int64 quota) { |
| 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 117 if (status_code == quota::kQuotaStatusOk) { | 118 if (status_code == storage::kQuotaStatusOk) { |
| 118 origin_.push_back(origin.spec()); | 119 origin_.push_back(origin.spec()); |
| 119 usage_.push_back(usage); | 120 usage_.push_back(usage); |
| 120 quota_.push_back(quota); | 121 quota_.push_back(quota); |
| 121 } | 122 } |
| 122 | 123 |
| 123 ++num_callbacks_received_; | 124 ++num_callbacks_received_; |
| 124 CheckDone(); | 125 CheckDone(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 void GetOriginsTask::CheckDone() { | 128 void GetOriginsTask::CheckDone() { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 jcallback_id, | 280 jcallback_id, |
| 280 base::android::ToJavaArrayOfStrings(env, origin).obj(), | 281 base::android::ToJavaArrayOfStrings(env, origin).obj(), |
| 281 base::android::ToJavaLongArray(env, usage).obj(), | 282 base::android::ToJavaLongArray(env, usage).obj(), |
| 282 base::android::ToJavaLongArray(env, quota).obj()); | 283 base::android::ToJavaLongArray(env, quota).obj()); |
| 283 } | 284 } |
| 284 | 285 |
| 285 namespace { | 286 namespace { |
| 286 | 287 |
| 287 void OnUsageAndQuotaObtained( | 288 void OnUsageAndQuotaObtained( |
| 288 const AwQuotaManagerBridgeImpl::QuotaUsageCallback& ui_callback, | 289 const AwQuotaManagerBridgeImpl::QuotaUsageCallback& ui_callback, |
| 289 quota::QuotaStatusCode status_code, | 290 storage::QuotaStatusCode status_code, |
| 290 int64 usage, | 291 int64 usage, |
| 291 int64 quota) { | 292 int64 quota) { |
| 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 293 if (status_code != quota::kQuotaStatusOk) { | 294 if (status_code != storage::kQuotaStatusOk) { |
| 294 usage = 0; | 295 usage = 0; |
| 295 quota = 0; | 296 quota = 0; |
| 296 } | 297 } |
| 297 BrowserThread::PostTask( | 298 BrowserThread::PostTask( |
| 298 BrowserThread::UI, | 299 BrowserThread::UI, |
| 299 FROM_HERE, | 300 FROM_HERE, |
| 300 base::Bind(ui_callback, usage, quota)); | 301 base::Bind(ui_callback, usage, quota)); |
| 301 } | 302 } |
| 302 | 303 |
| 303 } // namespace | 304 } // namespace |
| (...skipping 23 matching lines...) Expand all Loading... |
| 327 weak_factory_.GetWeakPtr(), | 328 weak_factory_.GetWeakPtr(), |
| 328 callback_id, | 329 callback_id, |
| 329 is_quota); | 330 is_quota); |
| 330 | 331 |
| 331 BrowserThread::PostTask( | 332 BrowserThread::PostTask( |
| 332 BrowserThread::IO, | 333 BrowserThread::IO, |
| 333 FROM_HERE, | 334 FROM_HERE, |
| 334 base::Bind(&QuotaManager::GetUsageAndQuota, | 335 base::Bind(&QuotaManager::GetUsageAndQuota, |
| 335 GetQuotaManager(), | 336 GetQuotaManager(), |
| 336 GURL(origin), | 337 GURL(origin), |
| 337 quota::kStorageTypeTemporary, | 338 storage::kStorageTypeTemporary, |
| 338 base::Bind(&OnUsageAndQuotaObtained, ui_callback))); | 339 base::Bind(&OnUsageAndQuotaObtained, ui_callback))); |
| 339 } | 340 } |
| 340 | 341 |
| 341 void AwQuotaManagerBridgeImpl::QuotaUsageCallbackImpl( | 342 void AwQuotaManagerBridgeImpl::QuotaUsageCallbackImpl( |
| 342 int jcallback_id, bool is_quota, int64 usage, int64 quota) { | 343 int jcallback_id, bool is_quota, int64 usage, int64 quota) { |
| 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 344 JNIEnv* env = AttachCurrentThread(); | 345 JNIEnv* env = AttachCurrentThread(); |
| 345 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 346 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 346 if (obj.is_null()) | 347 if (obj.is_null()) |
| 347 return; | 348 return; |
| 348 | 349 |
| 349 Java_AwQuotaManagerBridge_onGetUsageAndQuotaForOriginCallback( | 350 Java_AwQuotaManagerBridge_onGetUsageAndQuotaForOriginCallback( |
| 350 env, obj.obj(), jcallback_id, is_quota, usage, quota); | 351 env, obj.obj(), jcallback_id, is_quota, usage, quota); |
| 351 } | 352 } |
| 352 | 353 |
| 353 bool RegisterAwQuotaManagerBridge(JNIEnv* env) { | 354 bool RegisterAwQuotaManagerBridge(JNIEnv* env) { |
| 354 return RegisterNativesImpl(env); | 355 return RegisterNativesImpl(env); |
| 355 } | 356 } |
| 356 | 357 |
| 357 } // namespace android_webview | 358 } // namespace android_webview |
| OLD | NEW |