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

Side by Side Diff: content/browser/renderer_host/quota_dispatcher_host.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 "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/memory/scoped_callback_factory.h" 8 #include "base/memory/scoped_callback_factory.h"
8 #include "content/browser/quota_permission_context.h" 9 #include "content/browser/quota_permission_context.h"
9 #include "content/common/quota_messages.h" 10 #include "content/common/quota_messages.h"
10 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
11 #include "net/base/net_util.h" 12 #include "net/base/net_util.h"
12 #include "webkit/quota/quota_manager.h" 13 #include "webkit/quota/quota_manager.h"
13 14
14 using quota::QuotaClient; 15 using quota::QuotaClient;
15 using quota::QuotaManager; 16 using quota::QuotaManager;
16 using quota::QuotaStatusCode; 17 using quota::QuotaStatusCode;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 int request_id_; 51 int request_id_;
51 }; 52 };
52 53
53 class QuotaDispatcherHost::QueryUsageAndQuotaDispatcher 54 class QuotaDispatcherHost::QueryUsageAndQuotaDispatcher
54 : public RequestDispatcher { 55 : public RequestDispatcher {
55 public: 56 public:
56 QueryUsageAndQuotaDispatcher( 57 QueryUsageAndQuotaDispatcher(
57 QuotaDispatcherHost* dispatcher_host, 58 QuotaDispatcherHost* dispatcher_host,
58 int request_id) 59 int request_id)
59 : RequestDispatcher(dispatcher_host, request_id), 60 : RequestDispatcher(dispatcher_host, request_id),
60 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} 61 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
61 virtual ~QueryUsageAndQuotaDispatcher() {} 62 virtual ~QueryUsageAndQuotaDispatcher() {}
62 63
63 void QueryStorageUsageAndQuota(const GURL& origin, StorageType type) { 64 void QueryStorageUsageAndQuota(const GURL& origin, StorageType type) {
64 quota_manager()->GetUsageAndQuota(origin, type, 65 quota_manager()->GetUsageAndQuota(
65 callback_factory_.NewCallback( 66 origin, type,
66 &QueryUsageAndQuotaDispatcher::DidQueryStorageUsageAndQuota)); 67 base::Bind(&QueryUsageAndQuotaDispatcher::DidQueryStorageUsageAndQuota,
68 weak_factory_.GetWeakPtr()));
67 } 69 }
68 70
69 private: 71 private:
70 void DidQueryStorageUsageAndQuota( 72 void DidQueryStorageUsageAndQuota(
71 QuotaStatusCode status, int64 usage, int64 quota) { 73 QuotaStatusCode status, int64 usage, int64 quota) {
72 DCHECK(dispatcher_host()); 74 DCHECK(dispatcher_host());
73 if (status != quota::kQuotaStatusOk) { 75 if (status != quota::kQuotaStatusOk) {
74 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); 76 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status));
75 } else { 77 } else {
76 dispatcher_host()->Send(new QuotaMsg_DidQueryStorageUsageAndQuota( 78 dispatcher_host()->Send(new QuotaMsg_DidQueryStorageUsageAndQuota(
77 request_id(), usage, quota)); 79 request_id(), usage, quota));
78 } 80 }
79 Completed(); 81 Completed();
80 } 82 }
81 83
82 base::ScopedCallbackFactory<QueryUsageAndQuotaDispatcher> callback_factory_; 84 base::WeakPtrFactory<QueryUsageAndQuotaDispatcher> weak_factory_;
83 }; 85 };
84 86
85 class QuotaDispatcherHost::RequestQuotaDispatcher 87 class QuotaDispatcherHost::RequestQuotaDispatcher
86 : public RequestDispatcher { 88 : public RequestDispatcher {
87 public: 89 public:
88 typedef RequestQuotaDispatcher self_type; 90 typedef RequestQuotaDispatcher self_type;
89 91
90 RequestQuotaDispatcher(QuotaDispatcherHost* dispatcher_host, 92 RequestQuotaDispatcher(QuotaDispatcherHost* dispatcher_host,
91 int request_id, 93 int request_id,
92 const GURL& origin, 94 const GURL& origin,
93 StorageType type, 95 StorageType type,
94 int64 requested_quota, 96 int64 requested_quota,
95 int render_view_id) 97 int render_view_id)
96 : RequestDispatcher(dispatcher_host, request_id), 98 : RequestDispatcher(dispatcher_host, request_id),
97 origin_(origin), 99 origin_(origin),
98 host_(net::GetHostOrSpecFromURL(origin)), 100 host_(net::GetHostOrSpecFromURL(origin)),
99 type_(type), 101 type_(type),
100 current_quota_(0), 102 current_quota_(0),
101 requested_quota_(requested_quota), 103 requested_quota_(requested_quota),
102 render_view_id_(render_view_id), 104 render_view_id_(render_view_id),
105 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
103 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} 106 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
104 virtual ~RequestQuotaDispatcher() {} 107 virtual ~RequestQuotaDispatcher() {}
105 108
106 void Start() { 109 void Start() {
107 DCHECK(type_ == quota::kStorageTypeTemporary || 110 DCHECK(type_ == quota::kStorageTypeTemporary ||
108 type_ == quota::kStorageTypePersistent); 111 type_ == quota::kStorageTypePersistent);
109 if (type_ == quota::kStorageTypePersistent) { 112 if (type_ == quota::kStorageTypePersistent) {
110 quota_manager()->GetPersistentHostQuota( 113 quota_manager()->GetPersistentHostQuota(
111 host_, 114 host_,
112 callback_factory_.NewCallback(&self_type::DidGetHostQuota)); 115 base::Bind(&self_type::DidGetHostQuota,
116 weak_factory_.GetWeakPtr()));
113 } else { 117 } else {
114 quota_manager()->GetUsageAndQuota( 118 quota_manager()->GetUsageAndQuota(
115 origin_, type_, 119 origin_, type_,
116 callback_factory_.NewCallback( 120 base::Bind(&self_type::DidGetTemporaryUsageAndQuota,
117 &self_type::DidGetTemporaryUsageAndQuota)); 121 weak_factory_.GetWeakPtr()));
118 } 122 }
119 } 123 }
120 124
121 private: 125 private:
122 void DidGetHostQuota(QuotaStatusCode status, 126 void DidGetHostQuota(QuotaStatusCode status,
123 const std::string& host, 127 const std::string& host,
124 StorageType type, 128 StorageType type,
125 int64 quota) { 129 int64 quota) {
126 DCHECK_EQ(type_, type); 130 DCHECK_EQ(type_, type);
127 DCHECK_EQ(host_, host); 131 DCHECK_EQ(host_, host);
(...skipping 23 matching lines...) Expand all
151 155
152 void DidGetPermissionResponse(QuotaPermissionContext::Response response) { 156 void DidGetPermissionResponse(QuotaPermissionContext::Response response) {
153 if (response != QuotaPermissionContext::kResponseAllow) { 157 if (response != QuotaPermissionContext::kResponseAllow) {
154 // User didn't allow the new quota. Just returning the current quota. 158 // User didn't allow the new quota. Just returning the current quota.
155 DidFinish(quota::kQuotaStatusOk, current_quota_); 159 DidFinish(quota::kQuotaStatusOk, current_quota_);
156 return; 160 return;
157 } 161 }
158 // Now we're allowed to set the new quota. 162 // Now we're allowed to set the new quota.
159 quota_manager()->SetPersistentHostQuota( 163 quota_manager()->SetPersistentHostQuota(
160 host_, requested_quota_, 164 host_, requested_quota_,
161 callback_factory_.NewCallback(&self_type::DidSetHostQuota)); 165 base::Bind(&self_type::DidSetHostQuota,
166 weak_factory_.GetWeakPtr()));
162 } 167 }
163 168
164 void DidSetHostQuota(QuotaStatusCode status, 169 void DidSetHostQuota(QuotaStatusCode status,
165 const std::string& host, 170 const std::string& host,
166 StorageType type, 171 StorageType type,
167 int64 new_quota) { 172 int64 new_quota) {
168 DCHECK_EQ(host_, host); 173 DCHECK_EQ(host_, host);
169 DCHECK_EQ(type_, type); 174 DCHECK_EQ(type_, type);
170 DidFinish(status, new_quota); 175 DidFinish(status, new_quota);
171 } 176 }
172 177
173 void DidFinish(QuotaStatusCode status, int64 granted_quota) { 178 void DidFinish(QuotaStatusCode status, int64 granted_quota) {
174 DCHECK(dispatcher_host()); 179 DCHECK(dispatcher_host());
175 if (status != quota::kQuotaStatusOk) { 180 if (status != quota::kQuotaStatusOk) {
176 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); 181 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status));
177 } else { 182 } else {
178 dispatcher_host()->Send(new QuotaMsg_DidGrantStorageQuota( 183 dispatcher_host()->Send(new QuotaMsg_DidGrantStorageQuota(
179 request_id(), granted_quota)); 184 request_id(), granted_quota));
180 } 185 }
181 Completed(); 186 Completed();
182 } 187 }
183 188
184 const GURL origin_; 189 const GURL origin_;
185 const std::string host_; 190 const std::string host_;
186 const StorageType type_; 191 const StorageType type_;
187 int64 current_quota_; 192 int64 current_quota_;
188 const int64 requested_quota_; 193 const int64 requested_quota_;
189 const int render_view_id_; 194 const int render_view_id_;
195 base::WeakPtrFactory<self_type> weak_factory_;
190 base::ScopedCallbackFactory<self_type> callback_factory_; 196 base::ScopedCallbackFactory<self_type> callback_factory_;
191 }; 197 };
192 198
193 QuotaDispatcherHost::QuotaDispatcherHost( 199 QuotaDispatcherHost::QuotaDispatcherHost(
194 int process_id, 200 int process_id,
195 QuotaManager* quota_manager, 201 QuotaManager* quota_manager,
196 QuotaPermissionContext* permission_context) 202 QuotaPermissionContext* permission_context)
197 : process_id_(process_id), 203 : process_id_(process_id),
198 quota_manager_(quota_manager), 204 quota_manager_(quota_manager),
199 permission_context_(permission_context) { 205 permission_context_(permission_context) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 type != quota::kStorageTypePersistent) { 247 type != quota::kStorageTypePersistent) {
242 // Unsupported storage types. 248 // Unsupported storage types.
243 Send(new QuotaMsg_DidFail(request_id, quota::kQuotaErrorNotSupported)); 249 Send(new QuotaMsg_DidFail(request_id, quota::kQuotaErrorNotSupported));
244 return; 250 return;
245 } 251 }
246 252
247 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher( 253 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher(
248 this, request_id, origin, type, requested_size, render_view_id); 254 this, request_id, origin, type, requested_size, render_view_id);
249 dispatcher->Start(); 255 dispatcher->Start();
250 } 256 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/database_message_filter.cc ('k') | webkit/appcache/appcache_quota_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698