summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/blacklist.h
blob: 89705a5e7ea4822407590df53fc689541bf17c44 (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
68
69
70
71
// Copyright 2012 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_EXTENSIONS_BLACKLIST_H_
#define CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_

#include <set>
#include <string>
#include <vector>

#include "base/callback.h"
#include "base/observer_list.h"

namespace extensions {

class Extension;
class ExtensionPrefs;

// A blacklist of extensions.
class Blacklist {
 public:
  class Observer {
   public:
    // Observes |blacklist| on construction and unobserves on destruction.
    explicit Observer(Blacklist* blacklist);

    virtual void OnBlacklistUpdated() = 0;

   protected:
    virtual ~Observer();

   private:
    Blacklist* blacklist_;
  };

  typedef base::Callback<void(const std::set<std::string>&)>
      GetBlacklistedIDsCallback;

  // |prefs_| must outlive this.
  explicit Blacklist(ExtensionPrefs* prefs);

  ~Blacklist();

  // From the set of extension IDs passed in via |ids|, asynchronously checks
  // which are blacklisted and includes them in the resulting set passed
  // via |callback|, which will be sent on the caller's message loop.
  void GetBlacklistedIDs(const std::set<std::string>& ids,
                         const GetBlacklistedIDsCallback& callback);

  // Sets the blacklist from the updater to contain the extension IDs in |ids|
  void SetFromUpdater(const std::vector<std::string>& ids,
                      const std::string& version);

  // Adds/removes an observer to the blacklist.
  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

 private:
  ObserverList<Observer> observers_;

  ExtensionPrefs* const prefs_;

  std::set<std::string> prefs_blacklist_;

  DISALLOW_COPY_AND_ASSIGN(Blacklist);
};

}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_BLACKLIST_H_