| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/browsing_data/browsing_data_quota_helper_impl.h" | 5 #include "chrome/browser/browsing_data/browsing_data_quota_helper_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 quota_manager_->SetPersistentHostQuota( | 51 quota_manager_->SetPersistentHostQuota( |
| 52 host, 0, | 52 host, 0, |
| 53 base::Bind(&BrowsingDataQuotaHelperImpl::DidRevokeHostQuota, | 53 base::Bind(&BrowsingDataQuotaHelperImpl::DidRevokeHostQuota, |
| 54 weak_factory_.GetWeakPtr())); | 54 weak_factory_.GetWeakPtr())); |
| 55 } | 55 } |
| 56 | 56 |
| 57 BrowsingDataQuotaHelperImpl::BrowsingDataQuotaHelperImpl( | 57 BrowsingDataQuotaHelperImpl::BrowsingDataQuotaHelperImpl( |
| 58 base::MessageLoopProxy* ui_thread, | 58 base::MessageLoopProxy* ui_thread, |
| 59 base::MessageLoopProxy* io_thread, | 59 base::MessageLoopProxy* io_thread, |
| 60 quota::QuotaManager* quota_manager) | 60 storage::QuotaManager* quota_manager) |
| 61 : BrowsingDataQuotaHelper(io_thread), | 61 : BrowsingDataQuotaHelper(io_thread), |
| 62 quota_manager_(quota_manager), | 62 quota_manager_(quota_manager), |
| 63 is_fetching_(false), | 63 is_fetching_(false), |
| 64 ui_thread_(ui_thread), | 64 ui_thread_(ui_thread), |
| 65 io_thread_(io_thread), | 65 io_thread_(io_thread), |
| 66 weak_factory_(this) { | 66 weak_factory_(this) { |
| 67 DCHECK(quota_manager); | 67 DCHECK(quota_manager); |
| 68 } | 68 } |
| 69 | 69 |
| 70 BrowsingDataQuotaHelperImpl::~BrowsingDataQuotaHelperImpl() {} | 70 BrowsingDataQuotaHelperImpl::~BrowsingDataQuotaHelperImpl() {} |
| 71 | 71 |
| 72 void BrowsingDataQuotaHelperImpl::FetchQuotaInfo() { | 72 void BrowsingDataQuotaHelperImpl::FetchQuotaInfo() { |
| 73 if (!io_thread_->BelongsToCurrentThread()) { | 73 if (!io_thread_->BelongsToCurrentThread()) { |
| 74 io_thread_->PostTask( | 74 io_thread_->PostTask( |
| 75 FROM_HERE, | 75 FROM_HERE, |
| 76 base::Bind(&BrowsingDataQuotaHelperImpl::FetchQuotaInfo, this)); | 76 base::Bind(&BrowsingDataQuotaHelperImpl::FetchQuotaInfo, this)); |
| 77 return; | 77 return; |
| 78 } | 78 } |
| 79 | 79 |
| 80 quota_manager_->GetOriginsModifiedSince( | 80 quota_manager_->GetOriginsModifiedSince( |
| 81 quota::kStorageTypeTemporary, | 81 storage::kStorageTypeTemporary, |
| 82 base::Time(), | 82 base::Time(), |
| 83 base::Bind(&BrowsingDataQuotaHelperImpl::GotOrigins, | 83 base::Bind(&BrowsingDataQuotaHelperImpl::GotOrigins, |
| 84 weak_factory_.GetWeakPtr())); | 84 weak_factory_.GetWeakPtr())); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void BrowsingDataQuotaHelperImpl::GotOrigins( | 87 void BrowsingDataQuotaHelperImpl::GotOrigins(const std::set<GURL>& origins, |
| 88 const std::set<GURL>& origins, quota::StorageType type) { | 88 storage::StorageType type) { |
| 89 for (std::set<GURL>::const_iterator itr = origins.begin(); | 89 for (std::set<GURL>::const_iterator itr = origins.begin(); |
| 90 itr != origins.end(); | 90 itr != origins.end(); |
| 91 ++itr) | 91 ++itr) |
| 92 if (BrowsingDataHelper::HasWebScheme(*itr)) | 92 if (BrowsingDataHelper::HasWebScheme(*itr)) |
| 93 pending_hosts_.insert(std::make_pair(itr->host(), type)); | 93 pending_hosts_.insert(std::make_pair(itr->host(), type)); |
| 94 | 94 |
| 95 DCHECK(type == quota::kStorageTypeTemporary || | 95 DCHECK(type == storage::kStorageTypeTemporary || |
| 96 type == quota::kStorageTypePersistent || | 96 type == storage::kStorageTypePersistent || |
| 97 type == quota::kStorageTypeSyncable); | 97 type == storage::kStorageTypeSyncable); |
| 98 | 98 |
| 99 // Calling GetOriginsModifiedSince() for all types by chaining callbacks. | 99 // Calling GetOriginsModifiedSince() for all types by chaining callbacks. |
| 100 if (type == quota::kStorageTypeTemporary) { | 100 if (type == storage::kStorageTypeTemporary) { |
| 101 quota_manager_->GetOriginsModifiedSince( | 101 quota_manager_->GetOriginsModifiedSince( |
| 102 quota::kStorageTypePersistent, | 102 storage::kStorageTypePersistent, |
| 103 base::Time(), | 103 base::Time(), |
| 104 base::Bind(&BrowsingDataQuotaHelperImpl::GotOrigins, | 104 base::Bind(&BrowsingDataQuotaHelperImpl::GotOrigins, |
| 105 weak_factory_.GetWeakPtr())); | 105 weak_factory_.GetWeakPtr())); |
| 106 } else if (type == quota::kStorageTypePersistent) { | 106 } else if (type == storage::kStorageTypePersistent) { |
| 107 quota_manager_->GetOriginsModifiedSince( | 107 quota_manager_->GetOriginsModifiedSince( |
| 108 quota::kStorageTypeSyncable, | 108 storage::kStorageTypeSyncable, |
| 109 base::Time(), | 109 base::Time(), |
| 110 base::Bind(&BrowsingDataQuotaHelperImpl::GotOrigins, | 110 base::Bind(&BrowsingDataQuotaHelperImpl::GotOrigins, |
| 111 weak_factory_.GetWeakPtr())); | 111 weak_factory_.GetWeakPtr())); |
| 112 } else { | 112 } else { |
| 113 DCHECK(type == quota::kStorageTypeSyncable); | 113 DCHECK(type == storage::kStorageTypeSyncable); |
| 114 ProcessPendingHosts(); | 114 ProcessPendingHosts(); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 void BrowsingDataQuotaHelperImpl::ProcessPendingHosts() { | 118 void BrowsingDataQuotaHelperImpl::ProcessPendingHosts() { |
| 119 if (pending_hosts_.empty()) { | 119 if (pending_hosts_.empty()) { |
| 120 OnComplete(); | 120 OnComplete(); |
| 121 return; | 121 return; |
| 122 } | 122 } |
| 123 | 123 |
| 124 PendingHosts::iterator itr = pending_hosts_.begin(); | 124 PendingHosts::iterator itr = pending_hosts_.begin(); |
| 125 std::string host = itr->first; | 125 std::string host = itr->first; |
| 126 quota::StorageType type = itr->second; | 126 storage::StorageType type = itr->second; |
| 127 pending_hosts_.erase(itr); | 127 pending_hosts_.erase(itr); |
| 128 GetHostUsage(host, type); | 128 GetHostUsage(host, type); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void BrowsingDataQuotaHelperImpl::GetHostUsage(const std::string& host, | 131 void BrowsingDataQuotaHelperImpl::GetHostUsage(const std::string& host, |
| 132 quota::StorageType type) { | 132 storage::StorageType type) { |
| 133 DCHECK(quota_manager_.get()); | 133 DCHECK(quota_manager_.get()); |
| 134 quota_manager_->GetHostUsage( | 134 quota_manager_->GetHostUsage( |
| 135 host, type, | 135 host, type, |
| 136 base::Bind(&BrowsingDataQuotaHelperImpl::GotHostUsage, | 136 base::Bind(&BrowsingDataQuotaHelperImpl::GotHostUsage, |
| 137 weak_factory_.GetWeakPtr(), host, type)); | 137 weak_factory_.GetWeakPtr(), host, type)); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void BrowsingDataQuotaHelperImpl::GotHostUsage(const std::string& host, | 140 void BrowsingDataQuotaHelperImpl::GotHostUsage(const std::string& host, |
| 141 quota::StorageType type, | 141 storage::StorageType type, |
| 142 int64 usage) { | 142 int64 usage) { |
| 143 switch (type) { | 143 switch (type) { |
| 144 case quota::kStorageTypeTemporary: | 144 case storage::kStorageTypeTemporary: |
| 145 quota_info_[host].temporary_usage = usage; | 145 quota_info_[host].temporary_usage = usage; |
| 146 break; | 146 break; |
| 147 case quota::kStorageTypePersistent: | 147 case storage::kStorageTypePersistent: |
| 148 quota_info_[host].persistent_usage = usage; | 148 quota_info_[host].persistent_usage = usage; |
| 149 break; | 149 break; |
| 150 case quota::kStorageTypeSyncable: | 150 case storage::kStorageTypeSyncable: |
| 151 quota_info_[host].syncable_usage = usage; | 151 quota_info_[host].syncable_usage = usage; |
| 152 break; | 152 break; |
| 153 default: | 153 default: |
| 154 NOTREACHED(); | 154 NOTREACHED(); |
| 155 } | 155 } |
| 156 ProcessPendingHosts(); | 156 ProcessPendingHosts(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void BrowsingDataQuotaHelperImpl::OnComplete() { | 159 void BrowsingDataQuotaHelperImpl::OnComplete() { |
| 160 if (!ui_thread_->BelongsToCurrentThread()) { | 160 if (!ui_thread_->BelongsToCurrentThread()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 180 | 180 |
| 181 info->host = itr->first; | 181 info->host = itr->first; |
| 182 result.push_back(*info); | 182 result.push_back(*info); |
| 183 } | 183 } |
| 184 | 184 |
| 185 callback_.Run(result); | 185 callback_.Run(result); |
| 186 callback_.Reset(); | 186 callback_.Reset(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void BrowsingDataQuotaHelperImpl::DidRevokeHostQuota( | 189 void BrowsingDataQuotaHelperImpl::DidRevokeHostQuota( |
| 190 quota::QuotaStatusCode status_unused, | 190 storage::QuotaStatusCode status_unused, |
| 191 int64 quota_unused) { | 191 int64 quota_unused) { |
| 192 } | 192 } |
| OLD | NEW |