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

Side by Side Diff: Source/modules/background_sync/SyncRegistration.cpp

Issue 963683002: Add IDL and initial Blink API for Background Sync (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add missing serviceWorkerRegistration.syncManager to interface tests Created 5 years, 9 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 "config.h"
6 #include "modules/background_sync/SyncRegistration.h"
7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "modules/background_sync/SyncCallbacks.h"
11 #include "modules/background_sync/SyncError.h"
12 #include "modules/background_sync/SyncRegistrationOptions.h"
13 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
14 #include "public/platform/Platform.h"
15 #include "public/platform/modules/background_sync/WebSyncProvider.h"
16 #include "public/platform/modules/background_sync/WebSyncRegistration.h"
17 #include "wtf/OwnPtr.h"
18
19 namespace blink {
20
21 SyncRegistration* SyncRegistration::take(ScriptPromiseResolver*, WebSyncRegistra tion* syncRegistration, ServiceWorkerRegistration* serviceWorkerRegistration)
22 {
23 OwnPtr<WebSyncRegistration> registration = adoptPtr(syncRegistration);
24 SyncRegistrationOptions options = SyncRegistrationOptions();
25 options.setAllowOnBattery(syncRegistration->allowOnBattery);
26 options.setId(syncRegistration->id);
27 options.setIdleRequired(syncRegistration->idleRequired);
28 options.setMaxDelay(syncRegistration->maxDelayMs);
29 options.setMinDelay(syncRegistration->minDelayMs);
30 options.setMinPeriod(syncRegistration->minPeriodMs);
31 switch (syncRegistration->minRequiredNetwork) {
32 case WebSyncRegistration::NetworkType::NetworkTypeAny:
33 options.setMinRequiredNetwork("network-any");
34 break;
35 case WebSyncRegistration::NetworkType::NetworkTypeOffline:
36 options.setMinRequiredNetwork("network-offline");
37 break;
38 case WebSyncRegistration::NetworkType::NetworkTypeOnline:
39 options.setMinRequiredNetwork("network-online");
40 break;
41 case WebSyncRegistration::NetworkType::NetworkTypeNonMobile:
42 options.setMinRequiredNetwork("network-non-mobile");
43 break;
44 }
45 return new SyncRegistration(options, serviceWorkerRegistration);
46 }
47
48 void SyncRegistration::dispose(WebSyncRegistration* syncRegistration)
49 {
50 if (syncRegistration)
51 delete syncRegistration;
52 }
53
54 SyncRegistration::SyncRegistration(const SyncRegistrationOptions& options, Servi ceWorkerRegistration* serviceWorkerRegistration)
55 : m_allowOnBattery(options.allowOnBattery())
56 , m_id(options.id())
57 , m_idleRequired(options.idleRequired())
58 , m_maxDelay(options.maxDelay())
59 , m_minDelay(options.minDelay())
60 , m_minPeriod(options.minPeriod())
61 , m_minRequiredNetwork(options.minRequiredNetwork())
62 , m_serviceWorkerRegistration(serviceWorkerRegistration)
63 {
64 }
65
66 SyncRegistration::~SyncRegistration()
67 {
68 }
69
70 ScriptPromise SyncRegistration::unregister(ScriptState* scriptState)
71 {
72 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
73 ScriptPromise promise = resolver->promise();
74
75 WebSyncProvider* webSyncProvider = Platform::current()->backgroundSyncProvid er();
76 ASSERT(webSyncProvider);
77
78 webSyncProvider->unregisterBackgroundSync(m_id, m_serviceWorkerRegistration- >webRegistration(), new SyncUnregistrationCallbacks(resolver, m_serviceWorkerReg istration));
79
80 return promise;
81 }
82
83 DEFINE_TRACE(SyncRegistration)
84 {
85 visitor->trace(m_allowOnBattery);
86 visitor->trace(m_idleRequired);
87 visitor->trace(m_serviceWorkerRegistration);
88 }
89
90 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/background_sync/SyncRegistration.h ('k') | Source/modules/background_sync/SyncRegistration.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698