chrome: bluetooth: hook up the AdapterAdded signal
[chromium-blink-merge.git] / chrome / browser / plugin_data_remover_helper.cc
bloba53b3b24b3d35323156276afa9ea01c49d7d5544
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"
7 #include <string>
9 #include "base/bind.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()
24 : profile_(NULL),
25 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {}
27 PluginDataRemoverHelper::~PluginDataRemoverHelper() {
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();
40 // static
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(
48 int type,
49 const content::NotificationSource& source,
50 const content::NotificationDetails& details) {
51 if (type == chrome::NOTIFICATION_PLUGIN_ENABLE_STATUS_CHANGED) {
52 StartUpdate();
53 } else {
54 NOTREACHED();
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);