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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.cc

Issue 2230203002: chrome: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed accidental components/ change Created 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/api/declarative_content/chrome_content_rules _registry.h" 5 #include "chrome/browser/extensions/api/declarative_content/chrome_content_rules _registry.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 EvaluationScope evaluation_scope(this); 129 EvaluationScope evaluation_scope(this);
130 for (const std::unique_ptr<ContentPredicateEvaluator>& evaluator : 130 for (const std::unique_ptr<ContentPredicateEvaluator>& evaluator :
131 evaluators_) 131 evaluators_)
132 evaluator->TrackForWebContents(contents); 132 evaluator->TrackForWebContents(contents);
133 } 133 }
134 134
135 void ChromeContentRulesRegistry::DidNavigateMainFrame( 135 void ChromeContentRulesRegistry::DidNavigateMainFrame(
136 content::WebContents* contents, 136 content::WebContents* contents,
137 const content::LoadCommittedDetails& details, 137 const content::LoadCommittedDetails& details,
138 const content::FrameNavigateParams& params) { 138 const content::FrameNavigateParams& params) {
139 if (ContainsKey(active_rules_, contents)) { 139 if (base::ContainsKey(active_rules_, contents)) {
140 EvaluationScope evaluation_scope(this); 140 EvaluationScope evaluation_scope(this);
141 for (const std::unique_ptr<ContentPredicateEvaluator>& evaluator : 141 for (const std::unique_ptr<ContentPredicateEvaluator>& evaluator :
142 evaluators_) 142 evaluators_)
143 evaluator->OnWebContentsNavigation(contents, details, params); 143 evaluator->OnWebContentsNavigation(contents, details, params);
144 } 144 }
145 } 145 }
146 146
147 ChromeContentRulesRegistry::ContentRule::ContentRule( 147 ChromeContentRulesRegistry::ContentRule::ContentRule(
148 const Extension* extension, 148 const Extension* extension,
149 std::vector<std::unique_ptr<const ContentCondition>> conditions, 149 std::vector<std::unique_ptr<const ContentCondition>> conditions,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // Skip unknown rules. 314 // Skip unknown rules.
315 RulesMap::iterator content_rules_entry = 315 RulesMap::iterator content_rules_entry =
316 content_rules_.find(std::make_pair(extension_id, id)); 316 content_rules_.find(std::make_pair(extension_id, id));
317 if (content_rules_entry == content_rules_.end()) 317 if (content_rules_entry == content_rules_.end())
318 continue; 318 continue;
319 319
320 const ContentRule* rule = content_rules_entry->second.get(); 320 const ContentRule* rule = content_rules_entry->second.get();
321 321
322 // Remove the ContentRule from active_rules_. 322 // Remove the ContentRule from active_rules_.
323 for (auto& tab_rules_pair : active_rules_) { 323 for (auto& tab_rules_pair : active_rules_) {
324 if (ContainsKey(tab_rules_pair.second, rule)) { 324 if (base::ContainsKey(tab_rules_pair.second, rule)) {
325 ContentAction::ApplyInfo apply_info = 325 ContentAction::ApplyInfo apply_info =
326 {rule->extension, browser_context(), tab_rules_pair.first, 326 {rule->extension, browser_context(), tab_rules_pair.first,
327 rule->priority}; 327 rule->priority};
328 for (const auto& action : rule->actions) 328 for (const auto& action : rule->actions)
329 action->Revert(apply_info); 329 action->Revert(apply_info);
330 tab_rules_pair.second.erase(rule); 330 tab_rules_pair.second.erase(rule);
331 } 331 }
332 } 332 }
333 333
334 rules_to_erase.push_back(content_rules_entry); 334 rules_to_erase.push_back(content_rules_entry);
(...skipping 21 matching lines...) Expand all
356 if (extension_id_rule_id_pair.first == extension_id) 356 if (extension_id_rule_id_pair.first == extension_id)
357 rule_identifiers.push_back(extension_id_rule_id_pair.second); 357 rule_identifiers.push_back(extension_id_rule_id_pair.second);
358 } 358 }
359 359
360 return RemoveRulesImpl(extension_id, rule_identifiers); 360 return RemoveRulesImpl(extension_id, rule_identifiers);
361 } 361 }
362 362
363 void ChromeContentRulesRegistry::EvaluateConditionsForTab( 363 void ChromeContentRulesRegistry::EvaluateConditionsForTab(
364 content::WebContents* tab) { 364 content::WebContents* tab) {
365 std::set<const ContentRule*> matching_rules = GetMatchingRules(tab); 365 std::set<const ContentRule*> matching_rules = GetMatchingRules(tab);
366 if (matching_rules.empty() && !ContainsKey(active_rules_, tab)) 366 if (matching_rules.empty() && !base::ContainsKey(active_rules_, tab))
367 return; 367 return;
368 368
369 std::set<const ContentRule*>& prev_matching_rules = active_rules_[tab]; 369 std::set<const ContentRule*>& prev_matching_rules = active_rules_[tab];
370 for (const ContentRule* rule : matching_rules) { 370 for (const ContentRule* rule : matching_rules) {
371 ContentAction::ApplyInfo apply_info = 371 ContentAction::ApplyInfo apply_info =
372 {rule->extension, browser_context(), tab, rule->priority}; 372 {rule->extension, browser_context(), tab, rule->priority};
373 if (!ContainsKey(prev_matching_rules, rule)) { 373 if (!base::ContainsKey(prev_matching_rules, rule)) {
374 for (const std::unique_ptr<const ContentAction>& action : rule->actions) 374 for (const std::unique_ptr<const ContentAction>& action : rule->actions)
375 action->Apply(apply_info); 375 action->Apply(apply_info);
376 } else { 376 } else {
377 for (const std::unique_ptr<const ContentAction>& action : rule->actions) 377 for (const std::unique_ptr<const ContentAction>& action : rule->actions)
378 action->Reapply(apply_info); 378 action->Reapply(apply_info);
379 } 379 }
380 } 380 }
381 for (const ContentRule* rule : prev_matching_rules) { 381 for (const ContentRule* rule : prev_matching_rules) {
382 if (!ContainsKey(matching_rules, rule)) { 382 if (!base::ContainsKey(matching_rules, rule)) {
383 ContentAction::ApplyInfo apply_info = 383 ContentAction::ApplyInfo apply_info =
384 {rule->extension, browser_context(), tab, rule->priority}; 384 {rule->extension, browser_context(), tab, rule->priority};
385 for (const std::unique_ptr<const ContentAction>& action : rule->actions) 385 for (const std::unique_ptr<const ContentAction>& action : rule->actions)
386 action->Revert(apply_info); 386 action->Revert(apply_info);
387 } 387 }
388 } 388 }
389 389
390 if (matching_rules.empty()) 390 if (matching_rules.empty())
391 active_rules_[tab].clear(); 391 active_rules_[tab].clear();
392 else 392 else
(...skipping 30 matching lines...) Expand all
423 size_t count = 0; 423 size_t count = 0;
424 for (const auto& web_contents_rules_pair : active_rules_) 424 for (const auto& web_contents_rules_pair : active_rules_)
425 count += web_contents_rules_pair.second.size(); 425 count += web_contents_rules_pair.second.size();
426 return count; 426 return count;
427 } 427 }
428 428
429 ChromeContentRulesRegistry::~ChromeContentRulesRegistry() { 429 ChromeContentRulesRegistry::~ChromeContentRulesRegistry() {
430 } 430 }
431 431
432 } // namespace extensions 432 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698