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

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 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"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 68 }
69 69
70 private: 70 private:
71 scoped_ptr<blink::WebCallbacks<S, T>> callbacks_; 71 scoped_ptr<blink::WebCallbacks<S, T>> callbacks_;
72 int worker_thread_id_; 72 int worker_thread_id_;
73 }; 73 };
74 74
75 LazyInstance<ThreadLocalPointer<BackgroundSyncProviderThreadProxy>>::Leaky 75 LazyInstance<ThreadLocalPointer<BackgroundSyncProviderThreadProxy>>::Leaky
76 g_sync_provider_tls = LAZY_INSTANCE_INITIALIZER; 76 g_sync_provider_tls = LAZY_INSTANCE_INITIALIZER;
77 77
78 void DuplicateRegistrationHandleCallbackOnSWThread(
79 const BackgroundSyncService::DuplicateRegistrationHandleCallback& callback,
80 BackgroundSyncError error,
81 SyncRegistrationPtr registration) {
82 callback.Run(error, registration.Pass());
83 }
84
85 void DuplicateRegistrationHandleCallbackOnMainThread(
86 int worker_thread_id,
87 const BackgroundSyncService::DuplicateRegistrationHandleCallback& callback,
88 BackgroundSyncError error,
89 SyncRegistrationPtr registration) {
90 WorkerTaskRunner::Instance()->PostTask(
91 worker_thread_id,
92 base::Bind(&DuplicateRegistrationHandleCallbackOnSWThread, callback,
93 error, base::Passed(registration.Pass())));
94 }
95
78 } // anonymous namespace 96 } // anonymous namespace
79 97
80 // static 98 // static
81 BackgroundSyncProviderThreadProxy* 99 BackgroundSyncProviderThreadProxy*
82 BackgroundSyncProviderThreadProxy::GetThreadInstance( 100 BackgroundSyncProviderThreadProxy::GetThreadInstance(
83 base::SingleThreadTaskRunner* main_thread_task_runner, 101 base::SingleThreadTaskRunner* main_thread_task_runner,
84 BackgroundSyncProvider* sync_provider) { 102 BackgroundSyncProvider* sync_provider) {
85 if (g_sync_provider_tls.Pointer()->Get()) 103 if (g_sync_provider_tls.Pointer()->Get())
86 return g_sync_provider_tls.Pointer()->Get(); 104 return g_sync_provider_tls.Pointer()->Get();
87 105
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 FROM_HERE, 200 FROM_HERE,
183 base::Bind( 201 base::Bind(
184 &BackgroundSyncProvider::getPermissionStatus, 202 &BackgroundSyncProvider::getPermissionStatus,
185 base::Unretained(sync_provider_), periodicity, 203 base::Unretained(sync_provider_), periodicity,
186 service_worker_registration, 204 service_worker_registration,
187 new CallbackThreadAdapter<blink::WebSyncGetPermissionStatusCallbacks>( 205 new CallbackThreadAdapter<blink::WebSyncGetPermissionStatusCallbacks>(
188 make_scoped_ptr(callbacks), 206 make_scoped_ptr(callbacks),
189 WorkerTaskRunner::Instance()->CurrentWorkerId()))); 207 WorkerTaskRunner::Instance()->CurrentWorkerId())));
190 } 208 }
191 209
210 void BackgroundSyncProviderThreadProxy::releaseRegistration(int64_t handle_id) {
211 main_thread_task_runner_->PostTask(
212 FROM_HERE, base::Bind(&BackgroundSyncProvider::releaseRegistration,
213 base::Unretained(sync_provider_), handle_id));
214 }
215
216 void BackgroundSyncProviderThreadProxy::DuplicateRegistrationHandle(
217 int64 handle_id,
218 int64 service_worker_registration_id,
219 const BackgroundSyncService::DuplicateRegistrationHandleCallback&
220 callback) {
221 main_thread_task_runner_->PostTask(
222 FROM_HERE,
223 base::Bind(&BackgroundSyncProvider::DuplicateRegistrationHandle,
224 base::Unretained(sync_provider_), handle_id,
225 service_worker_registration_id,
226 base::Bind(&DuplicateRegistrationHandleCallbackOnMainThread,
227 WorkerTaskRunner::Instance()->CurrentWorkerId(),
228 callback)));
229 }
230
192 void BackgroundSyncProviderThreadProxy::OnWorkerRunLoopStopped() { 231 void BackgroundSyncProviderThreadProxy::OnWorkerRunLoopStopped() {
193 delete this; 232 delete this;
194 } 233 }
195 234
196 BackgroundSyncProviderThreadProxy::BackgroundSyncProviderThreadProxy( 235 BackgroundSyncProviderThreadProxy::BackgroundSyncProviderThreadProxy(
197 base::SingleThreadTaskRunner* main_thread_task_runner, 236 base::SingleThreadTaskRunner* main_thread_task_runner,
198 BackgroundSyncProvider* sync_provider) 237 BackgroundSyncProvider* sync_provider)
199 : main_thread_task_runner_(main_thread_task_runner), 238 : main_thread_task_runner_(main_thread_task_runner),
200 sync_provider_(sync_provider) { 239 sync_provider_(sync_provider) {
201 g_sync_provider_tls.Pointer()->Set(this); 240 g_sync_provider_tls.Pointer()->Set(this);
202 } 241 }
203 242
204 BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() { 243 BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() {
205 g_sync_provider_tls.Pointer()->Set(nullptr); 244 g_sync_provider_tls.Pointer()->Set(nullptr);
206 } 245 }
207 246
208 } // namespace content 247 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698