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