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