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

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

Issue 2227593002: ServiceWorker: Implement StartWorker by using mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added argument check and updated comment and BUILD.gn Created 4 years, 3 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; 19 struct EmbeddedWorkerMsg_StartWorker_Params;
18 class GURL; 20 class GURL;
19 21
22 namespace blink {
23
24 class WebEmbeddedWorker;
25
26 } // namespace blink
27
20 namespace content { 28 namespace content {
21 29
30 class EmbeddedWorkerDevToolsAgent;
31
22 // A tiny dispatcher which handles embedded worker start/stop messages. 32 // A tiny dispatcher which handles embedded worker start/stop messages.
23 class EmbeddedWorkerDispatcher : public IPC::Listener { 33 class EmbeddedWorkerDispatcher : public IPC::Listener {
24 public: 34 public:
25 EmbeddedWorkerDispatcher(); 35 EmbeddedWorkerDispatcher();
26 ~EmbeddedWorkerDispatcher() override; 36 ~EmbeddedWorkerDispatcher() override;
27 37
28 // IPC::Listener overrides. 38 // IPC::Listener overrides.
29 bool OnMessageReceived(const IPC::Message& message) override; 39 bool OnMessageReceived(const IPC::Message& message) override;
30 40
31 void WorkerContextDestroyed(int embedded_worker_id); 41 void WorkerContextDestroyed(int embedded_worker_id);
32 42
33 private: 43 private:
34 class WorkerWrapper; 44 friend class EmbeddedWorkerInstanceClientImpl;
45
46 // A thin wrapper of WebEmbeddedWorker which also adds and releases process
47 // references automatically.
48 class WorkerWrapper {
49 public:
50 WorkerWrapper(blink::WebEmbeddedWorker* worker,
51 int devtools_agent_route_id);
52 ~WorkerWrapper();
53
54 blink::WebEmbeddedWorker* worker() { return worker_.get(); }
55
56 private:
57 ScopedChildProcessReference process_ref_;
58 std::unique_ptr<blink::WebEmbeddedWorker> worker_;
59 std::unique_ptr<EmbeddedWorkerDevToolsAgent> dev_tools_agent_;
60 };
35 61
36 void OnStartWorker(const EmbeddedWorkerMsg_StartWorker_Params& params); 62 void OnStartWorker(const EmbeddedWorkerMsg_StartWorker_Params& params);
37 void OnStopWorker(int embedded_worker_id); 63 void OnStopWorker(int embedded_worker_id);
38 void OnResumeAfterDownload(int embedded_worker_id); 64 void OnResumeAfterDownload(int embedded_worker_id);
39 void OnAddMessageToConsole(int embedded_worker_id, 65 void OnAddMessageToConsole(int embedded_worker_id,
40 ConsoleMessageLevel level, 66 ConsoleMessageLevel level,
41 const std::string& message); 67 const std::string& message);
42 68
69 void RegisterWorker(int embedded_worker_id,
70 std::unique_ptr<WorkerWrapper> wrapper);
71
43 IDMap<WorkerWrapper, IDMapOwnPointer> workers_; 72 IDMap<WorkerWrapper, IDMapOwnPointer> workers_;
44 std::map<int /* embedded_worker_id */, base::TimeTicks> stop_worker_times_; 73 std::map<int /* embedded_worker_id */, base::TimeTicks> stop_worker_times_;
45 base::WeakPtrFactory<EmbeddedWorkerDispatcher> weak_factory_; 74 base::WeakPtrFactory<EmbeddedWorkerDispatcher> weak_factory_;
46 75
47 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDispatcher); 76 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDispatcher);
48 }; 77 };
49 78
50 } // namespace content 79 } // namespace content
51 80
52 #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