OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/devtools_service/devtools_registry_impl.h" | 5 #include "components/devtools_service/devtools_registry_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "components/devtools_service/devtools_agent_host.h" |
8 | 9 |
9 namespace devtools_service { | 10 namespace devtools_service { |
10 | 11 |
| 12 DevToolsRegistryImpl::Iterator::Iterator(DevToolsRegistryImpl* registry) |
| 13 : registry_(registry), iter_(registry->agents_.begin()) { |
| 14 } |
| 15 |
| 16 DevToolsRegistryImpl::Iterator::~Iterator() { |
| 17 } |
| 18 |
11 DevToolsRegistryImpl::DevToolsRegistryImpl(DevToolsService* service) | 19 DevToolsRegistryImpl::DevToolsRegistryImpl(DevToolsService* service) |
12 : service_(service) { | 20 : service_(service) { |
13 } | 21 } |
14 | 22 |
15 DevToolsRegistryImpl::~DevToolsRegistryImpl() { | 23 DevToolsRegistryImpl::~DevToolsRegistryImpl() { |
16 } | 24 } |
17 | 25 |
18 void DevToolsRegistryImpl::BindToRegistryRequest( | 26 void DevToolsRegistryImpl::BindToRegistryRequest( |
19 mojo::InterfaceRequest<DevToolsRegistry> request) { | 27 mojo::InterfaceRequest<DevToolsRegistry> request) { |
20 bindings_.AddBinding(this, request.Pass()); | 28 bindings_.AddBinding(this, request.Pass()); |
21 } | 29 } |
22 | 30 |
| 31 DevToolsAgentHost* DevToolsRegistryImpl::GetAgentById(const std::string& id) { |
| 32 auto iter = agents_.find(id); |
| 33 if (iter == agents_.end()) |
| 34 return nullptr; |
| 35 |
| 36 return iter->second.get(); |
| 37 } |
| 38 |
23 void DevToolsRegistryImpl::RegisterAgent(DevToolsAgentPtr agent) { | 39 void DevToolsRegistryImpl::RegisterAgent(DevToolsAgentPtr agent) { |
24 // TODO(yzshen): Implement it. | 40 linked_ptr<DevToolsAgentHost> agent_host(new DevToolsAgentHost(agent.Pass())); |
25 NOTIMPLEMENTED(); | 41 std::string id = agent_host->id(); |
| 42 agent_host->set_agent_connection_error_handler( |
| 43 [this, id]() { OnAgentConnectionError(id); }); |
| 44 |
| 45 agents_[agent_host->id()] = agent_host; |
| 46 } |
| 47 |
| 48 void DevToolsRegistryImpl::OnAgentConnectionError(const std::string& id) { |
| 49 DCHECK(agents_.find(id) != agents_.end()); |
| 50 agents_.erase(id); |
26 } | 51 } |
27 | 52 |
28 } // namespace devtools_service | 53 } // namespace devtools_service |
OLD | NEW |