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

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

Issue 1437993003: Revert of [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( 24 host->Send(new DevToolsAgentMsg_Attach(worker_id_.second, GetId()));
25 new DevToolsAgentMsg_Attach(worker_id_.second, GetId(), session_id()));
26 OnAttachedStateChanged(true); 25 OnAttachedStateChanged(true);
27 DevToolsAgentHostImpl::NotifyCallbacks(this, true); 26 DevToolsAgentHostImpl::NotifyCallbacks(this, true);
28 } 27 }
29 28
30 void WorkerDevToolsAgentHost::Detach() { 29 void WorkerDevToolsAgentHost::Detach() {
31 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) 30 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first))
32 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second)); 31 host->Send(new DevToolsAgentMsg_Detach(worker_id_.second));
33 OnAttachedStateChanged(false); 32 OnAttachedStateChanged(false);
34 if (state_ == WORKER_INSPECTED) { 33 if (state_ == WORKER_INSPECTED) {
35 state_ = WORKER_UNINSPECTED; 34 state_ = WORKER_UNINSPECTED;
36 DetachFromWorker(); 35 DetachFromWorker();
37 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { 36 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) {
38 state_ = WORKER_UNINSPECTED; 37 state_ = WORKER_UNINSPECTED;
39 } 38 }
40 DevToolsAgentHostImpl::NotifyCallbacks(this, false); 39 DevToolsAgentHostImpl::NotifyCallbacks(this, false);
41 } 40 }
42 41
43 bool WorkerDevToolsAgentHost::DispatchProtocolMessage( 42 bool WorkerDevToolsAgentHost::DispatchProtocolMessage(
44 const std::string& message) { 43 const std::string& message) {
45 if (state_ != WORKER_INSPECTED) 44 if (state_ != WORKER_INSPECTED)
46 return true; 45 return true;
47 46
48 int call_id; 47 int call_id;
49 if (protocol_handler_->HandleOptionalMessage(session_id(), message, &call_id)) 48 if (protocol_handler_->HandleOptionalMessage(message, &call_id))
50 return true; 49 return true;
51 50
52 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { 51 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) {
53 host->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend( 52 host->Send(new DevToolsAgentMsg_DispatchOnInspectorBackend(
54 worker_id_.second, session_id(), message)); 53 worker_id_.second, message));
55 } 54 }
56 return true; 55 return true;
57 } 56 }
58 57
59 bool WorkerDevToolsAgentHost::OnMessageReceived( 58 bool WorkerDevToolsAgentHost::OnMessageReceived(
60 const IPC::Message& msg) { 59 const IPC::Message& msg) {
61 DCHECK_CURRENTLY_ON(BrowserThread::UI); 60 DCHECK_CURRENTLY_ON(BrowserThread::UI);
62 bool handled = true; 61 bool handled = true;
63 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentHost, msg) 62 IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentHost, msg)
64 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, 63 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend,
(...skipping 12 matching lines...) Expand all
77 return state_ == WORKER_PAUSED_FOR_DEBUG_ON_START; 76 return state_ == WORKER_PAUSED_FOR_DEBUG_ON_START;
78 } 77 }
79 78
80 void WorkerDevToolsAgentHost::WorkerReadyForInspection() { 79 void WorkerDevToolsAgentHost::WorkerReadyForInspection() {
81 if (state_ == WORKER_PAUSED_FOR_REATTACH) { 80 if (state_ == WORKER_PAUSED_FOR_REATTACH) {
82 DCHECK(IsAttached()); 81 DCHECK(IsAttached());
83 state_ = WORKER_INSPECTED; 82 state_ = WORKER_INSPECTED;
84 AttachToWorker(); 83 AttachToWorker();
85 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) { 84 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) {
86 host->Send(new DevToolsAgentMsg_Reattach( 85 host->Send(new DevToolsAgentMsg_Reattach(
87 worker_id_.second, GetId(), session_id(), 86 worker_id_.second, GetId(), chunk_processor_.state_cookie()));
88 chunk_processor_.state_cookie()));
89 } 87 }
90 OnAttachedStateChanged(true); 88 OnAttachedStateChanged(true);
91 } 89 }
92 } 90 }
93 91
94 void WorkerDevToolsAgentHost::WorkerRestarted(WorkerId worker_id) { 92 void WorkerDevToolsAgentHost::WorkerRestarted(WorkerId worker_id) {
95 DCHECK_EQ(WORKER_TERMINATED, state_); 93 DCHECK_EQ(WORKER_TERMINATED, state_);
96 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED; 94 state_ = IsAttached() ? WORKER_PAUSED_FOR_REATTACH : WORKER_UNINSPECTED;
97 worker_id_ = worker_id; 95 worker_id_ = worker_id;
98 WorkerCreated(); 96 WorkerCreated();
99 } 97 }
100 98
101 void WorkerDevToolsAgentHost::WorkerDestroyed() { 99 void WorkerDevToolsAgentHost::WorkerDestroyed() {
102 DCHECK_NE(WORKER_TERMINATED, state_); 100 DCHECK_NE(WORKER_TERMINATED, state_);
103 if (state_ == WORKER_INSPECTED) { 101 if (state_ == WORKER_INSPECTED) {
104 DCHECK(IsAttached()); 102 DCHECK(IsAttached());
105 // Client host is debugging this worker agent host. 103 // Client host is debugging this worker agent host.
106 devtools::inspector::Client inspector(this); 104 base::Callback<void(const std::string&)> raw_message_callback(
105 base::Bind(&WorkerDevToolsAgentHost::SendMessageToClient,
106 base::Unretained(this)));
107 devtools::inspector::Client inspector(raw_message_callback);
107 inspector.TargetCrashed( 108 inspector.TargetCrashed(
108 devtools::inspector::TargetCrashedParams::Create()); 109 devtools::inspector::TargetCrashedParams::Create());
109 DetachFromWorker(); 110 DetachFromWorker();
110 } 111 }
111 state_ = WORKER_TERMINATED; 112 state_ = WORKER_TERMINATED;
112 Release(); // Balanced in WorkerCreated(). 113 Release(); // Balanced in WorkerCreated().
113 } 114 }
114 115
115 bool WorkerDevToolsAgentHost::IsTerminated() { 116 bool WorkerDevToolsAgentHost::IsTerminated() {
116 return state_ == WORKER_TERMINATED; 117 return state_ == WORKER_TERMINATED;
117 } 118 }
118 119
119 WorkerDevToolsAgentHost::WorkerDevToolsAgentHost(WorkerId worker_id) 120 WorkerDevToolsAgentHost::WorkerDevToolsAgentHost(
120 : protocol_handler_(new DevToolsProtocolHandler(this)), 121 WorkerId worker_id)
121 chunk_processor_(base::Bind(&WorkerDevToolsAgentHost::SendMessageToClient, 122 : protocol_handler_(new DevToolsProtocolHandler(
122 base::Unretained(this))), 123 this,
124 base::Bind(&WorkerDevToolsAgentHost::SendMessageToClient,
125 base::Unretained(this)))),
126 chunk_processor_(
127 base::Bind(&WorkerDevToolsAgentHost::SendMessageToClient,
128 base::Unretained(this))),
123 state_(WORKER_UNINSPECTED), 129 state_(WORKER_UNINSPECTED),
124 worker_id_(worker_id) { 130 worker_id_(worker_id) {
125 WorkerCreated(); 131 WorkerCreated();
126 } 132 }
127 133
128 WorkerDevToolsAgentHost::~WorkerDevToolsAgentHost() { 134 WorkerDevToolsAgentHost::~WorkerDevToolsAgentHost() {
129 DCHECK_EQ(WORKER_TERMINATED, state_); 135 DCHECK_EQ(WORKER_TERMINATED, state_);
130 } 136 }
131 137
132 void WorkerDevToolsAgentHost::OnAttachedStateChanged(bool attached) { 138 void WorkerDevToolsAgentHost::OnAttachedStateChanged(bool attached) {
(...skipping 15 matching lines...) Expand all
148 154
149 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend( 155 void WorkerDevToolsAgentHost::OnDispatchOnInspectorFrontend(
150 const DevToolsMessageChunk& message) { 156 const DevToolsMessageChunk& message) {
151 if (!IsAttached()) 157 if (!IsAttached())
152 return; 158 return;
153 159
154 chunk_processor_.ProcessChunkedMessageFromAgent(message); 160 chunk_processor_.ProcessChunkedMessageFromAgent(message);
155 } 161 }
156 162
157 } // namespace content 163 } // 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