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

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: Removed test 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 main_thread_task_runner_->PostTask( 198 main_thread_task_runner_->PostTask(
181 FROM_HERE, 199 FROM_HERE,
182 base::Bind( 200 base::Bind(
183 &BackgroundSyncProvider::getPermissionStatus, 201 &BackgroundSyncProvider::getPermissionStatus,
184 base::Unretained(sync_provider_), periodicity, 202 base::Unretained(sync_provider_), periodicity,
185 service_worker_registration, 203 service_worker_registration,
186 new CallbackThreadAdapter<blink::WebSyncGetPermissionStatusCallbacks>( 204 new CallbackThreadAdapter<blink::WebSyncGetPermissionStatusCallbacks>(
187 make_scoped_ptr(callbacks), WorkerThread::GetCurrentId()))); 205 make_scoped_ptr(callbacks), WorkerThread::GetCurrentId())));
188 } 206 }
189 207
208 void BackgroundSyncProviderThreadProxy::releaseRegistration(int64_t handle_id) {
209 main_thread_task_runner_->PostTask(
210 FROM_HERE, base::Bind(&BackgroundSyncProvider::releaseRegistration,
211 base::Unretained(sync_provider_), handle_id));
212 }
213
214 void BackgroundSyncProviderThreadProxy::DuplicateRegistrationHandle(
215 int64 handle_id,
216 const BackgroundSyncService::DuplicateRegistrationHandleCallback&
217 callback) {
218 main_thread_task_runner_->PostTask(
219 FROM_HERE,
220 base::Bind(&BackgroundSyncProvider::DuplicateRegistrationHandle,
221 base::Unretained(sync_provider_), handle_id,
222 base::Bind(&DuplicateRegistrationHandleCallbackOnMainThread,
223 WorkerThread::GetCurrentId(), callback)));
224 }
225
190 void BackgroundSyncProviderThreadProxy::WillStopCurrentWorkerThread() { 226 void BackgroundSyncProviderThreadProxy::WillStopCurrentWorkerThread() {
191 delete this; 227 delete this;
192 } 228 }
193 229
194 BackgroundSyncProviderThreadProxy::BackgroundSyncProviderThreadProxy( 230 BackgroundSyncProviderThreadProxy::BackgroundSyncProviderThreadProxy(
195 base::SingleThreadTaskRunner* main_thread_task_runner, 231 base::SingleThreadTaskRunner* main_thread_task_runner,
196 BackgroundSyncProvider* sync_provider) 232 BackgroundSyncProvider* sync_provider)
197 : main_thread_task_runner_(main_thread_task_runner), 233 : main_thread_task_runner_(main_thread_task_runner),
198 sync_provider_(sync_provider) { 234 sync_provider_(sync_provider) {
199 g_sync_provider_tls.Pointer()->Set(this); 235 g_sync_provider_tls.Pointer()->Set(this);
200 } 236 }
201 237
202 BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() { 238 BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() {
203 g_sync_provider_tls.Pointer()->Set(nullptr); 239 g_sync_provider_tls.Pointer()->Set(nullptr);
204 } 240 }
205 241
206 } // namespace content 242 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698