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 "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 Loading... |
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 18 matching lines...) Expand all Loading... |
157 void DidGetPermissionResponse( | 157 void DidGetPermissionResponse( |
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, weak_factory_.GetWeakPtr())); |
168 weak_factory_.GetWeakPtr())); | |
169 } | 168 } |
170 | 169 |
171 void DidSetHostQuota(QuotaStatusCode status, | 170 void DidSetHostQuota(QuotaStatusCode status, int64 new_quota) { |
172 const std::string& host, | |
173 StorageType type, | |
174 int64 new_quota) { | |
175 DCHECK_EQ(host_, host); | |
176 DCHECK_EQ(type_, type); | |
177 DidFinish(status, new_quota); | 171 DidFinish(status, new_quota); |
178 } | 172 } |
179 | 173 |
180 void DidFinish(QuotaStatusCode status, int64 granted_quota) { | 174 void DidFinish(QuotaStatusCode status, int64 granted_quota) { |
181 DCHECK(dispatcher_host()); | 175 DCHECK(dispatcher_host()); |
182 if (status != quota::kQuotaStatusOk) { | 176 if (status != quota::kQuotaStatusOk) { |
183 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); | 177 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); |
184 } else { | 178 } else { |
185 dispatcher_host()->Send(new QuotaMsg_DidGrantStorageQuota( | 179 dispatcher_host()->Send(new QuotaMsg_DidGrantStorageQuota( |
186 request_id(), granted_quota)); | 180 request_id(), granted_quota)); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 type != quota::kStorageTypePersistent) { | 241 type != quota::kStorageTypePersistent) { |
248 // Unsupported storage types. | 242 // Unsupported storage types. |
249 Send(new QuotaMsg_DidFail(request_id, quota::kQuotaErrorNotSupported)); | 243 Send(new QuotaMsg_DidFail(request_id, quota::kQuotaErrorNotSupported)); |
250 return; | 244 return; |
251 } | 245 } |
252 | 246 |
253 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher( | 247 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher( |
254 this, request_id, origin, type, requested_size, render_view_id); | 248 this, request_id, origin, type, requested_size, render_view_id); |
255 dispatcher->Start(); | 249 dispatcher->Start(); |
256 } | 250 } |
OLD | NEW |