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

Side by Side Diff: content/browser/renderer_host/quota_dispatcher_host.cc

Issue 10948006: Cleanup: quota::HostQuotaCallback do not need to pass host and type as arguments (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unittests somehow missed in previous patch Created 8 years, 3 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) 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 "content/browser/renderer_host/quota_dispatcher_host.h" 5 #include "content/browser/renderer_host/quota_dispatcher_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "content/common/quota_messages.h" 9 #include "content/common/quota_messages.h"
10 #include "content/public/browser/quota_permission_context.h" 10 #include "content/public/browser/quota_permission_context.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} 106 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
107 virtual ~RequestQuotaDispatcher() {} 107 virtual ~RequestQuotaDispatcher() {}
108 108
109 void Start() { 109 void Start() {
110 DCHECK(type_ == quota::kStorageTypeTemporary || 110 DCHECK(type_ == quota::kStorageTypeTemporary ||
111 type_ == quota::kStorageTypePersistent); 111 type_ == quota::kStorageTypePersistent);
112 if (type_ == quota::kStorageTypePersistent) { 112 if (type_ == quota::kStorageTypePersistent) {
113 quota_manager()->GetPersistentHostQuota( 113 quota_manager()->GetPersistentHostQuota(
114 host_, 114 host_,
115 base::Bind(&self_type::DidGetHostQuota, 115 base::Bind(&self_type::DidGetHostQuota,
116 weak_factory_.GetWeakPtr())); 116 weak_factory_.GetWeakPtr(), host_, type_));
117 } else { 117 } else {
118 quota_manager()->GetUsageAndQuota( 118 quota_manager()->GetUsageAndQuota(
119 origin_, type_, 119 origin_, type_,
120 base::Bind(&self_type::DidGetTemporaryUsageAndQuota, 120 base::Bind(&self_type::DidGetTemporaryUsageAndQuota,
121 weak_factory_.GetWeakPtr())); 121 weak_factory_.GetWeakPtr()));
122 } 122 }
123 } 123 }
124 124
125 private: 125 private:
126 void DidGetHostQuota(QuotaStatusCode status, 126 void DidGetHostQuota(const std::string& host,
127 const std::string& host,
128 StorageType type, 127 StorageType type,
128 QuotaStatusCode status,
129 int64 quota) { 129 int64 quota) {
130 DCHECK_EQ(type_, type); 130 DCHECK_EQ(type_, type);
131 DCHECK_EQ(host_, host); 131 DCHECK_EQ(host_, host);
132 if (status != quota::kQuotaStatusOk) { 132 if (status != quota::kQuotaStatusOk) {
133 DidFinish(status, 0); 133 DidFinish(status, 0);
134 return; 134 return;
135 } 135 }
136 if (requested_quota_ <= quota) { 136 if (requested_quota_ <= quota) {
137 // Seems like we can just let it go. 137 // Seems like we can just let it go.
138 DidFinish(quota::kQuotaStatusOk, requested_quota_); 138 DidFinish(quota::kQuotaStatusOk, requested_quota_);
(...skipping 19 matching lines...) Expand all
158 QuotaPermissionContext::QuotaPermissionResponse response) { 158 QuotaPermissionContext::QuotaPermissionResponse response) {
159 if (response != QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW) { 159 if (response != QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW) {
160 // User didn't allow the new quota. Just returning the current quota. 160 // User didn't allow the new quota. Just returning the current quota.
161 DidFinish(quota::kQuotaStatusOk, current_quota_); 161 DidFinish(quota::kQuotaStatusOk, current_quota_);
162 return; 162 return;
163 } 163 }
164 // Now we're allowed to set the new quota. 164 // Now we're allowed to set the new quota.
165 quota_manager()->SetPersistentHostQuota( 165 quota_manager()->SetPersistentHostQuota(
166 host_, requested_quota_, 166 host_, requested_quota_,
167 base::Bind(&self_type::DidSetHostQuota, 167 base::Bind(&self_type::DidSetHostQuota,
168 weak_factory_.GetWeakPtr())); 168 weak_factory_.GetWeakPtr(), host_, type_));
kinuko 2012/09/18 12:03:56 Ditto. Maybe there's no need to bind them here
calvinlo 2012/09/19 03:15:38 Done.
169 } 169 }
170 170
171 void DidSetHostQuota(QuotaStatusCode status, 171 void DidSetHostQuota(const std::string& host,
172 const std::string& host,
173 StorageType type, 172 StorageType type,
173 QuotaStatusCode status,
174 int64 new_quota) { 174 int64 new_quota) {
175 DCHECK_EQ(host_, host); 175 DCHECK_EQ(host_, host);
176 DCHECK_EQ(type_, type); 176 DCHECK_EQ(type_, type);
177 DidFinish(status, new_quota); 177 DidFinish(status, new_quota);
178 } 178 }
179 179
180 void DidFinish(QuotaStatusCode status, int64 granted_quota) { 180 void DidFinish(QuotaStatusCode status, int64 granted_quota) {
181 DCHECK(dispatcher_host()); 181 DCHECK(dispatcher_host());
182 if (status != quota::kQuotaStatusOk) { 182 if (status != quota::kQuotaStatusOk) {
183 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); 183 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 type != quota::kStorageTypePersistent) { 247 type != quota::kStorageTypePersistent) {
248 // Unsupported storage types. 248 // Unsupported storage types.
249 Send(new QuotaMsg_DidFail(request_id, quota::kQuotaErrorNotSupported)); 249 Send(new QuotaMsg_DidFail(request_id, quota::kQuotaErrorNotSupported));
250 return; 250 return;
251 } 251 }
252 252
253 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher( 253 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher(
254 this, request_id, origin, type, requested_size, render_view_id); 254 this, request_id, origin, type, requested_size, render_view_id);
255 dispatcher->Start(); 255 dispatcher->Start();
256 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698