OLD | NEW |
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> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 callback_message_loop_->PostTask(FROM_HERE, base::Bind(callback_, hits)); | 105 callback_message_loop_->PostTask(FROM_HERE, base::Bind(callback_, hits)); |
106 Release(); // Balanced in StartCheck. | 106 Release(); // Balanced in StartCheck. |
107 } | 107 } |
108 | 108 |
109 scoped_refptr<base::MessageLoopProxy> callback_message_loop_; | 109 scoped_refptr<base::MessageLoopProxy> callback_message_loop_; |
110 OnResultCallback callback_; | 110 OnResultCallback callback_; |
111 | 111 |
112 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingClientImpl); | 112 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingClientImpl); |
113 }; | 113 }; |
114 | 114 |
| 115 void IsNotEmpty(const Blacklist::IsBlacklistedCallback& callback, |
| 116 const std::set<std::string>& set) { |
| 117 callback.Run(!set.empty()); |
| 118 } |
| 119 |
115 } // namespace | 120 } // namespace |
116 | 121 |
117 Blacklist::Observer::Observer(Blacklist* blacklist) : blacklist_(blacklist) { | 122 Blacklist::Observer::Observer(Blacklist* blacklist) : blacklist_(blacklist) { |
118 blacklist_->AddObserver(this); | 123 blacklist_->AddObserver(this); |
119 } | 124 } |
120 | 125 |
121 Blacklist::Observer::~Observer() { | 126 Blacklist::Observer::~Observer() { |
122 blacklist_->RemoveObserver(this); | 127 blacklist_->RemoveObserver(this); |
123 } | 128 } |
124 | 129 |
(...skipping 25 matching lines...) Expand all Loading... |
150 // altogether (when we're sure it's a strict subset of the safebrowsing one). | 155 // altogether (when we're sure it's a strict subset of the safebrowsing one). |
151 } | 156 } |
152 | 157 |
153 Blacklist::~Blacklist() { | 158 Blacklist::~Blacklist() { |
154 } | 159 } |
155 | 160 |
156 void Blacklist::GetBlacklistedIDs(const std::set<std::string>& ids, | 161 void Blacklist::GetBlacklistedIDs(const std::set<std::string>& ids, |
157 const GetBlacklistedIDsCallback& callback) { | 162 const GetBlacklistedIDsCallback& callback) { |
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
159 | 164 |
| 165 if (ids.empty()) { |
| 166 base::MessageLoopProxy::current()->PostTask( |
| 167 FROM_HERE, |
| 168 base::Bind(callback, std::set<std::string>())); |
| 169 return; |
| 170 } |
| 171 |
160 // The blacklisted IDs are the union of those blacklisted in prefs and | 172 // The blacklisted IDs are the union of those blacklisted in prefs and |
161 // those blacklisted from safe browsing. | 173 // those blacklisted from safe browsing. |
162 std::set<std::string> pref_blacklisted_ids; | 174 std::set<std::string> pref_blacklisted_ids; |
163 for (std::set<std::string>::const_iterator it = ids.begin(); | 175 for (std::set<std::string>::const_iterator it = ids.begin(); |
164 it != ids.end(); ++it) { | 176 it != ids.end(); ++it) { |
165 if (prefs_->IsExtensionBlacklisted(*it)) | 177 if (prefs_->IsExtensionBlacklisted(*it)) |
166 pref_blacklisted_ids.insert(*it); | 178 pref_blacklisted_ids.insert(*it); |
167 } | 179 } |
168 | 180 |
169 if (!g_database_manager.Get().get()) { | 181 if (!g_database_manager.Get().get()) { |
170 base::MessageLoopProxy::current()->PostTask( | 182 base::MessageLoopProxy::current()->PostTask( |
171 FROM_HERE, | 183 FROM_HERE, |
172 base::Bind(callback, pref_blacklisted_ids)); | 184 base::Bind(callback, pref_blacklisted_ids)); |
173 return; | 185 return; |
174 } | 186 } |
175 | 187 |
176 // Constructing the SafeBrowsingClientImpl begins the process of asking | 188 // Constructing the SafeBrowsingClientImpl begins the process of asking |
177 // safebrowsing for the blacklisted extensions. | 189 // safebrowsing for the blacklisted extensions. |
178 new SafeBrowsingClientImpl( | 190 new SafeBrowsingClientImpl( |
179 ids, | 191 ids, |
180 base::Bind(&Blacklist::OnSafeBrowsingResponse, AsWeakPtr(), | 192 base::Bind(&Blacklist::OnSafeBrowsingResponse, AsWeakPtr(), |
181 pref_blacklisted_ids, | 193 pref_blacklisted_ids, |
182 callback)); | 194 callback)); |
183 } | 195 } |
184 | 196 |
| 197 void Blacklist::IsBlacklisted(const std::string& extension_id, |
| 198 const IsBlacklistedCallback& callback) { |
| 199 std::set<std::string> check; |
| 200 check.insert(extension_id); |
| 201 GetBlacklistedIDs(check, base::Bind(&IsNotEmpty, callback)); |
| 202 } |
| 203 |
185 void Blacklist::SetFromUpdater(const std::vector<std::string>& ids, | 204 void Blacklist::SetFromUpdater(const std::vector<std::string>& ids, |
186 const std::string& version) { | 205 const std::string& version) { |
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
188 | 207 |
189 std::set<std::string> ids_as_set; | 208 std::set<std::string> ids_as_set; |
190 for (std::vector<std::string>::const_iterator it = ids.begin(); | 209 for (std::vector<std::string>::const_iterator it = ids.begin(); |
191 it != ids.end(); ++it) { | 210 it != ids.end(); ++it) { |
192 if (Extension::IdIsValid(*it)) | 211 if (Extension::IdIsValid(*it)) |
193 ids_as_set.insert(*it); | 212 ids_as_set.insert(*it); |
194 else | 213 else |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 } | 277 } |
259 | 278 |
260 void Blacklist::Observe(int type, | 279 void Blacklist::Observe(int type, |
261 const content::NotificationSource& source, | 280 const content::NotificationSource& source, |
262 const content::NotificationDetails& details) { | 281 const content::NotificationDetails& details) { |
263 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); | 282 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); |
264 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); | 283 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); |
265 } | 284 } |
266 | 285 |
267 } // namespace extensions | 286 } // namespace extensions |
OLD | NEW |