| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/plugin_status_pref_setter.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "chrome/browser/plugin_prefs.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/notification_source.h" |
| 14 #include "content/public/browser/plugin_service.h" |
| 15 #include "webkit/plugins/webplugininfo.h" |
| 16 |
| 17 using content::BrowserThread; |
| 18 using content::PluginService; |
| 19 |
| 20 PluginStatusPrefSetter::Client::Client() { |
| 21 } |
| 22 |
| 23 PluginStatusPrefSetter::Client::~Client() { |
| 24 } |
| 25 |
| 26 void PluginStatusPrefSetter::Client::Init( |
| 27 PrefService* prefs, |
| 28 content::NotificationObserver* observer) { |
| 29 pref_.Init(GetPrefName(), prefs, observer); |
| 30 } |
| 31 |
| 32 PluginStatusPrefSetter::PluginStatusPrefSetter() |
| 33 : profile_(NULL), |
| 34 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} |
| 35 |
| 36 PluginStatusPrefSetter::~PluginStatusPrefSetter() { |
| 37 } |
| 38 |
| 39 void PluginStatusPrefSetter::Init(const std::vector<Client*>& clients, |
| 40 Profile* profile, |
| 41 content::NotificationObserver* observer) { |
| 42 clients_ = clients; |
| 43 for (std::vector<Client*>::iterator iter = clients_.begin(); |
| 44 iter != clients_.end(); ++iter) { |
| 45 (*iter)->Init(profile->GetPrefs(), observer); |
| 46 } |
| 47 profile_ = profile; |
| 48 registrar_.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED, |
| 49 content::Source<Profile>(profile)); |
| 50 StartUpdate(); |
| 51 } |
| 52 |
| 53 void PluginStatusPrefSetter::Observe( |
| 54 int type, |
| 55 const content::NotificationSource& source, |
| 56 const content::NotificationDetails& details) { |
| 57 if (type == chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED) { |
| 58 StartUpdate(); |
| 59 } else { |
| 60 NOTREACHED(); |
| 61 } |
| 62 } |
| 63 |
| 64 void PluginStatusPrefSetter::StartUpdate() { |
| 65 PluginService::GetInstance()->GetPlugins( |
| 66 base::Bind(&PluginStatusPrefSetter::GotPlugins, factory_.GetWeakPtr(), |
| 67 PluginPrefs::GetForProfile(profile_))); |
| 68 } |
| 69 |
| 70 void PluginStatusPrefSetter::GotPlugins( |
| 71 scoped_refptr<PluginPrefs> plugin_prefs, |
| 72 const std::vector<webkit::WebPluginInfo>& /* plugins */) { |
| 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 74 for (std::vector<Client*>::iterator iter = clients_.begin(); |
| 75 iter != clients_.end(); ++iter) { |
| 76 // Set the value on the PrefService instead of through the PrefMember in |
| 77 // Client to notify observers if it changed. |
| 78 profile_->GetPrefs()->SetBoolean( |
| 79 (*iter)->GetPrefName(), (*iter)->CalculatePrefValue(plugin_prefs)); |
| 80 } |
| 81 } |
| OLD | NEW |