Chromium Code Reviews| 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 "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/storage_partition.h" | 15 #include "content/public/browser/storage_partition.h" |
| 15 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 16 #include "jni/AwQuotaManagerBridge_jni.h" | 17 #include "jni/AwQuotaManagerBridge_jni.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 #include "webkit/browser/quota/quota_manager.h" | 19 #include "webkit/browser/quota/quota_manager.h" |
| 19 #include "webkit/common/quota/quota_types.h" | 20 #include "webkit/common/quota/quota_types.h" |
| 20 | 21 |
| 21 using base::android::AttachCurrentThread; | 22 using base::android::AttachCurrentThread; |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 NOTREACHED(); | 135 NOTREACHED(); |
| 135 } | 136 } |
| 136 } | 137 } |
| 137 | 138 |
| 138 // This method is to avoid copying the 3 vector arguments into a bound callback. | 139 // This method is to avoid copying the 3 vector arguments into a bound callback. |
| 139 void GetOriginsTask::DoneOnUIThread() { | 140 void GetOriginsTask::DoneOnUIThread() { |
| 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 141 ui_callback_.Run(origin_, usage_, quota_); | 142 ui_callback_.Run(origin_, usage_, quota_); |
| 142 } | 143 } |
| 143 | 144 |
| 145 void RunOnUIThread(const base::Closure& task) { | |
| 146 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 147 task.Run(); | |
| 148 } else { | |
| 149 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, task); | |
| 150 } | |
| 151 } | |
| 152 | |
| 144 } // namespace | 153 } // namespace |
| 145 | 154 |
| 146 | 155 |
| 147 // static | 156 // static |
| 148 jint GetDefaultNativeAwQuotaManagerBridge(JNIEnv* env, jclass clazz) { | 157 jint GetDefaultNativeAwQuotaManagerBridge(JNIEnv* env, jclass clazz) { |
| 149 AwBrowserContext* browser_context = | 158 AwBrowserContext* browser_context = |
| 150 AwContentBrowserClient::GetAwBrowserContext(); | 159 AwContentBrowserClient::GetAwBrowserContext(); |
| 151 | 160 |
| 152 AwQuotaManagerBridgeImpl* bridge = static_cast<AwQuotaManagerBridgeImpl*>( | 161 AwQuotaManagerBridgeImpl* bridge = static_cast<AwQuotaManagerBridgeImpl*>( |
| 153 browser_context->GetQuotaManagerBridge()); | 162 browser_context->GetQuotaManagerBridge()); |
| 154 DCHECK(bridge); | 163 DCHECK(bridge); |
| 155 return reinterpret_cast<jint>(bridge); | 164 return reinterpret_cast<jint>(bridge); |
| 156 } | 165 } |
| 157 | 166 |
| 167 // static | |
| 168 scoped_refptr<AwQuotaManagerBridge> AwQuotaManagerBridgeImpl::Create( | |
| 169 AwBrowserContext* browser_context) { | |
| 170 return new AwQuotaManagerBridgeImpl(browser_context); | |
| 171 } | |
| 172 | |
| 158 AwQuotaManagerBridgeImpl::AwQuotaManagerBridgeImpl( | 173 AwQuotaManagerBridgeImpl::AwQuotaManagerBridgeImpl( |
| 159 AwBrowserContext* browser_context) | 174 AwBrowserContext* browser_context) |
| 160 : weak_factory_(this), | 175 : weak_factory_(this), |
| 161 browser_context_(browser_context) { | 176 browser_context_(browser_context) { |
| 162 } | 177 } |
| 163 | 178 |
| 164 AwQuotaManagerBridgeImpl::~AwQuotaManagerBridgeImpl() {} | 179 AwQuotaManagerBridgeImpl::~AwQuotaManagerBridgeImpl() {} |
| 165 | 180 |
| 166 void AwQuotaManagerBridgeImpl::Init(JNIEnv* env, jobject object) { | 181 void AwQuotaManagerBridgeImpl::Init(JNIEnv* env, jobject object) { |
| 167 java_ref_ = JavaObjectWeakGlobalRef(env, object); | 182 java_ref_ = JavaObjectWeakGlobalRef(env, object); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 179 | 194 |
| 180 QuotaManager* AwQuotaManagerBridgeImpl::GetQuotaManager() const { | 195 QuotaManager* AwQuotaManagerBridgeImpl::GetQuotaManager() const { |
| 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 182 | 197 |
| 183 QuotaManager* quota_manager = GetStoragePartition()->GetQuotaManager(); | 198 QuotaManager* quota_manager = GetStoragePartition()->GetQuotaManager(); |
| 184 DCHECK(quota_manager); | 199 DCHECK(quota_manager); |
| 185 return quota_manager; | 200 return quota_manager; |
| 186 } | 201 } |
| 187 | 202 |
| 188 void AwQuotaManagerBridgeImpl::DeleteAllData(JNIEnv* env, jobject object) { | 203 void AwQuotaManagerBridgeImpl::DeleteAllData(JNIEnv* env, jobject object) { |
| 204 RunOnUIThread(base::Bind(&AwQuotaManagerBridgeImpl::DeleteAllDataOnUiThread, | |
| 205 this)); | |
| 206 } | |
| 207 | |
| 208 void AwQuotaManagerBridgeImpl::DeleteAllDataOnUiThread() { | |
| 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 190 GetStoragePartition()->ClearDataForUnboundedRange( | 210 GetStoragePartition()->ClearDataForUnboundedRange( |
| 191 // Clear all web storage data except cookies. | 211 // Clear all web storage data except cookies. |
| 192 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | 212 StoragePartition::REMOVE_DATA_MASK_APPCACHE | |
| 193 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | 213 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | |
| 194 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | | 214 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | |
| 195 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE | | 215 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE | |
| 196 StoragePartition::REMOVE_DATA_MASK_WEBSQL, | 216 StoragePartition::REMOVE_DATA_MASK_WEBSQL, |
| 197 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY); | 217 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY); |
| 198 } | 218 } |
| 199 | 219 |
| 200 void AwQuotaManagerBridgeImpl::DeleteOrigin( | 220 void AwQuotaManagerBridgeImpl::DeleteOrigin( |
| 201 JNIEnv* env, jobject object, jstring origin) { | 221 JNIEnv* env, jobject object, jstring origin) { |
| 222 base::string16 origin_string( | |
| 223 base::android::ConvertJavaStringToUTF16(env, origin)); | |
| 224 RunOnUIThread(base::Bind(&AwQuotaManagerBridgeImpl::DeleteOriginOnUiThread, | |
| 225 this, | |
| 226 origin_string)); | |
| 227 } | |
| 228 | |
| 229 void AwQuotaManagerBridgeImpl::DeleteOriginOnUiThread( | |
| 230 const base::string16& origin) { | |
| 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 203 StoragePartition* storage_partition = GetStoragePartition(); | 232 StoragePartition* storage_partition = GetStoragePartition(); |
| 204 storage_partition->ClearDataForOrigin( | 233 storage_partition->ClearDataForOrigin( |
| 205 // All (temporary) QuotaClient types. | 234 // All (temporary) QuotaClient types. |
| 206 StoragePartition::REMOVE_DATA_MASK_APPCACHE | | 235 StoragePartition::REMOVE_DATA_MASK_APPCACHE | |
| 207 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | | 236 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | |
| 208 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | | 237 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB | |
| 209 StoragePartition::REMOVE_DATA_MASK_WEBSQL, | 238 StoragePartition::REMOVE_DATA_MASK_WEBSQL, |
| 210 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY, | 239 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_TEMPORARY, |
| 211 GURL(base::android::ConvertJavaStringToUTF16(env, origin)), | 240 GURL(origin), |
| 212 storage_partition->GetURLRequestContext()); | 241 storage_partition->GetURLRequestContext()); |
| 213 } | 242 } |
| 214 | 243 |
| 215 void AwQuotaManagerBridgeImpl::GetOrigins( | 244 void AwQuotaManagerBridgeImpl::GetOrigins( |
| 216 JNIEnv* env, jobject object, jint callback_id) { | 245 JNIEnv* env, jobject object, jint callback_id) { |
| 246 RunOnUIThread(base::Bind(&AwQuotaManagerBridgeImpl::GetOriginsOnUiThread, | |
| 247 this, | |
| 248 callback_id)); | |
| 249 } | |
| 250 | |
| 251 void AwQuotaManagerBridgeImpl::GetOriginsOnUiThread(jint callback_id) { | |
| 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 218 | 253 |
| 219 const GetOriginsCallback ui_callback = base::Bind( | 254 const GetOriginsCallback ui_callback = base::Bind( |
| 220 &AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl, | 255 &AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl, |
| 221 weak_factory_.GetWeakPtr(), | 256 weak_factory_.GetWeakPtr(), |
| 222 callback_id); | 257 callback_id); |
| 223 | 258 |
| 224 (new GetOriginsTask(ui_callback, GetQuotaManager()))->Run(); | 259 (new GetOriginsTask(ui_callback, GetQuotaManager()))->Run(); |
| 225 } | 260 } |
| 226 | 261 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 base::Bind(ui_callback, usage, quota)); | 297 base::Bind(ui_callback, usage, quota)); |
| 263 } | 298 } |
| 264 | 299 |
| 265 } // namespace | 300 } // namespace |
| 266 | 301 |
| 267 void AwQuotaManagerBridgeImpl::GetUsageAndQuotaForOrigin( | 302 void AwQuotaManagerBridgeImpl::GetUsageAndQuotaForOrigin( |
| 268 JNIEnv* env, jobject object, | 303 JNIEnv* env, jobject object, |
| 269 jstring origin, | 304 jstring origin, |
| 270 jint callback_id, | 305 jint callback_id, |
| 271 bool is_quota) { | 306 bool is_quota) { |
| 307 base::string16 origin_string( | |
| 308 base::android::ConvertJavaStringToUTF16(env, origin)); | |
| 309 RunOnUIThread(base::Bind( | |
| 310 &AwQuotaManagerBridgeImpl::GetUsageAndQuotaForOriginOnUiThread, | |
| 311 this, | |
| 312 origin_string, | |
| 313 callback_id, | |
| 314 is_quota)); | |
| 315 } | |
| 316 | |
| 317 void AwQuotaManagerBridgeImpl::GetUsageAndQuotaForOriginOnUiThread( | |
| 318 const base::string16& origin, | |
| 319 jint callback_id, | |
| 320 bool is_quota) { | |
| 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 273 const QuotaUsageCallback ui_callback = base::Bind( | 322 const QuotaUsageCallback ui_callback = base::Bind( |
| 274 &AwQuotaManagerBridgeImpl::QuotaUsageCallbackImpl, | 323 &AwQuotaManagerBridgeImpl::QuotaUsageCallbackImpl, |
| 275 weak_factory_.GetWeakPtr(), | 324 weak_factory_.GetWeakPtr(), |
| 276 callback_id, | 325 callback_id, |
| 277 is_quota); | 326 is_quota); |
| 278 | 327 |
| 279 BrowserThread::PostTask( | 328 BrowserThread::PostTask( |
| 280 BrowserThread::IO, | 329 BrowserThread::IO, |
| 281 FROM_HERE, | 330 FROM_HERE, |
| 282 base::Bind(&QuotaManager::GetUsageAndQuota, | 331 base::Bind(&QuotaManager::GetUsageAndQuota, |
| 283 GetQuotaManager(), | 332 GetQuotaManager(), |
| 284 GURL(base::android::ConvertJavaStringToUTF16(env, origin)), | 333 GURL(), |
|
benm (inactive)
2013/10/08 11:30:11
origin?
Torne
2013/10/08 11:43:46
Oops, added.
| |
| 285 quota::kStorageTypeTemporary, | 334 quota::kStorageTypeTemporary, |
| 286 base::Bind(&OnUsageAndQuotaObtained, ui_callback))); | 335 base::Bind(&OnUsageAndQuotaObtained, ui_callback))); |
| 287 } | 336 } |
| 288 | 337 |
| 289 void AwQuotaManagerBridgeImpl::QuotaUsageCallbackImpl( | 338 void AwQuotaManagerBridgeImpl::QuotaUsageCallbackImpl( |
| 290 int jcallback_id, bool is_quota, int64 usage, int64 quota) { | 339 int jcallback_id, bool is_quota, int64 usage, int64 quota) { |
| 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 292 JNIEnv* env = AttachCurrentThread(); | 341 JNIEnv* env = AttachCurrentThread(); |
| 293 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 342 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 294 if (obj.is_null()) | 343 if (obj.is_null()) |
| 295 return; | 344 return; |
| 296 | 345 |
| 297 Java_AwQuotaManagerBridge_onGetUsageAndQuotaForOriginCallback( | 346 Java_AwQuotaManagerBridge_onGetUsageAndQuotaForOriginCallback( |
| 298 env, obj.obj(), jcallback_id, is_quota, usage, quota); | 347 env, obj.obj(), jcallback_id, is_quota, usage, quota); |
| 299 } | 348 } |
| 300 | 349 |
| 301 bool RegisterAwQuotaManagerBridge(JNIEnv* env) { | 350 bool RegisterAwQuotaManagerBridge(JNIEnv* env) { |
| 302 return RegisterNativesImpl(env) >= 0; | 351 return RegisterNativesImpl(env) >= 0; |
| 303 } | 352 } |
| 304 | 353 |
| 305 } // namespace android_webview | 354 } // namespace android_webview |
| OLD | NEW |