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

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

Issue 1096503002: [Background Sync] Converting Blink code to the MVP API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Unregister method requires the sync registration tag Created 5 years, 8 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 "config.h" 5 #include "config.h"
6 #include "modules/background_sync/SyncRegistration.h" 6 #include "modules/background_sync/SyncRegistration.h"
7 7
8 #include "bindings/core/v8/CallbackPromiseAdapter.h" 8 #include "bindings/core/v8/CallbackPromiseAdapter.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "core/dom/DOMException.h"
11 #include "core/dom/ExceptionCode.h"
10 #include "modules/background_sync/SyncCallbacks.h" 12 #include "modules/background_sync/SyncCallbacks.h"
11 #include "modules/background_sync/SyncError.h" 13 #include "modules/background_sync/SyncError.h"
12 #include "modules/background_sync/SyncRegistrationOptions.h" 14 #include "modules/background_sync/SyncRegistrationOptions.h"
13 #include "modules/serviceworkers/ServiceWorkerRegistration.h" 15 #include "modules/serviceworkers/ServiceWorkerRegistration.h"
14 #include "public/platform/Platform.h" 16 #include "public/platform/Platform.h"
15 #include "public/platform/modules/background_sync/WebSyncProvider.h" 17 #include "public/platform/modules/background_sync/WebSyncProvider.h"
16 #include "public/platform/modules/background_sync/WebSyncRegistration.h" 18 #include "public/platform/modules/background_sync/WebSyncRegistration.h"
17 #include "wtf/OwnPtr.h" 19 #include "wtf/OwnPtr.h"
18 20
19 namespace blink { 21 namespace blink {
20 22
21 SyncRegistration* SyncRegistration::take(ScriptPromiseResolver*, WebSyncRegistra tion* syncRegistration, ServiceWorkerRegistration* serviceWorkerRegistration) 23 SyncRegistration* SyncRegistration::take(ScriptPromiseResolver*, WebSyncRegistra tion* syncRegistration, ServiceWorkerRegistration* serviceWorkerRegistration)
22 { 24 {
23 OwnPtr<WebSyncRegistration> registration = adoptPtr(syncRegistration); 25 OwnPtr<WebSyncRegistration> registration = adoptPtr(syncRegistration);
24 SyncRegistrationOptions options = SyncRegistrationOptions(); 26 SyncRegistrationOptions options = SyncRegistrationOptions();
25 options.setAllowOnBattery(syncRegistration->allowOnBattery); 27 options.setTag(syncRegistration->tag);
26 options.setId(syncRegistration->id); 28 return new SyncRegistration(syncRegistration->id, options, serviceWorkerRegi stration);
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 } 29 }
47 30
48 void SyncRegistration::dispose(WebSyncRegistration* syncRegistration) 31 void SyncRegistration::dispose(WebSyncRegistration* syncRegistration)
49 { 32 {
50 if (syncRegistration) 33 if (syncRegistration)
51 delete syncRegistration; 34 delete syncRegistration;
52 } 35 }
53 36
54 SyncRegistration::SyncRegistration(const SyncRegistrationOptions& options, Servi ceWorkerRegistration* serviceWorkerRegistration) 37 SyncRegistration::SyncRegistration(int64_t id, const SyncRegistrationOptions& op tions, ServiceWorkerRegistration* serviceWorkerRegistration)
55 : m_allowOnBattery(options.allowOnBattery()) 38 : m_id(id)
56 , m_id(options.id()) 39 , m_tag(options.tag())
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) 40 , m_serviceWorkerRegistration(serviceWorkerRegistration)
63 { 41 {
64 } 42 }
65 43
66 SyncRegistration::~SyncRegistration() 44 SyncRegistration::~SyncRegistration()
67 { 45 {
68 } 46 }
69 47
70 ScriptPromise SyncRegistration::unregister(ScriptState* scriptState) 48 ScriptPromise SyncRegistration::unregister(ScriptState* scriptState)
71 { 49 {
50 if (m_id == WebSyncRegistration::UNREGISTERED_SYNC_ID)
51 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "Operation failed - not a valid registration object"));
52
72 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); 53 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState);
73 ScriptPromise promise = resolver->promise(); 54 ScriptPromise promise = resolver->promise();
74 55
75 WebSyncProvider* webSyncProvider = Platform::current()->backgroundSyncProvid er(); 56 WebSyncProvider* webSyncProvider = Platform::current()->backgroundSyncProvid er();
76 ASSERT(webSyncProvider); 57 ASSERT(webSyncProvider);
77 58
78 webSyncProvider->unregisterBackgroundSync(m_id, m_serviceWorkerRegistration- >webRegistration(), new SyncUnregistrationCallbacks(resolver, m_serviceWorkerReg istration)); 59 webSyncProvider->unregisterBackgroundSync(WebSyncRegistration::PeriodicityOn eShot, m_id, m_tag, m_serviceWorkerRegistration->webRegistration(), new SyncUnre gistrationCallbacks(resolver, m_serviceWorkerRegistration));
79 60
80 return promise; 61 return promise;
81 } 62 }
82 63
83 DEFINE_TRACE(SyncRegistration) 64 DEFINE_TRACE(SyncRegistration)
84 { 65 {
85 visitor->trace(m_allowOnBattery);
86 visitor->trace(m_idleRequired);
87 visitor->trace(m_serviceWorkerRegistration); 66 visitor->trace(m_serviceWorkerRegistration);
88 } 67 }
89 68
90 } // namespace blink 69 } // 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