Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: chrome/browser/browsing_data_quota_helper_impl.cc

Issue 8070001: Use base::Callback in Quota related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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());
(...skipping 19 matching lines...) Expand all
39 io_thread_->PostTask( 40 io_thread_->PostTask(
40 FROM_HERE, 41 FROM_HERE,
41 NewRunnableMethod( 42 NewRunnableMethod(
42 this, 43 this,
43 &BrowsingDataQuotaHelperImpl::RevokeHostQuota, 44 &BrowsingDataQuotaHelperImpl::RevokeHostQuota,
44 host)); 45 host));
45 return; 46 return;
46 } 47 }
47 48
48 quota_manager_->SetPersistentHostQuota( 49 quota_manager_->SetPersistentHostQuota(
49 host, 0, callback_factory_.NewCallback( 50 host, 0,
50 &BrowsingDataQuotaHelperImpl::DidRevokeHostQuota)); 51 base::Bind(&BrowsingDataQuotaHelperImpl::DidRevokeHostQuota,
52 weak_factory_.GetWeakPtr()));
51 } 53 }
52 54
53 BrowsingDataQuotaHelperImpl::BrowsingDataQuotaHelperImpl( 55 BrowsingDataQuotaHelperImpl::BrowsingDataQuotaHelperImpl(
54 base::MessageLoopProxy* ui_thread, 56 base::MessageLoopProxy* ui_thread,
55 base::MessageLoopProxy* io_thread, 57 base::MessageLoopProxy* io_thread,
56 quota::QuotaManager* quota_manager) 58 quota::QuotaManager* quota_manager)
57 : BrowsingDataQuotaHelper(io_thread), 59 : BrowsingDataQuotaHelper(io_thread),
58 quota_manager_(quota_manager), 60 quota_manager_(quota_manager),
59 is_fetching_(false), 61 is_fetching_(false),
60 ui_thread_(ui_thread), 62 ui_thread_(ui_thread),
61 io_thread_(io_thread), 63 io_thread_(io_thread),
62 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 64 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
63 DCHECK(quota_manager); 65 DCHECK(quota_manager);
64 } 66 }
65 67
66 BrowsingDataQuotaHelperImpl::~BrowsingDataQuotaHelperImpl() {} 68 BrowsingDataQuotaHelperImpl::~BrowsingDataQuotaHelperImpl() {}
67 69
68 void BrowsingDataQuotaHelperImpl::FetchQuotaInfo() { 70 void BrowsingDataQuotaHelperImpl::FetchQuotaInfo() {
69 if (!io_thread_->BelongsToCurrentThread()) { 71 if (!io_thread_->BelongsToCurrentThread()) {
70 io_thread_->PostTask( 72 io_thread_->PostTask(
71 FROM_HERE, 73 FROM_HERE,
72 NewRunnableMethod( 74 NewRunnableMethod(
73 this, 75 this,
74 &BrowsingDataQuotaHelperImpl::FetchQuotaInfo)); 76 &BrowsingDataQuotaHelperImpl::FetchQuotaInfo));
75 return; 77 return;
76 } 78 }
77 79
78 quota_manager_->GetOriginsModifiedSince( 80 quota_manager_->GetOriginsModifiedSince(
79 quota::kStorageTypeTemporary, 81 quota::kStorageTypeTemporary,
80 base::Time(), 82 base::Time(),
81 callback_factory_.NewCallback( 83 base::Bind(&BrowsingDataQuotaHelperImpl::GotOrigins,
82 &BrowsingDataQuotaHelperImpl::GotOrigins)); 84 weak_factory_.GetWeakPtr()));
83 } 85 }
84 86
85 void BrowsingDataQuotaHelperImpl::GotOrigins( 87 void BrowsingDataQuotaHelperImpl::GotOrigins(
86 const std::set<GURL>& origins, quota::StorageType type) { 88 const std::set<GURL>& origins, quota::StorageType type) {
87 for (std::set<GURL>::const_iterator itr = origins.begin(); 89 for (std::set<GURL>::const_iterator itr = origins.begin();
88 itr != origins.end(); 90 itr != origins.end();
89 ++itr) 91 ++itr)
90 pending_hosts_.insert(std::make_pair(itr->host(), type)); 92 pending_hosts_.insert(std::make_pair(itr->host(), type));
91 93
92 DCHECK(type == quota::kStorageTypeTemporary || 94 DCHECK(type == quota::kStorageTypeTemporary ||
93 type == quota::kStorageTypePersistent); 95 type == quota::kStorageTypePersistent);
94 96
95 if (type == quota::kStorageTypeTemporary) { 97 if (type == quota::kStorageTypeTemporary) {
96 quota_manager_->GetOriginsModifiedSince( 98 quota_manager_->GetOriginsModifiedSince(
97 quota::kStorageTypePersistent, 99 quota::kStorageTypePersistent,
98 base::Time(), 100 base::Time(),
99 callback_factory_.NewCallback( 101 base::Bind(&BrowsingDataQuotaHelperImpl::GotOrigins,
100 &BrowsingDataQuotaHelperImpl::GotOrigins)); 102 weak_factory_.GetWeakPtr()));
101 } else { 103 } else {
102 // type == quota::kStorageTypePersistent 104 // type == quota::kStorageTypePersistent
103 ProcessPendingHosts(); 105 ProcessPendingHosts();
104 } 106 }
105 } 107 }
106 108
107 void BrowsingDataQuotaHelperImpl::ProcessPendingHosts() { 109 void BrowsingDataQuotaHelperImpl::ProcessPendingHosts() {
108 if (pending_hosts_.empty()) { 110 if (pending_hosts_.empty()) {
109 OnComplete(); 111 OnComplete();
110 return; 112 return;
111 } 113 }
112 114
113 PendingHosts::iterator itr = pending_hosts_.begin(); 115 PendingHosts::iterator itr = pending_hosts_.begin();
114 std::string host = itr->first; 116 std::string host = itr->first;
115 quota::StorageType type = itr->second; 117 quota::StorageType type = itr->second;
116 pending_hosts_.erase(itr); 118 pending_hosts_.erase(itr);
117 GetHostUsage(host, type); 119 GetHostUsage(host, type);
118 } 120 }
119 121
120 void BrowsingDataQuotaHelperImpl::GetHostUsage(const std::string& host, 122 void BrowsingDataQuotaHelperImpl::GetHostUsage(const std::string& host,
121 quota::StorageType type) { 123 quota::StorageType type) {
122 DCHECK(quota_manager_.get()); 124 DCHECK(quota_manager_.get());
123 quota_manager_->GetHostUsage( 125 quota_manager_->GetHostUsage(
124 host, type, 126 host, type,
125 callback_factory_.NewCallback( 127 base::Bind(&BrowsingDataQuotaHelperImpl::GotHostUsage,
126 &BrowsingDataQuotaHelperImpl::GotHostUsage)); 128 weak_factory_.GetWeakPtr()));
127 } 129 }
128 130
129 void BrowsingDataQuotaHelperImpl::GotHostUsage(const std::string& host, 131 void BrowsingDataQuotaHelperImpl::GotHostUsage(const std::string& host,
130 quota::StorageType type, 132 quota::StorageType type,
131 int64 usage) { 133 int64 usage) {
132 switch (type) { 134 switch (type) {
133 case quota::kStorageTypeTemporary: 135 case quota::kStorageTypeTemporary:
134 quota_info_[host].temporary_usage = usage; 136 quota_info_[host].temporary_usage = usage;
135 break; 137 break;
136 case quota::kStorageTypePersistent: 138 case quota::kStorageTypePersistent:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 callback_->Run(result); 178 callback_->Run(result);
177 callback_.reset(); 179 callback_.reset();
178 } 180 }
179 181
180 void BrowsingDataQuotaHelperImpl::DidRevokeHostQuota( 182 void BrowsingDataQuotaHelperImpl::DidRevokeHostQuota(
181 quota::QuotaStatusCode status_unused, 183 quota::QuotaStatusCode status_unused,
182 const std::string& host_unused, 184 const std::string& host_unused,
183 quota::StorageType type_unused, 185 quota::StorageType type_unused,
184 int64 quota_unused) { 186 int64 quota_unused) {
185 } 187 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_quota_helper_impl.h ('k') | chrome/browser/browsing_data_quota_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698