| Index: third_party/WebKit/Source/modules/background_sync/BackgroundSyncClientImpl.cpp
|
| diff --git a/third_party/WebKit/Source/modules/background_sync/BackgroundSyncClientImpl.cpp b/third_party/WebKit/Source/modules/background_sync/BackgroundSyncClientImpl.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..57b592c5863b20f71707b15e04e7803eb35ba80b
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/background_sync/BackgroundSyncClientImpl.cpp
|
| @@ -0,0 +1,67 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "modules/background_sync/BackgroundSyncClientImpl.h"
|
| +
|
| +#include "core/EventTypeNames.h"
|
| +#include "core/events/Event.h"
|
| +#include "modules/background_sync/SyncEvent.h"
|
| +#include "modules/serviceworkers/WaitUntilObserver.h"
|
| +#include "mojo/public/cpp/bindings/strong_binding.h"
|
| +#include "platform/RuntimeEnabledFeatures.h"
|
| +#include "public/platform/Platform.h"
|
| +#include "public/platform/WebThread.h"
|
| +#include "wtf/CurrentTime.h"
|
| +#include "wtf/Functional.h"
|
| +#include "wtf/PtrUtil.h"
|
| +#include <utility>
|
| +
|
| +namespace blink {
|
| +
|
| +// static
|
| +void BackgroundSyncClientImpl::Create(
|
| + ServiceWorkerGlobalScope* globalScope,
|
| + mojo::InterfaceRequest<mojom::blink::BackgroundSyncServiceClient> request) {
|
| + mojo::MakeStrongBinding(wrapUnique(new BackgroundSyncClientImpl(globalScope)),
|
| + std::move(request));
|
| +}
|
| +
|
| +BackgroundSyncClientImpl::~BackgroundSyncClientImpl() {}
|
| +
|
| +BackgroundSyncClientImpl::BackgroundSyncClientImpl(
|
| + ServiceWorkerGlobalScope* globalScope)
|
| + : m_globalScope(globalScope) {}
|
| +
|
| +void BackgroundSyncClientImpl::Sync(
|
| + const WTF::String& tag,
|
| + mojom::blink::BackgroundSyncEventLastChance lastChance,
|
| + const SyncCallback& callback) {
|
| + DCHECK(!Platform::current()->mainThread()->isCurrentThread());
|
| +
|
| + if (!m_globalScope) {
|
| + callback.Run(mojom::blink::ServiceWorkerEventStatus::ABORTED,
|
| + WTF::currentTime());
|
| + return;
|
| + }
|
| +
|
| + if (!RuntimeEnabledFeatures::backgroundSyncEnabled()) {
|
| + callback.Run(mojom::blink::ServiceWorkerEventStatus::COMPLETED,
|
| + WTF::currentTime());
|
| + return;
|
| + }
|
| +
|
| + WaitUntilObserver* observer = WaitUntilObserver::create(
|
| + m_globalScope, WaitUntilObserver::Sync,
|
| + makeUnique<WTF::Function<void(blink::mojom::ServiceWorkerEventStatus,
|
| + const double&)>>(callback));
|
| +
|
| + Event* event = SyncEvent::create(
|
| + EventTypeNames::sync, tag,
|
| + lastChance == mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE,
|
| + observer);
|
| +
|
| + m_globalScope->dispatchExtendableEvent(event, observer);
|
| +}
|
| +
|
| +} // namespace blink
|
|
|