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

Side by Side Diff: chrome/browser/plugins/plugin_prefs.cc

Issue 10910168: Separate plugin_metadata from plugin_installer, thread-safe plugin_finder (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: .. Created 8 years, 2 months 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
OLDNEW
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 "chrome/browser/plugins/plugin_prefs.h" 5 #include "chrome/browser/plugins/plugin_prefs.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "chrome/browser/plugins/plugin_installer.h" 18 #include "chrome/browser/plugins/plugin_installer.h"
19 #include "chrome/browser/plugins/plugin_metadata.h"
18 #include "chrome/browser/plugins/plugin_prefs_factory.h" 20 #include "chrome/browser/plugins/plugin_prefs_factory.h"
21 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/prefs/scoped_user_pref_update.h" 22 #include "chrome/browser/prefs/scoped_user_pref_update.h"
20 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_keyed_service.h" 24 #include "chrome/browser/profiles/profile_keyed_service.h"
22 #include "chrome/common/chrome_constants.h" 25 #include "chrome/common/chrome_constants.h"
23 #include "chrome/common/chrome_content_client.h" 26 #include "chrome/common/chrome_content_client.h"
24 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
26 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
28 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 PluginPrefsFactory::GetInstance()->SetTestingFactoryAndUse( 104 PluginPrefsFactory::GetInstance()->SetTestingFactoryAndUse(
102 profile, &PluginPrefsFactory::CreateForTestingProfile).get()); 105 profile, &PluginPrefsFactory::CreateForTestingProfile).get());
103 } 106 }
104 107
105 void PluginPrefs::SetPluginListForTesting( 108 void PluginPrefs::SetPluginListForTesting(
106 webkit::npapi::PluginList* plugin_list) { 109 webkit::npapi::PluginList* plugin_list) {
107 plugin_list_ = plugin_list; 110 plugin_list_ = plugin_list;
108 } 111 }
109 112
110 void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) { 113 void PluginPrefs::EnablePluginGroup(bool enabled, const string16& group_name) {
111 PluginFinder::Get(
112 base::Bind(&PluginPrefs::GetPluginFinderForEnablePluginGroup,
113 this, enabled, group_name));
114 }
115
116 void PluginPrefs::GetPluginFinderForEnablePluginGroup(
117 bool enabled,
118 const string16& group_name,
119 PluginFinder* finder) {
120 PluginService::GetInstance()->GetPlugins( 114 PluginService::GetInstance()->GetPlugins(
121 base::Bind(&PluginPrefs::EnablePluginGroupInternal, 115 base::Bind(&PluginPrefs::EnablePluginGroupInternal,
122 this, enabled, group_name, finder)); 116 this, enabled, group_name));
123 } 117 }
124 118
125 void PluginPrefs::EnablePluginGroupInternal( 119 void PluginPrefs::EnablePluginGroupInternal(
126 bool enabled, 120 bool enabled,
127 const string16& group_name, 121 const string16& group_name,
128 PluginFinder* finder,
129 const std::vector<webkit::WebPluginInfo>& plugins) { 122 const std::vector<webkit::WebPluginInfo>& plugins) {
130 base::AutoLock auto_lock(lock_); 123 base::AutoLock auto_lock(lock_);
124 PluginFinder* finder = PluginFinder::GetInstance();
131 125
132 // Set the desired state for the group. 126 // Set the desired state for the group.
133 plugin_group_state_[group_name] = enabled; 127 plugin_group_state_[group_name] = enabled;
134 128
135 // Update the state for all plug-ins in the group. 129 // Update the state for all plug-ins in the group.
136 for (size_t i = 0; i < plugins.size(); ++i) { 130 for (size_t i = 0; i < plugins.size(); ++i) {
137 PluginInstaller* installer = finder->GetPluginInstaller(plugins[i]); 131 PluginMetadata* plugin = finder->GetPluginMetadata(plugins[i]);
138 if (group_name != installer->name()) 132 if (group_name != plugin->name())
139 continue; 133 continue;
140 plugin_state_.Set(plugins[i].path, enabled); 134 plugin_state_.Set(plugins[i].path, enabled);
141 } 135 }
142 136
143 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 137 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
144 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins, finder)); 138 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins));
145 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 139 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
146 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); 140 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this));
147 } 141 }
148 142
149 void PluginPrefs::EnablePluginIfPossibleCallback( 143 void PluginPrefs::EnablePlugin(
150 bool enabled, const FilePath& path, 144 bool enabled, const FilePath& path,
151 const base::Callback<void(bool)>& callback, 145 const base::Callback<void(bool)>& callback) {
152 PluginFinder* finder) { 146 PluginFinder* finder = PluginFinder::GetInstance();
153 webkit::WebPluginInfo plugin; 147 webkit::WebPluginInfo plugin;
154 bool can_enable = true; 148 bool can_enable = true;
155 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) { 149 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &plugin)) {
156 PluginInstaller* installer = finder->GetPluginInstaller(plugin); 150 PluginMetadata* plugin_metadata = finder->GetPluginMetadata(plugin);
157 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); 151 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name);
158 PolicyStatus group_status = PolicyStatusForPlugin(installer->name()); 152 PolicyStatus group_status = PolicyStatusForPlugin(plugin_metadata->name());
159 if (enabled) { 153 if (enabled) {
160 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) 154 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED)
161 can_enable = false; 155 can_enable = false;
162 } else { 156 } else {
163 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) 157 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED)
164 can_enable = false; 158 can_enable = false;
165 } 159 }
166 } else { 160 } else {
167 NOTREACHED(); 161 NOTREACHED();
168 } 162 }
169 163
170 if (!can_enable) { 164 if (!can_enable) {
171 callback.Run(false); 165 MessageLoop::current()->PostTask(FROM_HERE,
166 base::Bind(callback, false));
172 return; 167 return;
173 } 168 }
174 169
175 PluginService::GetInstance()->GetPlugins( 170 PluginService::GetInstance()->GetPlugins(
176 base::Bind(&PluginPrefs::EnablePluginInternal, this, 171 base::Bind(&PluginPrefs::EnablePluginInternal, this,
177 enabled, path, finder, callback)); 172 enabled, path, finder, callback));
178 } 173 }
179 174
180 void PluginPrefs::EnablePlugin(
181 bool enabled, const FilePath& path,
182 const base::Callback<void(bool)>& callback) {
183 PluginFinder::Get(base::Bind(&PluginPrefs::EnablePluginIfPossibleCallback,
184 this, enabled, path, callback));
185 }
186
187 void PluginPrefs::EnablePluginInternal( 175 void PluginPrefs::EnablePluginInternal(
188 bool enabled, 176 bool enabled,
189 const FilePath& path, 177 const FilePath& path,
190 PluginFinder* plugin_finder, 178 PluginFinder* plugin_finder,
191 const base::Callback<void(bool)>& callback, 179 const base::Callback<void(bool)>& callback,
192 const std::vector<webkit::WebPluginInfo>& plugins) { 180 const std::vector<webkit::WebPluginInfo>& plugins) {
193 { 181 {
194 // Set the desired state for the plug-in. 182 // Set the desired state for the plug-in.
195 base::AutoLock auto_lock(lock_); 183 base::AutoLock auto_lock(lock_);
196 plugin_state_.Set(path, enabled); 184 plugin_state_.Set(path, enabled);
197 } 185 }
198 186
199 string16 group_name; 187 string16 group_name;
200 for (size_t i = 0; i < plugins.size(); ++i) { 188 for (size_t i = 0; i < plugins.size(); ++i) {
201 if (plugins[i].path == path) { 189 if (plugins[i].path == path) {
202 PluginInstaller* installer = 190 PluginMetadata* plugin_metadata =
203 plugin_finder->GetPluginInstaller(plugins[i]); 191 plugin_finder->GetPluginMetadata(plugins[i]);
204 // set the group name for this plug-in. 192 // set the group name for this plug-in.
205 group_name = installer->name(); 193 group_name = plugin_metadata->name();
206 DCHECK_EQ(enabled, IsPluginEnabled(plugins[i])); 194 DCHECK_EQ(enabled, IsPluginEnabled(plugins[i]));
207 break; 195 break;
208 } 196 }
209 } 197 }
210 198
211 bool all_disabled = true; 199 bool all_disabled = true;
212 for (size_t i = 0; i < plugins.size(); ++i) { 200 for (size_t i = 0; i < plugins.size(); ++i) {
213 PluginInstaller* installer = plugin_finder->GetPluginInstaller(plugins[i]); 201 PluginMetadata* plugin_metadata =
214 DCHECK(!installer->name().empty()); 202 plugin_finder->GetPluginMetadata(plugins[i]);
215 if (group_name == installer->name()) { 203 DCHECK(!plugin_metadata->name().empty());
204 if (group_name == plugin_metadata->name()) {
216 all_disabled = all_disabled && !IsPluginEnabled(plugins[i]); 205 all_disabled = all_disabled && !IsPluginEnabled(plugins[i]);
217 } 206 }
218 } 207 }
219 208
220 if (!group_name.empty()) { 209 if (!group_name.empty()) {
221 // Update the state for the corresponding plug-in group. 210 // Update the state for the corresponding plug-in group.
222 base::AutoLock auto_lock(lock_); 211 base::AutoLock auto_lock(lock_);
223 plugin_group_state_[group_name] = !all_disabled; 212 plugin_group_state_[group_name] = !all_disabled;
224 } 213 }
225 214
226 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 215 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
227 base::Bind(&PluginPrefs::OnUpdatePreferences, this, 216 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins));
228 plugins, plugin_finder));
229 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 217 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
230 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this)); 218 base::Bind(&PluginPrefs::NotifyPluginStatusChanged, this));
231 callback.Run(true); 219 callback.Run(true);
232 } 220 }
233 221
234 PluginPrefs::PolicyStatus PluginPrefs::PolicyStatusForPlugin( 222 PluginPrefs::PolicyStatus PluginPrefs::PolicyStatusForPlugin(
235 const string16& name) const { 223 const string16& name) const {
236 base::AutoLock auto_lock(lock_); 224 base::AutoLock auto_lock(lock_);
237 if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_)) { 225 if (IsStringMatchedInSet(name, policy_enabled_plugin_patterns_)) {
238 return POLICY_ENABLED; 226 return POLICY_ENABLED;
239 } else if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) && 227 } else if (IsStringMatchedInSet(name, policy_disabled_plugin_patterns_) &&
240 !IsStringMatchedInSet( 228 !IsStringMatchedInSet(
241 name, policy_disabled_plugin_exception_patterns_)) { 229 name, policy_disabled_plugin_exception_patterns_)) {
242 return POLICY_DISABLED; 230 return POLICY_DISABLED;
243 } else { 231 } else {
244 return NO_POLICY; 232 return NO_POLICY;
245 } 233 }
246 } 234 }
247 235
248 bool PluginPrefs::IsPluginEnabled(const webkit::WebPluginInfo& plugin) const { 236 bool PluginPrefs::IsPluginEnabled(const webkit::WebPluginInfo& plugin) const {
249 scoped_ptr<webkit::npapi::PluginGroup> group( 237 PluginFinder* finder = PluginFinder::GetInstance();
250 GetPluginList()->GetPluginGroup(plugin)); 238 string16 group_name = finder->GetPluginMetadata(plugin)->name();
251 string16 group_name = group->GetGroupName();
252 239
253 // Check if the plug-in or its group is enabled by policy. 240 // Check if the plug-in or its group is enabled by policy.
254 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name); 241 PolicyStatus plugin_status = PolicyStatusForPlugin(plugin.name);
255 PolicyStatus group_status = PolicyStatusForPlugin(group_name); 242 PolicyStatus group_status = PolicyStatusForPlugin(group_name);
256 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED) 243 if (plugin_status == POLICY_ENABLED || group_status == POLICY_ENABLED)
257 return true; 244 return true;
258 245
259 // Check if the plug-in or its group is disabled by policy. 246 // Check if the plug-in or its group is disabled by policy.
260 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED) 247 if (plugin_status == POLICY_DISABLED || group_status == POLICY_DISABLED)
261 return false; 248 return false;
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 policy_enabled_plugin_patterns_ = enabled_patterns; 571 policy_enabled_plugin_patterns_ = enabled_patterns;
585 } 572 }
586 573
587 webkit::npapi::PluginList* PluginPrefs::GetPluginList() const { 574 webkit::npapi::PluginList* PluginPrefs::GetPluginList() const {
588 if (plugin_list_) 575 if (plugin_list_)
589 return plugin_list_; 576 return plugin_list_;
590 return PluginService::GetInstance()->GetPluginList(); 577 return PluginService::GetInstance()->GetPluginList();
591 } 578 }
592 579
593 void PluginPrefs::GetPreferencesDataOnFileThread() { 580 void PluginPrefs::GetPreferencesDataOnFileThread() {
594 PluginFinder::Get(
595 base::Bind(&PluginPrefs::GetPluginFinderForGetPreferencesDataOnFileThread,
596 this));
597 }
598
599 void PluginPrefs::GetPluginFinderForGetPreferencesDataOnFileThread(
600 PluginFinder* finder) {
601 std::vector<webkit::WebPluginInfo> plugins; 581 std::vector<webkit::WebPluginInfo> plugins;
602 webkit::npapi::PluginList* plugin_list = GetPluginList(); 582 webkit::npapi::PluginList* plugin_list = GetPluginList();
603 plugin_list->GetPluginsNoRefresh(&plugins); 583 plugin_list->GetPluginsNoRefresh(&plugins);
604 584
605 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 585 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
606 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins, finder)); 586 base::Bind(&PluginPrefs::OnUpdatePreferences, this, plugins));
607 } 587 }
608 588
609 void PluginPrefs::OnUpdatePreferences( 589 void PluginPrefs::OnUpdatePreferences(
610 const std::vector<webkit::WebPluginInfo>& plugins, 590 const std::vector<webkit::WebPluginInfo>& plugins) {
611 PluginFinder* finder) {
612 if (!prefs_) 591 if (!prefs_)
613 return; 592 return;
614 593
594 PluginFinder* finder = PluginFinder::GetInstance();
615 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList); 595 ListPrefUpdate update(prefs_, prefs::kPluginsPluginsList);
616 ListValue* plugins_list = update.Get(); 596 ListValue* plugins_list = update.Get();
617 plugins_list->Clear(); 597 plugins_list->Clear();
618 598
619 FilePath internal_dir; 599 FilePath internal_dir;
620 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir)) 600 if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &internal_dir))
621 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir); 601 prefs_->SetFilePath(prefs::kPluginsLastInternalDirectory, internal_dir);
622 602
623 base::AutoLock auto_lock(lock_); 603 base::AutoLock auto_lock(lock_);
624 604
625 // Add the plugin files. 605 // Add the plugin files.
626 std::set<string16> group_names; 606 std::set<string16> group_names;
627 for (size_t i = 0; i < plugins.size(); ++i) { 607 for (size_t i = 0; i < plugins.size(); ++i) {
628 DictionaryValue* summary = new DictionaryValue(); 608 DictionaryValue* summary = new DictionaryValue();
629 summary->SetString("path", plugins[i].path.value()); 609 summary->SetString("path", plugins[i].path.value());
630 summary->SetString("name", plugins[i].name); 610 summary->SetString("name", plugins[i].name);
631 summary->SetString("version", plugins[i].version); 611 summary->SetString("version", plugins[i].version);
632 bool enabled = true; 612 bool enabled = true;
633 plugin_state_.Get(plugins[i].path, &enabled); 613 plugin_state_.Get(plugins[i].path, &enabled);
634 summary->SetBoolean("enabled", enabled); 614 summary->SetBoolean("enabled", enabled);
635 plugins_list->Append(summary); 615 plugins_list->Append(summary);
636 616
637 PluginInstaller* installer = finder->GetPluginInstaller(plugins[i]); 617 PluginMetadata* plugin_metadata = finder->GetPluginMetadata(plugins[i]);
638 // Insert into a set of all group names. 618 // Insert into a set of all group names.
639 group_names.insert(installer->name()); 619 group_names.insert(plugin_metadata->name());
640 } 620 }
641 621
642 // Add the plug-in groups. 622 // Add the plug-in groups.
643 for (std::set<string16>::const_iterator it = group_names.begin(); 623 for (std::set<string16>::const_iterator it = group_names.begin();
644 it != group_names.end(); ++it) { 624 it != group_names.end(); ++it) {
645 DictionaryValue* summary = new DictionaryValue(); 625 DictionaryValue* summary = new DictionaryValue();
646 summary->SetString("name", *it); 626 summary->SetString("name", *it);
647 bool enabled = true; 627 bool enabled = true;
648 std::map<string16, bool>::iterator gstate_it = 628 std::map<string16, bool>::iterator gstate_it =
649 plugin_group_state_.find(*it); 629 plugin_group_state_.find(*it);
650 if (gstate_it != plugin_group_state_.end()) 630 if (gstate_it != plugin_group_state_.end())
651 enabled = gstate_it->second; 631 enabled = gstate_it->second;
652 summary->SetBoolean("enabled", enabled); 632 summary->SetBoolean("enabled", enabled);
653 plugins_list->Append(summary); 633 plugins_list->Append(summary);
654 } 634 }
655 } 635 }
656 636
657 void PluginPrefs::NotifyPluginStatusChanged() { 637 void PluginPrefs::NotifyPluginStatusChanged() {
658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
659 content::NotificationService::current()->Notify( 639 content::NotificationService::current()->Notify(
660 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, 640 chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
661 content::Source<Profile>(profile_), 641 content::Source<Profile>(profile_),
662 content::NotificationService::NoDetails()); 642 content::NotificationService::NoDetails());
663 } 643 }
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_prefs.h ('k') | chrome/browser/renderer_host/plugin_info_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698