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

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

Issue 2378073002: Reland of ServiceWorker: Implement StartWorker by using mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 2 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 10
10 #include "base/id_map.h" 11 #include "base/id_map.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "content/child/scoped_child_process_reference.h"
14 #include "content/public/common/console_message_level.h" 16 #include "content/public/common/console_message_level.h"
15 #include "ipc/ipc_listener.h" 17 #include "ipc/ipc_listener.h"
16 18
17 struct EmbeddedWorkerMsg_StartWorker_Params;
18 class GURL; 19 class GURL;
19 20
21 namespace blink {
22
23 class WebEmbeddedWorker;
24
25 } // namespace blink
26
20 namespace content { 27 namespace content {
21 28
29 class EmbeddedWorkerDevToolsAgent;
30 class ServiceWorkerContextClient;
31 struct EmbeddedWorkerStartParams;
32
22 // A tiny dispatcher which handles embedded worker start/stop messages. 33 // A tiny dispatcher which handles embedded worker start/stop messages.
23 class EmbeddedWorkerDispatcher : public IPC::Listener { 34 class EmbeddedWorkerDispatcher : public IPC::Listener {
24 public: 35 public:
25 EmbeddedWorkerDispatcher(); 36 EmbeddedWorkerDispatcher();
26 ~EmbeddedWorkerDispatcher() override; 37 ~EmbeddedWorkerDispatcher() override;
27 38
28 // IPC::Listener overrides. 39 // IPC::Listener overrides.
29 bool OnMessageReceived(const IPC::Message& message) override; 40 bool OnMessageReceived(const IPC::Message& message) override;
30 41
31 void WorkerContextDestroyed(int embedded_worker_id); 42 void WorkerContextDestroyed(int embedded_worker_id);
32 43
33 private: 44 private:
34 class WorkerWrapper; 45 friend class EmbeddedWorkerInstanceClientImpl;
35 46
36 void OnStartWorker(const EmbeddedWorkerMsg_StartWorker_Params& params); 47 // A thin wrapper of WebEmbeddedWorker which also adds and releases process
48 // references automatically.
49 class WorkerWrapper {
50 public:
51 WorkerWrapper(blink::WebEmbeddedWorker* worker,
52 int devtools_agent_route_id);
53 ~WorkerWrapper();
54
55 blink::WebEmbeddedWorker* worker() { return worker_.get(); }
56
57 private:
58 ScopedChildProcessReference process_ref_;
59 std::unique_ptr<blink::WebEmbeddedWorker> worker_;
60 std::unique_ptr<EmbeddedWorkerDevToolsAgent> dev_tools_agent_;
61 };
62
63 void OnStartWorker(const EmbeddedWorkerStartParams& params);
37 void OnStopWorker(int embedded_worker_id); 64 void OnStopWorker(int embedded_worker_id);
38 void OnResumeAfterDownload(int embedded_worker_id); 65 void OnResumeAfterDownload(int embedded_worker_id);
39 void OnAddMessageToConsole(int embedded_worker_id, 66 void OnAddMessageToConsole(int embedded_worker_id,
40 ConsoleMessageLevel level, 67 ConsoleMessageLevel level,
41 const std::string& message); 68 const std::string& message);
42 69
70 std::unique_ptr<WorkerWrapper> StartWorkerContext(
71 const EmbeddedWorkerStartParams& params,
72 std::unique_ptr<ServiceWorkerContextClient> context_client);
73 void RegisterWorker(int embedded_worker_id,
74 std::unique_ptr<WorkerWrapper> wrapper);
75
43 IDMap<WorkerWrapper, IDMapOwnPointer> workers_; 76 IDMap<WorkerWrapper, IDMapOwnPointer> workers_;
44 std::map<int /* embedded_worker_id */, base::TimeTicks> stop_worker_times_; 77 std::map<int /* embedded_worker_id */, base::TimeTicks> stop_worker_times_;
45 base::WeakPtrFactory<EmbeddedWorkerDispatcher> weak_factory_; 78 base::WeakPtrFactory<EmbeddedWorkerDispatcher> weak_factory_;
46 79
47 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDispatcher); 80 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDispatcher);
48 }; 81 };
49 82
50 } // namespace content 83 } // namespace content
51 84
52 #endif // CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_DISPATCHER_H_ 85 #endif // CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_DISPATCHER_H_
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.cc ('k') | content/renderer/service_worker/embedded_worker_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698