| 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/child/quota_dispatcher.h" | 5 #include "content/child/quota_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
| 10 #include "content/child/child_thread.h" | 10 #include "content/child/child_thread.h" |
| 11 #include "content/child/quota_message_filter.h" | 11 #include "content/child/quota_message_filter.h" |
| 12 #include "content/child/thread_safe_sender.h" | 12 #include "content/child/thread_safe_sender.h" |
| 13 #include "content/common/quota_messages.h" | 13 #include "content/common/quota_messages.h" |
| 14 #include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h" | 14 #include "third_party/WebKit/public/web/WebStorageQuotaCallbacks.h" |
| 15 #include "third_party/WebKit/public/web/WebStorageQuotaType.h" | 15 #include "third_party/WebKit/public/web/WebStorageQuotaType.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 using quota::QuotaStatusCode; | 18 using quota::QuotaStatusCode; |
| 19 using quota::StorageType; | 19 using quota::StorageType; |
| 20 | 20 |
| 21 using WebKit::WebStorageQuotaCallbacks; | 21 using blink::WebStorageQuotaCallbacks; |
| 22 using WebKit::WebStorageQuotaError; | 22 using blink::WebStorageQuotaError; |
| 23 using WebKit::WebStorageQuotaType; | 23 using blink::WebStorageQuotaType; |
| 24 | 24 |
| 25 using webkit_glue::WorkerTaskRunner; | 25 using webkit_glue::WorkerTaskRunner; |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 static base::LazyInstance<base::ThreadLocalPointer<QuotaDispatcher> >::Leaky | 29 static base::LazyInstance<base::ThreadLocalPointer<QuotaDispatcher> >::Leaky |
| 30 g_quota_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; | 30 g_quota_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // QuotaDispatcher::Callback implementation for WebStorageQuotaCallbacks. | 34 // QuotaDispatcher::Callback implementation for WebStorageQuotaCallbacks. |
| 35 class WebStorageQuotaDispatcherCallback : public QuotaDispatcher::Callback { | 35 class WebStorageQuotaDispatcherCallback : public QuotaDispatcher::Callback { |
| 36 public: | 36 public: |
| 37 WebStorageQuotaDispatcherCallback(WebKit::WebStorageQuotaCallbacks* callback) | 37 WebStorageQuotaDispatcherCallback(blink::WebStorageQuotaCallbacks* callback) |
| 38 : callbacks_(callback) { | 38 : callbacks_(callback) { |
| 39 DCHECK(callbacks_); | 39 DCHECK(callbacks_); |
| 40 } | 40 } |
| 41 virtual ~WebStorageQuotaDispatcherCallback() {} | 41 virtual ~WebStorageQuotaDispatcherCallback() {} |
| 42 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE { | 42 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE { |
| 43 callbacks_->didQueryStorageUsageAndQuota(usage, quota); | 43 callbacks_->didQueryStorageUsageAndQuota(usage, quota); |
| 44 } | 44 } |
| 45 virtual void DidGrantStorageQuota(int64 granted_quota) OVERRIDE { | 45 virtual void DidGrantStorageQuota(int64 granted_quota) OVERRIDE { |
| 46 callbacks_->didGrantStorageQuota(granted_quota); | 46 callbacks_->didGrantStorageQuota(granted_quota); |
| 47 } | 47 } |
| 48 virtual void DidFail(quota::QuotaStatusCode error) OVERRIDE { | 48 virtual void DidFail(quota::QuotaStatusCode error) OVERRIDE { |
| 49 callbacks_->didFail(static_cast<WebStorageQuotaError>(error)); | 49 callbacks_->didFail(static_cast<WebStorageQuotaError>(error)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 // Not owned (self-destructed). | 53 // Not owned (self-destructed). |
| 54 WebKit::WebStorageQuotaCallbacks* callbacks_; | 54 blink::WebStorageQuotaCallbacks* callbacks_; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 int CurrentWorkerId() { | 57 int CurrentWorkerId() { |
| 58 return WorkerTaskRunner::Instance()->CurrentWorkerId(); | 58 return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace | 61 } // namespace |
| 62 | 62 |
| 63 QuotaDispatcher::QuotaDispatcher(ThreadSafeSender* thread_safe_sender, | 63 QuotaDispatcher::QuotaDispatcher(ThreadSafeSender* thread_safe_sender, |
| 64 QuotaMessageFilter* quota_message_filter) | 64 QuotaMessageFilter* quota_message_filter) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 DCHECK(CurrentWorkerId() == 0); | 128 DCHECK(CurrentWorkerId() == 0); |
| 129 int request_id = quota_message_filter_->GenerateRequestID(CurrentWorkerId()); | 129 int request_id = quota_message_filter_->GenerateRequestID(CurrentWorkerId()); |
| 130 pending_quota_callbacks_.AddWithID(callback, request_id); | 130 pending_quota_callbacks_.AddWithID(callback, request_id); |
| 131 thread_safe_sender_->Send(new QuotaHostMsg_RequestStorageQuota( | 131 thread_safe_sender_->Send(new QuotaHostMsg_RequestStorageQuota( |
| 132 render_view_id, request_id, origin_url, type, requested_size)); | 132 render_view_id, request_id, origin_url, type, requested_size)); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // static | 135 // static |
| 136 QuotaDispatcher::Callback* | 136 QuotaDispatcher::Callback* |
| 137 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper( | 137 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper( |
| 138 WebKit::WebStorageQuotaCallbacks* callbacks) { | 138 blink::WebStorageQuotaCallbacks* callbacks) { |
| 139 return new WebStorageQuotaDispatcherCallback(callbacks); | 139 return new WebStorageQuotaDispatcherCallback(callbacks); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void QuotaDispatcher::DidGrantStorageQuota( | 142 void QuotaDispatcher::DidGrantStorageQuota( |
| 143 int request_id, | 143 int request_id, |
| 144 int64 granted_quota) { | 144 int64 granted_quota) { |
| 145 Callback* callback = pending_quota_callbacks_.Lookup(request_id); | 145 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| 146 DCHECK(callback); | 146 DCHECK(callback); |
| 147 callback->DidGrantStorageQuota(granted_quota); | 147 callback->DidGrantStorageQuota(granted_quota); |
| 148 pending_quota_callbacks_.Remove(request_id); | 148 pending_quota_callbacks_.Remove(request_id); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 160 | 160 |
| 161 void QuotaDispatcher::DidFail( | 161 void QuotaDispatcher::DidFail( |
| 162 int request_id, | 162 int request_id, |
| 163 QuotaStatusCode error) { | 163 QuotaStatusCode error) { |
| 164 Callback* callback = pending_quota_callbacks_.Lookup(request_id); | 164 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| 165 DCHECK(callback); | 165 DCHECK(callback); |
| 166 callback->DidFail(error); | 166 callback->DidFail(error); |
| 167 pending_quota_callbacks_.Remove(request_id); | 167 pending_quota_callbacks_.Remove(request_id); |
| 168 } | 168 } |
| 169 | 169 |
| 170 COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypeTemporary) == \ | 170 COMPILE_ASSERT(int(blink::WebStorageQuotaTypeTemporary) == \ |
| 171 int(quota::kStorageTypeTemporary), mismatching_enums); | 171 int(quota::kStorageTypeTemporary), mismatching_enums); |
| 172 COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypePersistent) == \ | 172 COMPILE_ASSERT(int(blink::WebStorageQuotaTypePersistent) == \ |
| 173 int(quota::kStorageTypePersistent), mismatching_enums); | 173 int(quota::kStorageTypePersistent), mismatching_enums); |
| 174 | 174 |
| 175 COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorNotSupported) == \ | 175 COMPILE_ASSERT(int(blink::WebStorageQuotaErrorNotSupported) == \ |
| 176 int(quota::kQuotaErrorNotSupported), mismatching_enums); | 176 int(quota::kQuotaErrorNotSupported), mismatching_enums); |
| 177 COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorAbort) == \ | 177 COMPILE_ASSERT(int(blink::WebStorageQuotaErrorAbort) == \ |
| 178 int(quota::kQuotaErrorAbort), mismatching_enums); | 178 int(quota::kQuotaErrorAbort), mismatching_enums); |
| 179 | 179 |
| 180 } // namespace content | 180 } // namespace content |
| OLD | NEW |