| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/ui_devtools/devtools_client.h" | 5 #include "components/ui_devtools/devtools_client.h" |
| 6 | 6 |
| 7 #include "components/ui_devtools/devtools_server.h" | 7 #include "components/ui_devtools/devtools_server.h" |
| 8 | 8 |
| 9 namespace ui { | 9 namespace ui { |
| 10 namespace devtools { | 10 namespace devtools { |
| 11 | 11 |
| 12 UiDevToolsClient::UiDevToolsClient(const std::string& name, | 12 UiDevToolsClient::UiDevToolsClient(const std::string& name, |
| 13 UiDevToolsServer* server) | 13 UiDevToolsServer* server) |
| 14 : name_(name), | 14 : name_(name), |
| 15 connection_id_(kNotConnected), | 15 connection_id_(kNotConnected), |
| 16 dispatcher_(this), | 16 dispatcher_(this), |
| 17 server_(server) { | 17 server_(server) { |
| 18 DCHECK(server_); | 18 DCHECK(server_); |
| 19 } | 19 } |
| 20 | 20 |
| 21 UiDevToolsClient::~UiDevToolsClient() {} | 21 UiDevToolsClient::~UiDevToolsClient() {} |
| 22 | 22 |
| 23 void UiDevToolsClient::AddAgent(std::unique_ptr<UiDevToolsAgent> agent) { | 23 void UiDevToolsClient::AddAgent(std::unique_ptr<UiDevToolsAgent> agent) { |
| 24 agent->Init(&dispatcher_); | 24 agent->Init(&dispatcher_); |
| 25 agents_.push_back(std::move(agent)); | 25 agents_.push_back(std::move(agent)); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void UiDevToolsClient::Disconnect() { |
| 29 connection_id_ = kNotConnected; |
| 30 DisableAllAgents(); |
| 31 } |
| 32 |
| 28 void UiDevToolsClient::Dispatch(const std::string& data) { | 33 void UiDevToolsClient::Dispatch(const std::string& data) { |
| 29 dispatcher_.dispatch(protocol::parseJSON(data)); | 34 dispatcher_.dispatch(protocol::parseJSON(data)); |
| 30 } | 35 } |
| 31 | 36 |
| 32 bool UiDevToolsClient::connected() const { | 37 bool UiDevToolsClient::connected() const { |
| 33 return connection_id_ != kNotConnected; | 38 return connection_id_ != kNotConnected; |
| 34 } | 39 } |
| 35 | 40 |
| 36 void UiDevToolsClient::set_connection_id(int connection_id) { | 41 void UiDevToolsClient::set_connection_id(int connection_id) { |
| 37 connection_id_ = connection_id; | 42 connection_id_ = connection_id; |
| 38 } | 43 } |
| 39 | 44 |
| 40 const std::string& UiDevToolsClient::name() const { | 45 const std::string& UiDevToolsClient::name() const { |
| 41 return name_; | 46 return name_; |
| 42 } | 47 } |
| 43 | 48 |
| 49 void UiDevToolsClient::DisableAllAgents() { |
| 50 for (std::unique_ptr<UiDevToolsAgent>& agent : agents_) |
| 51 agent->Disable(); |
| 52 } |
| 53 |
| 44 void UiDevToolsClient::sendProtocolResponse(int callId, const String& message) { | 54 void UiDevToolsClient::sendProtocolResponse(int callId, const String& message) { |
| 45 if (connected()) | 55 if (connected()) |
| 46 server_->SendOverWebSocket(connection_id_, message); | 56 server_->SendOverWebSocket(connection_id_, message); |
| 47 } | 57 } |
| 48 | 58 |
| 49 void UiDevToolsClient::sendProtocolNotification(const String& message) { | 59 void UiDevToolsClient::sendProtocolNotification(const String& message) { |
| 50 if (connected()) | 60 if (connected()) |
| 51 server_->SendOverWebSocket(connection_id_, message); | 61 server_->SendOverWebSocket(connection_id_, message); |
| 52 } | 62 } |
| 53 | 63 |
| 54 void UiDevToolsClient::flushProtocolNotifications() { | 64 void UiDevToolsClient::flushProtocolNotifications() { |
| 55 NOTIMPLEMENTED(); | 65 NOTIMPLEMENTED(); |
| 56 } | 66 } |
| 57 | 67 |
| 58 } // namespace devtools | 68 } // namespace devtools |
| 59 } // namespace ui | 69 } // namespace ui |
| OLD | NEW |