OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | |
6 | |
7 #include "base/lazy_instance.h" | |
8 #include "base/threading/thread_local.h" | |
9 #include "content/public/renderer/render_thread.h" | |
10 #include "content/renderer/browser_plugin/browser_plugin.h" | |
11 | |
12 namespace content { | |
13 | |
14 static base::LazyInstance<base::ThreadLocalPointer< | |
15 BrowserPluginManager> > lazy_tls = LAZY_INSTANCE_INITIALIZER; | |
16 | |
17 BrowserPluginManager* BrowserPluginManager::Get() { | |
18 return lazy_tls.Pointer()->Get(); | |
19 } | |
20 | |
21 BrowserPluginManager::BrowserPluginManager() { | |
22 lazy_tls.Pointer()->Set(this); | |
23 RenderThread::Get()->AddObserver(this); | |
24 } | |
25 | |
26 BrowserPluginManager::~BrowserPluginManager() { | |
27 lazy_tls.Pointer()->Set(NULL); | |
28 } | |
29 | |
30 void BrowserPluginManager::AddBrowserPlugin( | |
31 int instance_id, | |
32 BrowserPlugin* browser_plugin) { | |
33 DCHECK(CalledOnValidThread()); | |
34 instances_.AddWithID(browser_plugin, instance_id); | |
35 } | |
36 | |
37 void BrowserPluginManager::RemoveBrowserPlugin(int instance_id) { | |
38 DCHECK(CalledOnValidThread()); | |
39 instances_.Remove(instance_id); | |
40 } | |
41 | |
42 BrowserPlugin* BrowserPluginManager::GetBrowserPlugin(int instance_id) const { | |
43 DCHECK(CalledOnValidThread()); | |
44 return instances_.Lookup(instance_id); | |
45 } | |
46 | |
47 } // namespace content | |
OLD | NEW |