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

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

Issue 216513002: Replace DCHECK(BrowserThread::CurrentlyOn) with DCHECK_CURRENTLY_ON in extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months 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
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> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 private: 85 private:
86 friend class base::RefCountedThreadSafe<SafeBrowsingClientImpl>; 86 friend class base::RefCountedThreadSafe<SafeBrowsingClientImpl>;
87 virtual ~SafeBrowsingClientImpl() {} 87 virtual ~SafeBrowsingClientImpl() {}
88 88
89 // Pass |database_manager| as a parameter to avoid touching 89 // Pass |database_manager| as a parameter to avoid touching
90 // SafeBrowsingService on the IO thread. 90 // SafeBrowsingService on the IO thread.
91 void StartCheck(scoped_refptr<SafeBrowsingDatabaseManager> database_manager, 91 void StartCheck(scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
92 const std::set<std::string>& extension_ids) { 92 const std::set<std::string>& extension_ids) {
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 93 DCHECK_CURRENTLY_ON(BrowserThread::IO);
94 if (database_manager->CheckExtensionIDs(extension_ids, this)) { 94 if (database_manager->CheckExtensionIDs(extension_ids, this)) {
95 // Definitely not blacklisted. Callback immediately. 95 // Definitely not blacklisted. Callback immediately.
96 callback_message_loop_->PostTask( 96 callback_message_loop_->PostTask(
97 FROM_HERE, 97 FROM_HERE,
98 base::Bind(callback_, std::set<std::string>())); 98 base::Bind(callback_, std::set<std::string>()));
99 return; 99 return;
100 } 100 }
101 // Something might be blacklisted, response will come in 101 // Something might be blacklisted, response will come in
102 // OnCheckExtensionsResult. 102 // OnCheckExtensionsResult.
103 AddRef(); // Balanced in OnCheckExtensionsResult 103 AddRef(); // Balanced in OnCheckExtensionsResult
104 } 104 }
105 105
106 virtual void OnCheckExtensionsResult( 106 virtual void OnCheckExtensionsResult(
107 const std::set<std::string>& hits) OVERRIDE { 107 const std::set<std::string>& hits) OVERRIDE {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 108 DCHECK_CURRENTLY_ON(BrowserThread::IO);
109 callback_message_loop_->PostTask(FROM_HERE, base::Bind(callback_, hits)); 109 callback_message_loop_->PostTask(FROM_HERE, base::Bind(callback_, hits));
110 Release(); // Balanced in StartCheck. 110 Release(); // Balanced in StartCheck.
111 } 111 }
112 112
113 scoped_refptr<base::MessageLoopProxy> callback_message_loop_; 113 scoped_refptr<base::MessageLoopProxy> callback_message_loop_;
114 OnResultCallback callback_; 114 OnResultCallback callback_;
115 115
116 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingClientImpl); 116 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingClientImpl);
117 }; 117 };
118 118
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 if (!prefs->GetInstalledExtensionInfo(*it)) 177 if (!prefs->GetInstalledExtensionInfo(*it))
178 prefs->DeleteExtensionPrefs(*it); 178 prefs->DeleteExtensionPrefs(*it);
179 } 179 }
180 } 180 }
181 181
182 Blacklist::~Blacklist() { 182 Blacklist::~Blacklist() {
183 } 183 }
184 184
185 void Blacklist::GetBlacklistedIDs(const std::set<std::string>& ids, 185 void Blacklist::GetBlacklistedIDs(const std::set<std::string>& ids,
186 const GetBlacklistedIDsCallback& callback) { 186 const GetBlacklistedIDsCallback& callback) {
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 187 DCHECK_CURRENTLY_ON(BrowserThread::UI);
188 188
189 if (ids.empty() || !g_database_manager.Get().get().get()) { 189 if (ids.empty() || !g_database_manager.Get().get().get()) {
190 base::MessageLoopProxy::current()->PostTask( 190 base::MessageLoopProxy::current()->PostTask(
191 FROM_HERE, base::Bind(callback, BlacklistStateMap())); 191 FROM_HERE, base::Bind(callback, BlacklistStateMap()));
192 return; 192 return;
193 } 193 }
194 194
195 // Constructing the SafeBrowsingClientImpl begins the process of asking 195 // Constructing the SafeBrowsingClientImpl begins the process of asking
196 // safebrowsing for the blacklisted extensions. The set of blacklisted 196 // safebrowsing for the blacklisted extensions. The set of blacklisted
197 // extensions returned by SafeBrowsing will then be passed to 197 // extensions returned by SafeBrowsing will then be passed to
(...skipping 13 matching lines...) Expand all
211 void Blacklist::IsBlacklisted(const std::string& extension_id, 211 void Blacklist::IsBlacklisted(const std::string& extension_id,
212 const IsBlacklistedCallback& callback) { 212 const IsBlacklistedCallback& callback) {
213 std::set<std::string> check; 213 std::set<std::string> check;
214 check.insert(extension_id); 214 check.insert(extension_id);
215 GetBlacklistedIDs(check, base::Bind(&CheckOneExtensionState, callback)); 215 GetBlacklistedIDs(check, base::Bind(&CheckOneExtensionState, callback));
216 } 216 }
217 217
218 void Blacklist::GetBlacklistStateForIDs( 218 void Blacklist::GetBlacklistStateForIDs(
219 const GetBlacklistedIDsCallback& callback, 219 const GetBlacklistedIDsCallback& callback,
220 const std::set<std::string>& blacklisted_ids) { 220 const std::set<std::string>& blacklisted_ids) {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 221 DCHECK_CURRENTLY_ON(BrowserThread::UI);
222 222
223 std::set<std::string> ids_unknown_state; 223 std::set<std::string> ids_unknown_state;
224 BlacklistStateMap extensions_state; 224 BlacklistStateMap extensions_state;
225 for (std::set<std::string>::const_iterator it = blacklisted_ids.begin(); 225 for (std::set<std::string>::const_iterator it = blacklisted_ids.begin();
226 it != blacklisted_ids.end(); ++it) { 226 it != blacklisted_ids.end(); ++it) {
227 BlacklistStateMap::const_iterator cache_it = 227 BlacklistStateMap::const_iterator cache_it =
228 blacklist_state_cache_.find(*it); 228 blacklist_state_cache_.find(*it);
229 if (cache_it == blacklist_state_cache_.end() || 229 if (cache_it == blacklist_state_cache_.end() ||
230 cache_it->second == BLACKLISTED_UNKNOWN) // Do not return UNKNOWN 230 cache_it->second == BLACKLISTED_UNKNOWN) // Do not return UNKNOWN
231 // from cache, retry request. 231 // from cache, retry request.
(...skipping 28 matching lines...) Expand all
260 extensions_state[*it] = cache_it->second; 260 extensions_state[*it] = cache_it->second;
261 // If for some reason we still haven't cached the state of this extension, 261 // If for some reason we still haven't cached the state of this extension,
262 // we silently skip it. 262 // we silently skip it.
263 } 263 }
264 264
265 callback.Run(extensions_state); 265 callback.Run(extensions_state);
266 } 266 }
267 267
268 void Blacklist::RequestExtensionsBlacklistState( 268 void Blacklist::RequestExtensionsBlacklistState(
269 const std::set<std::string>& ids, const base::Callback<void()>& callback) { 269 const std::set<std::string>& ids, const base::Callback<void()>& callback) {
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 270 DCHECK_CURRENTLY_ON(BrowserThread::UI);
271 if (!state_fetcher_) 271 if (!state_fetcher_)
272 state_fetcher_.reset(new BlacklistStateFetcher()); 272 state_fetcher_.reset(new BlacklistStateFetcher());
273 273
274 state_requests_.push_back( 274 state_requests_.push_back(
275 make_pair(std::vector<std::string>(ids.begin(), ids.end()), callback)); 275 make_pair(std::vector<std::string>(ids.begin(), ids.end()), callback));
276 for (std::set<std::string>::const_iterator it = ids.begin(); 276 for (std::set<std::string>::const_iterator it = ids.begin();
277 it != ids.end(); 277 it != ids.end();
278 ++it) { 278 ++it) {
279 state_fetcher_->Request( 279 state_fetcher_->Request(
280 *it, 280 *it,
281 base::Bind(&Blacklist::OnBlacklistStateReceived, AsWeakPtr(), *it)); 281 base::Bind(&Blacklist::OnBlacklistStateReceived, AsWeakPtr(), *it));
282 } 282 }
283 } 283 }
284 284
285 void Blacklist::OnBlacklistStateReceived(const std::string& id, 285 void Blacklist::OnBlacklistStateReceived(const std::string& id,
286 BlacklistState state) { 286 BlacklistState state) {
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 287 DCHECK_CURRENTLY_ON(BrowserThread::UI);
288 blacklist_state_cache_[id] = state; 288 blacklist_state_cache_[id] = state;
289 289
290 // Go through the opened requests and call the callbacks for those requests 290 // Go through the opened requests and call the callbacks for those requests
291 // for which we already got all the required blacklist states. 291 // for which we already got all the required blacklist states.
292 StateRequestsList::iterator requests_it = state_requests_.begin(); 292 StateRequestsList::iterator requests_it = state_requests_.begin();
293 while (requests_it != state_requests_.end()) { 293 while (requests_it != state_requests_.end()) {
294 const std::vector<std::string>& ids = requests_it->first; 294 const std::vector<std::string>& ids = requests_it->first;
295 295
296 bool have_all_in_cache = true; 296 bool have_all_in_cache = true;
297 for (std::vector<std::string>::const_iterator ids_it = ids.begin(); 297 for (std::vector<std::string>::const_iterator ids_it = ids.begin();
(...skipping 17 matching lines...) Expand all
315 void Blacklist::SetBlacklistStateFetcherForTest( 315 void Blacklist::SetBlacklistStateFetcherForTest(
316 BlacklistStateFetcher* fetcher) { 316 BlacklistStateFetcher* fetcher) {
317 state_fetcher_.reset(fetcher); 317 state_fetcher_.reset(fetcher);
318 } 318 }
319 319
320 BlacklistStateFetcher* Blacklist::ResetBlacklistStateFetcherForTest() { 320 BlacklistStateFetcher* Blacklist::ResetBlacklistStateFetcherForTest() {
321 return state_fetcher_.release(); 321 return state_fetcher_.release();
322 } 322 }
323 323
324 void Blacklist::AddObserver(Observer* observer) { 324 void Blacklist::AddObserver(Observer* observer) {
325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 325 DCHECK_CURRENTLY_ON(BrowserThread::UI);
326 observers_.AddObserver(observer); 326 observers_.AddObserver(observer);
327 } 327 }
328 328
329 void Blacklist::RemoveObserver(Observer* observer) { 329 void Blacklist::RemoveObserver(Observer* observer) {
330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 330 DCHECK_CURRENTLY_ON(BrowserThread::UI);
331 observers_.RemoveObserver(observer); 331 observers_.RemoveObserver(observer);
332 } 332 }
333 333
334 // static 334 // static
335 void Blacklist::SetDatabaseManager( 335 void Blacklist::SetDatabaseManager(
336 scoped_refptr<SafeBrowsingDatabaseManager> database_manager) { 336 scoped_refptr<SafeBrowsingDatabaseManager> database_manager) {
337 g_database_manager.Get().set(database_manager); 337 g_database_manager.Get().set(database_manager);
338 } 338 }
339 339
340 // static 340 // static
341 scoped_refptr<SafeBrowsingDatabaseManager> Blacklist::GetDatabaseManager() { 341 scoped_refptr<SafeBrowsingDatabaseManager> Blacklist::GetDatabaseManager() {
342 return g_database_manager.Get().get(); 342 return g_database_manager.Get().get();
343 } 343 }
344 344
345 void Blacklist::Observe(int type, 345 void Blacklist::Observe(int type,
346 const content::NotificationSource& source, 346 const content::NotificationSource& source,
347 const content::NotificationDetails& details) { 347 const content::NotificationDetails& details) {
348 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); 348 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type);
349 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); 349 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated());
350 } 350 }
351 351
352 } // namespace extensions 352 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698