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

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

Issue 1104283002: [Background Sync] Add renderer code to interface between JS API and back-end service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bgsync-mojo
Patch Set: Add comment re: BackgroundSyncProvider lifetime Created 5 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/child/background_sync/background_sync_provider_thread_proxy.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h"
10 #include "base/location.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/thread_local.h"
13 #include "content/child/background_sync/background_sync_provider.h"
14
15 using base::LazyInstance;
16 using base::ThreadLocalPointer;
17
18 namespace content {
19
20 namespace {
21
22 LazyInstance<ThreadLocalPointer<BackgroundSyncProviderThreadProxy>>::Leaky
23 g_sync_provider_tls = LAZY_INSTANCE_INITIALIZER;
24
25 } // anonymous namespace
26
27 BackgroundSyncProviderThreadProxy*
28 BackgroundSyncProviderThreadProxy::GetThreadInstance(
29 base::SingleThreadTaskRunner* main_thread_task_runner,
30 BackgroundSyncProvider* sync_provider) {
31 if (g_sync_provider_tls.Pointer()->Get())
32 return g_sync_provider_tls.Pointer()->Get();
33
34 BackgroundSyncProviderThreadProxy* instance =
35 new BackgroundSyncProviderThreadProxy(main_thread_task_runner,
36 sync_provider);
37 DCHECK(WorkerTaskRunner::Instance()->CurrentWorkerId());
38 WorkerTaskRunner::Instance()->AddStopObserver(instance);
39 return instance;
40 }
41
42 void BackgroundSyncProviderThreadProxy::registerBackgroundSync(
43 const blink::WebSyncRegistration* options,
44 blink::WebServiceWorkerRegistration* service_worker_registration,
45 blink::WebSyncRegistrationCallbacks* callbacks) {
46 DCHECK(options);
47 DCHECK(service_worker_registration);
48 DCHECK(callbacks);
49 scoped_ptr<blink::WebSyncRegistration> options_ptr(
50 const_cast<blink::WebSyncRegistration*>(options));
51 main_thread_task_runner_->PostTask(
52 FROM_HERE,
53 base::Bind(&BackgroundSyncProvider::RegisterBackgroundSyncForWorker,
54 base::Unretained(sync_provider_),
55 Passed(options_ptr.Pass()),
jkarlin 2015/05/07 11:51:53 base::Passed? This could be "base::Passed(make_sc
iclelland 2015/05/09 06:41:17 Yes; that's better -- but based on the other comme
56 service_worker_registration,
57 base::Unretained(callbacks),
58 WorkerTaskRunner::Instance()->CurrentWorkerId()));
59 }
60
61 void BackgroundSyncProviderThreadProxy::unregisterBackgroundSync(
62 blink::WebSyncRegistration::Periodicity periodicity,
63 int64_t id,
64 const blink::WebString& tag,
65 blink::WebServiceWorkerRegistration* service_worker_registration,
66 blink::WebSyncUnregistrationCallbacks* callbacks) {
67 DCHECK(service_worker_registration);
68 DCHECK(callbacks);
69 main_thread_task_runner_->PostTask(
70 FROM_HERE,
71 base::Bind(&BackgroundSyncProvider::UnregisterBackgroundSyncForWorker,
72 base::Unretained(sync_provider_),
73 periodicity,
74 id,
75 tag,
76 service_worker_registration,
77 base::Unretained(callbacks),
78 WorkerTaskRunner::Instance()->CurrentWorkerId()));
79 }
80
81 void BackgroundSyncProviderThreadProxy::getRegistration(
82 blink::WebSyncRegistration::Periodicity periodicity,
83 const blink::WebString& tag,
84 blink::WebServiceWorkerRegistration* service_worker_registration,
85 blink::WebSyncRegistrationCallbacks* callbacks) {
86 DCHECK(service_worker_registration);
87 DCHECK(callbacks);
88 main_thread_task_runner_->PostTask(
89 FROM_HERE,
90 base::Bind(&BackgroundSyncProvider::GetRegistrationForWorker,
91 base::Unretained(sync_provider_),
92 periodicity,
93 tag,
94 service_worker_registration,
95 base::Unretained(callbacks),
96 WorkerTaskRunner::Instance()->CurrentWorkerId()));
97 }
98
99 void BackgroundSyncProviderThreadProxy::getRegistrations(
100 blink::WebSyncRegistration::Periodicity periodicity,
101 blink::WebServiceWorkerRegistration* service_worker_registration,
102 blink::WebSyncGetRegistrationsCallbacks* callbacks) {
103 DCHECK(service_worker_registration);
104 DCHECK(callbacks);
105 main_thread_task_runner_->PostTask(
106 FROM_HERE,
107 base::Bind(&BackgroundSyncProvider::GetRegistrationsForWorker,
108 base::Unretained(sync_provider_),
109 periodicity,
110 service_worker_registration,
111 base::Unretained(callbacks),
112 WorkerTaskRunner::Instance()->CurrentWorkerId()));
113 }
114
115 void BackgroundSyncProviderThreadProxy::OnWorkerRunLoopStopped() {
116 delete this;
117 }
118
119 BackgroundSyncProviderThreadProxy::BackgroundSyncProviderThreadProxy(
120 base::SingleThreadTaskRunner* main_thread_task_runner,
121 BackgroundSyncProvider* sync_provider)
122 : main_thread_task_runner_(main_thread_task_runner),
123 sync_provider_(sync_provider) {
124 g_sync_provider_tls.Pointer()->Set(this);
125 }
126
127 BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() {
128 g_sync_provider_tls.Pointer()->Set(nullptr);
129 }
130
131 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698