Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: content/child/background_sync/background_sync_provider_thread_proxy.cc

Issue 1282013004: BackgroundSyncManager tracks client registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address comments from PS17 Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/background_sync/background_sync_provider_thread_proxy.h" 5 #include "content/child/background_sync/background_sync_provider_thread_proxy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_local.h" 13 #include "base/threading/thread_local.h"
14 #include "content/child/background_sync/background_sync_provider.h" 14 #include "content/child/background_sync/background_sync_provider.h"
15 15
16 using base::LazyInstance; 16 using base::LazyInstance;
17 using base::ThreadLocalPointer; 17 using base::ThreadLocalPointer;
18 18
19 namespace content { 19 namespace content {
20 20
21 namespace { 21 namespace {
22 22
23 void DuplicateRegistrationHandleCallbackOnSWThread(
24 const BackgroundSyncService::DuplicateRegistrationHandleCallback& callback,
25 BackgroundSyncError error,
26 SyncRegistrationPtr registration) {
27 callback.Run(error, registration.Pass());
28 }
29
30 void DuplicateRegistrationHandleCallbackOnMainThread(
31 int worker_thread_id,
32 const BackgroundSyncService::DuplicateRegistrationHandleCallback& callback,
33 BackgroundSyncError error,
34 SyncRegistrationPtr registration) {
35 WorkerTaskRunner::Instance()->PostTask(
36 worker_thread_id,
37 base::Bind(&DuplicateRegistrationHandleCallbackOnSWThread, callback,
38 error, base::Passed(registration.Pass())));
39 }
40
23 // CallbackThreadAdapter<S,T> is a wrapper for WebCallbacks<S,T> which 41 // CallbackThreadAdapter<S,T> is a wrapper for WebCallbacks<S,T> which
24 // switches to a specific thread before calling the wrapped callback's 42 // switches to a specific thread before calling the wrapped callback's
25 // onSuccess or onError methods. 43 // onSuccess or onError methods.
26 // 44 //
27 // Takes ownership of the WebCallbacks object which it wraps. 45 // Takes ownership of the WebCallbacks object which it wraps.
28 template <typename S, typename T> 46 template <typename S, typename T>
29 class CallbackThreadAdapter : public blink::WebCallbacks<S, T> { 47 class CallbackThreadAdapter : public blink::WebCallbacks<S, T> {
30 public: 48 public:
31 CallbackThreadAdapter(scoped_ptr<blink::WebCallbacks<S, T>> callbacks, 49 CallbackThreadAdapter(scoped_ptr<blink::WebCallbacks<S, T>> callbacks,
32 int worker_thread_id) 50 int worker_thread_id)
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 FROM_HERE, 187 FROM_HERE,
170 base::Bind(&BackgroundSyncProvider::getPermissionStatus, 188 base::Bind(&BackgroundSyncProvider::getPermissionStatus,
171 base::Unretained(sync_provider_), periodicity, 189 base::Unretained(sync_provider_), periodicity,
172 service_worker_registration, 190 service_worker_registration,
173 new CallbackThreadAdapter<blink::WebSyncPermissionStatus*, 191 new CallbackThreadAdapter<blink::WebSyncPermissionStatus*,
174 blink::WebSyncError*>( 192 blink::WebSyncError*>(
175 make_scoped_ptr(callbacks), 193 make_scoped_ptr(callbacks),
176 WorkerTaskRunner::Instance()->CurrentWorkerId()))); 194 WorkerTaskRunner::Instance()->CurrentWorkerId())));
177 } 195 }
178 196
197 void BackgroundSyncProviderThreadProxy::releaseRegistration(int64_t handle_id) {
198 main_thread_task_runner_->PostTask(
199 FROM_HERE, base::Bind(&BackgroundSyncProvider::releaseRegistration,
200 base::Unretained(sync_provider_), handle_id));
201 }
202
203 void BackgroundSyncProviderThreadProxy::DuplicateRegistrationHandle(
204 int64 handle_id,
205 int64 service_worker_registration_id,
206 const BackgroundSyncService::DuplicateRegistrationHandleCallback&
207 callback) {
208 main_thread_task_runner_->PostTask(
209 FROM_HERE,
210 base::Bind(&BackgroundSyncProvider::DuplicateRegistrationHandle,
211 base::Unretained(sync_provider_), handle_id,
212 service_worker_registration_id,
213 base::Bind(&DuplicateRegistrationHandleCallbackOnMainThread,
214 WorkerTaskRunner::Instance()->CurrentWorkerId(),
215 callback)));
216 }
217
179 void BackgroundSyncProviderThreadProxy::OnWorkerRunLoopStopped() { 218 void BackgroundSyncProviderThreadProxy::OnWorkerRunLoopStopped() {
180 delete this; 219 delete this;
181 } 220 }
182 221
183 BackgroundSyncProviderThreadProxy::BackgroundSyncProviderThreadProxy( 222 BackgroundSyncProviderThreadProxy::BackgroundSyncProviderThreadProxy(
184 base::SingleThreadTaskRunner* main_thread_task_runner, 223 base::SingleThreadTaskRunner* main_thread_task_runner,
185 BackgroundSyncProvider* sync_provider) 224 BackgroundSyncProvider* sync_provider)
186 : main_thread_task_runner_(main_thread_task_runner), 225 : main_thread_task_runner_(main_thread_task_runner),
187 sync_provider_(sync_provider) { 226 sync_provider_(sync_provider) {
188 g_sync_provider_tls.Pointer()->Set(this); 227 g_sync_provider_tls.Pointer()->Set(this);
189 } 228 }
190 229
191 BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() { 230 BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() {
192 g_sync_provider_tls.Pointer()->Set(nullptr); 231 g_sync_provider_tls.Pointer()->Set(nullptr);
193 } 232 }
194 233
195 } // namespace content 234 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698