| 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" | |
| 8 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/macros.h" |
| 9 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
| 10 #include "content/child/quota_message_filter.h" | 10 #include "content/child/quota_message_filter.h" |
| 11 #include "content/child/thread_safe_sender.h" | 11 #include "content/child/thread_safe_sender.h" |
| 12 #include "content/common/quota_messages.h" | 12 #include "content/common/quota_messages.h" |
| 13 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" | 13 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" |
| 14 #include "third_party/WebKit/public/platform/WebStorageQuotaType.h" | 14 #include "third_party/WebKit/public/platform/WebStorageQuotaType.h" |
| 15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 using blink::WebStorageQuotaCallbacks; | 18 using blink::WebStorageQuotaCallbacks; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // QuotaDispatcher::Callback implementation for WebStorageQuotaCallbacks. | 31 // QuotaDispatcher::Callback implementation for WebStorageQuotaCallbacks. |
| 32 class WebStorageQuotaDispatcherCallback : public QuotaDispatcher::Callback { | 32 class WebStorageQuotaDispatcherCallback : public QuotaDispatcher::Callback { |
| 33 public: | 33 public: |
| 34 explicit WebStorageQuotaDispatcherCallback( | 34 explicit WebStorageQuotaDispatcherCallback( |
| 35 blink::WebStorageQuotaCallbacks callback) | 35 blink::WebStorageQuotaCallbacks callback) |
| 36 : callbacks_(callback) {} | 36 : callbacks_(callback) {} |
| 37 ~WebStorageQuotaDispatcherCallback() override {} | 37 ~WebStorageQuotaDispatcherCallback() override {} |
| 38 | 38 |
| 39 void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) override { | 39 void DidQueryStorageUsageAndQuota(int64_t usage, int64_t quota) override { |
| 40 callbacks_.didQueryStorageUsageAndQuota(usage, quota); | 40 callbacks_.didQueryStorageUsageAndQuota(usage, quota); |
| 41 } | 41 } |
| 42 void DidGrantStorageQuota(int64 usage, int64 granted_quota) override { | 42 void DidGrantStorageQuota(int64_t usage, int64_t granted_quota) override { |
| 43 callbacks_.didGrantStorageQuota(usage, granted_quota); | 43 callbacks_.didGrantStorageQuota(usage, granted_quota); |
| 44 } | 44 } |
| 45 void DidFail(storage::QuotaStatusCode error) override { | 45 void DidFail(storage::QuotaStatusCode error) override { |
| 46 callbacks_.didFail(static_cast<WebStorageQuotaError>(error)); | 46 callbacks_.didFail(static_cast<WebStorageQuotaError>(error)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 blink::WebStorageQuotaCallbacks callbacks_; | 50 blink::WebStorageQuotaCallbacks callbacks_; |
| 51 | 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(WebStorageQuotaDispatcherCallback); | 52 DISALLOW_COPY_AND_ASSIGN(WebStorageQuotaDispatcherCallback); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 const GURL& origin_url, | 109 const GURL& origin_url, |
| 110 StorageType type, | 110 StorageType type, |
| 111 Callback* callback) { | 111 Callback* callback) { |
| 112 DCHECK(callback); | 112 DCHECK(callback); |
| 113 int request_id = quota_message_filter_->GenerateRequestID(CurrentWorkerId()); | 113 int request_id = quota_message_filter_->GenerateRequestID(CurrentWorkerId()); |
| 114 pending_quota_callbacks_.AddWithID(callback, request_id); | 114 pending_quota_callbacks_.AddWithID(callback, request_id); |
| 115 thread_safe_sender_->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( | 115 thread_safe_sender_->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
| 116 request_id, origin_url, type)); | 116 request_id, origin_url, type)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void QuotaDispatcher::RequestStorageQuota( | 119 void QuotaDispatcher::RequestStorageQuota(int render_view_id, |
| 120 int render_view_id, | 120 const GURL& origin_url, |
| 121 const GURL& origin_url, | 121 StorageType type, |
| 122 StorageType type, | 122 uint64_t requested_size, |
| 123 uint64 requested_size, | 123 Callback* callback) { |
| 124 Callback* callback) { | |
| 125 DCHECK(callback); | 124 DCHECK(callback); |
| 126 DCHECK(CurrentWorkerId() == 0); | 125 DCHECK(CurrentWorkerId() == 0); |
| 127 int request_id = quota_message_filter_->GenerateRequestID(CurrentWorkerId()); | 126 int request_id = quota_message_filter_->GenerateRequestID(CurrentWorkerId()); |
| 128 pending_quota_callbacks_.AddWithID(callback, request_id); | 127 pending_quota_callbacks_.AddWithID(callback, request_id); |
| 129 | 128 |
| 130 StorageQuotaParams params; | 129 StorageQuotaParams params; |
| 131 params.render_view_id = render_view_id; | 130 params.render_view_id = render_view_id; |
| 132 params.request_id = request_id; | 131 params.request_id = request_id; |
| 133 params.origin_url = origin_url; | 132 params.origin_url = origin_url; |
| 134 params.storage_type = type; | 133 params.storage_type = type; |
| 135 params.requested_size = requested_size; | 134 params.requested_size = requested_size; |
| 136 params.user_gesture = | 135 params.user_gesture = |
| 137 blink::WebUserGestureIndicator::isProcessingUserGesture(); | 136 blink::WebUserGestureIndicator::isProcessingUserGesture(); |
| 138 thread_safe_sender_->Send(new QuotaHostMsg_RequestStorageQuota(params)); | 137 thread_safe_sender_->Send(new QuotaHostMsg_RequestStorageQuota(params)); |
| 139 } | 138 } |
| 140 | 139 |
| 141 // static | 140 // static |
| 142 QuotaDispatcher::Callback* | 141 QuotaDispatcher::Callback* |
| 143 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper( | 142 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper( |
| 144 blink::WebStorageQuotaCallbacks callbacks) { | 143 blink::WebStorageQuotaCallbacks callbacks) { |
| 145 return new WebStorageQuotaDispatcherCallback(callbacks); | 144 return new WebStorageQuotaDispatcherCallback(callbacks); |
| 146 } | 145 } |
| 147 | 146 |
| 148 void QuotaDispatcher::DidGrantStorageQuota( | 147 void QuotaDispatcher::DidGrantStorageQuota(int request_id, |
| 149 int request_id, | 148 int64_t current_usage, |
| 150 int64 current_usage, | 149 int64_t granted_quota) { |
| 151 int64 granted_quota) { | |
| 152 Callback* callback = pending_quota_callbacks_.Lookup(request_id); | 150 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| 153 DCHECK(callback); | 151 DCHECK(callback); |
| 154 callback->DidGrantStorageQuota(current_usage, granted_quota); | 152 callback->DidGrantStorageQuota(current_usage, granted_quota); |
| 155 pending_quota_callbacks_.Remove(request_id); | 153 pending_quota_callbacks_.Remove(request_id); |
| 156 } | 154 } |
| 157 | 155 |
| 158 void QuotaDispatcher::DidQueryStorageUsageAndQuota( | 156 void QuotaDispatcher::DidQueryStorageUsageAndQuota(int request_id, |
| 159 int request_id, | 157 int64_t current_usage, |
| 160 int64 current_usage, | 158 int64_t current_quota) { |
| 161 int64 current_quota) { | |
| 162 Callback* callback = pending_quota_callbacks_.Lookup(request_id); | 159 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| 163 DCHECK(callback); | 160 DCHECK(callback); |
| 164 callback->DidQueryStorageUsageAndQuota(current_usage, current_quota); | 161 callback->DidQueryStorageUsageAndQuota(current_usage, current_quota); |
| 165 pending_quota_callbacks_.Remove(request_id); | 162 pending_quota_callbacks_.Remove(request_id); |
| 166 } | 163 } |
| 167 | 164 |
| 168 void QuotaDispatcher::DidFail( | 165 void QuotaDispatcher::DidFail( |
| 169 int request_id, | 166 int request_id, |
| 170 QuotaStatusCode error) { | 167 QuotaStatusCode error) { |
| 171 Callback* callback = pending_quota_callbacks_.Lookup(request_id); | 168 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 182 "mismatching enums: kStorageTypePersistent"); | 179 "mismatching enums: kStorageTypePersistent"); |
| 183 | 180 |
| 184 static_assert(int(blink::WebStorageQuotaErrorNotSupported) == | 181 static_assert(int(blink::WebStorageQuotaErrorNotSupported) == |
| 185 int(storage::kQuotaErrorNotSupported), | 182 int(storage::kQuotaErrorNotSupported), |
| 186 "mismatching enums: kQuotaErrorNotSupported"); | 183 "mismatching enums: kQuotaErrorNotSupported"); |
| 187 static_assert(int(blink::WebStorageQuotaErrorAbort) == | 184 static_assert(int(blink::WebStorageQuotaErrorAbort) == |
| 188 int(storage::kQuotaErrorAbort), | 185 int(storage::kQuotaErrorAbort), |
| 189 "mismatching enums: kQuotaErrorAbort"); | 186 "mismatching enums: kQuotaErrorAbort"); |
| 190 | 187 |
| 191 } // namespace content | 188 } // namespace content |
| OLD | NEW |