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

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

Issue 22460011: [CleanUp] Use base::STLSetDifference in place of std::set_difference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing head file. Created 7 years, 4 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
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 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/stl_util.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/extensions/extension_prefs.h" 16 #include "chrome/browser/extensions/extension_prefs.h"
16 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 17 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
17 #include "chrome/browser/safe_browsing/safe_browsing_util.h" 18 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "content/public/browser/notification_details.h" 20 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_source.h" 21 #include "content/public/browser/notification_source.h"
21 22
22 using content::BrowserThread; 23 using content::BrowserThread;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 for (std::vector<std::string>::const_iterator it = ids.begin(); 211 for (std::vector<std::string>::const_iterator it = ids.begin();
211 it != ids.end(); ++it) { 212 it != ids.end(); ++it) {
212 if (Extension::IdIsValid(*it)) 213 if (Extension::IdIsValid(*it))
213 ids_as_set.insert(*it); 214 ids_as_set.insert(*it);
214 else 215 else
215 LOG(WARNING) << "Got invalid extension ID \"" << *it << "\""; 216 LOG(WARNING) << "Got invalid extension ID \"" << *it << "\"";
216 } 217 }
217 218
218 std::set<std::string> from_prefs = prefs_->GetBlacklistedExtensions(); 219 std::set<std::string> from_prefs = prefs_->GetBlacklistedExtensions();
219 220
220 std::set<std::string> no_longer_blacklisted; 221 std::set<std::string> no_longer_blacklisted =
221 std::set_difference(from_prefs.begin(), from_prefs.end(), 222 base::STLSetDifference<std::set<std::string> >(from_prefs,
222 ids_as_set.begin(), ids_as_set.end(), 223 ids_as_set);
223 std::inserter(no_longer_blacklisted, 224 std::set<std::string> not_yet_blacklisted =
224 no_longer_blacklisted.begin())); 225 base::STLSetDifference<std::set<std::string> >(ids_as_set,
225 std::set<std::string> not_yet_blacklisted; 226 from_prefs);
226 std::set_difference(ids_as_set.begin(), ids_as_set.end(),
227 from_prefs.begin(), from_prefs.end(),
228 std::inserter(not_yet_blacklisted,
229 not_yet_blacklisted.begin()));
230 227
231 for (std::set<std::string>::iterator it = no_longer_blacklisted.begin(); 228 for (std::set<std::string>::iterator it = no_longer_blacklisted.begin();
232 it != no_longer_blacklisted.end(); ++it) { 229 it != no_longer_blacklisted.end(); ++it) {
233 prefs_->SetExtensionBlacklisted(*it, false); 230 prefs_->SetExtensionBlacklisted(*it, false);
234 } 231 }
235 for (std::set<std::string>::iterator it = not_yet_blacklisted.begin(); 232 for (std::set<std::string>::iterator it = not_yet_blacklisted.begin();
236 it != not_yet_blacklisted.end(); ++it) { 233 it != not_yet_blacklisted.end(); ++it) {
237 prefs_->SetExtensionBlacklisted(*it, true); 234 prefs_->SetExtensionBlacklisted(*it, true);
238 } 235 }
239 236
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 275 }
279 276
280 void Blacklist::Observe(int type, 277 void Blacklist::Observe(int type,
281 const content::NotificationSource& source, 278 const content::NotificationSource& source,
282 const content::NotificationDetails& details) { 279 const content::NotificationDetails& details) {
283 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type); 280 DCHECK_EQ(chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, type);
284 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated()); 281 FOR_EACH_OBSERVER(Observer, observers_, OnBlacklistUpdated());
285 } 282 }
286 283
287 } // namespace extensions 284 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/download/download_history_unittest.cc ('k') | chrome/browser/extensions/extension_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698