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

Side by Side Diff: content/browser/devtools/worker_devtools_agent_host.cc

Issue 1408363004: [DevTools] Filter any messages from previous sessions in DevToolsAgentHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/browser/devtools/worker_devtools_agent_host.h" 5 #include "content/browser/devtools/worker_devtools_agent_host.h"
6 6
7 #include "content/browser/devtools/devtools_protocol_handler.h" 7 #include "content/browser/devtools/devtools_protocol_handler.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/render_process_host.h" 9 #include "content/public/browser/render_process_host.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 BrowserContext* WorkerDevToolsAgentHost::GetBrowserContext() { 13 BrowserContext* WorkerDevToolsAgentHost::GetBrowserContext() {
14 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); 14 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first);
15 return rph ? rph->GetBrowserContext() : nullptr; 15 return rph ? rph->GetBrowserContext() : nullptr;
16 } 16 }
17 17
18 void WorkerDevToolsAgentHost::Attach() { 18 void WorkerDevToolsAgentHost::Attach() {
19 if (state_ != WORKER_INSPECTED) { 19 if (state_ != WORKER_INSPECTED) {
20 state_ = WORKER_INSPECTED; 20 state_ = WORKER_INSPECTED;
21 AttachToWorker(); 21 AttachToWorker();
22 } 22 }
23 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) 23 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
24 host->Send(new DevToolsAgentMsg_Attach(worker_id_.second, GetId())); 24 host->Send(
25 new DevToolsAgentMsg_Attach(worker_id_.second, GetId(), session_id()));
25 OnAttachedStateChanged(true); 26 OnAttachedStateChanged(true);
26 DevToolsAgentHostImpl::NotifyCallbacks(this, true); 27 DevToolsAgentHostImpl::NotifyCallbacks(this, true);
27 } 28 }
28 29
29 void WorkerDevToolsAgentHost::Detach() { 30 void WorkerDevToolsAgentHost::Detach() {
30 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) 31 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
31 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second)); 32 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second));
32 OnAttachedStateChanged(false); 33 OnAttachedStateChanged(false);
33 if (state_ == WORKER_INSPECTED) { 34 if (state_ == WORKER_INSPECTED) {
34 state_ = WORKER_UNINSPECTED; 35 state_ = WORKER_UNINSPECTED;
35 DetachFromWorker(); 36 DetachFromWorker();
36 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { 37 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) {
37 state_ = WORKER_UNINSPECTED; 38 state_ = WORKER_UNINSPECTED;
38 } 39 }
39 DevToolsAgentHostImpl::NotifyCallbacks(this, false); 40 DevToolsAgentHostImpl::NotifyCallbacks(this, false);
40 } 41 }
41 42
42 bool WorkerDevToolsAgentHost::DispatchProtocolMessage( 43 bool WorkerDevToolsAgentHost::DispatchProtocolMessage(
43 const std::string& message) { 44 const std::string& message) {
44 if (state_ != WORKER_INSPECTED) 45 if (state_ != WORKER_INSPECTED)
45 return true; 46 return true;
46 47
47 int call_id; 48 int call_id;
48 if (protocol_handler_->HandleOptionalMessage(message, &call_id)) 49 if (protocol_handler_->HandleOptionalMessage(session_id(), message, &call_id))
49 return true; 50 return true;
50 51
51 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { 52 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) {
52 host->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( 53 host->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend(
53 worker_id_.second, message)); 54 worker_id_.second, session_id(), message));
54 } 55 }
55 return true; 56 return true;
56 } 57 }
57 58
58 bool WorkerDevToolsAgentHost::OnMessageReceived( 59 bool WorkerDevToolsAgentHost::OnMessageReceived(
59 const IPC::Message& msg) { 60 const IPC::Message& msg) {
60 DCHECK_CURRENTLY_ON(BrowserThread::UI); 61 DCHECK_CURRENTLY_ON(BrowserThread::UI);
61 bool handled = true; 62 bool handled = true;
62 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentHost, msg) 63 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentHost, msg)
63 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, 64 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend,
(...skipping 12 matching lines...) Expand all
76 return state_ == WORKER_PAUSED_FOR_DEBUG_ON_START; 77 return state_ == WORKER_PAUSED_FOR_DEBUG_ON_START;
77 } 78 }
78 79
79 void WorkerDevToolsAgentHost::WorkerReadyForInspection() { 80 void WorkerDevToolsAgentHost::WorkerReadyForInspection() {
80 if (state_ == WORKER_PAUSED_FOR_REATTACH) { 81 if (state_ == WORKER_PAUSED_FOR_REATTACH) {
81 DCHECK(IsAttached()); 82 DCHECK(IsAttached());
82 state_ = WORKER_INSPECTED; 83 state_ = WORKER_INSPECTED;
83 AttachToWorker(); 84 AttachToWorker();
84 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { 85 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) {
85 host->Send(new DevToolsAgentMsg_Reattach( 86 host->Send(new DevToolsAgentMsg_Reattach(
86 worker_id_.second, GetId(), chunk_processor_.state_cookie())); 87 worker_id_.second, GetId(), session_id(),
88 chunk_processor_.state_cookie()));
87 } 89 }
88 OnAttachedStateChanged(true); 90 OnAttachedStateChanged(true);
89 } 91 }
90 } 92 }
91 93
92 void WorkerDevToolsAgentHost::WorkerRestarted(WorkerId worker_id) { 94 void WorkerDevToolsAgentHost::WorkerRestarted(WorkerId worker_id) {
93 DCHECK_EQ(WORKER_TERMINATED, state_); 95 DCHECK_EQ(WORKER_TERMINATED, state_);
94 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; 96 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED;
95 worker_id_ = worker_id; 97 worker_id_ = worker_id;
96 WorkerCreated(); 98 WorkerCreated();
97 } 99 }
98 100
99 void WorkerDevToolsAgentHost::WorkerDestroyed() { 101 void WorkerDevToolsAgentHost::WorkerDestroyed() {
100 DCHECK_NE(WORKER_TERMINATED, state_); 102 DCHECK_NE(WORKER_TERMINATED, state_);
101 if (state_ == WORKER_INSPECTED) { 103 if (state_ == WORKER_INSPECTED) {
102 DCHECK(IsAttached()); 104 DCHECK(IsAttached());
103 // Client host is debugging this worker agent host. 105 // Client host is debugging this worker agent host.
104 base::Callback<void(const std::string&)> raw_message_callback( 106 devtools::inspector::Client inspector(this);
105 base::Bind(&WorkerDevToolsAgentHost::SendMessageToClient,
106 base::Unretained(this)));
107 devtools::inspector::Client inspector(raw_message_callback);
108 inspector.TargetCrashed( 107 inspector.TargetCrashed(
109 devtools::inspector::TargetCrashedParams::Create()); 108 devtools::inspector::TargetCrashedParams::Create());
110 DetachFromWorker(); 109 DetachFromWorker();
111 } 110 }
112 state_ = WORKER_TERMINATED; 111 state_ = WORKER_TERMINATED;
113 Release(); // Balanced in WorkerCreated(). 112 Release(); // Balanced in WorkerCreated().
114 } 113 }
115 114
116 bool WorkerDevToolsAgentHost::IsTerminated() { 115 bool WorkerDevToolsAgentHost::IsTerminated() {
117 return state_ == WORKER_TERMINATED; 116 return state_ == WORKER_TERMINATED;
118 } 117 }
119 118
120 WorkerDevToolsAgentHost::WorkerDevToolsAgentHost( 119 WorkerDevToolsAgentHost::WorkerDevToolsAgentHost(WorkerId worker_id)
121 WorkerId worker_id) 120 : protocol_handler_(new DevToolsProtocolHandler(this)),
122 : protocol_handler_(new DevToolsProtocolHandler( 121 chunk_processor_(base::Bind(&WorkerDevToolsAgentHost::SendMessageToClient,
123 this, 122 base::Unretained(this))),
124 base::Bind(&WorkerDevToolsAgentHost::SendMessageToClient,
125 base::Unretained(this)))),
126 chunk_processor_(
127 base::Bind(&WorkerDevToolsAgentHost::SendMessageToClient,
128 base::Unretained(this))),
129 state_(WORKER_UNINSPECTED), 123 state_(WORKER_UNINSPECTED),
130 worker_id_(worker_id) { 124 worker_id_(worker_id) {
131 WorkerCreated(); 125 WorkerCreated();
132 } 126 }
133 127
134 WorkerDevToolsAgentHost::~WorkerDevToolsAgentHost() { 128 WorkerDevToolsAgentHost::~WorkerDevToolsAgentHost() {
135 DCHECK_EQ(WORKER_TERMINATED, state_); 129 DCHECK_EQ(WORKER_TERMINATED, state_);
136 } 130 }
137 131
138 void WorkerDevToolsAgentHost::OnAttachedStateChanged(bool attached) { 132 void WorkerDevToolsAgentHost::OnAttachedStateChanged(bool attached) {
(...skipping 15 matching lines...) Expand all
154 148
155 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( 149 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend(
156 const DevToolsMessageChunk& message) { 150 const DevToolsMessageChunk& message) {
157 if (!IsAttached()) 151 if (!IsAttached())
158 return; 152 return;
159 153
160 chunk_processor_.ProcessChunkedMessageFromAgent(message); 154 chunk_processor_.ProcessChunkedMessageFromAgent(message);
161 } 155 }
162 156
163 } // namespace content 157 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/render_frame_devtools_agent_host.cc ('k') | content/child/shared_worker_devtools_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698