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

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

Issue 251723002: Introduce EmbeddedWorkerDevToolsAgent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 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 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" 5 #include "content/renderer/service_worker/embedded_worker_dispatcher.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string16.h" 8 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/child/child_process.h" 10 #include "content/child/child_process.h"
11 #include "content/child/scoped_child_process_reference.h" 11 #include "content/child/scoped_child_process_reference.h"
12 #include "content/child/thread_safe_sender.h" 12 #include "content/child/thread_safe_sender.h"
13 #include "content/child/worker_task_runner.h" 13 #include "content/child/worker_task_runner.h"
14 #include "content/common/devtools_messages.h"
14 #include "content/common/service_worker/embedded_worker_messages.h" 15 #include "content/common/service_worker/embedded_worker_messages.h"
15 #include "content/public/common/content_client.h" 16 #include "content/public/common/content_client.h"
16 #include "content/renderer/render_thread_impl.h" 17 #include "content/renderer/render_thread_impl.h"
17 #include "content/renderer/service_worker/embedded_worker_context_client.h" 18 #include "content/renderer/service_worker/embedded_worker_context_client.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 19 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/platform/WebURL.h" 20 #include "third_party/WebKit/public/platform/WebURL.h"
20 #include "third_party/WebKit/public/web/WebEmbeddedWorker.h" 21 #include "third_party/WebKit/public/web/WebEmbeddedWorker.h"
21 #include "third_party/WebKit/public/web/WebEmbeddedWorkerStartData.h" 22 #include "third_party/WebKit/public/web/WebEmbeddedWorkerStartData.h"
22 23
23 namespace content { 24 namespace content {
24 25
25 // A thin wrapper of WebEmbeddedWorker which also adds and releases process 26 // A thin wrapper of WebEmbeddedWorker which also adds and releases process
26 // references automatically. 27 // references automatically.
27 class EmbeddedWorkerDispatcher::WorkerWrapper { 28 class EmbeddedWorkerDispatcher::WorkerWrapper {
kinuko 2014/04/28 07:25:56 Now that it also handles messages the comment and
horo 2014/04/28 08:33:09 Done. Added EmbeddedWorkerDevToolsAgent.
28 public: 29 public:
29 explicit WorkerWrapper(blink::WebEmbeddedWorker* worker) : worker_(worker) {} 30 explicit WorkerWrapper(blink::WebEmbeddedWorker* worker) : worker_(worker) {}
30 ~WorkerWrapper() {} 31 ~WorkerWrapper() {}
31 32
32 blink::WebEmbeddedWorker* worker() { return worker_.get(); } 33 blink::WebEmbeddedWorker* worker() { return worker_.get(); }
34 void OnMessageReceived(const IPC::Message& message);
33 35
34 private: 36 private:
37 void OnAttachDevTools();
38 void OnReattachDevTools(const std::string& state);
39 void OnDetachDevTools();
40 void OnDispatchOnInspectorBackend(const std::string& message);
41 void OnResumeWorkerContext();
42
35 ScopedChildProcessReference process_ref_; 43 ScopedChildProcessReference process_ref_;
36 scoped_ptr<blink::WebEmbeddedWorker> worker_; 44 scoped_ptr<blink::WebEmbeddedWorker> worker_;
37 }; 45 };
38 46
47 void EmbeddedWorkerDispatcher::WorkerWrapper::OnMessageReceived(
48 const IPC::Message& message) {
49 IPC_BEGIN_MESSAGE_MAP(WorkerWrapper, message)
50 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttachDevTools)
51 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Reattach, OnReattachDevTools)
52 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetachDevTools)
53 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend,
54 OnDispatchOnInspectorBackend)
55 IPC_MESSAGE_HANDLER(DevToolsAgentMsg_ResumeWorkerContext,
56 OnResumeWorkerContext)
57 IPC_END_MESSAGE_MAP()
58 }
59
60 void EmbeddedWorkerDispatcher::WorkerWrapper::OnAttachDevTools() {
61 worker_->attachDevTools();
62 }
63
64 void EmbeddedWorkerDispatcher::WorkerWrapper::OnReattachDevTools(
65 const std::string& state) {
66 worker_->reattachDevTools(blink::WebString::fromUTF8(state));
67 }
68
69 void EmbeddedWorkerDispatcher::WorkerWrapper::OnDetachDevTools() {
70 worker_->detachDevTools();
71 }
72
73 void EmbeddedWorkerDispatcher::WorkerWrapper::OnDispatchOnInspectorBackend(
74 const std::string& message) {
75 worker_->dispatchDevToolsMessage(blink::WebString::fromUTF8(message));
76 }
77
78 void EmbeddedWorkerDispatcher::WorkerWrapper::OnResumeWorkerContext() {
79 worker_->resumeWorkerContext();
80 }
81
39 EmbeddedWorkerDispatcher::EmbeddedWorkerDispatcher() : weak_factory_(this) {} 82 EmbeddedWorkerDispatcher::EmbeddedWorkerDispatcher() : weak_factory_(this) {}
40 83
41 EmbeddedWorkerDispatcher::~EmbeddedWorkerDispatcher() {} 84 EmbeddedWorkerDispatcher::~EmbeddedWorkerDispatcher() {}
42 85
43 bool EmbeddedWorkerDispatcher::OnMessageReceived( 86 bool EmbeddedWorkerDispatcher::OnMessageReceived(
44 const IPC::Message& message) { 87 const IPC::Message& message) {
45 bool handled = true; 88 bool handled = true;
46 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerDispatcher, message) 89 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerDispatcher, message)
47 IPC_MESSAGE_HANDLER(EmbeddedWorkerMsg_StartWorker, OnStartWorker) 90 IPC_MESSAGE_HANDLER(EmbeddedWorkerMsg_StartWorker, OnStartWorker)
48 IPC_MESSAGE_HANDLER(EmbeddedWorkerMsg_StopWorker, OnStopWorker) 91 IPC_MESSAGE_HANDLER(EmbeddedWorkerMsg_StopWorker, OnStopWorker)
92 IPC_MESSAGE_HANDLER(EmbeddedWorkerMsg_MessageToWorker,
93 OnMessageToWorker)
49 IPC_MESSAGE_UNHANDLED(handled = false) 94 IPC_MESSAGE_UNHANDLED(handled = false)
50 IPC_END_MESSAGE_MAP() 95 IPC_END_MESSAGE_MAP()
51 return handled; 96 return handled;
52 } 97 }
53 98
54 void EmbeddedWorkerDispatcher::WorkerContextDestroyed( 99 void EmbeddedWorkerDispatcher::WorkerContextDestroyed(
55 int embedded_worker_id) { 100 int embedded_worker_id) {
56 RenderThreadImpl::current()->thread_safe_sender()->Send( 101 RenderThreadImpl::current()->thread_safe_sender()->Send(
57 new EmbeddedWorkerHostMsg_WorkerStopped(embedded_worker_id)); 102 new EmbeddedWorkerHostMsg_WorkerStopped(embedded_worker_id));
58 workers_.Remove(embedded_worker_id); 103 workers_.Remove(embedded_worker_id);
(...skipping 28 matching lines...) Expand all
87 LOG(WARNING) << "Got OnStopWorker for nonexistent worker"; 132 LOG(WARNING) << "Got OnStopWorker for nonexistent worker";
88 return; 133 return;
89 } 134 }
90 135
91 // This should eventually call WorkerContextDestroyed. (We may need to post 136 // This should eventually call WorkerContextDestroyed. (We may need to post
92 // a delayed task to forcibly abort the worker context if we find it 137 // a delayed task to forcibly abort the worker context if we find it
93 // necessary) 138 // necessary)
94 wrapper->worker()->terminateWorkerContext(); 139 wrapper->worker()->terminateWorkerContext();
95 } 140 }
96 141
142 void EmbeddedWorkerDispatcher::OnMessageToWorker(
143 int embedded_worker_id,
144 const IPC::Message& message) {
145 WorkerWrapper* wrapper = workers_.Lookup(embedded_worker_id);
146 if (!wrapper) {
147 LOG(WARNING) << "Got OnMessageToWorker for nonexistent worker";
148 return;
149 }
150 wrapper->OnMessageReceived(message);
151 }
152
97 } // namespace content 153 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698