Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: content/browser/devtools/devtools_agent_host_impl.cc

Issue 2408133004: [DevTools] Implement Target.setDiscoverTargets method. (Closed)
Patch Set: force creation Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/bind.h" 10 #include "base/bind.h"
(...skipping 24 matching lines...) Expand all
35 } // namespace 35 } // namespace
36 36
37 char DevToolsAgentHost::kTypePage[] = "page"; 37 char DevToolsAgentHost::kTypePage[] = "page";
38 char DevToolsAgentHost::kTypeFrame[] = "iframe"; 38 char DevToolsAgentHost::kTypeFrame[] = "iframe";
39 char DevToolsAgentHost::kTypeSharedWorker[] = "shared_worker"; 39 char DevToolsAgentHost::kTypeSharedWorker[] = "shared_worker";
40 char DevToolsAgentHost::kTypeServiceWorker[] = "service_worker"; 40 char DevToolsAgentHost::kTypeServiceWorker[] = "service_worker";
41 char DevToolsAgentHost::kTypeExternal[] = "external"; 41 char DevToolsAgentHost::kTypeExternal[] = "external";
42 char DevToolsAgentHost::kTypeBrowser[] = "browser"; 42 char DevToolsAgentHost::kTypeBrowser[] = "browser";
43 char DevToolsAgentHost::kTypeOther[] = "other"; 43 char DevToolsAgentHost::kTypeOther[] = "other";
44 int DevToolsAgentHostImpl::s_attached_count_ = 0; 44 int DevToolsAgentHostImpl::s_attached_count_ = 0;
45 int DevToolsAgentHostImpl::s_force_creation_count_ = 0;
45 46
46 // static 47 // static
47 std::string DevToolsAgentHost::GetProtocolVersion() { 48 std::string DevToolsAgentHost::GetProtocolVersion() {
48 return std::string(devtools::kProtocolVersion); 49 return std::string(devtools::kProtocolVersion);
49 } 50 }
50 51
51 // static 52 // static
52 bool DevToolsAgentHost::IsSupportedProtocolVersion(const std::string& version) { 53 bool DevToolsAgentHost::IsSupportedProtocolVersion(const std::string& version) {
53 return devtools::IsSupportedProtocolVersion(version); 54 return devtools::IsSupportedProtocolVersion(version);
54 } 55 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 91 }
91 return ServiceWorkerDevToolsManager::GetInstance() 92 return ServiceWorkerDevToolsManager::GetInstance()
92 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); 93 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id);
93 } 94 }
94 95
95 DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id) 96 DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id)
96 : id_(id), 97 : id_(id),
97 session_id_(0), 98 session_id_(0),
98 client_(NULL) { 99 client_(NULL) {
99 DCHECK_CURRENTLY_ON(BrowserThread::UI); 100 DCHECK_CURRENTLY_ON(BrowserThread::UI);
100 DCHECK(g_instances.Get().find(id_) == g_instances.Get().end());
101 g_instances.Get()[id_] = this;
102 } 101 }
103 102
104 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { 103 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() {
105 DCHECK_CURRENTLY_ON(BrowserThread::UI); 104 DCHECK_CURRENTLY_ON(BrowserThread::UI);
106 g_instances.Get().erase(g_instances.Get().find(id_)); 105 NotifyDestroyed();
107 } 106 }
108 107
109 // static 108 // static
110 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( 109 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId(
111 const std::string& id) { 110 const std::string& id) {
112 if (g_instances == NULL) 111 if (g_instances == NULL)
113 return NULL; 112 return NULL;
114 Instances::iterator it = g_instances.Get().find(id); 113 Instances::iterator it = g_instances.Get().find(id);
115 if (it == g_instances.Get().end()) 114 if (it == g_instances.Get().end())
116 return NULL; 115 return NULL;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 DevToolsAgentHostClient* client = agent_host->client_; 286 DevToolsAgentHostClient* client = agent_host->client_;
288 agent_host->client_ = NULL; 287 agent_host->client_ = NULL;
289 client->AgentHostClosed(agent_host, true); 288 client->AgentHostClosed(agent_host, true);
290 agent_host->InnerDetach(); 289 agent_host->InnerDetach();
291 } 290 }
292 } 291 }
293 } 292 }
294 293
295 // static 294 // static
296 void DevToolsAgentHost::AddObserver(DevToolsAgentHostObserver* observer) { 295 void DevToolsAgentHost::AddObserver(DevToolsAgentHostObserver* observer) {
296 if (observer->ShouldForceDevToolsAgentHostCreation()) {
297 if (!DevToolsAgentHostImpl::s_force_creation_count_) {
298 // Force all agent hosts when first observer is added.
299 DevToolsAgentHost::GetOrCreateAll();
pfeldman 2016/10/14 23:58:52 DevToolsAgentHost::GetOrCreateAll DCHECK notified
300 }
301 DevToolsAgentHostImpl::s_force_creation_count_++;
302 }
303
297 g_observers.Get().AddObserver(observer); 304 g_observers.Get().AddObserver(observer);
305 for (const auto& id_host : g_instances.Get())
306 observer->DevToolsAgentHostCreated(id_host.second);
298 } 307 }
299 308
300 // static 309 // static
301 void DevToolsAgentHost::RemoveObserver(DevToolsAgentHostObserver* observer) { 310 void DevToolsAgentHost::RemoveObserver(DevToolsAgentHostObserver* observer) {
311 if (observer->ShouldForceDevToolsAgentHostCreation())
312 DevToolsAgentHostImpl::s_force_creation_count_--;
302 g_observers.Get().RemoveObserver(observer); 313 g_observers.Get().RemoveObserver(observer);
303 } 314 }
304 315
316 // static
317 bool DevToolsAgentHostImpl::ShouldForceCreation() {
318 return s_force_creation_count_;
319 }
320
321 void DevToolsAgentHostImpl::NotifyCreated() {
322 DCHECK(g_instances.Get().find(id_) == g_instances.Get().end());
323 g_instances.Get()[id_] = this;
324 for (auto& observer : g_observers.Get())
325 observer.DevToolsAgentHostCreated(this);
326 }
327
305 void DevToolsAgentHostImpl::NotifyAttached() { 328 void DevToolsAgentHostImpl::NotifyAttached() {
306 if (!s_attached_count_) { 329 if (!s_attached_count_) {
307 BrowserThread::PostTask( 330 BrowserThread::PostTask(
308 BrowserThread::IO, 331 BrowserThread::IO,
309 FROM_HERE, 332 FROM_HERE,
310 base::Bind(&NetLogObserver::Attach, 333 base::Bind(&NetLogObserver::Attach,
311 GetContentClient()->browser()->GetNetLog())); 334 GetContentClient()->browser()->GetNetLog()));
312 } 335 }
313 ++s_attached_count_; 336 ++s_attached_count_;
314 337
315 for (auto& observer : g_observers.Get()) 338 for (auto& observer : g_observers.Get())
316 observer.DevToolsAgentHostAttached(this); 339 observer.DevToolsAgentHostAttached(this);
317 } 340 }
318 341
319 void DevToolsAgentHostImpl::NotifyDetached() { 342 void DevToolsAgentHostImpl::NotifyDetached() {
320 --s_attached_count_; 343 --s_attached_count_;
321 if (!s_attached_count_) { 344 if (!s_attached_count_) {
322 BrowserThread::PostTask( 345 BrowserThread::PostTask(
323 BrowserThread::IO, 346 BrowserThread::IO,
324 FROM_HERE, 347 FROM_HERE,
325 base::Bind(&NetLogObserver::Detach)); 348 base::Bind(&NetLogObserver::Detach));
326 } 349 }
327 350
328 for (auto& observer : g_observers.Get()) 351 for (auto& observer : g_observers.Get())
329 observer.DevToolsAgentHostDetached(this); 352 observer.DevToolsAgentHostDetached(this);
330 } 353 }
331 354
355 void DevToolsAgentHostImpl::NotifyDestroyed() {
356 DCHECK(g_instances.Get().find(id_) != g_instances.Get().end());
357 for (auto& observer : g_observers.Get())
358 observer.DevToolsAgentHostDestroyed(this);
359 g_instances.Get().erase(g_instances.Get().find(id_));
pfeldman 2016/10/14 23:58:52 Erase by id.
360 }
361
332 // DevToolsMessageChunkProcessor ----------------------------------------------- 362 // DevToolsMessageChunkProcessor -----------------------------------------------
333 363
334 DevToolsMessageChunkProcessor::DevToolsMessageChunkProcessor( 364 DevToolsMessageChunkProcessor::DevToolsMessageChunkProcessor(
335 const SendMessageCallback& callback) 365 const SendMessageCallback& callback)
336 : callback_(callback), 366 : callback_(callback),
337 message_buffer_size_(0), 367 message_buffer_size_(0),
338 last_call_id_(0) { 368 last_call_id_(0) {
339 } 369 }
340 370
341 DevToolsMessageChunkProcessor::~DevToolsMessageChunkProcessor() { 371 DevToolsMessageChunkProcessor::~DevToolsMessageChunkProcessor() {
(...skipping 27 matching lines...) Expand all
369 if (message_buffer_.size() != message_buffer_size_) 399 if (message_buffer_.size() != message_buffer_size_)
370 return false; 400 return false;
371 callback_.Run(chunk.session_id, message_buffer_); 401 callback_.Run(chunk.session_id, message_buffer_);
372 message_buffer_ = std::string(); 402 message_buffer_ = std::string();
373 message_buffer_size_ = 0; 403 message_buffer_size_ = 0;
374 } 404 }
375 return true; 405 return true;
376 } 406 }
377 407
378 } // namespace content 408 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_agent_host_impl.h ('k') | content/browser/devtools/forwarding_agent_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698