| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 166 : weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 167 browser_context_(browser_context) { | 167 browser_context_(browser_context) { |
| 168 } | 168 } |
| 169 | 169 |
| 170 AwQuotaManagerBridgeImpl::~AwQuotaManagerBridgeImpl() {} | 170 AwQuotaManagerBridgeImpl::~AwQuotaManagerBridgeImpl() {} |
| 171 | 171 |
| 172 void AwQuotaManagerBridgeImpl::Init(JNIEnv* env, jobject object) { | 172 void AwQuotaManagerBridgeImpl::Init(JNIEnv* env, jobject object) { |
| 173 java_ref_ = JavaObjectWeakGlobalRef(env, object); | 173 java_ref_ = JavaObjectWeakGlobalRef(env, object); |
| 174 } | 174 } |
| 175 | 175 |
| 176 StoragePartition* AwQuotaManagerBridgeImpl::GetStoragePartition() const { |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 178 |
| 179 // AndroidWebview does not use per-site storage partitions. |
| 180 StoragePartition* storage_partition = |
| 181 content::BrowserContext::GetDefaultStoragePartition(browser_context_); |
| 182 DCHECK(storage_partition); |
| 183 return storage_partition; |
| 184 } |
| 185 |
| 176 QuotaManager* AwQuotaManagerBridgeImpl::GetQuotaManager() const { | 186 QuotaManager* AwQuotaManagerBridgeImpl::GetQuotaManager() const { |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 178 | 188 |
| 179 // AndroidWebview does not use per-site storage partitions. | 189 QuotaManager* quota_manager = GetStoragePartition()->GetQuotaManager(); |
| 180 StoragePartition* storage_partition = | |
| 181 content::BrowserContext::GetStoragePartitionForSite( | |
| 182 browser_context_, GURL()); | |
| 183 DCHECK(storage_partition); | |
| 184 | |
| 185 QuotaManager* quota_manager = storage_partition->GetQuotaManager(); | |
| 186 DCHECK(quota_manager); | 190 DCHECK(quota_manager); |
| 187 return quota_manager; | 191 return quota_manager; |
| 188 } | 192 } |
| 189 | 193 |
| 190 namespace { | |
| 191 | |
| 192 void IgnoreStatus(quota::QuotaStatusCode status_code) {} | |
| 193 | |
| 194 void DeleteAllOriginData( | |
| 195 QuotaManager* quota_manager, | |
| 196 const std::set<GURL>& origins, | |
| 197 quota::StorageType type) { | |
| 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 199 for (std::set<GURL>::const_iterator origin = origins.begin(); | |
| 200 origin != origins.end(); | |
| 201 ++origin) { | |
| 202 quota_manager->DeleteOriginData(*origin, | |
| 203 type, | |
| 204 QuotaClient::kAllClientsMask, | |
| 205 base::Bind(&IgnoreStatus)); | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 } // namespace | |
| 210 | |
| 211 // Cannot directly call StoragePartition clear data methods because cookies are | 194 // Cannot directly call StoragePartition clear data methods because cookies are |
| 212 // controlled separately. | 195 // controlled separately. |
| 213 // TODO(boliu): Should consider dedup delete code with StoragePartition. | |
| 214 void AwQuotaManagerBridgeImpl::DeleteAllData(JNIEnv* env, jobject object) { | 196 void AwQuotaManagerBridgeImpl::DeleteAllData(JNIEnv* env, jobject object) { |
| 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 216 scoped_refptr<QuotaManager> quota_manager = GetQuotaManager(); | 198 GetStoragePartition()->AsyncClearData( |
| 217 BrowserThread::PostTask( | 199 StoragePartition::kQuotaManagedTemporaryStorage | |
| 218 BrowserThread::IO, | 200 StoragePartition::kLocalDomStorage | |
| 219 FROM_HERE, | 201 StoragePartition::kSessionDomStorage); |
| 220 base::Bind(&QuotaManager::GetOriginsModifiedSince, | |
| 221 quota_manager, | |
| 222 quota::kStorageTypeTemporary, | |
| 223 base::Time() /* Since beginning of time. */, | |
| 224 base::Bind(&DeleteAllOriginData, quota_manager))); | |
| 225 | |
| 226 // TODO(boliu): This needs to clear WebStorage (ie localStorage and | |
| 227 // sessionStorage). | |
| 228 } | 202 } |
| 229 | 203 |
| 230 void AwQuotaManagerBridgeImpl::DeleteOrigin( | 204 void AwQuotaManagerBridgeImpl::DeleteOrigin( |
| 231 JNIEnv* env, jobject object, jstring origin) { | 205 JNIEnv* env, jobject object, jstring origin) { |
| 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 233 BrowserThread::PostTask( | 207 StoragePartition* storage_partition = GetStoragePartition(); |
| 234 BrowserThread::IO, | 208 storage_partition->AsyncClearDataForOrigin( |
| 235 FROM_HERE, | 209 StoragePartition::kQuotaManagedTemporaryStorage, |
| 236 base::Bind(&QuotaManager::DeleteOriginData, | 210 GURL(base::android::ConvertJavaStringToUTF16(env, origin)), |
| 237 GetQuotaManager(), | 211 storage_partition->GetURLRequestContext()); |
| 238 GURL(base::android::ConvertJavaStringToUTF16(env, origin)), | |
| 239 quota::kStorageTypeTemporary, | |
| 240 QuotaClient::kAllClientsMask, | |
| 241 base::Bind(&IgnoreStatus))); | |
| 242 } | 212 } |
| 243 | 213 |
| 244 void AwQuotaManagerBridgeImpl::GetOrigins( | 214 void AwQuotaManagerBridgeImpl::GetOrigins( |
| 245 JNIEnv* env, jobject object, jint callback_id) { | 215 JNIEnv* env, jobject object, jint callback_id) { |
| 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 247 | 217 |
| 248 // TODO(boliu): Consider expanding QuotaManager::GetUsageInfo to include | |
| 249 // quota so can be used here. | |
| 250 | |
| 251 const GetOriginsCallback ui_callback = base::Bind( | 218 const GetOriginsCallback ui_callback = base::Bind( |
| 252 &AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl, | 219 &AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl, |
| 253 weak_factory_.GetWeakPtr(), | 220 weak_factory_.GetWeakPtr(), |
| 254 callback_id); | 221 callback_id); |
| 255 | 222 |
| 256 (new GetOriginsTask(ui_callback, GetQuotaManager()))->Run(); | 223 (new GetOriginsTask(ui_callback, GetQuotaManager()))->Run(); |
| 257 } | 224 } |
| 258 | 225 |
| 259 void AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl( | 226 void AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl( |
| 260 int jcallback_id, | 227 int jcallback_id, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 295 |
| 329 Java_AwQuotaManagerBridge_onGetUsageAndQuotaForOriginCallback( | 296 Java_AwQuotaManagerBridge_onGetUsageAndQuotaForOriginCallback( |
| 330 env, obj.obj(), jcallback_id, is_quota, usage, quota); | 297 env, obj.obj(), jcallback_id, is_quota, usage, quota); |
| 331 } | 298 } |
| 332 | 299 |
| 333 bool RegisterAwQuotaManagerBridge(JNIEnv* env) { | 300 bool RegisterAwQuotaManagerBridge(JNIEnv* env) { |
| 334 return RegisterNativesImpl(env) >= 0; | 301 return RegisterNativesImpl(env) >= 0; |
| 335 } | 302 } |
| 336 | 303 |
| 337 } // namespace android_webview | 304 } // namespace android_webview |
| OLD | NEW |