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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_REGISTRY_IMPL_H_
6 #define COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_REGISTRY_IMPL_H_
11 #include "base/macros.h"
12 #include "base/memory/linked_ptr.h"
13 #include "components/devtools_service/public/interfaces/devtools_service.mojom.h"
14 #include "mojo/common/weak_binding_set.h"
16 namespace devtools_service
{
18 class DevToolsAgentHost
;
19 class DevToolsService
;
21 class DevToolsRegistryImpl
: public DevToolsRegistry
{
25 // |registry| must outlive this object.
26 explicit Iterator(DevToolsRegistryImpl
* registry
);
29 bool IsAtEnd() const { return iter_
== registry_
->agents_
.end(); }
30 void Advance() { ++iter_
; }
32 DevToolsAgentHost
* value() { return iter_
->second
.get(); }
35 DevToolsRegistryImpl
* const registry_
;
36 std::map
<std::string
, linked_ptr
<DevToolsAgentHost
>>::const_iterator iter_
;
39 // |service| must outlive this object.
40 explicit DevToolsRegistryImpl(DevToolsService
* service
);
41 ~DevToolsRegistryImpl() override
;
43 void BindToRegistryRequest(mojo::InterfaceRequest
<DevToolsRegistry
> request
);
45 DevToolsAgentHost
* GetAgentById(const std::string
& id
);
48 // DevToolsRegistry implementation.
49 void RegisterAgent(DevToolsAgentPtr agent
) override
;
51 void OnAgentConnectionError(const std::string
& id
);
53 DevToolsService
* const service_
;
55 mojo::WeakBindingSet
<DevToolsRegistry
> bindings_
;
57 std::map
<std::string
, linked_ptr
<DevToolsAgentHost
>> agents_
;
59 DISALLOW_COPY_AND_ASSIGN(DevToolsRegistryImpl
);
62 } // namespace devtools_service
64 #endif // COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_REGISTRY_IMPL_H_