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" |
| (...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 QuotaManager* AwQuotaManagerBridgeImpl::GetQuotaManager() const { | 176 StoragePartition* AwQuotaManagerBridgeImpl::GetStoragePartition() const { |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 178 | 178 |
| 179 // AndroidWebview does not use per-site storage partitions. | 179 // AndroidWebview does not use per-site storage partitions. |
| 180 StoragePartition* storage_partition = | 180 StoragePartition* storage_partition = |
| 181 content::BrowserContext::GetStoragePartitionForSite( | 181 content::BrowserContext::GetStoragePartitionForSite( |
|
awong
2013/03/04 23:44:28
Please prefer BrowserContext::GetDefaultStoragePar
boliu
2013/03/05 00:00:00
Done.
| |
| 182 browser_context_, GURL()); | 182 browser_context_, GURL()); |
| 183 DCHECK(storage_partition); | 183 DCHECK(storage_partition); |
| 184 return storage_partition; | |
| 185 } | |
| 184 | 186 |
| 185 QuotaManager* quota_manager = storage_partition->GetQuotaManager(); | 187 QuotaManager* AwQuotaManagerBridgeImpl::GetQuotaManager() const { |
| 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 189 | |
| 190 QuotaManager* quota_manager = GetStoragePartition()->GetQuotaManager(); | |
| 186 DCHECK(quota_manager); | 191 DCHECK(quota_manager); |
| 187 return quota_manager; | 192 return quota_manager; |
| 188 } | 193 } |
| 189 | 194 |
| 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 | 195 // Cannot directly call StoragePartition clear data methods because cookies are |
| 212 // controlled separately. | 196 // controlled separately. |
| 213 // TODO(boliu): Should consider dedup delete code with StoragePartition. | |
| 214 void AwQuotaManagerBridgeImpl::DeleteAllData(JNIEnv* env, jobject object) { | 197 void AwQuotaManagerBridgeImpl::DeleteAllData(JNIEnv* env, jobject object) { |
| 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 216 scoped_refptr<QuotaManager> quota_manager = GetQuotaManager(); | 199 GetStoragePartition()->AsyncClearData( |
| 217 BrowserThread::PostTask( | 200 StoragePartition::kQuotaManagedTemporaryStorage | |
| 218 BrowserThread::IO, | 201 StoragePartition::kLocalDomStorage | |
| 219 FROM_HERE, | 202 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 } | 203 } |
| 229 | 204 |
| 230 void AwQuotaManagerBridgeImpl::DeleteOrigin( | 205 void AwQuotaManagerBridgeImpl::DeleteOrigin( |
| 231 JNIEnv* env, jobject object, jstring origin) { | 206 JNIEnv* env, jobject object, jstring origin) { |
| 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 233 BrowserThread::PostTask( | 208 StoragePartition* storage_partition = GetStoragePartition(); |
| 234 BrowserThread::IO, | 209 storage_partition->AsyncClearDataForOrigin( |
| 235 FROM_HERE, | 210 StoragePartition::kQuotaManagedTemporaryStorage, |
| 236 base::Bind(&QuotaManager::DeleteOriginData, | 211 GURL(base::android::ConvertJavaStringToUTF16(env, origin)), |
| 237 GetQuotaManager(), | 212 storage_partition->GetURLRequestContext()); |
| 238 GURL(base::android::ConvertJavaStringToUTF16(env, origin)), | |
| 239 quota::kStorageTypeTemporary, | |
| 240 QuotaClient::kAllClientsMask, | |
| 241 base::Bind(&IgnoreStatus))); | |
| 242 } | 213 } |
| 243 | 214 |
| 244 void AwQuotaManagerBridgeImpl::GetOrigins( | 215 void AwQuotaManagerBridgeImpl::GetOrigins( |
| 245 JNIEnv* env, jobject object, jint callback_id) { | 216 JNIEnv* env, jobject object, jint callback_id) { |
| 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 247 | 218 |
| 248 // TODO(boliu): Consider expanding QuotaManager::GetUsageInfo to include | |
| 249 // quota so can be used here. | |
| 250 | |
| 251 const GetOriginsCallback ui_callback = base::Bind( | 219 const GetOriginsCallback ui_callback = base::Bind( |
| 252 &AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl, | 220 &AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl, |
| 253 weak_factory_.GetWeakPtr(), | 221 weak_factory_.GetWeakPtr(), |
| 254 callback_id); | 222 callback_id); |
| 255 | 223 |
| 256 (new GetOriginsTask(ui_callback, GetQuotaManager()))->Run(); | 224 (new GetOriginsTask(ui_callback, GetQuotaManager()))->Run(); |
| 257 } | 225 } |
| 258 | 226 |
| 259 void AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl( | 227 void AwQuotaManagerBridgeImpl::GetOriginsCallbackImpl( |
| 260 int jcallback_id, | 228 int jcallback_id, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 | 296 |
| 329 Java_AwQuotaManagerBridge_onGetUsageAndQuotaForOriginCallback( | 297 Java_AwQuotaManagerBridge_onGetUsageAndQuotaForOriginCallback( |
| 330 env, obj.obj(), jcallback_id, is_quota, usage, quota); | 298 env, obj.obj(), jcallback_id, is_quota, usage, quota); |
| 331 } | 299 } |
| 332 | 300 |
| 333 bool RegisterAwQuotaManagerBridge(JNIEnv* env) { | 301 bool RegisterAwQuotaManagerBridge(JNIEnv* env) { |
| 334 return RegisterNativesImpl(env) >= 0; | 302 return RegisterNativesImpl(env) >= 0; |
| 335 } | 303 } |
| 336 | 304 |
| 337 } // namespace android_webview | 305 } // namespace android_webview |
| OLD | NEW |