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

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

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: Add OWNERS and PRESUBMIT.py 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.h
diff --git a/content/renderer/background_sync/background_sync_client_impl.h b/content/renderer/background_sync/background_sync_client_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..167f055ac6f9b3ff0117ec0b89b7a60467c34abc
--- /dev/null
+++ b/content/renderer/background_sync/background_sync_client_impl.h
@@ -0,0 +1,67 @@
+// 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.
+
+#ifndef CONTENT_RENDERER_BACKGROUND_SYNC_BACKGROUND_SYNC_CLIENT_IMPL_H_
+#define CONTENT_RENDERER_BACKGROUND_SYNC_BACKGROUND_SYNC_CLIENT_IMPL_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "content/common/background_sync_service.mojom.h"
+#include "content/common/content_export.h"
+#include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
+
+namespace content {
+
+// This class implements the mojo service for firing background sync events in a
+// service worker thread. It is constructed and lives on the renderer main
+// thread, but can dispatch to any worker thread to fire events.
+// Return messages from the workers are rerouted to the main thread in order to
michaeln 2015/06/24 02:02:05 Routing everything, coming and going, thru the mai
iclelland 2015/06/24 14:29:30 It is, and I'd like to get rid of it
jkarlin 2015/06/24 14:38:09 Not sure I'm entirely following this. I think you
iclelland 2015/06/24 14:42:05 Right -- so in this case, we're moving *both* endp
+// be sent back over the mojo message channel.
+class CONTENT_EXPORT BackgroundSyncClientImpl
+ : public NON_EXPORTED_BASE(BackgroundSyncServiceClient) {
+ public:
+ static void Create(
+ const scoped_refptr<base::SingleThreadTaskRunner>&
+ main_thread_task_runner,
+ mojo::InterfaceRequest<BackgroundSyncServiceClient> request);
+
+ ~BackgroundSyncClientImpl() override;
+
+ private:
+ using SyncCallback = mojo::Callback<void(ServiceWorkerEventStatus)>;
+ explicit BackgroundSyncClientImpl(
+ const scoped_refptr<base::SingleThreadTaskRunner>&
+ main_thread_task_runner,
+ mojo::InterfaceRequest<BackgroundSyncServiceClient> request);
+
+ // BackgroundSyncClient methods:
+ void Sync(content::SyncRegistrationPtr registration,
+ int thread_id,
+ const SyncCallback& callback) override;
+
+ static void DispatchSyncOnWorkerThread(
+ const scoped_refptr<base::SingleThreadTaskRunner>&
+ main_thread_task_runner,
+ content::SyncRegistrationPtr event,
+ const SyncCallback& callback);
+ static void OnSyncCompleteOnWorkerThread(
+ const scoped_refptr<base::SingleThreadTaskRunner>&
+ main_thread_task_runner,
+ const SyncCallback& callback,
+ ServiceWorkerEventStatus status);
+ static void OnSyncCompleteOnMainThread(const SyncCallback& callback,
+ ServiceWorkerEventStatus status);
+
+ mojo::StrongBinding<BackgroundSyncServiceClient> binding_;
+
+ scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
+
+ base::WeakPtrFactory<BackgroundSyncClientImpl> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(BackgroundSyncClientImpl);
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_BACKGROUND_SYNC_BACKGROUND_SYNC_CLIENT_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698