OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 class DevToolsAgentHostClientImpl : public DevToolsAgentHostClient { | 261 class DevToolsAgentHostClientImpl : public DevToolsAgentHostClient { |
262 public: | 262 public: |
263 DevToolsAgentHostClientImpl(base::MessageLoop* message_loop, | 263 DevToolsAgentHostClientImpl(base::MessageLoop* message_loop, |
264 ServerWrapper* server_wrapper, | 264 ServerWrapper* server_wrapper, |
265 int connection_id, | 265 int connection_id, |
266 scoped_refptr<DevToolsAgentHost> agent_host) | 266 scoped_refptr<DevToolsAgentHost> agent_host) |
267 : message_loop_(message_loop), | 267 : message_loop_(message_loop), |
268 server_wrapper_(server_wrapper), | 268 server_wrapper_(server_wrapper), |
269 connection_id_(connection_id), | 269 connection_id_(connection_id), |
270 agent_host_(agent_host) { | 270 agent_host_(agent_host) { |
| 271 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
271 agent_host_->AttachClient(this); | 272 agent_host_->AttachClient(this); |
272 } | 273 } |
273 | 274 |
274 ~DevToolsAgentHostClientImpl() override { | 275 ~DevToolsAgentHostClientImpl() override { |
| 276 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
275 if (agent_host_.get()) | 277 if (agent_host_.get()) |
276 agent_host_->DetachClient(); | 278 agent_host_->DetachClient(); |
277 } | 279 } |
278 | 280 |
279 void AgentHostClosed(DevToolsAgentHost* agent_host, | 281 void AgentHostClosed(DevToolsAgentHost* agent_host, |
280 bool replaced_with_another_client) override { | 282 bool replaced_with_another_client) override { |
| 283 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
281 DCHECK(agent_host == agent_host_.get()); | 284 DCHECK(agent_host == agent_host_.get()); |
282 | 285 |
283 std::string message = base::StringPrintf( | 286 std::string message = base::StringPrintf( |
284 "{ \"method\": \"Inspector.detached\", " | 287 "{ \"method\": \"Inspector.detached\", " |
285 "\"params\": { \"reason\": \"%s\"} }", | 288 "\"params\": { \"reason\": \"%s\"} }", |
286 replaced_with_another_client ? | 289 replaced_with_another_client ? |
287 "replaced_with_devtools" : "target_closed"); | 290 "replaced_with_devtools" : "target_closed"); |
288 DispatchProtocolMessage(agent_host, message); | 291 DispatchProtocolMessage(agent_host, message); |
289 | 292 |
290 agent_host_ = nullptr; | 293 agent_host_ = nullptr; |
291 message_loop_->PostTask( | 294 message_loop_->PostTask( |
292 FROM_HERE, | 295 FROM_HERE, |
293 base::Bind(&ServerWrapper::Close, | 296 base::Bind(&ServerWrapper::Close, |
294 base::Unretained(server_wrapper_), | 297 base::Unretained(server_wrapper_), |
295 connection_id_)); | 298 connection_id_)); |
296 } | 299 } |
297 | 300 |
298 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, | 301 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, |
299 const std::string& message) override { | 302 const std::string& message) override { |
| 303 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
300 DCHECK(agent_host == agent_host_.get()); | 304 DCHECK(agent_host == agent_host_.get()); |
301 message_loop_->PostTask( | 305 message_loop_->PostTask( |
302 FROM_HERE, | 306 FROM_HERE, |
303 base::Bind(&ServerWrapper::SendOverWebSocket, | 307 base::Bind(&ServerWrapper::SendOverWebSocket, |
304 base::Unretained(server_wrapper_), | 308 base::Unretained(server_wrapper_), |
305 connection_id_, | 309 connection_id_, |
306 message)); | 310 message)); |
307 } | 311 } |
308 | 312 |
309 void OnMessage(const std::string& message) { | 313 void OnMessage(const std::string& message) { |
| 314 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
310 if (agent_host_.get()) | 315 if (agent_host_.get()) |
311 agent_host_->DispatchProtocolMessage(message); | 316 agent_host_->DispatchProtocolMessage(message); |
312 } | 317 } |
313 | 318 |
314 private: | 319 private: |
315 base::MessageLoop* const message_loop_; | 320 base::MessageLoop* const message_loop_; |
316 ServerWrapper* const server_wrapper_; | 321 ServerWrapper* const server_wrapper_; |
317 const int connection_id_; | 322 const int connection_id_; |
318 scoped_refptr<DevToolsAgentHost> agent_host_; | 323 scoped_refptr<DevToolsAgentHost> agent_host_; |
319 }; | 324 }; |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 id.c_str(), | 921 id.c_str(), |
917 host); | 922 host); |
918 dictionary->SetString( | 923 dictionary->SetString( |
919 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 924 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
920 } | 925 } |
921 | 926 |
922 return dictionary; | 927 return dictionary; |
923 } | 928 } |
924 | 929 |
925 } // namespace devtools_http_handler | 930 } // namespace devtools_http_handler |
OLD | NEW |