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

Unified Diff: content/renderer/background_sync/background_sync_client_impl.cc

Issue 1171173002: [Background Sync] Use Mojo IPC to fire background sync events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove Chromium IPC for Sync from unit tests' Created 5 years, 6 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/renderer/background_sync/background_sync_client_impl.cc
diff --git a/content/renderer/background_sync/background_sync_client_impl.cc b/content/renderer/background_sync/background_sync_client_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..de28fb02f8d2d5980e16003e983fdc76de260b1b
--- /dev/null
+++ b/content/renderer/background_sync/background_sync_client_impl.cc
@@ -0,0 +1,86 @@
+// 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/renderer/background_sync/background_sync_client_impl.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/memory/weak_ptr.h"
+#include "content/child/worker_task_runner.h"
+#include "content/renderer/service_worker/service_worker_context_client.h"
+
+namespace content {
+
+// static
+void BackgroundSyncClientImpl::Create(
+ const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner,
+ mojo::InterfaceRequest<BackgroundSyncServiceClient> request) {
+ new BackgroundSyncClientImpl(main_thread_task_runner, request.Pass());
+}
+
+BackgroundSyncClientImpl::~BackgroundSyncClientImpl() {
+}
+
+BackgroundSyncClientImpl::BackgroundSyncClientImpl(
+ const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner,
+ mojo::InterfaceRequest<BackgroundSyncServiceClient> request)
+ : binding_(this, request.Pass()),
+ main_thread_task_runner_(main_thread_task_runner),
+ weak_ptr_factory_(this) {
+ DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread());
+}
+
+void BackgroundSyncClientImpl::Sync(content::SyncRegistrationPtr registration,
+ int thread_id,
+ const SyncCallback& callback) {
+ DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread());
+
+ WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance();
+ if (!worker_task_runner ||
+ !worker_task_runner->GetTaskRunnerFor(thread_id)->PostTask(
+ FROM_HERE,
+ base::Bind(&BackgroundSyncClientImpl::DispatchSyncOnWorkerThread,
+ main_thread_task_runner_,
+ base::Passed(registration.Pass()), callback))) {
+ callback.Run(SERVICE_WORKER_EVENT_STATUS_ABORTED);
+ }
+}
+
+// static
+void BackgroundSyncClientImpl::DispatchSyncOnWorkerThread(
+ const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner,
+ content::SyncRegistrationPtr registration,
+ const SyncCallback& callback) {
+ ServiceWorkerContextClient* client =
+ ServiceWorkerContextClient::ThreadSpecificInstance();
+ if (!client) {
+ OnSyncCompleteOnWorkerThread(main_thread_task_runner, callback,
+ SERVICE_WORKER_EVENT_STATUS_ABORTED);
+ return;
+ }
+ client->DispatchSyncEvent(
+ base::Bind(&BackgroundSyncClientImpl::OnSyncCompleteOnWorkerThread,
+ main_thread_task_runner, callback));
+}
+
+// static
+void BackgroundSyncClientImpl::OnSyncCompleteOnWorkerThread(
+ const scoped_refptr<base::SingleThreadTaskRunner>& main_thread_task_runner,
+ const SyncCallback& callback,
+ ServiceWorkerEventStatus status) {
+ // Run callback on main thread
+ main_thread_task_runner->PostTask(
+ FROM_HERE,
+ base::Bind(&BackgroundSyncClientImpl::OnSyncCompleteOnMainThread,
+ callback, status));
+}
+
+// static
+void BackgroundSyncClientImpl::OnSyncCompleteOnMainThread(
+ const SyncCallback& callback,
+ ServiceWorkerEventStatus status) {
+ callback.Run(status);
+}
+
+} // namespace content
« no previous file with comments | « content/renderer/background_sync/background_sync_client_impl.h ('k') | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698