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

Unified Diff: content/child/background_sync/background_sync_provider_thread_proxy.cc

Issue 1104283002: [Background Sync] Add renderer code to interface between JS API and back-end service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bgsync-mojo
Patch Set: Updates based on recent changes to mojo definitions. 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 side-by-side diff with in-line comments
Download patch
Index: content/child/background_sync/background_sync_provider_thread_proxy.cc
diff --git a/content/child/background_sync/background_sync_provider_thread_proxy.cc b/content/child/background_sync/background_sync_provider_thread_proxy.cc
new file mode 100644
index 0000000000000000000000000000000000000000..35ff78eddce2211c71117210643ca21d4f21abd2
--- /dev/null
+++ b/content/child/background_sync/background_sync_provider_thread_proxy.cc
@@ -0,0 +1,129 @@
+// Copyright 2015 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 "content/child/background_sync/background_sync_provider_thread_proxy.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/lazy_instance.h"
+#include "base/location.h"
+#include "base/single_thread_task_runner.h"
+#include "base/threading/thread_local.h"
+#include "content/child/background_sync/background_sync_provider.h"
+
+using base::LazyInstance;
+using base::ThreadLocalPointer;
+
+namespace content {
+
+namespace {
+
+LazyInstance<ThreadLocalPointer<BackgroundSyncProviderThreadProxy>>::Leaky
+ g_sync_provider_tls = LAZY_INSTANCE_INITIALIZER;
+
+} // anonymous namespace
+
+BackgroundSyncProviderThreadProxy*
+BackgroundSyncProviderThreadProxy::GetThreadInstance(
+ base::SingleThreadTaskRunner* main_thread_task_runner,
+ BackgroundSyncProvider* sync_provider) {
+ if (g_sync_provider_tls.Pointer()->Get())
+ return g_sync_provider_tls.Pointer()->Get();
+
+ BackgroundSyncProviderThreadProxy* instance =
+ new BackgroundSyncProviderThreadProxy(main_thread_task_runner,
+ sync_provider);
+ DCHECK(WorkerTaskRunner::Instance()->CurrentWorkerId());
+ WorkerTaskRunner::Instance()->AddStopObserver(instance);
+ return instance;
+}
+
+void BackgroundSyncProviderThreadProxy::registerBackgroundSync(
+ const blink::WebSyncRegistration* options,
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebSyncRegistrationCallbacks* callbacks) {
+ DCHECK(options);
+ DCHECK(service_worker_registration);
+ DCHECK(callbacks);
+ main_thread_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&BackgroundSyncProvider::RegisterBackgroundSyncForWorker,
+ base::Unretained(sync_provider_),
+ options,
+ service_worker_registration,
+ base::Unretained(callbacks),
+ WorkerTaskRunner::Instance()->CurrentWorkerId()));
+}
+
+void BackgroundSyncProviderThreadProxy::unregisterBackgroundSync(
+ blink::WebSyncRegistration::Periodicity periodicity,
+ int64_t id,
+ const blink::WebString& tag,
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebSyncUnregistrationCallbacks* callbacks) {
+ DCHECK(service_worker_registration);
+ DCHECK(callbacks);
+ main_thread_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&BackgroundSyncProvider::UnregisterBackgroundSyncForWorker,
+ base::Unretained(sync_provider_),
+ periodicity,
+ id,
+ tag,
+ service_worker_registration,
+ base::Unretained(callbacks),
+ WorkerTaskRunner::Instance()->CurrentWorkerId()));
+}
+
+void BackgroundSyncProviderThreadProxy::getRegistration(
+ blink::WebSyncRegistration::Periodicity periodicity,
+ const blink::WebString& tag,
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebSyncRegistrationCallbacks* callbacks) {
+ DCHECK(service_worker_registration);
+ DCHECK(callbacks);
+ main_thread_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&BackgroundSyncProvider::GetRegistrationForWorker,
+ base::Unretained(sync_provider_),
+ periodicity,
+ tag,
+ service_worker_registration,
+ base::Unretained(callbacks),
+ WorkerTaskRunner::Instance()->CurrentWorkerId()));
+}
+
+void BackgroundSyncProviderThreadProxy::getRegistrations(
+ blink::WebSyncRegistration::Periodicity periodicity,
+ blink::WebServiceWorkerRegistration* service_worker_registration,
+ blink::WebSyncGetRegistrationsCallbacks* callbacks) {
+ DCHECK(service_worker_registration);
+ DCHECK(callbacks);
+ main_thread_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&BackgroundSyncProvider::GetRegistrationsForWorker,
+ base::Unretained(sync_provider_),
+ periodicity,
+ service_worker_registration,
+ base::Unretained(callbacks),
+ WorkerTaskRunner::Instance()->CurrentWorkerId()));
+}
+
+void BackgroundSyncProviderThreadProxy::OnWorkerRunLoopStopped() {
+ delete this;
+}
+
+BackgroundSyncProviderThreadProxy::BackgroundSyncProviderThreadProxy(
+ base::SingleThreadTaskRunner* main_thread_task_runner,
+ BackgroundSyncProvider* sync_provider)
+ : main_thread_task_runner_(main_thread_task_runner),
+ sync_provider_(sync_provider) {
+ g_sync_provider_tls.Pointer()->Set(this);
+}
+
+BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() {
+ g_sync_provider_tls.Pointer()->Set(nullptr);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698