| 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/platform/WebStorageQuotaCallbacks.h" | 14 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" |
| 15 #include "third_party/WebKit/public/platform/WebStorageQuotaType.h" | 15 #include "third_party/WebKit/public/platform/WebStorageQuotaType.h" |
| 16 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 16 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 18 | 18 |
| 19 using blink::WebStorageQuotaCallbacks; | 19 using blink::WebStorageQuotaCallbacks; |
| 20 using blink::WebStorageQuotaError; | 20 using blink::WebStorageQuotaError; |
| 21 using blink::WebStorageQuotaType; | 21 using blink::WebStorageQuotaType; |
| 22 using quota::QuotaStatusCode; | 22 using storage::QuotaStatusCode; |
| 23 using quota::StorageType; | 23 using storage::StorageType; |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 | 26 |
| 27 static base::LazyInstance<base::ThreadLocalPointer<QuotaDispatcher> >::Leaky | 27 static base::LazyInstance<base::ThreadLocalPointer<QuotaDispatcher> >::Leaky |
| 28 g_quota_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; | 28 g_quota_dispatcher_tls = LAZY_INSTANCE_INITIALIZER; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // QuotaDispatcher::Callback implementation for WebStorageQuotaCallbacks. | 32 // QuotaDispatcher::Callback implementation for WebStorageQuotaCallbacks. |
| 33 class WebStorageQuotaDispatcherCallback : public QuotaDispatcher::Callback { | 33 class WebStorageQuotaDispatcherCallback : public QuotaDispatcher::Callback { |
| 34 public: | 34 public: |
| 35 explicit WebStorageQuotaDispatcherCallback( | 35 explicit WebStorageQuotaDispatcherCallback( |
| 36 blink::WebStorageQuotaCallbacks callback) | 36 blink::WebStorageQuotaCallbacks callback) |
| 37 : callbacks_(callback) {} | 37 : callbacks_(callback) {} |
| 38 virtual ~WebStorageQuotaDispatcherCallback() {} | 38 virtual ~WebStorageQuotaDispatcherCallback() {} |
| 39 | 39 |
| 40 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE { | 40 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE { |
| 41 callbacks_.didQueryStorageUsageAndQuota(usage, quota); | 41 callbacks_.didQueryStorageUsageAndQuota(usage, quota); |
| 42 } | 42 } |
| 43 virtual void DidGrantStorageQuota(int64 usage, int64 granted_quota) OVERRIDE { | 43 virtual void DidGrantStorageQuota(int64 usage, int64 granted_quota) OVERRIDE { |
| 44 callbacks_.didGrantStorageQuota(usage, granted_quota); | 44 callbacks_.didGrantStorageQuota(usage, granted_quota); |
| 45 } | 45 } |
| 46 virtual void DidFail(quota::QuotaStatusCode error) OVERRIDE { | 46 virtual void DidFail(storage::QuotaStatusCode error) OVERRIDE { |
| 47 callbacks_.didFail(static_cast<WebStorageQuotaError>(error)); | 47 callbacks_.didFail(static_cast<WebStorageQuotaError>(error)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 blink::WebStorageQuotaCallbacks callbacks_; | 51 blink::WebStorageQuotaCallbacks callbacks_; |
| 52 | 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(WebStorageQuotaDispatcherCallback); | 53 DISALLOW_COPY_AND_ASSIGN(WebStorageQuotaDispatcherCallback); |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 int CurrentWorkerId() { | 56 int CurrentWorkerId() { |
| 57 return WorkerTaskRunner::Instance()->CurrentWorkerId(); | 57 return WorkerTaskRunner::Instance()->CurrentWorkerId(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 QuotaDispatcher::QuotaDispatcher(ThreadSafeSender* thread_safe_sender, | 62 QuotaDispatcher::QuotaDispatcher(ThreadSafeSender* thread_safe_sender, |
| 63 QuotaMessageFilter* quota_message_filter) | 63 QuotaMessageFilter* quota_message_filter) |
| 64 : thread_safe_sender_(thread_safe_sender), | 64 : thread_safe_sender_(thread_safe_sender), |
| 65 quota_message_filter_(quota_message_filter) { | 65 quota_message_filter_(quota_message_filter) { |
| 66 g_quota_dispatcher_tls.Pointer()->Set(this); | 66 g_quota_dispatcher_tls.Pointer()->Set(this); |
| 67 } | 67 } |
| 68 | 68 |
| 69 QuotaDispatcher::~QuotaDispatcher() { | 69 QuotaDispatcher::~QuotaDispatcher() { |
| 70 IDMap<Callback, IDMapOwnPointer>::iterator iter(&pending_quota_callbacks_); | 70 IDMap<Callback, IDMapOwnPointer>::iterator iter(&pending_quota_callbacks_); |
| 71 while (!iter.IsAtEnd()) { | 71 while (!iter.IsAtEnd()) { |
| 72 iter.GetCurrentValue()->DidFail(quota::kQuotaErrorAbort); | 72 iter.GetCurrentValue()->DidFail(storage::kQuotaErrorAbort); |
| 73 iter.Advance(); | 73 iter.Advance(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 g_quota_dispatcher_tls.Pointer()->Set(NULL); | 76 g_quota_dispatcher_tls.Pointer()->Set(NULL); |
| 77 } | 77 } |
| 78 | 78 |
| 79 QuotaDispatcher* QuotaDispatcher::ThreadSpecificInstance( | 79 QuotaDispatcher* QuotaDispatcher::ThreadSpecificInstance( |
| 80 ThreadSafeSender* thread_safe_sender, | 80 ThreadSafeSender* thread_safe_sender, |
| 81 QuotaMessageFilter* quota_message_filter) { | 81 QuotaMessageFilter* quota_message_filter) { |
| 82 if (g_quota_dispatcher_tls.Pointer()->Get()) | 82 if (g_quota_dispatcher_tls.Pointer()->Get()) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 void QuotaDispatcher::DidFail( | 169 void QuotaDispatcher::DidFail( |
| 170 int request_id, | 170 int request_id, |
| 171 QuotaStatusCode error) { | 171 QuotaStatusCode error) { |
| 172 Callback* callback = pending_quota_callbacks_.Lookup(request_id); | 172 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| 173 DCHECK(callback); | 173 DCHECK(callback); |
| 174 callback->DidFail(error); | 174 callback->DidFail(error); |
| 175 pending_quota_callbacks_.Remove(request_id); | 175 pending_quota_callbacks_.Remove(request_id); |
| 176 } | 176 } |
| 177 | 177 |
| 178 COMPILE_ASSERT(int(blink::WebStorageQuotaTypeTemporary) == \ | 178 COMPILE_ASSERT(int(blink::WebStorageQuotaTypeTemporary) == |
| 179 int(quota::kStorageTypeTemporary), mismatching_enums); | 179 int(storage::kStorageTypeTemporary), |
| 180 COMPILE_ASSERT(int(blink::WebStorageQuotaTypePersistent) == \ | 180 mismatching_enums); |
| 181 int(quota::kStorageTypePersistent), mismatching_enums); | 181 COMPILE_ASSERT(int(blink::WebStorageQuotaTypePersistent) == |
| 182 int(storage::kStorageTypePersistent), |
| 183 mismatching_enums); |
| 182 | 184 |
| 183 COMPILE_ASSERT(int(blink::WebStorageQuotaErrorNotSupported) == \ | 185 COMPILE_ASSERT(int(blink::WebStorageQuotaErrorNotSupported) == |
| 184 int(quota::kQuotaErrorNotSupported), mismatching_enums); | 186 int(storage::kQuotaErrorNotSupported), |
| 185 COMPILE_ASSERT(int(blink::WebStorageQuotaErrorAbort) == \ | 187 mismatching_enums); |
| 186 int(quota::kQuotaErrorAbort), mismatching_enums); | 188 COMPILE_ASSERT(int(blink::WebStorageQuotaErrorAbort) == |
| 189 int(storage::kQuotaErrorAbort), |
| 190 mismatching_enums); |
| 187 | 191 |
| 188 } // namespace content | 192 } // namespace content |
| OLD | NEW |