summaryrefslogtreecommitdiff
path: root/chromium/content/browser/devtools/devtools_manager.cc
blob: 8b269b265fdd89139337633dad2b80e826f3aed2 (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
// Copyright (c) 2012 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 "content/browser/devtools/devtools_manager.h"

#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "content/browser/devtools/devtools_agent_host_impl.h"
#include "content/browser/devtools/devtools_netlog_observer.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"

namespace content {

// static
DevToolsManager* DevToolsManager::GetInstance() {
  return base::Singleton<DevToolsManager>::get();
}

DevToolsManager::DevToolsManager()
    : delegate_(GetContentClient()->browser()->GetDevToolsManagerDelegate()),
      attached_hosts_count_(0) {
}

DevToolsManager::~DevToolsManager() {
  DCHECK(!attached_hosts_count_);
}

void DevToolsManager::AgentHostStateChanged(
    DevToolsAgentHostImpl* agent_host, bool attached) {
  if (attached) {
    if (!attached_hosts_count_) {
      BrowserThread::PostTask(
          BrowserThread::IO,
          FROM_HERE,
          base::Bind(&DevToolsNetLogObserver::Attach));
    }
    ++attached_hosts_count_;
  } else {
    --attached_hosts_count_;
    if (!attached_hosts_count_) {
      BrowserThread::PostTask(
          BrowserThread::IO,
          FROM_HERE,
          base::Bind(&DevToolsNetLogObserver::Detach));
    }
  }
}

}  // namespace content