Chromium Code Reviews| 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. |
|
mattm
2013/12/03 02:55:45
It seems that nothing checks whether safebrowsing
Oleg Eterevsky
2013/12/04 10:45:11
I followed the way how it now works with just chec
not at google - send to devlin
2013/12/04 17:59:53
For us, safebrowsing is the infrastructure but not
mattm
2013/12/10 11:09:41
Okay. Thanks for the explanation.
| |
| 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 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/extensions/blacklist_state_fetcher.h" | |
| 17 #include "chrome/browser/extensions/extension_prefs.h" | 18 #include "chrome/browser/extensions/extension_prefs.h" |
| 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 19 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 23 | 24 |
| 24 using content::BrowserThread; | 25 using content::BrowserThread; |
| 25 | 26 |
| 26 namespace extensions { | 27 namespace extensions { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 callback.Run(state_map.empty() ? Blacklist::NOT_BLACKLISTED | 122 callback.Run(state_map.empty() ? Blacklist::NOT_BLACKLISTED |
| 122 : state_map.begin()->second); | 123 : state_map.begin()->second); |
| 123 } | 124 } |
| 124 | 125 |
| 125 void GetMalwareFromBlacklistStateMap( | 126 void GetMalwareFromBlacklistStateMap( |
| 126 const Blacklist::GetMalwareIDsCallback& callback, | 127 const Blacklist::GetMalwareIDsCallback& callback, |
| 127 const Blacklist::BlacklistStateMap& state_map) { | 128 const Blacklist::BlacklistStateMap& state_map) { |
| 128 std::set<std::string> malware; | 129 std::set<std::string> malware; |
| 129 for (Blacklist::BlacklistStateMap::const_iterator it = state_map.begin(); | 130 for (Blacklist::BlacklistStateMap::const_iterator it = state_map.begin(); |
| 130 it != state_map.end(); ++it) { | 131 it != state_map.end(); ++it) { |
| 131 if (it->second == Blacklist::BLACKLISTED_MALWARE) | 132 // TODO(oleg): UNKNOWN is treated as MALWARE for backwards compatibility. |
| 133 // In future GetMalwareIDs will be removed and the caller will have to | |
| 134 // deal with BLACKLISTED_UNKNOWN state returned from GetBlacklistedIDs. | |
| 135 if (it->second == Blacklist::BLACKLISTED_MALWARE || | |
| 136 it->second == Blacklist::BLACKLISTED_UNKNOWN) | |
| 132 malware.insert(it->first); | 137 malware.insert(it->first); |
| 133 } | 138 } |
| 134 callback.Run(malware); | 139 callback.Run(malware); |
| 135 } | 140 } |
| 136 | 141 |
| 137 } // namespace | 142 } // namespace |
| 138 | 143 |
| 139 Blacklist::Observer::Observer(Blacklist* blacklist) : blacklist_(blacklist) { | 144 Blacklist::Observer::Observer(Blacklist* blacklist) : blacklist_(blacklist) { |
| 140 blacklist_->AddObserver(this); | 145 blacklist_->AddObserver(this); |
| 141 } | 146 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 const GetBlacklistedIDsCallback& callback, | 221 const GetBlacklistedIDsCallback& callback, |
| 217 const std::set<std::string>& blacklisted_ids) { | 222 const std::set<std::string>& blacklisted_ids) { |
| 218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 219 | 224 |
| 220 std::set<std::string> ids_unknown_state; | 225 std::set<std::string> ids_unknown_state; |
| 221 BlacklistStateMap extensions_state; | 226 BlacklistStateMap extensions_state; |
| 222 for (std::set<std::string>::const_iterator it = blacklisted_ids.begin(); | 227 for (std::set<std::string>::const_iterator it = blacklisted_ids.begin(); |
| 223 it != blacklisted_ids.end(); ++it) { | 228 it != blacklisted_ids.end(); ++it) { |
| 224 BlacklistStateMap::const_iterator cache_it = | 229 BlacklistStateMap::const_iterator cache_it = |
| 225 blacklist_state_cache_.find(*it); | 230 blacklist_state_cache_.find(*it); |
| 226 if (cache_it == blacklist_state_cache_.end()) | 231 if (cache_it == blacklist_state_cache_.end() || |
| 232 cache_it->second == BLACKLISTED_UNKNOWN) // Do not return UNKNOWN | |
| 233 // from cache, retry request. | |
| 227 ids_unknown_state.insert(*it); | 234 ids_unknown_state.insert(*it); |
| 228 else | 235 else |
| 229 extensions_state[*it] = cache_it->second; | 236 extensions_state[*it] = cache_it->second; |
| 230 } | 237 } |
| 231 | 238 |
| 232 if (ids_unknown_state.empty()) { | 239 if (ids_unknown_state.empty()) { |
| 233 callback.Run(extensions_state); | 240 callback.Run(extensions_state); |
| 234 } else { | 241 } else { |
| 235 // After the extension blacklist states have been downloaded, call this | 242 // After the extension blacklist states have been downloaded, call this |
| 236 // functions again, but prevent infinite cycle in case server is offline | 243 // functions again, but prevent infinite cycle in case server is offline |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 254 if (cache_it != blacklist_state_cache_.end()) | 261 if (cache_it != blacklist_state_cache_.end()) |
| 255 extensions_state[*it] = cache_it->second; | 262 extensions_state[*it] = cache_it->second; |
| 256 // If for some reason we still haven't cached the state of this extension, | 263 // If for some reason we still haven't cached the state of this extension, |
| 257 // we silently skip it. | 264 // we silently skip it. |
| 258 } | 265 } |
| 259 | 266 |
| 260 callback.Run(extensions_state); | 267 callback.Run(extensions_state); |
| 261 } | 268 } |
| 262 | 269 |
| 263 void Blacklist::RequestExtensionsBlacklistState( | 270 void Blacklist::RequestExtensionsBlacklistState( |
| 264 const std::set<std::string> ids, base::Callback<void()> callback) { | 271 const std::set<std::string>& ids, const base::Callback<void()>& callback) { |
| 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 266 // This is a stub. The request will be made here, but the server is not up | 273 if (!state_fetcher_) |
| 267 // yet. For compatibility with current blacklist logic, mark all extensions | 274 state_fetcher_.reset(new BlacklistStateFetcher()); |
| 268 // as malicious. | 275 |
| 276 state_requests_.push_back( | |
| 277 make_pair(std::vector<std::string>(ids.begin(), ids.end()), callback)); | |
| 269 for (std::set<std::string>::const_iterator it = ids.begin(); | 278 for (std::set<std::string>::const_iterator it = ids.begin(); |
| 270 it != ids.end(); | 279 it != ids.end(); |
| 271 ++it) { | 280 ++it) { |
| 272 blacklist_state_cache_[*it] = BLACKLISTED_MALWARE; | 281 state_fetcher_->Request( |
| 282 *it, | |
| 283 base::Bind(&Blacklist::OnBlacklistStateReceived, AsWeakPtr(), *it)); | |
| 273 } | 284 } |
| 274 callback.Run(); | 285 } |
| 286 | |
| 287 void Blacklist::OnBlacklistStateReceived(const std::string& id, | |
| 288 BlacklistState state) { | |
| 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 290 blacklist_state_cache_[id] = state; | |
| 291 | |
| 292 // Go through the opened requests and call the callbacks for those requests | |
| 293 // for which we already got all the required blacklist states. | |
| 294 StateRequestsList::iterator requests_it = state_requests_.begin(); | |
| 295 while (requests_it != state_requests_.end()) { | |
| 296 const std::vector<std::string>& ids = requests_it->first; | |
| 297 | |
| 298 bool have_all_in_cache = true; | |
| 299 for (std::vector<std::string>::const_iterator ids_it = ids.begin(); | |
| 300 ids_it != ids.end(); | |
| 301 ++ids_it) { | |
| 302 if (!ContainsKey(blacklist_state_cache_, *ids_it)) { | |
| 303 have_all_in_cache = false; | |
| 304 break; | |
| 305 } | |
| 306 } | |
| 307 | |
| 308 if (have_all_in_cache) { | |
| 309 requests_it->second.Run(); | |
| 310 requests_it = state_requests_.erase(requests_it); // returns next element | |
| 311 } else { | |
| 312 ++requests_it; | |
| 313 } | |
| 314 } | |
| 315 } | |
| 316 | |
| 317 void Blacklist::SetBlacklistStateFetcherForTest( | |
| 318 BlacklistStateFetcher* fetcher) { | |
| 319 state_fetcher_.reset(fetcher); | |
| 275 } | 320 } |
| 276 | 321 |
| 277 void Blacklist::AddObserver(Observer* observer) { | 322 void Blacklist::AddObserver(Observer* observer) { |
| 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 279 observers_.AddObserver(observer); | 324 observers_.AddObserver(observer); |
| 280 } | 325 } |
| 281 | 326 |
| 282 void Blacklist::RemoveObserver(Observer* observer) { | 327 void Blacklist::RemoveObserver(Observer* observer) { |
| 283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 284 observers_.RemoveObserver(observer); | 329 observers_.RemoveObserver(observer); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 296 } | 341 } |
| 297 | 342 |
| 298 void Blacklist::Observe(int type, | 343 void Blacklist::Observe(int type, |
| 299 const content::NotificationSource& source, | 344 const content::NotificationSource& source, |
| 300 const content::NotificationDetails& details) { | 345 const content::NotificationDetails& details) { |
| 301 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); | 346 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); |
| 302 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); | 347 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); |
| 303 } | 348 } |
| 304 | 349 |
| 305 } // namespace extensions | 350 } // namespace extensions |
| OLD | NEW |