| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_quota_helper_impl.h" | 5 #include "chrome/browser/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/logging.h" | 11 #include "base/logging.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "webkit/quota/quota_manager.h" | 13 #include "webkit/quota/quota_manager.h" |
| 13 | 14 |
| 14 // static | 15 // static |
| 15 BrowsingDataQuotaHelper* BrowsingDataQuotaHelper::Create(Profile* profile) { | 16 BrowsingDataQuotaHelper* BrowsingDataQuotaHelper::Create(Profile* profile) { |
| 16 return new BrowsingDataQuotaHelperImpl( | 17 return new BrowsingDataQuotaHelperImpl( |
| 17 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 18 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
| 18 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 19 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 19 profile->GetQuotaManager()); | 20 profile->GetQuotaManager()); |
| 20 } | 21 } |
| 21 | 22 |
| 22 BrowsingDataQuotaHelperImpl::BrowsingDataQuotaHelperImpl( | 23 BrowsingDataQuotaHelperImpl::BrowsingDataQuotaHelperImpl( |
| 23 base::MessageLoopProxy* ui_thread, | 24 base::MessageLoopProxy* ui_thread, |
| 24 base::MessageLoopProxy* io_thread, | 25 base::MessageLoopProxy* io_thread, |
| 25 quota::QuotaManager* quota_manager) | 26 quota::QuotaManager* quota_manager) |
| 26 : BrowsingDataQuotaHelper(io_thread), | 27 : BrowsingDataQuotaHelper(io_thread), |
| 27 quota_manager_(quota_manager), | 28 quota_manager_(quota_manager), |
| 28 is_fetching_(false), | 29 is_fetching_(false), |
| 29 ui_thread_(ui_thread), | 30 ui_thread_(ui_thread), |
| 30 io_thread_(io_thread), | 31 io_thread_(io_thread), |
| 31 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 32 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 32 DCHECK(quota_manager); | 33 DCHECK(quota_manager); |
| 33 } | 34 } |
| 34 | 35 |
| 35 BrowsingDataQuotaHelperImpl::~BrowsingDataQuotaHelperImpl() {} | 36 BrowsingDataQuotaHelperImpl::~BrowsingDataQuotaHelperImpl() {} |
| 36 | 37 |
| 37 void BrowsingDataQuotaHelperImpl::StartFetching(FetchResultCallback* callback) { | 38 void BrowsingDataQuotaHelperImpl::StartFetching(FetchResultCallback* callback) { |
| 38 DCHECK(callback); | 39 DCHECK(callback); |
| 39 DCHECK(!callback_.get()); | 40 DCHECK(!callback_.get()); |
| 40 DCHECK(!is_fetching_); | 41 DCHECK(!is_fetching_); |
| 41 callback_.reset(callback); | 42 callback_.reset(callback); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 55 FROM_HERE, | 56 FROM_HERE, |
| 56 NewRunnableMethod( | 57 NewRunnableMethod( |
| 57 this, | 58 this, |
| 58 &BrowsingDataQuotaHelperImpl::FetchQuotaInfo)); | 59 &BrowsingDataQuotaHelperImpl::FetchQuotaInfo)); |
| 59 return; | 60 return; |
| 60 } | 61 } |
| 61 | 62 |
| 62 quota_manager_->GetOriginsModifiedSince( | 63 quota_manager_->GetOriginsModifiedSince( |
| 63 quota::kStorageTypeTemporary, | 64 quota::kStorageTypeTemporary, |
| 64 base::Time(), | 65 base::Time(), |
| 65 callback_factory_.NewCallback( | 66 base::Bind(&BrowsingDataQuotaHelperImpl::GotOrigins, |
| 66 &BrowsingDataQuotaHelperImpl::GotOrigins)); | 67 weak_factory_.GetWeakPtr())); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void BrowsingDataQuotaHelperImpl::GotOrigins( | 70 void BrowsingDataQuotaHelperImpl::GotOrigins( |
| 70 const std::set<GURL>& origins, quota::StorageType type) { | 71 const std::set<GURL>& origins, quota::StorageType type) { |
| 71 for (std::set<GURL>::const_iterator itr = origins.begin(); | 72 for (std::set<GURL>::const_iterator itr = origins.begin(); |
| 72 itr != origins.end(); | 73 itr != origins.end(); |
| 73 ++itr) | 74 ++itr) |
| 74 pending_hosts_.insert(std::make_pair(itr->host(), type)); | 75 pending_hosts_.insert(std::make_pair(itr->host(), type)); |
| 75 | 76 |
| 76 DCHECK(type == quota::kStorageTypeTemporary || | 77 DCHECK(type == quota::kStorageTypeTemporary || |
| 77 type == quota::kStorageTypePersistent); | 78 type == quota::kStorageTypePersistent); |
| 78 | 79 |
| 79 if (type == quota::kStorageTypeTemporary) { | 80 if (type == quota::kStorageTypeTemporary) { |
| 80 quota_manager_->GetOriginsModifiedSince( | 81 quota_manager_->GetOriginsModifiedSince( |
| 81 quota::kStorageTypePersistent, | 82 quota::kStorageTypePersistent, |
| 82 base::Time(), | 83 base::Time(), |
| 83 callback_factory_.NewCallback( | 84 base::Bind(&BrowsingDataQuotaHelperImpl::GotOrigins, |
| 84 &BrowsingDataQuotaHelperImpl::GotOrigins)); | 85 weak_factory_.GetWeakPtr())); |
| 85 } else { | 86 } else { |
| 86 // type == quota::kStorageTypePersistent | 87 // type == quota::kStorageTypePersistent |
| 87 ProcessPendingHosts(); | 88 ProcessPendingHosts(); |
| 88 } | 89 } |
| 89 } | 90 } |
| 90 | 91 |
| 91 void BrowsingDataQuotaHelperImpl::ProcessPendingHosts() { | 92 void BrowsingDataQuotaHelperImpl::ProcessPendingHosts() { |
| 92 if (pending_hosts_.empty()) { | 93 if (pending_hosts_.empty()) { |
| 93 OnComplete(); | 94 OnComplete(); |
| 94 return; | 95 return; |
| 95 } | 96 } |
| 96 | 97 |
| 97 PendingHosts::iterator itr = pending_hosts_.begin(); | 98 PendingHosts::iterator itr = pending_hosts_.begin(); |
| 98 std::string host = itr->first; | 99 std::string host = itr->first; |
| 99 quota::StorageType type = itr->second; | 100 quota::StorageType type = itr->second; |
| 100 pending_hosts_.erase(itr); | 101 pending_hosts_.erase(itr); |
| 101 GetHostUsage(host, type); | 102 GetHostUsage(host, type); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void BrowsingDataQuotaHelperImpl::GetHostUsage(const std::string& host, | 105 void BrowsingDataQuotaHelperImpl::GetHostUsage(const std::string& host, |
| 105 quota::StorageType type) { | 106 quota::StorageType type) { |
| 106 DCHECK(quota_manager_.get()); | 107 DCHECK(quota_manager_.get()); |
| 107 quota_manager_->GetHostUsage( | 108 quota_manager_->GetHostUsage( |
| 108 host, type, | 109 host, type, |
| 109 callback_factory_.NewCallback( | 110 base::Bind(&BrowsingDataQuotaHelperImpl::GotHostUsage, |
| 110 &BrowsingDataQuotaHelperImpl::GotHostUsage)); | 111 weak_factory_.GetWeakPtr())); |
| 111 } | 112 } |
| 112 | 113 |
| 113 void BrowsingDataQuotaHelperImpl::GotHostUsage(const std::string& host, | 114 void BrowsingDataQuotaHelperImpl::GotHostUsage(const std::string& host, |
| 114 quota::StorageType type, | 115 quota::StorageType type, |
| 115 int64 usage) { | 116 int64 usage) { |
| 116 switch (type) { | 117 switch (type) { |
| 117 case quota::kStorageTypeTemporary: | 118 case quota::kStorageTypeTemporary: |
| 118 quota_info_[host].temporary_usage = usage; | 119 quota_info_[host].temporary_usage = usage; |
| 119 break; | 120 break; |
| 120 case quota::kStorageTypePersistent: | 121 case quota::kStorageTypePersistent: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 info->persistent_usage <= 0) | 154 info->persistent_usage <= 0) |
| 154 continue; | 155 continue; |
| 155 | 156 |
| 156 info->host = itr->first; | 157 info->host = itr->first; |
| 157 result.push_back(*info); | 158 result.push_back(*info); |
| 158 } | 159 } |
| 159 | 160 |
| 160 callback_->Run(result); | 161 callback_->Run(result); |
| 161 callback_.reset(); | 162 callback_.reset(); |
| 162 } | 163 } |
| OLD | NEW |