summaryrefslogtreecommitdiffstats
path: root/chrome/browser/plugin_data_remover_helper.h
blob: 938b17c9dd153e14017572d6cb360814a34dbbda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PLUGIN_DATA_REMOVER_HELPER_H_
#define CHROME_BROWSER_PLUGIN_DATA_REMOVER_HELPER_H_
#pragma once

#include <vector>

#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/prefs/pref_member.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"

class PluginPrefs;
class Profile;

namespace webkit {
struct WebPluginInfo;
}

// Helper class modeled after BooleanPrefMember to (asynchronously) update
// the preference specifying whether clearing plug-in data is supported
// by an installed plug-in.
// It should only be used from the UI thread. The client has to make sure that
// the passed profile outlives this object.
class PluginDataRemoverHelper : public content::NotificationObserver {
 public:
  PluginDataRemoverHelper();
  virtual ~PluginDataRemoverHelper();

  // Binds this object to the |pref_name| preference in the profile's
  // PrefService, notifying |observer| if the value changes.
  // This asynchronously calls the PluginService to get the list of installed
  // plug-ins.
  void Init(const char* pref_name,
            Profile* profile,
            content::NotificationObserver* observer);

  bool GetValue() const { return pref_.GetValue(); }

  // Like PluginDataRemover::IsSupported, but checks that the returned plugin
  // is enabled by PluginPrefs
  static bool IsSupported(PluginPrefs* plugin_prefs);

  // content::NotificationObserver methods:
  virtual void Observe(int type,
                       const content::NotificationSource& source,
                       const content::NotificationDetails& details) OVERRIDE;

 private:
  void StartUpdate();
  void GotPlugins(scoped_refptr<PluginPrefs> plugin_prefs,
                  const std::vector<webkit::WebPluginInfo>& plugins);

  BooleanPrefMember pref_;
  content::NotificationRegistrar registrar_;
  // Weak pointer.
  Profile* profile_;
  base::WeakPtrFactory<PluginDataRemoverHelper> factory_;

  DISALLOW_COPY_AND_ASSIGN(PluginDataRemoverHelper);
};

#endif  // CHROME_BROWSER_PLUGIN_DATA_REMOVER_HELPER_H_