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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// 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.
#include "chrome/browser/extensions/blacklist.h"
#include <algorithm>
#include "base/bind.h"
#include "base/message_loop.h"
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/pref_names.h"
namespace extensions {
Blacklist::Observer::Observer(Blacklist* blacklist) : blacklist_(blacklist) {
blacklist_->AddObserver(this);
}
Blacklist::Observer::~Observer() {
blacklist_->RemoveObserver(this);
}
Blacklist::Blacklist(ExtensionPrefs* prefs) : prefs_(prefs) {
}
Blacklist::~Blacklist() {
}
void Blacklist::GetBlacklistedIDs(const std::set<std::string>& ids,
const GetBlacklistedIDsCallback& callback) {
// TODO(kalman): Get the blacklisted IDs from the safebrowsing list.
// This will require going to the IO thread and back.
std::set<std::string> blacklisted_ids;
for (std::set<std::string>::const_iterator it = ids.begin();
it != ids.end(); ++it) {
if (prefs_->IsExtensionBlacklisted(*it))
blacklisted_ids.insert(*it);
}
MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(callback, blacklisted_ids));
}
void Blacklist::SetFromUpdater(const std::vector<std::string>& ids,
const std::string& version) {
std::set<std::string> ids_as_set;
for (std::vector<std::string>::const_iterator it = ids.begin();
it != ids.end(); ++it) {
if (Extension::IdIsValid(*it))
ids_as_set.insert(*it);
else
LOG(WARNING) << "Got invalid extension ID \"" << *it << "\"";
}
std::set<std::string> from_prefs = prefs_->GetBlacklistedExtensions();
std::set<std::string> no_longer_blacklisted;
std::set_difference(from_prefs.begin(), from_prefs.end(),
ids_as_set.begin(), ids_as_set.end(),
std::inserter(no_longer_blacklisted,
no_longer_blacklisted.begin()));
std::set<std::string> not_yet_blacklisted;
std::set_difference(ids_as_set.begin(), ids_as_set.end(),
from_prefs.begin(), from_prefs.end(),
std::inserter(not_yet_blacklisted,
not_yet_blacklisted.begin()));
for (std::set<std::string>::iterator it = no_longer_blacklisted.begin();
it != no_longer_blacklisted.end(); ++it) {
prefs_->SetExtensionBlacklisted(*it, false);
}
for (std::set<std::string>::iterator it = not_yet_blacklisted.begin();
it != not_yet_blacklisted.end(); ++it) {
prefs_->SetExtensionBlacklisted(*it, true);
}
prefs_->pref_service()->SetString(prefs::kExtensionBlacklistUpdateVersion,
version);
FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated());
}
void Blacklist::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void Blacklist::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
} // namespace extensions
|