| Index: chrome/browser/plugin_status_pref_setter.cc
|
| diff --git a/chrome/browser/plugin_status_pref_setter.cc b/chrome/browser/plugin_status_pref_setter.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ce4699d847b2c1ea0501e6af435bb8cb87cc7e7f
|
| --- /dev/null
|
| +++ b/chrome/browser/plugin_status_pref_setter.cc
|
| @@ -0,0 +1,81 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/plugin_status_pref_setter.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "chrome/browser/plugin_prefs.h"
|
| +#include "chrome/browser/prefs/pref_service.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/common/chrome_notification_types.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "content/public/browser/notification_source.h"
|
| +#include "content/public/browser/plugin_service.h"
|
| +#include "webkit/plugins/webplugininfo.h"
|
| +
|
| +using content::BrowserThread;
|
| +using content::PluginService;
|
| +
|
| +PluginStatusPrefSetter::Client::Client() {
|
| +}
|
| +
|
| +PluginStatusPrefSetter::Client::~Client() {
|
| +}
|
| +
|
| +void PluginStatusPrefSetter::Client::Init(
|
| + PrefService* prefs,
|
| + content::NotificationObserver* observer) {
|
| + pref_.Init(GetPrefName(), prefs, observer);
|
| +}
|
| +
|
| +PluginStatusPrefSetter::PluginStatusPrefSetter()
|
| + : profile_(NULL),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
|
| +
|
| +PluginStatusPrefSetter::~PluginStatusPrefSetter() {
|
| +}
|
| +
|
| +void PluginStatusPrefSetter::Init(const std::vector<Client*>& clients,
|
| + Profile* profile,
|
| + content::NotificationObserver* observer) {
|
| + clients_ = clients;
|
| + for (std::vector<Client*>::iterator iter = clients_.begin();
|
| + iter != clients_.end(); ++iter) {
|
| + (*iter)->Init(profile->GetPrefs(), observer);
|
| + }
|
| + profile_ = profile;
|
| + registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED,
|
| + content::Source<Profile>(profile));
|
| + StartUpdate();
|
| +}
|
| +
|
| +void PluginStatusPrefSetter::Observe(
|
| + int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) {
|
| + if (type == chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED) {
|
| + StartUpdate();
|
| + } else {
|
| + NOTREACHED();
|
| + }
|
| +}
|
| +
|
| +void PluginStatusPrefSetter::StartUpdate() {
|
| + PluginService::GetInstance()->GetPlugins(
|
| + base::Bind(&PluginStatusPrefSetter::GotPlugins, factory_.GetWeakPtr(),
|
| + PluginPrefs::GetForProfile(profile_)));
|
| +}
|
| +
|
| +void PluginStatusPrefSetter::GotPlugins(
|
| + scoped_refptr<PluginPrefs> plugin_prefs,
|
| + const std::vector<webkit::WebPluginInfo>& /* plugins */) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + for (std::vector<Client*>::iterator iter = clients_.begin();
|
| + iter != clients_.end(); ++iter) {
|
| + // Set the value on the PrefService instead of through the PrefMember in
|
| + // Client to notify observers if it changed.
|
| + profile_->GetPrefs()->SetBoolean(
|
| + (*iter)->GetPrefName(), (*iter)->CalculatePrefValue(plugin_prefs));
|
| + }
|
| +}
|
|
|