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 #include "components/devtools_discovery/devtools_discovery_manager.h"
7 #include "base/stl_util.h"
8 #include "components/devtools_discovery/basic_target_descriptor.h"
9 #include "content/public/browser/devtools_agent_host.h"
11 using content::DevToolsAgentHost
;
13 namespace devtools_discovery
{
16 DevToolsDiscoveryManager
* DevToolsDiscoveryManager::GetInstance() {
17 return Singleton
<DevToolsDiscoveryManager
>::get();
20 DevToolsDiscoveryManager::DevToolsDiscoveryManager() {
23 DevToolsDiscoveryManager::~DevToolsDiscoveryManager() {
24 STLDeleteElements(&providers_
);
27 void DevToolsDiscoveryManager::AddProvider(scoped_ptr
<Provider
> provider
) {
28 providers_
.push_back(provider
.release());
31 DevToolsTargetDescriptor::List
DevToolsDiscoveryManager::GetDescriptors() {
32 if (providers_
.size())
33 return GetDescriptorsFromProviders();
35 DevToolsAgentHost::List agent_hosts
= DevToolsAgentHost::GetOrCreateAll();
36 DevToolsTargetDescriptor::List result
;
37 result
.reserve(agent_hosts
.size());
38 for (const auto& agent_host
: agent_hosts
)
39 result
.push_back(new BasicTargetDescriptor(agent_host
));
43 void DevToolsDiscoveryManager::SetCreateCallback(
44 const CreateCallback
& callback
) {
45 create_callback_
= callback
;
48 scoped_ptr
<DevToolsTargetDescriptor
>
49 DevToolsDiscoveryManager::CreateNew(const GURL
& url
) {
50 if (create_callback_
.is_null())
51 return scoped_ptr
<DevToolsTargetDescriptor
>();
52 return create_callback_
.Run(url
);
55 DevToolsTargetDescriptor::List
56 DevToolsDiscoveryManager::GetDescriptorsFromProviders() {
57 DevToolsTargetDescriptor::List result
;
58 for (const auto& provider
: providers_
) {
59 DevToolsTargetDescriptor::List partial
= provider
->GetDescriptors();
60 result
.insert(result
.begin(), partial
.begin(), partial
.end());
65 } // namespace devtools_discovery