Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/browser/extensions/blacklist.cc

Issue 11415216: Make Blacklist::IsBlacklist asynchronous (it will need to be for safe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix another test Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/blacklist.h ('k') | chrome/browser/extensions/blacklist_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/extensions/blacklist.h" 5 #include "chrome/browser/extensions/blacklist.h"
6 6
7 #include <algorithm>
8
9 #include "base/bind.h"
10 #include "base/message_loop.h"
7 #include "chrome/browser/extensions/extension_prefs.h" 11 #include "chrome/browser/extensions/extension_prefs.h"
8 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
10 14
11 namespace extensions { 15 namespace extensions {
12 16
13 Blacklist::Observer::Observer(Blacklist* blacklist) : blacklist_(blacklist) { 17 Blacklist::Observer::Observer(Blacklist* blacklist) : blacklist_(blacklist) {
14 blacklist_->AddObserver(this); 18 blacklist_->AddObserver(this);
15 } 19 }
16 20
17 Blacklist::Observer::~Observer() { 21 Blacklist::Observer::~Observer() {
18 blacklist_->RemoveObserver(this); 22 blacklist_->RemoveObserver(this);
19 } 23 }
20 24
21 Blacklist::Blacklist(ExtensionPrefs* prefs) : prefs_(prefs) { 25 Blacklist::Blacklist(ExtensionPrefs* prefs) : prefs_(prefs) {
22 } 26 }
23 27
24 Blacklist::~Blacklist() { 28 Blacklist::~Blacklist() {
25 } 29 }
26 30
27 bool Blacklist::IsBlacklisted(const Extension* extension) const { 31 void Blacklist::GetBlacklistedIDs(const std::set<std::string>& ids,
28 return prefs_->IsExtensionBlacklisted(extension->id()); 32 const GetBlacklistedIDsCallback& callback) {
29 } 33 // TODO(kalman): Get the blacklisted IDs from the safebrowsing list.
30 34 // This will require going to the IO thread and back.
31 bool Blacklist::IsBlacklisted(const std::string& extension_id) const { 35 std::set<std::string> blacklisted_ids;
32 return prefs_->IsExtensionBlacklisted(extension_id); 36 for (std::set<std::string>::const_iterator it = ids.begin();
37 it != ids.end(); ++it) {
38 if (prefs_->IsExtensionBlacklisted(*it))
39 blacklisted_ids.insert(*it);
40 }
41 MessageLoop::current()->PostTask(FROM_HERE,
42 base::Bind(callback, blacklisted_ids));
33 } 43 }
34 44
35 void Blacklist::SetFromUpdater(const std::vector<std::string>& ids, 45 void Blacklist::SetFromUpdater(const std::vector<std::string>& ids,
36 const std::string& version) { 46 const std::string& version) {
37 std::set<std::string> ids_as_set; 47 std::set<std::string> ids_as_set;
38 for (std::vector<std::string>::const_iterator it = ids.begin(); 48 for (std::vector<std::string>::const_iterator it = ids.begin();
39 it != ids.end(); ++it) { 49 it != ids.end(); ++it) {
40 if (Extension::IdIsValid(*it)) 50 if (Extension::IdIsValid(*it))
41 ids_as_set.insert(*it); 51 ids_as_set.insert(*it);
42 else 52 else
43 LOG(WARNING) << "Got invalid extension ID \"" << *it << "\""; 53 LOG(WARNING) << "Got invalid extension ID \"" << *it << "\"";
44 } 54 }
45 55
46 prefs_->UpdateBlacklist(ids_as_set); 56 std::set<std::string> from_prefs = prefs_->GetBlacklistedExtensions();
57
58 std::set<std::string> no_longer_blacklisted;
59 std::set_difference(from_prefs.begin(), from_prefs.end(),
60 ids_as_set.begin(), ids_as_set.end(),
61 std::inserter(no_longer_blacklisted,
62 no_longer_blacklisted.begin()));
63 std::set<std::string> not_yet_blacklisted;
64 std::set_difference(ids_as_set.begin(), ids_as_set.end(),
65 from_prefs.begin(), from_prefs.end(),
66 std::inserter(not_yet_blacklisted,
67 not_yet_blacklisted.begin()));
68
69 for (std::set<std::string>::iterator it = no_longer_blacklisted.begin();
70 it != no_longer_blacklisted.end(); ++it) {
71 prefs_->SetExtensionBlacklisted(*it, false);
72 }
73 for (std::set<std::string>::iterator it = not_yet_blacklisted.begin();
74 it != not_yet_blacklisted.end(); ++it) {
75 prefs_->SetExtensionBlacklisted(*it, true);
76 }
77
47 prefs_->pref_service()->SetString(prefs::kExtensionBlacklistUpdateVersion, 78 prefs_->pref_service()->SetString(prefs::kExtensionBlacklistUpdateVersion,
48 version); 79 version);
49 80
50 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); 81 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated());
51 } 82 }
52 83
53 void Blacklist::AddObserver(Observer* observer) { 84 void Blacklist::AddObserver(Observer* observer) {
54 observers_.AddObserver(observer); 85 observers_.AddObserver(observer);
55 } 86 }
56 87
57 void Blacklist::RemoveObserver(Observer* observer) { 88 void Blacklist::RemoveObserver(Observer* observer) {
58 observers_.RemoveObserver(observer); 89 observers_.RemoveObserver(observer);
59 } 90 }
60 91
61 } // namespace extensions 92 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/blacklist.h ('k') | chrome/browser/extensions/blacklist_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698