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

Side by Side Diff: third_party/WebKit/Source/modules/background_sync/SyncManager.cpp

Issue 2473483012: Move content/child/background_sync to Blink. (Closed)
Patch Set: Update OWNERS to make presubmit happy Created 4 years, 1 month 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 "modules/background_sync/SyncManager.h" 5 #include "modules/background_sync/SyncManager.h"
6 6
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" 7 #include "bindings/core/v8/CallbackPromiseAdapter.h"
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
11 #include "core/dom/DOMException.h" 11 #include "core/dom/DOMException.h"
12 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
13 #include "core/dom/ExecutionContext.h" 13 #include "core/dom/ExecutionContext.h"
14 #include "modules/background_sync/SyncCallbacks.h" 14 #include "modules/background_sync/SyncCallbacks.h"
15 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 15 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
16 #include "public/platform/Platform.h" 16 #include "public/platform/Platform.h"
17 #include "public/platform/modules/background_sync/WebSyncProvider.h" 17 #include "wtf/ThreadSpecific.h"
18 #include "public/platform/modules/background_sync/WebSyncRegistration.h"
19 #include "wtf/RefPtr.h"
20 18
21 namespace blink { 19 namespace blink {
22 namespace {
23 20
24 WebSyncProvider* backgroundSyncProvider() { 21 // static
25 WebSyncProvider* webSyncProvider = 22 BackgroundSyncProvider* SyncManager::backgroundSyncProvider() {
26 Platform::current()->backgroundSyncProvider(); 23 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<BackgroundSyncProvider>,
27 ASSERT(webSyncProvider); 24 sync_provider,
jbroman 2016/11/05 22:51:09 nit: no underscores in variable names in Blink (fo
adithyas 2016/11/07 19:22:55 Done.
28 return webSyncProvider; 25 new ThreadSpecific<BackgroundSyncProvider>);
haraken 2016/11/05 13:00:19 Is there any per-worker object with which Backgrou
jbroman 2016/11/05 22:51:09 My two cents: a thread-specific object is how this
29 } 26 DCHECK(sync_provider);
27 return sync_provider;
30 } 28 }
31 29
32 SyncManager::SyncManager(ServiceWorkerRegistration* registration) 30 SyncManager::SyncManager(ServiceWorkerRegistration* registration)
33 : m_registration(registration) { 31 : m_registration(registration) {
34 ASSERT(registration); 32 DCHECK(registration);
35 } 33 }
36 34
37 ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, 35 ScriptPromise SyncManager::registerFunction(ScriptState* scriptState,
38 ExecutionContext* context, 36 ExecutionContext* context,
39 const String& tag) { 37 const String& tag) {
40 // TODO(jkarlin): Wait for the registration to become active instead of 38 // TODO(jkarlin): Wait for the registration to become active instead of
41 // rejecting. See crbug.com/542437. 39 // rejecting. See crbug.com/542437.
42 if (!m_registration->active()) 40 if (!m_registration->active())
43 return ScriptPromise::rejectWithDOMException( 41 return ScriptPromise::rejectWithDOMException(
44 scriptState, 42 scriptState,
45 DOMException::create(AbortError, 43 DOMException::create(AbortError,
46 "Registration failed - no active Service Worker")); 44 "Registration failed - no active Service Worker"));
47 45
48 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 46 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
49 ScriptPromise promise = resolver->promise(); 47 ScriptPromise promise = resolver->promise();
50 48
51 WebSyncRegistration* webSyncRegistration = new WebSyncRegistration( 49 mojom::blink::SyncRegistrationPtr syncRegistration =
52 WebSyncRegistration::UNREGISTERED_SYNC_ID /* id */, tag, 50 mojom::blink::SyncRegistration::New();
53 WebSyncRegistration::NetworkStateOnline /* networkState */ 51 syncRegistration->id = SyncManager::UNREGISTERED_SYNC_ID;
54 ); 52 syncRegistration->tag = tag;
53 syncRegistration->network_state =
54 blink::mojom::BackgroundSyncNetworkState::ONLINE;
55
55 backgroundSyncProvider()->registerBackgroundSync( 56 backgroundSyncProvider()->registerBackgroundSync(
56 webSyncRegistration, m_registration->webRegistration(), 57 syncRegistration, m_registration->webRegistration(),
57 new SyncRegistrationCallbacks(resolver, m_registration)); 58 new SyncRegistrationCallbacks(resolver, m_registration));
58 59
59 return promise; 60 return promise;
60 } 61 }
61 62
62 ScriptPromise SyncManager::getTags(ScriptState* scriptState) { 63 ScriptPromise SyncManager::getTags(ScriptState* scriptState) {
63 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 64 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
64 ScriptPromise promise = resolver->promise(); 65 ScriptPromise promise = resolver->promise();
65 66
66 backgroundSyncProvider()->getRegistrations( 67 backgroundSyncProvider()->getRegistrations(
67 m_registration->webRegistration(), 68 m_registration->webRegistration(),
68 new SyncGetRegistrationsCallbacks(resolver, m_registration)); 69 new SyncGetRegistrationsCallbacks(resolver, m_registration));
69 70
70 return promise; 71 return promise;
71 } 72 }
72 73
73 DEFINE_TRACE(SyncManager) { 74 DEFINE_TRACE(SyncManager) {
74 visitor->trace(m_registration); 75 visitor->trace(m_registration);
75 } 76 }
76 77
77 } // namespace blink 78 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698