blob: 752dec10c350f0e47417f47622a1a8a8ab6f2ded (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/devtools_discovery/devtools_discovery_manager.h"
#include "base/stl_util.h"
#include "components/devtools_discovery/basic_target_descriptor.h"
#include "content/public/browser/devtools_agent_host.h"
using content::DevToolsAgentHost;
namespace devtools_discovery {
// static
DevToolsDiscoveryManager* DevToolsDiscoveryManager::GetInstance() {
return base::Singleton<DevToolsDiscoveryManager>::get();
}
DevToolsDiscoveryManager::DevToolsDiscoveryManager() {
}
DevToolsDiscoveryManager::~DevToolsDiscoveryManager() {
STLDeleteElements(&providers_);
}
void DevToolsDiscoveryManager::AddProvider(scoped_ptr<Provider> provider) {
providers_.push_back(provider.release());
}
DevToolsTargetDescriptor::List DevToolsDiscoveryManager::GetDescriptors() {
if (providers_.size())
return GetDescriptorsFromProviders();
DevToolsAgentHost::List agent_hosts = DevToolsAgentHost::GetOrCreateAll();
DevToolsTargetDescriptor::List result;
result.reserve(agent_hosts.size());
for (const auto& agent_host : agent_hosts)
result.push_back(new BasicTargetDescriptor(agent_host));
return result;
}
void DevToolsDiscoveryManager::SetCreateCallback(
const CreateCallback& callback) {
create_callback_ = callback;
}
scoped_ptr<DevToolsTargetDescriptor>
DevToolsDiscoveryManager::CreateNew(const GURL& url) {
if (create_callback_.is_null())
return scoped_ptr<DevToolsTargetDescriptor>();
return create_callback_.Run(url);
}
DevToolsTargetDescriptor::List
DevToolsDiscoveryManager::GetDescriptorsFromProviders() {
DevToolsTargetDescriptor::List result;
for (const auto& provider : providers_) {
DevToolsTargetDescriptor::List partial = provider->GetDescriptors();
result.insert(result.begin(), partial.begin(), partial.end());
}
return result;
}
} // namespace devtools_discovery
|