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/renderer/browser_plugin/browser_plugin_manager.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/threading/thread_local.h" | 8 #include "base/threading/thread_local.h" |
9 #include "content/public/renderer/render_thread.h" | 9 #include "content/public/renderer/render_thread.h" |
10 #include "content/renderer/browser_plugin/browser_plugin.h" | 10 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 11 #include "content/renderer/browser_plugin/browser_plugin_manager_factory.h" |
11 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" | 12 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" |
12 | 13 |
13 namespace content { | 14 namespace content { |
14 | 15 |
15 static base::LazyInstance<base::ThreadLocalPointer< | 16 // static |
16 BrowserPluginManager> > lazy_tls = LAZY_INSTANCE_INITIALIZER; | 17 BrowserPluginManagerFactory* BrowserPluginManager::factory_ = NULL; |
17 | 18 |
18 BrowserPluginManager* BrowserPluginManager::Get() { | 19 BrowserPluginManager* BrowserPluginManager::Create( |
19 BrowserPluginManager* manager = lazy_tls.Pointer()->Get(); | 20 RenderViewImpl* render_view) { |
20 if (!manager) { | 21 if (factory_) |
21 manager = new BrowserPluginManagerImpl(); | 22 return factory_->CreateBrowserPluginManager(render_view); |
22 lazy_tls.Pointer()->Set(manager); | 23 return new BrowserPluginManagerImpl(render_view); |
23 } | |
24 return manager; | |
25 } | 24 } |
26 | 25 |
27 BrowserPluginManager::BrowserPluginManager() | 26 BrowserPluginManager::BrowserPluginManager(RenderViewImpl* render_view) |
28 : browser_plugin_counter_(0) { | 27 : RenderViewObserver(render_view), |
29 lazy_tls.Pointer()->Set(this); | 28 render_view_(render_view->AsWeakPtr()), |
30 RenderThread::Get()->AddObserver(this); | 29 browser_plugin_counter_(0) { |
31 } | 30 } |
32 | 31 |
33 BrowserPluginManager::~BrowserPluginManager() { | 32 BrowserPluginManager::~BrowserPluginManager() { |
34 lazy_tls.Pointer()->Set(NULL); | |
35 } | 33 } |
36 | 34 |
37 void BrowserPluginManager::AddBrowserPlugin( | 35 void BrowserPluginManager::AddBrowserPlugin( |
38 int instance_id, | 36 int instance_id, |
39 BrowserPlugin* browser_plugin) { | 37 BrowserPlugin* browser_plugin) { |
40 DCHECK(CalledOnValidThread()); | |
41 instances_.AddWithID(browser_plugin, instance_id); | 38 instances_.AddWithID(browser_plugin, instance_id); |
42 } | 39 } |
43 | 40 |
44 void BrowserPluginManager::RemoveBrowserPlugin(int instance_id) { | 41 void BrowserPluginManager::RemoveBrowserPlugin(int instance_id) { |
45 DCHECK(CalledOnValidThread()); | |
46 instances_.Remove(instance_id); | 42 instances_.Remove(instance_id); |
47 } | 43 } |
48 | 44 |
49 BrowserPlugin* BrowserPluginManager::GetBrowserPlugin(int instance_id) const { | 45 BrowserPlugin* BrowserPluginManager::GetBrowserPlugin(int instance_id) const { |
50 DCHECK(CalledOnValidThread()); | |
51 return instances_.Lookup(instance_id); | 46 return instances_.Lookup(instance_id); |
52 } | 47 } |
53 | 48 |
54 void BrowserPluginManager::SetEmbedderFocus(const RenderViewImpl* embedder, | 49 void BrowserPluginManager::SetEmbedderFocus(const RenderViewImpl* embedder, |
55 bool focused) { | 50 bool focused) { |
56 IDMap<BrowserPlugin>::iterator iter(&instances_); | 51 IDMap<BrowserPlugin>::iterator iter(&instances_); |
57 while (!iter.IsAtEnd()) { | 52 while (!iter.IsAtEnd()) { |
58 BrowserPlugin* browser_plugin = iter.GetCurrentValue(); | 53 BrowserPlugin* browser_plugin = iter.GetCurrentValue(); |
59 if (browser_plugin->render_view() == embedder) | 54 if (browser_plugin->render_view() == embedder) |
60 browser_plugin->SetEmbedderFocus(focused); | 55 browser_plugin->SetEmbedderFocus(focused); |
61 iter.Advance(); | 56 iter.Advance(); |
62 } | 57 } |
63 } | 58 } |
64 | 59 |
65 } // namespace content | 60 } // namespace content |
OLD | NEW |