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

Side by Side Diff: content/renderer/service_worker/embedded_worker_dispatcher.h

Issue 2787883003: [ServiceWorker] Add EmbeddedWorkerInstanceHost Interface. (Closed)
Patch Set: Address comments from shimazu@ Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_DISPATCHER_H_ 5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_DISPATCHER_H_
6 #define CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_DISPATCHER_H_ 6 #define CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_DISPATCHER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/id_map.h" 11 #include "base/id_map.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "content/child/scoped_child_process_reference.h" 15 #include "content/child/scoped_child_process_reference.h"
16 #include "ipc/ipc_listener.h"
17 16
18 namespace blink { 17 namespace blink {
19 18
20 class WebEmbeddedWorker; 19 class WebEmbeddedWorker;
21 20
22 } // namespace blink 21 } // namespace blink
23 22
24 namespace content { 23 namespace content {
25 24
26 class EmbeddedWorkerDevToolsAgent; 25 class EmbeddedWorkerDevToolsAgent;
27 class ServiceWorkerContextClient; 26 class ServiceWorkerContextClient;
28 struct EmbeddedWorkerStartParams; 27 struct EmbeddedWorkerStartParams;
29 28
30 // A tiny dispatcher which handles embedded worker start/stop messages. 29 // A tiny dispatcher which handles embedded worker start/stop messages.
31 class EmbeddedWorkerDispatcher : public IPC::Listener { 30 class EmbeddedWorkerDispatcher {
shimazu 2017/04/10 05:09:22 Sorry for additional comment. EWDispatcher seems n
leonhsl(Using Gerrit) 2017/04/10 06:10:36 Yeah, thank you very much for the confirmation! I
shimazu 2017/04/10 09:33:40 I'm happy if you would remove this class in this C
leonhsl(Using Gerrit) 2017/04/10 09:41:00 Understood, I'd like to do this in this CL :)
32 public: 31 public:
33 EmbeddedWorkerDispatcher(); 32 EmbeddedWorkerDispatcher();
34 ~EmbeddedWorkerDispatcher() override; 33 ~EmbeddedWorkerDispatcher();
35
36 // IPC::Listener overrides.
37 bool OnMessageReceived(const IPC::Message& message) override;
38 34
39 void WorkerContextDestroyed(int embedded_worker_id); 35 void WorkerContextDestroyed(int embedded_worker_id);
40 36
41 private: 37 private:
42 friend class EmbeddedWorkerInstanceClientImpl; 38 friend class EmbeddedWorkerInstanceClientImpl;
43 39
44 // A thin wrapper of WebEmbeddedWorker which also adds and releases process 40 // A thin wrapper of WebEmbeddedWorker which also adds and releases process
45 // references automatically. 41 // references automatically.
46 class WorkerWrapper { 42 class WorkerWrapper {
47 public: 43 public:
48 WorkerWrapper(blink::WebEmbeddedWorker* worker, 44 WorkerWrapper(blink::WebEmbeddedWorker* worker,
49 int devtools_agent_route_id); 45 int devtools_agent_route_id);
50 ~WorkerWrapper(); 46 ~WorkerWrapper();
51 47
52 blink::WebEmbeddedWorker* worker() { return worker_.get(); } 48 blink::WebEmbeddedWorker* worker() { return worker_.get(); }
53 EmbeddedWorkerDevToolsAgent* devtools_agent() { 49 EmbeddedWorkerDevToolsAgent* devtools_agent() {
54 return devtools_agent_.get(); 50 return devtools_agent_.get();
55 } 51 }
56 52
57 private: 53 private:
58 ScopedChildProcessReference process_ref_; 54 ScopedChildProcessReference process_ref_;
59 std::unique_ptr<blink::WebEmbeddedWorker> worker_; 55 std::unique_ptr<blink::WebEmbeddedWorker> worker_;
60 std::unique_ptr<EmbeddedWorkerDevToolsAgent> devtools_agent_; 56 std::unique_ptr<EmbeddedWorkerDevToolsAgent> devtools_agent_;
61 }; 57 };
62 58
63 void OnStopWorker(int embedded_worker_id);
64
65 std::unique_ptr<WorkerWrapper> StartWorkerContext( 59 std::unique_ptr<WorkerWrapper> StartWorkerContext(
66 const EmbeddedWorkerStartParams& params, 60 const EmbeddedWorkerStartParams& params,
67 std::unique_ptr<ServiceWorkerContextClient> context_client); 61 std::unique_ptr<ServiceWorkerContextClient> context_client);
68 62
69 // These methods are used by EmbeddedWorkerInstanceClientImpl to keep 63 // These methods are used by EmbeddedWorkerInstanceClientImpl to keep
70 // consistency between chromium IPC and mojo IPC. 64 // consistency between chromium IPC and mojo IPC.
71 // TODO(shimazu): Remove them after all messages for EmbeddedWorker are 65 // TODO(shimazu): Remove them after all messages for EmbeddedWorker are
72 // replaced by mojo IPC. (Tracking issue: https://crbug.com/629701) 66 // replaced by mojo IPC. (Tracking issue: https://crbug.com/629701)
73 void RegisterWorker(int embedded_worker_id, 67 void RegisterWorker(int embedded_worker_id,
74 std::unique_ptr<WorkerWrapper> wrapper); 68 std::unique_ptr<WorkerWrapper> wrapper);
75 void UnregisterWorker(int embedded_worker_id); 69 void UnregisterWorker(int embedded_worker_id);
76 void RecordStopWorkerTimer(int embedded_worker_id); 70 void RecordStopWorkerTimer(int embedded_worker_id);
77 71
78 IDMap<std::unique_ptr<WorkerWrapper>> workers_; 72 IDMap<std::unique_ptr<WorkerWrapper>> workers_;
79 std::map<int /* embedded_worker_id */, base::TimeTicks> stop_worker_times_; 73 std::map<int /* embedded_worker_id */, base::TimeTicks> stop_worker_times_;
80 base::WeakPtrFactory<EmbeddedWorkerDispatcher> weak_factory_; 74 base::WeakPtrFactory<EmbeddedWorkerDispatcher> weak_factory_;
81 75
82 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDispatcher); 76 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDispatcher);
83 }; 77 };
84 78
85 } // namespace content 79 } // namespace content
86 80
87 #endif // CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_DISPATCHER_H_ 81 #endif // CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698