| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/declarative_content_
page_url_condition_tracker.h" | 5 #include "chrome/browser/extensions/api/declarative_content/declarative_content_
page_url_condition_tracker.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 base::Bind(&DeclarativeContentPageUrlConditionTracker:: | 187 base::Bind(&DeclarativeContentPageUrlConditionTracker:: |
| 188 DeletePerWebContentsTracker, | 188 DeletePerWebContentsTracker, |
| 189 base::Unretained(this)))); | 189 base::Unretained(this)))); |
| 190 per_web_contents_tracker_[contents]->UpdateMatchesForCurrentUrl(true); | 190 per_web_contents_tracker_[contents]->UpdateMatchesForCurrentUrl(true); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void DeclarativeContentPageUrlConditionTracker::OnWebContentsNavigation( | 193 void DeclarativeContentPageUrlConditionTracker::OnWebContentsNavigation( |
| 194 content::WebContents* contents, | 194 content::WebContents* contents, |
| 195 const content::LoadCommittedDetails& details, | 195 const content::LoadCommittedDetails& details, |
| 196 const content::FrameNavigateParams& params) { | 196 const content::FrameNavigateParams& params) { |
| 197 DCHECK(ContainsKey(per_web_contents_tracker_, contents)); | 197 DCHECK(base::ContainsKey(per_web_contents_tracker_, contents)); |
| 198 per_web_contents_tracker_[contents]->UpdateMatchesForCurrentUrl(true); | 198 per_web_contents_tracker_[contents]->UpdateMatchesForCurrentUrl(true); |
| 199 } | 199 } |
| 200 | 200 |
| 201 bool DeclarativeContentPageUrlConditionTracker::EvaluatePredicate( | 201 bool DeclarativeContentPageUrlConditionTracker::EvaluatePredicate( |
| 202 const ContentPredicate* predicate, | 202 const ContentPredicate* predicate, |
| 203 content::WebContents* tab) const { | 203 content::WebContents* tab) const { |
| 204 DCHECK_EQ(this, predicate->GetEvaluator()); | 204 DCHECK_EQ(this, predicate->GetEvaluator()); |
| 205 const DeclarativeContentPageUrlPredicate* typed_predicate = | 205 const DeclarativeContentPageUrlPredicate* typed_predicate = |
| 206 static_cast<const DeclarativeContentPageUrlPredicate*>(predicate); | 206 static_cast<const DeclarativeContentPageUrlPredicate*>(predicate); |
| 207 auto loc = per_web_contents_tracker_.find(tab); | 207 auto loc = per_web_contents_tracker_.find(tab); |
| 208 DCHECK(loc != per_web_contents_tracker_.end()); | 208 DCHECK(loc != per_web_contents_tracker_.end()); |
| 209 const std::set<url_matcher::URLMatcherConditionSet::ID>& | 209 const std::set<url_matcher::URLMatcherConditionSet::ID>& |
| 210 web_contents_id_matches = loc->second->matches(); | 210 web_contents_id_matches = loc->second->matches(); |
| 211 return ContainsKey(web_contents_id_matches, | 211 return base::ContainsKey(web_contents_id_matches, |
| 212 typed_predicate->url_matcher_condition_set()->id()); | 212 typed_predicate->url_matcher_condition_set()->id()); |
| 213 } | 213 } |
| 214 | 214 |
| 215 bool DeclarativeContentPageUrlConditionTracker::IsEmpty() const { | 215 bool DeclarativeContentPageUrlConditionTracker::IsEmpty() const { |
| 216 return url_matcher_.IsEmpty(); | 216 return url_matcher_.IsEmpty(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void DeclarativeContentPageUrlConditionTracker::DeletePerWebContentsTracker( | 219 void DeclarativeContentPageUrlConditionTracker::DeletePerWebContentsTracker( |
| 220 content::WebContents* contents) { | 220 content::WebContents* contents) { |
| 221 DCHECK(ContainsKey(per_web_contents_tracker_, contents)); | 221 DCHECK(base::ContainsKey(per_web_contents_tracker_, contents)); |
| 222 per_web_contents_tracker_.erase(contents); | 222 per_web_contents_tracker_.erase(contents); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void DeclarativeContentPageUrlConditionTracker::UpdateMatchesForAllTrackers() { | 225 void DeclarativeContentPageUrlConditionTracker::UpdateMatchesForAllTrackers() { |
| 226 for (const auto& web_contents_tracker_pair : per_web_contents_tracker_) | 226 for (const auto& web_contents_tracker_pair : per_web_contents_tracker_) |
| 227 web_contents_tracker_pair.second->UpdateMatchesForCurrentUrl(false); | 227 web_contents_tracker_pair.second->UpdateMatchesForCurrentUrl(false); |
| 228 } | 228 } |
| 229 | 229 |
| 230 } // namespace extensions | 230 } // namespace extensions |
| OLD | NEW |