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 <memory> |
| 8 #include <utility> |
| 9 |
7 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
8 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
9 #include "base/threading/thread_local.h" | 13 #include "base/threading/thread_local.h" |
10 #include "content/child/quota_message_filter.h" | 14 #include "content/child/quota_message_filter.h" |
11 #include "content/child/thread_safe_sender.h" | 15 #include "content/child/thread_safe_sender.h" |
12 #include "content/common/quota_messages.h" | 16 #include "content/common/quota_messages.h" |
13 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" | 17 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" |
14 #include "third_party/WebKit/public/platform/WebStorageQuotaType.h" | 18 #include "third_party/WebKit/public/platform/WebStorageQuotaType.h" |
15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 19 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
16 #include "url/gurl.h" | 20 #include "url/gurl.h" |
17 | 21 |
18 using blink::WebStorageQuotaCallbacks; | 22 using blink::WebStorageQuotaCallbacks; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 DidQueryStorageUsageAndQuota); | 105 DidQueryStorageUsageAndQuota); |
102 IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail); | 106 IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail); |
103 IPC_MESSAGE_UNHANDLED(handled = false) | 107 IPC_MESSAGE_UNHANDLED(handled = false) |
104 IPC_END_MESSAGE_MAP() | 108 IPC_END_MESSAGE_MAP() |
105 DCHECK(handled) << "Unhandled message:" << msg.type(); | 109 DCHECK(handled) << "Unhandled message:" << msg.type(); |
106 } | 110 } |
107 | 111 |
108 void QuotaDispatcher::QueryStorageUsageAndQuota( | 112 void QuotaDispatcher::QueryStorageUsageAndQuota( |
109 const GURL& origin_url, | 113 const GURL& origin_url, |
110 StorageType type, | 114 StorageType type, |
111 Callback* callback) { | 115 std::unique_ptr<Callback> callback) { |
112 DCHECK(callback); | 116 DCHECK(callback); |
113 int request_id = quota_message_filter_->GenerateRequestID(CurrentWorkerId()); | 117 int request_id = quota_message_filter_->GenerateRequestID(CurrentWorkerId()); |
114 pending_quota_callbacks_.AddWithID(callback, request_id); | 118 pending_quota_callbacks_.AddWithID(std::move(callback), request_id); |
115 thread_safe_sender_->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( | 119 thread_safe_sender_->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( |
116 request_id, origin_url, type)); | 120 request_id, origin_url, type)); |
117 } | 121 } |
118 | 122 |
119 void QuotaDispatcher::RequestStorageQuota(int render_view_id, | 123 void QuotaDispatcher::RequestStorageQuota(int render_view_id, |
120 const GURL& origin_url, | 124 const GURL& origin_url, |
121 StorageType type, | 125 StorageType type, |
122 uint64_t requested_size, | 126 uint64_t requested_size, |
123 Callback* callback) { | 127 std::unique_ptr<Callback> callback) { |
124 DCHECK(callback); | 128 DCHECK(callback); |
125 DCHECK(CurrentWorkerId() == 0); | 129 DCHECK(CurrentWorkerId() == 0); |
126 int request_id = quota_message_filter_->GenerateRequestID(CurrentWorkerId()); | 130 int request_id = quota_message_filter_->GenerateRequestID(CurrentWorkerId()); |
127 pending_quota_callbacks_.AddWithID(callback, request_id); | 131 pending_quota_callbacks_.AddWithID(std::move(callback), request_id); |
128 | 132 |
129 StorageQuotaParams params; | 133 StorageQuotaParams params; |
130 params.render_view_id = render_view_id; | 134 params.render_view_id = render_view_id; |
131 params.request_id = request_id; | 135 params.request_id = request_id; |
132 params.origin_url = origin_url; | 136 params.origin_url = origin_url; |
133 params.storage_type = type; | 137 params.storage_type = type; |
134 params.requested_size = requested_size; | 138 params.requested_size = requested_size; |
135 params.user_gesture = | 139 params.user_gesture = |
136 blink::WebUserGestureIndicator::isProcessingUserGesture(); | 140 blink::WebUserGestureIndicator::isProcessingUserGesture(); |
137 thread_safe_sender_->Send(new QuotaHostMsg_RequestStorageQuota(params)); | 141 thread_safe_sender_->Send(new QuotaHostMsg_RequestStorageQuota(params)); |
138 } | 142 } |
139 | 143 |
140 // static | 144 // static |
141 QuotaDispatcher::Callback* | 145 std::unique_ptr<QuotaDispatcher::Callback> |
142 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper( | 146 QuotaDispatcher::CreateWebStorageQuotaCallbacksWrapper( |
143 blink::WebStorageQuotaCallbacks callbacks) { | 147 blink::WebStorageQuotaCallbacks callbacks) { |
144 return new WebStorageQuotaDispatcherCallback(callbacks); | 148 return base::MakeUnique<WebStorageQuotaDispatcherCallback>(callbacks); |
145 } | 149 } |
146 | 150 |
147 void QuotaDispatcher::DidGrantStorageQuota(int request_id, | 151 void QuotaDispatcher::DidGrantStorageQuota(int request_id, |
148 int64_t current_usage, | 152 int64_t current_usage, |
149 int64_t granted_quota) { | 153 int64_t granted_quota) { |
150 Callback* callback = pending_quota_callbacks_.Lookup(request_id); | 154 Callback* callback = pending_quota_callbacks_.Lookup(request_id); |
151 DCHECK(callback); | 155 DCHECK(callback); |
152 callback->DidGrantStorageQuota(current_usage, granted_quota); | 156 callback->DidGrantStorageQuota(current_usage, granted_quota); |
153 pending_quota_callbacks_.Remove(request_id); | 157 pending_quota_callbacks_.Remove(request_id); |
154 } | 158 } |
(...skipping 24 matching lines...) Expand all Loading... |
179 "mismatching enums: kStorageTypePersistent"); | 183 "mismatching enums: kStorageTypePersistent"); |
180 | 184 |
181 static_assert(int(blink::WebStorageQuotaErrorNotSupported) == | 185 static_assert(int(blink::WebStorageQuotaErrorNotSupported) == |
182 int(storage::kQuotaErrorNotSupported), | 186 int(storage::kQuotaErrorNotSupported), |
183 "mismatching enums: kQuotaErrorNotSupported"); | 187 "mismatching enums: kQuotaErrorNotSupported"); |
184 static_assert(int(blink::WebStorageQuotaErrorAbort) == | 188 static_assert(int(blink::WebStorageQuotaErrorAbort) == |
185 int(storage::kQuotaErrorAbort), | 189 int(storage::kQuotaErrorAbort), |
186 "mismatching enums: kQuotaErrorAbort"); | 190 "mismatching enums: kQuotaErrorAbort"); |
187 | 191 |
188 } // namespace content | 192 } // namespace content |
OLD | NEW |