| 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 17 matching lines...) Expand all Loading... |
| 207 | 204 |
| 208 bool QuotaDispatcherHost::OnMessageReceived( | 205 bool QuotaDispatcherHost::OnMessageReceived( |
| 209 const IPC::Message& message, bool* message_was_ok) { | 206 const IPC::Message& message, bool* message_was_ok) { |
| 210 *message_was_ok = true; | 207 *message_was_ok = true; |
| 211 bool handled = true; | 208 bool handled = true; |
| 212 IPC_BEGIN_MESSAGE_MAP_EX(QuotaDispatcherHost, message, *message_was_ok) | 209 IPC_BEGIN_MESSAGE_MAP_EX(QuotaDispatcherHost, message, *message_was_ok) |
| 213 IPC_MESSAGE_HANDLER(QuotaHostMsg_QueryStorageUsageAndQuota, | 210 IPC_MESSAGE_HANDLER(QuotaHostMsg_QueryStorageUsageAndQuota, |
| 214 OnQueryStorageUsageAndQuota) | 211 OnQueryStorageUsageAndQuota) |
| 215 IPC_MESSAGE_HANDLER(QuotaHostMsg_RequestStorageQuota, | 212 IPC_MESSAGE_HANDLER(QuotaHostMsg_RequestStorageQuota, |
| 216 OnRequestStorageQuota) | 213 OnRequestStorageQuota) |
| 214 IPC_MESSAGE_HANDLER(QuotaHostMsg_NotifyStorageModified, |
| 215 OnNotifyStorageModified) |
| 217 IPC_MESSAGE_UNHANDLED(handled = false) | 216 IPC_MESSAGE_UNHANDLED(handled = false) |
| 218 IPC_END_MESSAGE_MAP_EX() | 217 IPC_END_MESSAGE_MAP_EX() |
| 219 return handled; | 218 return handled; |
| 220 } | 219 } |
| 221 | 220 |
| 222 void QuotaDispatcherHost::OnQueryStorageUsageAndQuota( | 221 void QuotaDispatcherHost::OnQueryStorageUsageAndQuota( |
| 223 int request_id, | 222 int request_id, |
| 224 const GURL& origin, | 223 const GURL& origin, |
| 225 WebKit::WebStorageQuotaType type) { | 224 StorageType type) { |
| 226 QueryUsageAndQuotaDispatcher* dispatcher = new QueryUsageAndQuotaDispatcher( | 225 QueryUsageAndQuotaDispatcher* dispatcher = new QueryUsageAndQuotaDispatcher( |
| 227 this, request_id); | 226 this, request_id); |
| 228 dispatcher->QueryStorageUsageAndQuota(origin, static_cast<StorageType>(type)); | 227 dispatcher->QueryStorageUsageAndQuota(origin, type); |
| 229 } | 228 } |
| 230 | 229 |
| 231 void QuotaDispatcherHost::OnRequestStorageQuota( | 230 void QuotaDispatcherHost::OnRequestStorageQuota( |
| 232 int render_view_id, | 231 int render_view_id, |
| 233 int request_id, | 232 int request_id, |
| 234 const GURL& origin, | 233 const GURL& origin, |
| 235 WebKit::WebStorageQuotaType type, | 234 StorageType type, |
| 236 int64 requested_size) { | 235 int64 requested_size) { |
| 237 if (quota_manager_->IsStorageUnlimited(origin)) { | 236 if (quota_manager_->IsStorageUnlimited(origin)) { |
| 238 // If the origin is marked 'unlimited' we always just return ok. | 237 // If the origin is marked 'unlimited' we always just return ok. |
| 239 Send(new QuotaMsg_DidGrantStorageQuota(request_id, requested_size)); | 238 Send(new QuotaMsg_DidGrantStorageQuota(request_id, requested_size)); |
| 240 return; | 239 return; |
| 241 } | 240 } |
| 242 | 241 |
| 243 StorageType storage_type = static_cast<StorageType>(type); | 242 if (type != quota::kStorageTypeTemporary && |
| 244 if (storage_type != quota::kStorageTypeTemporary && | 243 type != quota::kStorageTypePersistent) { |
| 245 storage_type != quota::kStorageTypePersistent) { | |
| 246 // Unsupported storage types. | 244 // Unsupported storage types. |
| 247 Send(new QuotaMsg_DidFail( | 245 Send(new QuotaMsg_DidFail(request_id, quota::kQuotaErrorNotSupported)); |
| 248 request_id, | |
| 249 WebKit::WebStorageQuotaErrorNotSupported)); | |
| 250 return; | 246 return; |
| 251 } | 247 } |
| 252 | 248 |
| 253 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher( | 249 RequestQuotaDispatcher* dispatcher = new RequestQuotaDispatcher( |
| 254 this, request_id, origin, storage_type, | 250 this, request_id, origin, type, requested_size, render_view_id); |
| 255 requested_size, render_view_id); | |
| 256 dispatcher->Start(); | 251 dispatcher->Start(); |
| 257 } | 252 } |
| 258 | 253 |
| 259 COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypeTemporary) == \ | 254 void QuotaDispatcherHost::OnNotifyStorageModified( |
| 260 int(quota::kStorageTypeTemporary), mismatching_enums); | 255 quota::QuotaClient::ID client_id, |
| 261 COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypePersistent) == \ | 256 const GURL& origin_url, |
| 262 int(quota::kStorageTypePersistent), mismatching_enums); | 257 StorageType type, |
| 263 | 258 int64 growth) { |
| 264 COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorNotSupported) == \ | 259 quota_manager_->NotifyStorageModified(client_id, origin_url, type, growth); |
| 265 int(quota::kQuotaErrorNotSupported), mismatching_enums); | 260 } |
| 266 COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorAbort) == \ | |
| 267 int(quota::kQuotaErrorAbort), mismatching_enums); | |
| OLD | NEW |