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
3 // found in the LICENSE file.
5 #include "chrome/browser/plugin_data_remover_helper.h"
10 #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"
17 #include "content/public/browser/plugin_service.h"
18 #include "webkit/plugins/webplugininfo.h"
20 using content::BrowserThread
;
21 using content::PluginService
;
23 PluginDataRemoverHelper::PluginDataRemoverHelper()
25 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
27 PluginDataRemoverHelper::~PluginDataRemoverHelper() {
30 void PluginDataRemoverHelper::Init(const char* pref_name
,
32 content::NotificationObserver
* observer
) {
33 pref_
.Init(pref_name
, profile
->GetPrefs(), observer
);
35 registrar_
.Add(this, chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED
,
36 content::Source
<Profile
>(profile
));
41 bool PluginDataRemoverHelper::IsSupported(PluginPrefs
* plugin_prefs
) {
42 webkit::WebPluginInfo plugin
;
43 return content::PluginDataRemover::IsSupported(&plugin
) &&
44 plugin_prefs
->IsPluginEnabled(plugin
);
47 void PluginDataRemoverHelper::Observe(
49 const content::NotificationSource
& source
,
50 const content::NotificationDetails
& details
) {
51 if (type
== chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED
) {
58 void PluginDataRemoverHelper::StartUpdate() {
59 PluginService::GetInstance()->GetPlugins(
60 base::Bind(&PluginDataRemoverHelper::GotPlugins
, factory_
.GetWeakPtr(),
61 make_scoped_refptr(PluginPrefs::GetForProfile(profile_
))));
64 void PluginDataRemoverHelper::GotPlugins(
65 scoped_refptr
<PluginPrefs
> plugin_prefs
,
66 const std::vector
<webkit::WebPluginInfo
>& plugins
) {
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
68 bool supported
= IsSupported(plugin_prefs
);
69 // Set the value on the PrefService instead of through the PrefMember to
70 // notify observers if it changed.
71 profile_
->GetPrefs()->SetBoolean(pref_
.GetPrefName().c_str(), supported
);