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/plugin_service_impl.h" | 5 #include "content/browser/plugin_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // the number of processes which start at least one NPAPI/PPAPI Flash process. | 150 // the number of processes which start at least one NPAPI/PPAPI Flash process. |
151 static bool counted = false; | 151 static bool counted = false; |
152 if (!counted) { | 152 if (!counted) { |
153 counted = true; | 153 counted = true; |
154 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES, | 154 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES, |
155 FLASH_USAGE_ENUM_COUNT); | 155 FLASH_USAGE_ENUM_COUNT); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 PluginServiceImpl::~PluginServiceImpl() { | 159 PluginServiceImpl::~PluginServiceImpl() { |
| 160 #if defined(OS_WIN) |
| 161 // Release the events since they're owned by RegKey, not WaitableEvent. |
| 162 hkcu_watcher_.StopWatching(); |
| 163 hklm_watcher_.StopWatching(); |
| 164 if (hkcu_event_) |
| 165 hkcu_event_->Release(); |
| 166 if (hklm_event_) |
| 167 hklm_event_->Release(); |
| 168 #endif |
160 // Make sure no plugin channel requests have been leaked. | 169 // Make sure no plugin channel requests have been leaked. |
161 DCHECK(pending_plugin_clients_.empty()); | 170 DCHECK(pending_plugin_clients_.empty()); |
162 } | 171 } |
163 | 172 |
164 void PluginServiceImpl::Init() { | 173 void PluginServiceImpl::Init() { |
165 plugin_list_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); | 174 plugin_list_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); |
166 PluginList::Singleton()->set_will_load_plugins_callback( | 175 PluginList::Singleton()->set_will_load_plugins_callback( |
167 base::Bind(&WillLoadPluginsCallback, plugin_list_token_)); | 176 base::Bind(&WillLoadPluginsCallback, plugin_list_token_)); |
168 | 177 |
169 RegisterPepperPlugins(); | 178 RegisterPepperPlugins(); |
(...skipping 14 matching lines...) Expand all Loading... |
184 } | 193 } |
185 | 194 |
186 void PluginServiceImpl::StartWatchingPlugins() { | 195 void PluginServiceImpl::StartWatchingPlugins() { |
187 // Start watching for changes in the plugin list. This means watching | 196 // Start watching for changes in the plugin list. This means watching |
188 // for changes in the Windows registry keys and on both Windows and POSIX | 197 // for changes in the Windows registry keys and on both Windows and POSIX |
189 // watch for changes in the paths that are expected to contain plugins. | 198 // watch for changes in the paths that are expected to contain plugins. |
190 #if defined(OS_WIN) | 199 #if defined(OS_WIN) |
191 if (hkcu_key_.Create(HKEY_CURRENT_USER, | 200 if (hkcu_key_.Create(HKEY_CURRENT_USER, |
192 kRegistryMozillaPlugins, | 201 kRegistryMozillaPlugins, |
193 KEY_NOTIFY) == ERROR_SUCCESS) { | 202 KEY_NOTIFY) == ERROR_SUCCESS) { |
194 base::win::RegKey::ChangeCallback callback = | 203 if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { |
195 base::Bind(&PluginServiceImpl::OnKeyChanged, base::Unretained(this), | 204 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); |
196 base::Unretained(&hkcu_key_)); | 205 base::WaitableEventWatcher::EventCallback callback = |
197 hkcu_key_.StartWatching(callback); | 206 base::Bind(&PluginServiceImpl::OnWaitableEventSignaled, |
| 207 base::Unretained(this)); |
| 208 hkcu_watcher_.StartWatching(hkcu_event_.get(), callback); |
| 209 } |
198 } | 210 } |
199 if (hklm_key_.Create(HKEY_LOCAL_MACHINE, | 211 if (hklm_key_.Create(HKEY_LOCAL_MACHINE, |
200 kRegistryMozillaPlugins, | 212 kRegistryMozillaPlugins, |
201 KEY_NOTIFY) == ERROR_SUCCESS) { | 213 KEY_NOTIFY) == ERROR_SUCCESS) { |
202 base::win::RegKey::ChangeCallback callback = | 214 if (hklm_key_.StartWatching() == ERROR_SUCCESS) { |
203 base::Bind(&PluginServiceImpl::OnKeyChanged, base::Unretained(this), | 215 hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event())); |
204 base::Unretained(&hkcu_key_)); | 216 base::WaitableEventWatcher::EventCallback callback = |
205 hklm_key_.StartWatching(callback); | 217 base::Bind(&PluginServiceImpl::OnWaitableEventSignaled, |
| 218 base::Unretained(this)); |
| 219 hklm_watcher_.StartWatching(hklm_event_.get(), callback); |
| 220 } |
206 } | 221 } |
207 #endif | 222 #endif |
208 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) | 223 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
209 // On ChromeOS the user can't install plugins anyway and on Windows all | 224 // On ChromeOS the user can't install plugins anyway and on Windows all |
210 // important plugins register themselves in the registry so no need to do that. | 225 // important plugins register themselves in the registry so no need to do that. |
211 | 226 |
212 // Get the list of all paths for registering the FilePathWatchers | 227 // Get the list of all paths for registering the FilePathWatchers |
213 // that will track and if needed reload the list of plugins on runtime. | 228 // that will track and if needed reload the list of plugins on runtime. |
214 std::vector<base::FilePath> plugin_dirs; | 229 std::vector<base::FilePath> plugin_dirs; |
215 PluginList::Singleton()->GetPluginDirectories(&plugin_dirs); | 230 PluginList::Singleton()->GetPluginDirectories(&plugin_dirs); |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 // sure g_thread_init() gets called since plugins may call glib at load. | 635 // sure g_thread_init() gets called since plugins may call glib at load. |
621 | 636 |
622 if (!plugin_loader_.get()) | 637 if (!plugin_loader_.get()) |
623 plugin_loader_ = new PluginLoaderPosix; | 638 plugin_loader_ = new PluginLoaderPosix; |
624 | 639 |
625 plugin_loader_->GetPlugins( | 640 plugin_loader_->GetPlugins( |
626 base::Bind(&ForwardCallback, make_scoped_refptr(target_loop), callback)); | 641 base::Bind(&ForwardCallback, make_scoped_refptr(target_loop), callback)); |
627 } | 642 } |
628 #endif | 643 #endif |
629 | 644 |
| 645 void PluginServiceImpl::OnWaitableEventSignaled( |
| 646 base::WaitableEvent* waitable_event) { |
630 #if defined(OS_WIN) | 647 #if defined(OS_WIN) |
631 void PluginServiceImpl::OnKeyChanged(base::win::RegKey* key) { | 648 if (waitable_event == hkcu_event_) { |
632 key->StartWatching(base::Bind(&PluginServiceImpl::OnKeyChanged, | 649 hkcu_key_.StartWatching(); |
633 base::Unretained(this), | 650 } else { |
634 base::Unretained(&hkcu_key_))); | 651 hklm_key_.StartWatching(); |
| 652 } |
635 | 653 |
636 PluginList::Singleton()->RefreshPlugins(); | 654 PluginList::Singleton()->RefreshPlugins(); |
637 PurgePluginListCache(NULL, false); | 655 PurgePluginListCache(NULL, false); |
| 656 #else |
| 657 // This event should only get signaled on a Windows machine. |
| 658 NOTREACHED(); |
| 659 #endif // defined(OS_WIN) |
638 } | 660 } |
639 #endif // defined(OS_WIN) | |
640 | 661 |
641 void PluginServiceImpl::RegisterPepperPlugins() { | 662 void PluginServiceImpl::RegisterPepperPlugins() { |
642 ComputePepperPluginList(&ppapi_plugins_); | 663 ComputePepperPluginList(&ppapi_plugins_); |
643 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { | 664 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
644 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true); | 665 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true); |
645 } | 666 } |
646 } | 667 } |
647 | 668 |
648 // There should generally be very few plugins so a brute-force search is fine. | 669 // There should generally be very few plugins so a brute-force search is fine. |
649 PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo( | 670 PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo( |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 #endif | 859 #endif |
839 | 860 |
840 bool PluginServiceImpl::PpapiDevChannelSupported( | 861 bool PluginServiceImpl::PpapiDevChannelSupported( |
841 BrowserContext* browser_context, | 862 BrowserContext* browser_context, |
842 const GURL& document_url) { | 863 const GURL& document_url) { |
843 return content::GetContentClient()->browser()-> | 864 return content::GetContentClient()->browser()-> |
844 IsPluginAllowedToUseDevChannelAPIs(browser_context, document_url); | 865 IsPluginAllowedToUseDevChannelAPIs(browser_context, document_url); |
845 } | 866 } |
846 | 867 |
847 } // namespace content | 868 } // namespace content |
OLD | NEW |