| 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" |
| 11 #include "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 #include "webkit/browser/quota/quota_manager.h" | 13 #include "webkit/browser/quota/quota_manager.h" |
| 14 | 14 |
| 15 using quota::QuotaClient; | 15 using quota::QuotaClient; |
| 16 using quota::QuotaManager; | 16 using quota::QuotaManager; |
| 17 using quota::QuotaStatusCode; | 17 using quota::QuotaStatusCode; |
| 18 using quota::StorageType; | 18 using quota::StorageType; |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 namespace { |
| 23 const int kDefaultThreadId = 0; |
| 24 } |
| 25 |
| 22 // Created one per request to carry the request's request_id around. | 26 // Created one per request to carry the request's request_id around. |
| 23 // Dispatches requests from renderer/worker to the QuotaManager and | 27 // Dispatches requests from renderer/worker to the QuotaManager and |
| 24 // sends back the response to the renderer/worker. | 28 // sends back the response to the renderer/worker. |
| 25 class QuotaDispatcherHost::RequestDispatcher { | 29 class QuotaDispatcherHost::RequestDispatcher { |
| 26 public: | 30 public: |
| 27 RequestDispatcher(QuotaDispatcherHost* dispatcher_host, | 31 RequestDispatcher(QuotaDispatcherHost* dispatcher_host, |
| 28 int request_id) | 32 int request_id) |
| 29 : dispatcher_host_(dispatcher_host), | 33 : dispatcher_host_(dispatcher_host), |
| 30 request_id_(request_id) { | 34 request_id_(request_id) { |
| 31 dispatcher_host_->outstanding_requests_.AddWithID(this, request_id_); | 35 dispatcher_host_->outstanding_requests_.AddWithID(this, request_id_); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 private: | 55 private: |
| 52 QuotaDispatcherHost* dispatcher_host_; | 56 QuotaDispatcherHost* dispatcher_host_; |
| 53 int request_id_; | 57 int request_id_; |
| 54 }; | 58 }; |
| 55 | 59 |
| 56 class QuotaDispatcherHost::QueryUsageAndQuotaDispatcher | 60 class QuotaDispatcherHost::QueryUsageAndQuotaDispatcher |
| 57 : public RequestDispatcher { | 61 : public RequestDispatcher { |
| 58 public: | 62 public: |
| 59 QueryUsageAndQuotaDispatcher( | 63 QueryUsageAndQuotaDispatcher( |
| 60 QuotaDispatcherHost* dispatcher_host, | 64 QuotaDispatcherHost* dispatcher_host, |
| 65 int ipc_thread_id, |
| 61 int request_id) | 66 int request_id) |
| 62 : RequestDispatcher(dispatcher_host, request_id), | 67 : RequestDispatcher(dispatcher_host, request_id), |
| 68 ipc_thread_id_(ipc_thread_id), |
| 63 weak_factory_(this) {} | 69 weak_factory_(this) {} |
| 64 virtual ~QueryUsageAndQuotaDispatcher() {} | 70 virtual ~QueryUsageAndQuotaDispatcher() {} |
| 65 | 71 |
| 66 void QueryStorageUsageAndQuota(const GURL& origin, StorageType type) { | 72 void QueryStorageUsageAndQuota(const GURL& origin, StorageType type) { |
| 67 quota_manager()->GetUsageAndQuotaForWebApps( | 73 quota_manager()->GetUsageAndQuotaForWebApps( |
| 68 origin, type, | 74 origin, type, |
| 69 base::Bind(&QueryUsageAndQuotaDispatcher::DidQueryStorageUsageAndQuota, | 75 base::Bind(&QueryUsageAndQuotaDispatcher::DidQueryStorageUsageAndQuota, |
| 70 weak_factory_.GetWeakPtr())); | 76 weak_factory_.GetWeakPtr())); |
| 71 } | 77 } |
| 72 | 78 |
| 73 private: | 79 private: |
| 74 void DidQueryStorageUsageAndQuota( | 80 void DidQueryStorageUsageAndQuota( |
| 75 QuotaStatusCode status, int64 usage, int64 quota) { | 81 QuotaStatusCode status, int64 usage, int64 quota) { |
| 76 DCHECK(dispatcher_host()); | 82 DCHECK(dispatcher_host()); |
| 77 if (status != quota::kQuotaStatusOk) { | 83 if (status != quota::kQuotaStatusOk) { |
| 78 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); | 84 dispatcher_host()->Send(new QuotaMsg_DidFail( |
| 85 ipc_thread_id_, request_id(), status)); |
| 79 } else { | 86 } else { |
| 80 dispatcher_host()->Send(new QuotaMsg_DidQueryStorageUsageAndQuota( | 87 dispatcher_host()->Send(new QuotaMsg_DidQueryStorageUsageAndQuota( |
| 81 request_id(), usage, quota)); | 88 ipc_thread_id_, request_id(), usage, quota)); |
| 82 } | 89 } |
| 83 Completed(); | 90 Completed(); |
| 84 } | 91 } |
| 85 | 92 |
| 93 int ipc_thread_id_; |
| 86 base::WeakPtrFactory<QueryUsageAndQuotaDispatcher> weak_factory_; | 94 base::WeakPtrFactory<QueryUsageAndQuotaDispatcher> weak_factory_; |
| 87 }; | 95 }; |
| 88 | 96 |
| 89 class QuotaDispatcherHost::RequestQuotaDispatcher | 97 class QuotaDispatcherHost::RequestQuotaDispatcher |
| 90 : public RequestDispatcher { | 98 : public RequestDispatcher { |
| 91 public: | 99 public: |
| 92 typedef RequestQuotaDispatcher self_type; | 100 typedef RequestQuotaDispatcher self_type; |
| 93 | 101 |
| 94 RequestQuotaDispatcher(QuotaDispatcherHost* dispatcher_host, | 102 RequestQuotaDispatcher(QuotaDispatcherHost* dispatcher_host, |
| 95 int request_id, | 103 int request_id, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 base::Bind(&self_type::DidSetHostQuota, weak_factory_.GetWeakPtr())); | 181 base::Bind(&self_type::DidSetHostQuota, weak_factory_.GetWeakPtr())); |
| 174 } | 182 } |
| 175 | 183 |
| 176 void DidSetHostQuota(QuotaStatusCode status, int64 new_quota) { | 184 void DidSetHostQuota(QuotaStatusCode status, int64 new_quota) { |
| 177 DidFinish(status, new_quota); | 185 DidFinish(status, new_quota); |
| 178 } | 186 } |
| 179 | 187 |
| 180 void DidFinish(QuotaStatusCode status, int64 granted_quota) { | 188 void DidFinish(QuotaStatusCode status, int64 granted_quota) { |
| 181 DCHECK(dispatcher_host()); | 189 DCHECK(dispatcher_host()); |
| 182 if (status != quota::kQuotaStatusOk) { | 190 if (status != quota::kQuotaStatusOk) { |
| 183 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); | 191 dispatcher_host()->Send( |
| 192 new QuotaMsg_DidFail(kDefaultThreadId, request_id(), status)); |
| 184 } else { | 193 } else { |
| 185 dispatcher_host()->Send(new QuotaMsg_DidGrantStorageQuota( | 194 dispatcher_host()->Send(new QuotaMsg_DidGrantStorageQuota( |
| 186 request_id(), granted_quota)); | 195 kDefaultThreadId, request_id(), granted_quota)); |
| 187 } | 196 } |
| 188 Completed(); | 197 Completed(); |
| 189 } | 198 } |
| 190 | 199 |
| 191 const GURL origin_; | 200 const GURL origin_; |
| 192 const std::string host_; | 201 const std::string host_; |
| 193 const StorageType type_; | 202 const StorageType type_; |
| 194 int64 current_quota_; | 203 int64 current_quota_; |
| 195 const int64 requested_quota_; | 204 const int64 requested_quota_; |
| 196 const int render_view_id_; | 205 const int render_view_id_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 216 IPC_MESSAGE_HANDLER(QuotaHostMsg_RequestStorageQuota, | 225 IPC_MESSAGE_HANDLER(QuotaHostMsg_RequestStorageQuota, |
| 217 OnRequestStorageQuota) | 226 OnRequestStorageQuota) |
| 218 IPC_MESSAGE_UNHANDLED(handled = false) | 227 IPC_MESSAGE_UNHANDLED(handled = false) |
| 219 IPC_END_MESSAGE_MAP_EX() | 228 IPC_END_MESSAGE_MAP_EX() |
| 220 return handled; | 229 return handled; |
| 221 } | 230 } |
| 222 | 231 |
| 223 QuotaDispatcherHost::~QuotaDispatcherHost() {} | 232 QuotaDispatcherHost::~QuotaDispatcherHost() {} |
| 224 | 233 |
| 225 void QuotaDispatcherHost::OnQueryStorageUsageAndQuota( | 234 void QuotaDispatcherHost::OnQueryStorageUsageAndQuota( |
| 235 int ipc_thread_id, |
| 226 int request_id, | 236 int request_id, |
| 227 const GURL& origin, | 237 const GURL& origin, |
| 228 StorageType type) { | 238 StorageType type) { |
| 229 QueryUsageAndQuotaDispatcher* dispatcher = new QueryUsageAndQuotaDispatcher( | 239 QueryUsageAndQuotaDispatcher* dispatcher = new QueryUsageAndQuotaDispatcher( |
| 230 this, request_id); | 240 this, ipc_thread_id, request_id); |
| 231 dispatcher->QueryStorageUsageAndQuota(origin, type); | 241 dispatcher->QueryStorageUsageAndQuota(origin, type); |
| 232 } | 242 } |
| 233 | 243 |
| 234 void QuotaDispatcherHost::OnRequestStorageQuota( | 244 void QuotaDispatcherHost::OnRequestStorageQuota( |
| 235 int render_view_id, | 245 int render_view_id, |
| 236 int request_id, | 246 int request_id, |
| 237 const GURL& origin, | 247 const GURL& origin, |
| 238 StorageType type, | 248 StorageType type, |
| 239 int64 requested_size) { | 249 int64 requested_size) { |
| 240 if (quota_manager_->IsStorageUnlimited(origin, type)) { | 250 if (quota_manager_->IsStorageUnlimited(origin, type)) { |
| 241 // If the origin is marked 'unlimited' we always just return ok. | 251 // If the origin is marked 'unlimited' we always just return ok. |
| 242 Send(new QuotaMsg_DidGrantStorageQuota(request_id, requested_size)); | 252 Send(new QuotaMsg_DidGrantStorageQuota( |
| 253 kDefaultThreadId, request_id, requested_size)); |
| 243 return; | 254 return; |
| 244 } | 255 } |
| 245 | 256 |
| 246 if (type != quota::kStorageTypeTemporary && | 257 if (type != quota::kStorageTypeTemporary && |
| 247 type != quota::kStorageTypePersistent) { | 258 type != quota::kStorageTypePersistent) { |
| 248 // Unsupported storage types. | 259 // Unsupported storage types. |
| 249 Send(new QuotaMsg_DidFail(request_id, quota::kQuotaErrorNotSupported)); | 260 Send(new QuotaMsg_DidFail( |
| 261 kDefaultThreadId, request_id, quota::kQuotaErrorNotSupported)); |
| 250 return; | 262 return; |
| 251 } | 263 } |
| 252 | 264 |
| 253 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher( | 265 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher( |
| 254 this, request_id, origin, type, requested_size, render_view_id); | 266 this, request_id, origin, type, requested_size, render_view_id); |
| 255 dispatcher->Start(); | 267 dispatcher->Start(); |
| 256 } | 268 } |
| 257 | 269 |
| 258 } // namespace content | 270 } // namespace content |
| OLD | NEW |