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

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: 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
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 virtual void OnFilePathError(const FilePath& path) OVERRIDE { 102 virtual void OnFilePathError(const FilePath& path) OVERRIDE {
103 // TODO(pastarmovj): Add some sensible error handling. Maybe silently 103 // TODO(pastarmovj): Add some sensible error handling. Maybe silently
104 // stopping the watcher would be enough. Or possibly restart it. 104 // stopping the watcher would be enough. Or possibly restart it.
105 NOTREACHED(); 105 NOTREACHED();
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 PluginService* service = Singleton<PluginService>::get();
113 if (!service->did_init_)
jam 2011/11/08 23:12:57 we should know who creates this for the first time
114 service->Init();
115 return service;
113 } 116 }
114 117
115 PluginService::PluginService() 118 PluginService::PluginService()
116 : ui_locale_( 119 : did_init_(false),
120 plugin_list_(NULL),
121 ui_locale_(
117 content::GetContentClient()->browser()->GetApplicationLocale()), 122 content::GetContentClient()->browser()->GetApplicationLocale()),
118 filter_(NULL) { 123 filter_(NULL) {
124 }
125
126 PluginService::~PluginService() {
127 #if defined(OS_WIN)
128 // Release the events since they're owned by RegKey, not WaitableEvent.
129 hkcu_watcher_.StopWatching();
130 hklm_watcher_.StopWatching();
131 if (hkcu_event_.get())
132 hkcu_event_->Release();
133 if (hklm_event_.get())
134 hklm_event_->Release();
135 #endif
136 // Make sure no plugin channel requests have been leaked.
137 DCHECK(pending_plugin_clients_.empty());
138 }
139
140 void PluginService::Init() {
141 DCHECK(!did_init_);
142
143 if (!plugin_list_)
144 plugin_list_ = webkit::npapi::PluginList::Singleton();
145
119 plugin_list()->set_will_load_plugins_callback( 146 plugin_list()->set_will_load_plugins_callback(
120 base::Bind(&WillLoadPluginsCallback)); 147 base::Bind(&WillLoadPluginsCallback));
121 148
122 RegisterPepperPlugins(); 149 RegisterPepperPlugins();
123 150
124 content::GetContentClient()->AddNPAPIPlugins(plugin_list()); 151 content::GetContentClient()->AddNPAPIPlugins(plugin_list());
125 152
126 // Load any specified on the command line as well. 153 // Load any specified on the command line as well.
127 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 154 const CommandLine* command_line = CommandLine::ForCurrentProcess();
128 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); 155 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin);
129 if (!path.empty()) 156 if (!path.empty())
130 AddExtraPluginPath(path); 157 AddExtraPluginPath(path);
131 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); 158 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir);
132 if (!path.empty()) 159 if (!path.empty())
133 plugin_list()->AddExtraPluginDir(path); 160 plugin_list()->AddExtraPluginDir(path);
134 161
135 #if defined(OS_MACOSX) 162 #if defined(OS_MACOSX)
136 // We need to know when the browser comes forward so we can bring modal plugin 163 // We need to know when the browser comes forward so we can bring modal plugin
137 // windows forward too. 164 // windows forward too.
138 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, 165 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED,
139 content::NotificationService::AllSources()); 166 content::NotificationService::AllSources());
140 #endif 167 #endif
141 }
142 168
143 PluginService::~PluginService() { 169 did_init_ = true;
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 } 170 }
156 171
157 void PluginService::StartWatchingPlugins() { 172 void PluginService::StartWatchingPlugins() {
158 // Start watching for changes in the plugin list. This means watching 173 // 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 174 // 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. 175 // watch for changes in the paths that are expected to contain plugins.
161 #if defined(OS_WIN) 176 #if defined(OS_WIN)
162 if (hkcu_key_.Create(HKEY_CURRENT_USER, 177 if (hkcu_key_.Create(HKEY_CURRENT_USER,
163 webkit::npapi::kRegistryMozillaPlugins, 178 webkit::npapi::kRegistryMozillaPlugins,
164 KEY_NOTIFY) == ERROR_SUCCESS) { 179 KEY_NOTIFY) == ERROR_SUCCESS) {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 } 648 }
634 649
635 void PluginService::UnregisterInternalPlugin(const FilePath& path) { 650 void PluginService::UnregisterInternalPlugin(const FilePath& path) {
636 plugin_list()->UnregisterInternalPlugin(path); 651 plugin_list()->UnregisterInternalPlugin(path);
637 } 652 }
638 653
639 webkit::npapi::PluginList* PluginService::plugin_list() { 654 webkit::npapi::PluginList* PluginService::plugin_list() {
640 return webkit::npapi::PluginList::Singleton(); 655 return webkit::npapi::PluginList::Singleton();
641 } 656 }
642 657
658 void PluginService::SetPluginListForTesting(
659 webkit::npapi::PluginList* plugin_list) {
660 plugin_list_ = plugin_list;
661 }
662
643 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) { 663 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) {
644 plugin_list()->RegisterInternalPlugin(info); 664 plugin_list()->RegisterInternalPlugin(info);
645 } 665 }
646 666
647 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) { 667 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) {
648 return plugin_list()->GetPluginGroupName(plugin_name); 668 return plugin_list()->GetPluginGroupName(plugin_name);
649 } 669 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698