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

Side by Side 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: Addressing review comments on event dispatcher 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 #ifndef CONTENT_RENDERER_BACKGROUND_SYNC_BACKGROUND_SYNC_CLIENT_IMPL_H_
6 #define CONTENT_RENDERER_BACKGROUND_SYNC_BACKGROUND_SYNC_CLIENT_IMPL_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/common/background_sync_service.mojom.h"
11 #include "content/common/content_export.h"
12 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
13
14 namespace content {
15
16 using SyncCallback = mojo::Callback<void(ServiceWorkerEventStatus)>;
17
18 // This class implements the mojo service for firing background sync events in a
19 // service worker thread. It is constructed and lives on the renderer main
20 // thread, but can dispatch to any worker thread to fire events.
21 // Return messages from the workers are rerouted to the main thread in order to
22 // be sent back over the mojo message channel.
23 class CONTENT_EXPORT BackgroundSyncClientImpl
24 : public NON_EXPORTED_BASE(BackgroundSyncServiceClient) {
25 public:
26 static void Create(
27 const scoped_refptr<base::SingleThreadTaskRunner>&
28 main_thread_task_runner,
29 mojo::InterfaceRequest<BackgroundSyncServiceClient> request);
30
31 ~BackgroundSyncClientImpl() override;
32
33 private:
34 explicit BackgroundSyncClientImpl(
35 const scoped_refptr<base::SingleThreadTaskRunner>&
36 main_thread_task_runner,
37 mojo::InterfaceRequest<BackgroundSyncServiceClient> request);
38
39 // BackgroundSyncClient methods:
40 void Sync(content::SyncRegistrationPtr registration,
41 int thread_id,
42 const SyncCallback& callback) override;
43
44 static void DispatchSyncForWorker(
45 const scoped_refptr<base::SingleThreadTaskRunner>&
46 main_thread_task_runner,
47 content::SyncRegistrationPtr event,
48 const SyncCallback& callback);
49 static void OnSyncComplete(const scoped_refptr<base::SingleThreadTaskRunner>&
50 main_thread_task_runner,
51 const SyncCallback& callback,
52 ServiceWorkerEventStatus status);
53 static void OnSyncCompleteOnMainThread(const SyncCallback& callback,
54 ServiceWorkerEventStatus status);
55
56 mojo::StrongBinding<BackgroundSyncServiceClient> binding_;
57
58 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
59
60 base::WeakPtrFactory<BackgroundSyncClientImpl> weak_ptr_factory_;
61
62 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncClientImpl);
63 };
64
65 } // namespace content
66
67 #endif // CONTENT_RENDERER_BACKGROUND_SYNC_BACKGROUND_SYNC_CLIENT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698