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 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "content/browser/devtools/devtools_manager_impl.h" | 12 #include "content/browser/devtools/devtools_manager_impl.h" |
| 13 #include "content/public/browser/browser_thread.h" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 namespace { | 17 namespace { |
17 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; | 18 typedef std::map<std::string, DevToolsAgentHostImpl*> Instances; |
18 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; | 19 base::LazyInstance<Instances>::Leaky g_instances = LAZY_INSTANCE_INITIALIZER; |
19 } // namespace | 20 } // namespace |
20 | 21 |
21 DevToolsAgentHostImpl::DevToolsAgentHostImpl() | 22 DevToolsAgentHostImpl::DevToolsAgentHostImpl() |
22 : close_listener_(NULL), | 23 : close_listener_(NULL), |
23 id_(base::GenerateGUID()) { | 24 id_(base::GenerateGUID()) { |
| 25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
24 g_instances.Get()[id_] = this; | 26 g_instances.Get()[id_] = this; |
25 } | 27 } |
26 | 28 |
27 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { | 29 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
28 g_instances.Get().erase(g_instances.Get().find(id_)); | 31 g_instances.Get().erase(g_instances.Get().find(id_)); |
29 } | 32 } |
30 | 33 |
31 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( | 34 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId( |
32 const std::string& id) { | 35 const std::string& id) { |
33 if (g_instances == NULL) | 36 if (g_instances == NULL) |
34 return NULL; | 37 return NULL; |
35 Instances::iterator it = g_instances.Get().find(id); | 38 Instances::iterator it = g_instances.Get().find(id); |
36 if (it == g_instances.Get().end()) | 39 if (it == g_instances.Get().end()) |
37 return NULL; | 40 return NULL; |
(...skipping 21 matching lines...) Expand all Loading... |
59 | 62 |
60 void DevToolsAgentHostImpl::NotifyCloseListener() { | 63 void DevToolsAgentHostImpl::NotifyCloseListener() { |
61 if (close_listener_) { | 64 if (close_listener_) { |
62 scoped_refptr<DevToolsAgentHostImpl> protect(this); | 65 scoped_refptr<DevToolsAgentHostImpl> protect(this); |
63 close_listener_->AgentHostClosing(this); | 66 close_listener_->AgentHostClosing(this); |
64 close_listener_ = NULL; | 67 close_listener_ = NULL; |
65 } | 68 } |
66 } | 69 } |
67 | 70 |
68 } // namespace content | 71 } // namespace content |
OLD | NEW |