Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "modules/background_sync/BackgroundSyncClientImpl.h" | |
| 6 | |
| 7 #include "core/EventTypeNames.h" | |
| 8 #include "core/events/Event.h" | |
| 9 #include "modules/background_sync/SyncEvent.h" | |
| 10 #include "modules/serviceworkers/WaitUntilObserver.h" | |
| 11 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 12 #include "platform/RuntimeEnabledFeatures.h" | |
| 13 #include "public/platform/Platform.h" | |
| 14 #include "public/platform/WebThread.h" | |
| 15 #include "wtf/CurrentTime.h" | |
| 16 #include "wtf/Functional.h" | |
| 17 #include "wtf/PtrUtil.h" | |
| 18 #include <utility> | |
| 19 | |
| 20 namespace blink { | |
| 21 | |
| 22 // static | |
| 23 void BackgroundSyncClientImpl::Create( | |
| 24 ServiceWorkerGlobalScope* globalScope, | |
| 25 mojo::InterfaceRequest<mojom::blink::BackgroundSyncServiceClient> request) { | |
| 26 mojo::MakeStrongBinding(wrapUnique(new BackgroundSyncClientImpl(globalScope)), | |
|
jbroman
2016/11/21 21:36:01
nit: since makeUnique has started to make its way
| |
| 27 std::move(request)); | |
| 28 } | |
| 29 | |
| 30 BackgroundSyncClientImpl::~BackgroundSyncClientImpl() {} | |
| 31 | |
| 32 BackgroundSyncClientImpl::BackgroundSyncClientImpl( | |
| 33 ServiceWorkerGlobalScope* globalScope) | |
| 34 : m_globalScope(globalScope) {} | |
| 35 | |
| 36 void BackgroundSyncClientImpl::Sync( | |
| 37 const WTF::String& tag, | |
| 38 mojom::blink::BackgroundSyncEventLastChance lastChance, | |
| 39 const SyncCallback& callback) { | |
| 40 DCHECK(!Platform::current()->mainThread()->isCurrentThread()); | |
| 41 | |
| 42 if (!m_globalScope) { | |
| 43 callback.Run(mojom::blink::ServiceWorkerEventStatus::ABORTED, | |
| 44 WTF::currentTime()); | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 if (!RuntimeEnabledFeatures::backgroundSyncEnabled()) { | |
| 49 callback.Run(mojom::blink::ServiceWorkerEventStatus::COMPLETED, | |
| 50 WTF::currentTime()); | |
| 51 return; | |
| 52 } | |
| 53 | |
| 54 WaitUntilObserver* observer = WaitUntilObserver::create( | |
| 55 m_globalScope, WaitUntilObserver::Sync, | |
| 56 makeUnique<WTF::Function<void(blink::mojom::ServiceWorkerEventStatus, | |
|
jbroman
2016/11/21 21:36:01
nit: probably easier to read if you use the type a
| |
| 57 const double&)>>(callback)); | |
| 58 | |
| 59 Event* event = SyncEvent::create( | |
| 60 EventTypeNames::sync, tag, | |
| 61 lastChance == mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE, | |
| 62 observer); | |
| 63 | |
| 64 m_globalScope->dispatchExtendableEvent(event, observer); | |
| 65 } | |
| 66 | |
| 67 } // namespace blink | |
| OLD | NEW |