OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/devtools/devtools_agent_host_impl.h" | 5 #include "content/browser/devtools/devtools_agent_host_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 char DevToolsAgentHost::kTypePage[] = "page"; | 38 char DevToolsAgentHost::kTypePage[] = "page"; |
39 char DevToolsAgentHost::kTypeFrame[] = "iframe"; | 39 char DevToolsAgentHost::kTypeFrame[] = "iframe"; |
40 char DevToolsAgentHost::kTypeSharedWorker[] = "shared_worker"; | 40 char DevToolsAgentHost::kTypeSharedWorker[] = "shared_worker"; |
41 char DevToolsAgentHost::kTypeServiceWorker[] = "service_worker"; | 41 char DevToolsAgentHost::kTypeServiceWorker[] = "service_worker"; |
42 char DevToolsAgentHost::kTypeExternal[] = "external"; | 42 char DevToolsAgentHost::kTypeExternal[] = "external"; |
43 char DevToolsAgentHost::kTypeBrowser[] = "browser"; | 43 char DevToolsAgentHost::kTypeBrowser[] = "browser"; |
44 char DevToolsAgentHost::kTypeOther[] = "other"; | 44 char DevToolsAgentHost::kTypeOther[] = "other"; |
45 | 45 |
46 // static | 46 // static |
47 DevToolsManagerDelegate* DevToolsAgentHost::GetDevToolsManagerDelegate() { | |
48 DevToolsManager* manager = DevToolsManager::GetInstance(); | |
49 return manager->delegate(); | |
50 } | |
51 | |
52 // static | |
53 std::string DevToolsAgentHost::GetProtocolVersion() { | 47 std::string DevToolsAgentHost::GetProtocolVersion() { |
54 return std::string(devtools::kProtocolVersion); | 48 return std::string(devtools::kProtocolVersion); |
55 } | 49 } |
56 | 50 |
57 // static | 51 // static |
58 bool DevToolsAgentHost::IsSupportedProtocolVersion(const std::string& version) { | 52 bool DevToolsAgentHost::IsSupportedProtocolVersion(const std::string& version) { |
59 return devtools::IsSupportedProtocolVersion(version); | 53 return devtools::IsSupportedProtocolVersion(version); |
60 } | 54 } |
61 | 55 |
62 // static | 56 // static |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 worker_route_id)) { | 101 worker_route_id)) { |
108 return host; | 102 return host; |
109 } | 103 } |
110 return ServiceWorkerDevToolsManager::GetInstance() | 104 return ServiceWorkerDevToolsManager::GetInstance() |
111 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); | 105 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); |
112 } | 106 } |
113 | 107 |
114 DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id) | 108 DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id) |
115 : id_(id), | 109 : id_(id), |
116 session_id_(0), | 110 session_id_(0), |
117 description_(""), | |
118 client_(NULL) { | 111 client_(NULL) { |
119 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 113 DCHECK(g_instances.Get().find(id_) == g_instances.Get().end()); |
120 g_instances.Get()[id_] = this; | 114 g_instances.Get()[id_] = this; |
121 } | 115 } |
122 | 116 |
123 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { | 117 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { |
124 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
125 g_instances.Get().erase(g_instances.Get().find(id_)); | 119 g_instances.Get().erase(g_instances.Get().find(id_)); |
126 } | 120 } |
127 | 121 |
128 // static | 122 // static |
129 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( | 123 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( |
130 const std::string& id) { | 124 const std::string& id) { |
131 if (g_instances == NULL) | 125 if (g_instances == NULL) |
132 return NULL; | 126 return NULL; |
133 Instances::iterator it = g_instances.Get().find(id); | 127 Instances::iterator it = g_instances.Get().find(id); |
134 if (it == g_instances.Get().end()) | 128 if (it == g_instances.Get().end()) |
135 return NULL; | 129 return NULL; |
136 return it->second; | 130 return it->second; |
137 } | 131 } |
138 | 132 |
139 // static | 133 // static |
140 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Create( | 134 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Forward( |
141 DevToolsExternalAgentProxyDelegate* delegate) { | 135 const std::string& id, |
142 return new ForwardingAgentHost(delegate); | 136 std::unique_ptr<DevToolsExternalAgentProxyDelegate> delegate) { |
| 137 scoped_refptr<DevToolsAgentHost> result = DevToolsAgentHost::GetForId(id); |
| 138 if (result) |
| 139 return result; |
| 140 return new ForwardingAgentHost(id, std::move(delegate)); |
143 } | 141 } |
144 | 142 |
145 bool DevToolsAgentHostImpl::InnerAttach(DevToolsAgentHostClient* client, | 143 bool DevToolsAgentHostImpl::InnerAttach(DevToolsAgentHostClient* client, |
146 bool force) { | 144 bool force) { |
147 if (client_ && !force) | 145 if (client_ && !force) |
148 return false; | 146 return false; |
149 | 147 |
150 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 148 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
151 ++session_id_; | 149 ++session_id_; |
152 if (client_) { | 150 if (client_) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 202 |
205 std::string DevToolsAgentHostImpl::GetId() { | 203 std::string DevToolsAgentHostImpl::GetId() { |
206 return id_; | 204 return id_; |
207 } | 205 } |
208 | 206 |
209 std::string DevToolsAgentHostImpl::GetParentId() { | 207 std::string DevToolsAgentHostImpl::GetParentId() { |
210 return ""; | 208 return ""; |
211 } | 209 } |
212 | 210 |
213 std::string DevToolsAgentHostImpl::GetDescription() { | 211 std::string DevToolsAgentHostImpl::GetDescription() { |
214 return description_; | 212 return ""; |
215 } | |
216 | |
217 void DevToolsAgentHostImpl::SetDescriptionOverride( | |
218 const std::string& description) { | |
219 description_ = description; | |
220 } | 213 } |
221 | 214 |
222 GURL DevToolsAgentHostImpl::GetFaviconURL() { | 215 GURL DevToolsAgentHostImpl::GetFaviconURL() { |
223 return GURL(); | 216 return GURL(); |
224 } | 217 } |
225 | 218 |
226 base::TimeTicks DevToolsAgentHostImpl::GetLastActivityTime() { | 219 base::TimeTicks DevToolsAgentHostImpl::GetLastActivityTime() { |
227 return base::TimeTicks(); | 220 return base::TimeTicks(); |
228 } | 221 } |
229 | 222 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 if (message_buffer_.size() != message_buffer_size_) | 369 if (message_buffer_.size() != message_buffer_size_) |
377 return false; | 370 return false; |
378 callback_.Run(chunk.session_id, message_buffer_); | 371 callback_.Run(chunk.session_id, message_buffer_); |
379 message_buffer_ = std::string(); | 372 message_buffer_ = std::string(); |
380 message_buffer_size_ = 0; | 373 message_buffer_size_ = 0; |
381 } | 374 } |
382 return true; | 375 return true; |
383 } | 376 } |
384 | 377 |
385 } // namespace content | 378 } // namespace content |
OLD | NEW |