| OLD | NEW |
| 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/memory/scoped_callback_factory.h" | 7 #include "base/memory/scoped_callback_factory.h" |
| 8 #include "content/browser/quota_permission_context.h" | 8 #include "content/browser/quota_permission_context.h" |
| 9 #include "content/common/quota_messages.h" | 9 #include "content/common/quota_messages.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaError.
h" | |
| 13 #include "webkit/quota/quota_manager.h" | 12 #include "webkit/quota/quota_manager.h" |
| 14 | 13 |
| 14 using quota::QuotaClient; |
| 15 using quota::QuotaManager; | 15 using quota::QuotaManager; |
| 16 using quota::QuotaStatusCode; | 16 using quota::QuotaStatusCode; |
| 17 using quota::StorageType; | 17 using quota::StorageType; |
| 18 using WebKit::WebStorageQuotaError; | |
| 19 | 18 |
| 20 // Created one per request to carry the request's request_id around. | 19 // Created one per request to carry the request's request_id around. |
| 21 // Dispatches requests from renderer/worker to the QuotaManager and | 20 // Dispatches requests from renderer/worker to the QuotaManager and |
| 22 // sends back the response to the renderer/worker. | 21 // sends back the response to the renderer/worker. |
| 23 class QuotaDispatcherHost::RequestDispatcher { | 22 class QuotaDispatcherHost::RequestDispatcher { |
| 24 public: | 23 public: |
| 25 RequestDispatcher(QuotaDispatcherHost* dispatcher_host, | 24 RequestDispatcher(QuotaDispatcherHost* dispatcher_host, |
| 26 int request_id) | 25 int request_id) |
| 27 : dispatcher_host_(dispatcher_host), | 26 : dispatcher_host_(dispatcher_host), |
| 28 request_id_(request_id) { | 27 request_id_(request_id) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 quota_manager()->GetUsageAndQuota(origin, type, | 64 quota_manager()->GetUsageAndQuota(origin, type, |
| 66 callback_factory_.NewCallback( | 65 callback_factory_.NewCallback( |
| 67 &QueryUsageAndQuotaDispatcher::DidQueryStorageUsageAndQuota)); | 66 &QueryUsageAndQuotaDispatcher::DidQueryStorageUsageAndQuota)); |
| 68 } | 67 } |
| 69 | 68 |
| 70 private: | 69 private: |
| 71 void DidQueryStorageUsageAndQuota( | 70 void DidQueryStorageUsageAndQuota( |
| 72 QuotaStatusCode status, int64 usage, int64 quota) { | 71 QuotaStatusCode status, int64 usage, int64 quota) { |
| 73 DCHECK(dispatcher_host()); | 72 DCHECK(dispatcher_host()); |
| 74 if (status != quota::kQuotaStatusOk) { | 73 if (status != quota::kQuotaStatusOk) { |
| 75 dispatcher_host()->Send(new QuotaMsg_DidFail( | 74 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); |
| 76 request_id(), static_cast<WebStorageQuotaError>(status))); | |
| 77 } else { | 75 } else { |
| 78 dispatcher_host()->Send(new QuotaMsg_DidQueryStorageUsageAndQuota( | 76 dispatcher_host()->Send(new QuotaMsg_DidQueryStorageUsageAndQuota( |
| 79 request_id(), usage, quota)); | 77 request_id(), usage, quota)); |
| 80 } | 78 } |
| 81 Completed(); | 79 Completed(); |
| 82 } | 80 } |
| 83 | 81 |
| 84 base::ScopedCallbackFactory<QueryUsageAndQuotaDispatcher> callback_factory_; | 82 base::ScopedCallbackFactory<QueryUsageAndQuotaDispatcher> callback_factory_; |
| 85 }; | 83 }; |
| 86 | 84 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 StorageType type, | 166 StorageType type, |
| 169 int64 new_quota) { | 167 int64 new_quota) { |
| 170 DCHECK_EQ(host_, host); | 168 DCHECK_EQ(host_, host); |
| 171 DCHECK_EQ(type_, type); | 169 DCHECK_EQ(type_, type); |
| 172 DidFinish(status, new_quota); | 170 DidFinish(status, new_quota); |
| 173 } | 171 } |
| 174 | 172 |
| 175 void DidFinish(QuotaStatusCode status, int64 granted_quota) { | 173 void DidFinish(QuotaStatusCode status, int64 granted_quota) { |
| 176 DCHECK(dispatcher_host()); | 174 DCHECK(dispatcher_host()); |
| 177 if (status != quota::kQuotaStatusOk) { | 175 if (status != quota::kQuotaStatusOk) { |
| 178 dispatcher_host()->Send(new QuotaMsg_DidFail( | 176 dispatcher_host()->Send(new QuotaMsg_DidFail(request_id(), status)); |
| 179 request_id(), static_cast<WebStorageQuotaError>(status))); | |
| 180 } else { | 177 } else { |
| 181 dispatcher_host()->Send(new QuotaMsg_DidGrantStorageQuota( | 178 dispatcher_host()->Send(new QuotaMsg_DidGrantStorageQuota( |
| 182 request_id(), granted_quota)); | 179 request_id(), granted_quota)); |
| 183 } | 180 } |
| 184 Completed(); | 181 Completed(); |
| 185 } | 182 } |
| 186 | 183 |
| 187 const GURL origin_; | 184 const GURL origin_; |
| 188 const std::string host_; | 185 const std::string host_; |
| 189 const StorageType type_; | 186 const StorageType type_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 215 IPC_MESSAGE_HANDLER(QuotaHostMsg_RequestStorageQuota, | 212 IPC_MESSAGE_HANDLER(QuotaHostMsg_RequestStorageQuota, |
| 216 OnRequestStorageQuota) | 213 OnRequestStorageQuota) |
| 217 IPC_MESSAGE_UNHANDLED(handled = false) | 214 IPC_MESSAGE_UNHANDLED(handled = false) |
| 218 IPC_END_MESSAGE_MAP_EX() | 215 IPC_END_MESSAGE_MAP_EX() |
| 219 return handled; | 216 return handled; |
| 220 } | 217 } |
| 221 | 218 |
| 222 void QuotaDispatcherHost::OnQueryStorageUsageAndQuota( | 219 void QuotaDispatcherHost::OnQueryStorageUsageAndQuota( |
| 223 int request_id, | 220 int request_id, |
| 224 const GURL& origin, | 221 const GURL& origin, |
| 225 WebKit::WebStorageQuotaType type) { | 222 StorageType type) { |
| 226 QueryUsageAndQuotaDispatcher* dispatcher = new QueryUsageAndQuotaDispatcher( | 223 QueryUsageAndQuotaDispatcher* dispatcher = new QueryUsageAndQuotaDispatcher( |
| 227 this, request_id); | 224 this, request_id); |
| 228 dispatcher->QueryStorageUsageAndQuota(origin, static_cast<StorageType>(type)); | 225 dispatcher->QueryStorageUsageAndQuota(origin, type); |
| 229 } | 226 } |
| 230 | 227 |
| 231 void QuotaDispatcherHost::OnRequestStorageQuota( | 228 void QuotaDispatcherHost::OnRequestStorageQuota( |
| 232 int render_view_id, | 229 int render_view_id, |
| 233 int request_id, | 230 int request_id, |
| 234 const GURL& origin, | 231 const GURL& origin, |
| 235 WebKit::WebStorageQuotaType type, | 232 StorageType type, |
| 236 int64 requested_size) { | 233 int64 requested_size) { |
| 237 if (quota_manager_->IsStorageUnlimited(origin)) { | 234 if (quota_manager_->IsStorageUnlimited(origin)) { |
| 238 // If the origin is marked 'unlimited' we always just return ok. | 235 // If the origin is marked 'unlimited' we always just return ok. |
| 239 Send(new QuotaMsg_DidGrantStorageQuota(request_id, requested_size)); | 236 Send(new QuotaMsg_DidGrantStorageQuota(request_id, requested_size)); |
| 240 return; | 237 return; |
| 241 } | 238 } |
| 242 | 239 |
| 243 StorageType storage_type = static_cast<StorageType>(type); | 240 if (type != quota::kStorageTypeTemporary && |
| 244 if (storage_type != quota::kStorageTypeTemporary && | 241 type != quota::kStorageTypePersistent) { |
| 245 storage_type != quota::kStorageTypePersistent) { | |
| 246 // Unsupported storage types. | 242 // Unsupported storage types. |
| 247 Send(new QuotaMsg_DidFail( | 243 Send(new QuotaMsg_DidFail(request_id, quota::kQuotaErrorNotSupported)); |
| 248 request_id, | |
| 249 WebKit::WebStorageQuotaErrorNotSupported)); | |
| 250 return; | 244 return; |
| 251 } | 245 } |
| 252 | 246 |
| 253 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher( | 247 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher( |
| 254 this, request_id, origin, storage_type, | 248 this, request_id, origin, type, requested_size, render_view_id); |
| 255 requested_size, render_view_id); | |
| 256 dispatcher->Start(); | 249 dispatcher->Start(); |
| 257 } | 250 } |
| 258 | |
| 259 COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypeTemporary) == \ | |
| 260 int(quota::kStorageTypeTemporary), mismatching_enums); | |
| 261 COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypePersistent) == \ | |
| 262 int(quota::kStorageTypePersistent), mismatching_enums); | |
| 263 | |
| 264 COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorNotSupported) == \ | |
| 265 int(quota::kQuotaErrorNotSupported), mismatching_enums); | |
| 266 COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorAbort) == \ | |
| 267 int(quota::kQuotaErrorAbort), mismatching_enums); | |
| OLD | NEW |