Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: content/browser/plugin_service.cc

Issue 8493019: Refactor PluginService to take PluginList as a dependency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: did_init Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/plugin_service.h ('k') | webkit/plugins/npapi/mock_plugin_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "content/browser/plugin_service.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/file_path.h" 10 #include "base/file_path.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 }; 107 };
108 #endif 108 #endif
109 109
110 // static 110 // static
111 PluginService* PluginService::GetInstance() { 111 PluginService* PluginService::GetInstance() {
112 return Singleton<PluginService>::get(); 112 return Singleton<PluginService>::get();
113 } 113 }
114 114
115 PluginService::PluginService() 115 PluginService::PluginService()
116 : ui_locale_( 116 : plugin_list_(NULL),
117 ui_locale_(
117 content::GetContentClient()->browser()->GetApplicationLocale()), 118 content::GetContentClient()->browser()->GetApplicationLocale()),
118 filter_(NULL) { 119 filter_(NULL) {
120 }
121
122 PluginService::~PluginService() {
123 #if defined(OS_WIN)
124 // Release the events since they're owned by RegKey, not WaitableEvent.
125 hkcu_watcher_.StopWatching();
126 hklm_watcher_.StopWatching();
127 if (hkcu_event_.get())
128 hkcu_event_->Release();
129 if (hklm_event_.get())
130 hklm_event_->Release();
131 #endif
132 // Make sure no plugin channel requests have been leaked.
133 DCHECK(pending_plugin_clients_.empty());
134 }
135
136 void PluginService::Init() {
137 if (!plugin_list_)
138 plugin_list_ = webkit::npapi::PluginList::Singleton();
139
119 plugin_list()->set_will_load_plugins_callback( 140 plugin_list()->set_will_load_plugins_callback(
120 base::Bind(&WillLoadPluginsCallback)); 141 base::Bind(&WillLoadPluginsCallback));
121 142
122 RegisterPepperPlugins(); 143 RegisterPepperPlugins();
123 144
124 content::GetContentClient()->AddNPAPIPlugins(plugin_list()); 145 content::GetContentClient()->AddNPAPIPlugins(plugin_list());
125 146
126 // Load any specified on the command line as well. 147 // Load any specified on the command line as well.
127 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 148 const CommandLine* command_line = CommandLine::ForCurrentProcess();
128 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); 149 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin);
129 if (!path.empty()) 150 if (!path.empty())
130 AddExtraPluginPath(path); 151 AddExtraPluginPath(path);
131 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); 152 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir);
132 if (!path.empty()) 153 if (!path.empty())
133 plugin_list()->AddExtraPluginDir(path); 154 plugin_list()->AddExtraPluginDir(path);
134 155
135 #if defined(OS_MACOSX) 156 #if defined(OS_MACOSX)
136 // We need to know when the browser comes forward so we can bring modal plugin 157 // We need to know when the browser comes forward so we can bring modal plugin
137 // windows forward too. 158 // windows forward too.
138 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, 159 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED,
139 content::NotificationService::AllSources()); 160 content::NotificationService::AllSources());
140 #endif 161 #endif
141 } 162 }
142 163
143 PluginService::~PluginService() {
144 #if defined(OS_WIN)
145 // Release the events since they're owned by RegKey, not WaitableEvent.
146 hkcu_watcher_.StopWatching();
147 hklm_watcher_.StopWatching();
148 if (hkcu_event_.get())
149 hkcu_event_->Release();
150 if (hklm_event_.get())
151 hklm_event_->Release();
152 #endif
153 // Make sure no plugin channel requests have been leaked.
154 DCHECK(pending_plugin_clients_.empty());
155 }
156
157 void PluginService::StartWatchingPlugins() { 164 void PluginService::StartWatchingPlugins() {
158 // Start watching for changes in the plugin list. This means watching 165 // Start watching for changes in the plugin list. This means watching
159 // for changes in the Windows registry keys and on both Windows and POSIX 166 // for changes in the Windows registry keys and on both Windows and POSIX
160 // watch for changes in the paths that are expected to contain plugins. 167 // watch for changes in the paths that are expected to contain plugins.
161 #if defined(OS_WIN) 168 #if defined(OS_WIN)
162 if (hkcu_key_.Create(HKEY_CURRENT_USER, 169 if (hkcu_key_.Create(HKEY_CURRENT_USER,
163 webkit::npapi::kRegistryMozillaPlugins, 170 webkit::npapi::kRegistryMozillaPlugins,
164 KEY_NOTIFY) == ERROR_SUCCESS) { 171 KEY_NOTIFY) == ERROR_SUCCESS) {
165 if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { 172 if (hkcu_key_.StartWatching() == ERROR_SUCCESS) {
166 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); 173 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event()));
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 } 640 }
634 641
635 void PluginService::UnregisterInternalPlugin(const FilePath& path) { 642 void PluginService::UnregisterInternalPlugin(const FilePath& path) {
636 plugin_list()->UnregisterInternalPlugin(path); 643 plugin_list()->UnregisterInternalPlugin(path);
637 } 644 }
638 645
639 webkit::npapi::PluginList* PluginService::plugin_list() { 646 webkit::npapi::PluginList* PluginService::plugin_list() {
640 return webkit::npapi::PluginList::Singleton(); 647 return webkit::npapi::PluginList::Singleton();
641 } 648 }
642 649
650 void PluginService::SetPluginListForTesting(
651 webkit::npapi::PluginList* plugin_list) {
652 plugin_list_ = plugin_list;
653 }
654
643 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) { 655 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) {
644 plugin_list()->RegisterInternalPlugin(info); 656 plugin_list()->RegisterInternalPlugin(info);
645 } 657 }
646 658
647 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) { 659 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) {
648 return plugin_list()->GetPluginGroupName(plugin_name); 660 return plugin_list()->GetPluginGroupName(plugin_name);
649 } 661 }
OLDNEW
« no previous file with comments | « content/browser/plugin_service.h ('k') | webkit/plugins/npapi/mock_plugin_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698