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

Side by Side Diff: extensions/common/event_filter.cc

Issue 2937623002: [Extensions] Simplify EventFilteringInfo (Closed)
Patch Set: karan's Created 3 years, 6 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 "extensions/common/event_filter.h" 5 #include "extensions/common/event_filter.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 const EventFilteringInfo& event_info, 137 const EventFilteringInfo& event_info,
138 int routing_id) const { 138 int routing_id) const {
139 std::set<MatcherID> matchers; 139 std::set<MatcherID> matchers;
140 140
141 auto it = event_matchers_.find(event_name); 141 auto it = event_matchers_.find(event_name);
142 if (it == event_matchers_.end()) 142 if (it == event_matchers_.end())
143 return matchers; 143 return matchers;
144 144
145 const EventMatcherMap& matcher_map = it->second; 145 const EventMatcherMap& matcher_map = it->second;
146 const GURL& url_to_match_against = 146 const GURL& url_to_match_against =
147 event_info.has_url() ? event_info.url() : GURL::EmptyGURL(); 147 event_info.url ? *event_info.url : GURL::EmptyGURL();
148 std::set<URLMatcherConditionSet::ID> matching_condition_set_ids = 148 std::set<URLMatcherConditionSet::ID> matching_condition_set_ids =
149 url_matcher_.MatchURL(url_to_match_against); 149 url_matcher_.MatchURL(url_to_match_against);
150 for (const auto& id_key : matching_condition_set_ids) { 150 for (const auto& id_key : matching_condition_set_ids) {
151 auto matcher_id = condition_set_id_to_event_matcher_id_.find(id_key); 151 auto matcher_id = condition_set_id_to_event_matcher_id_.find(id_key);
152 if (matcher_id == condition_set_id_to_event_matcher_id_.end()) { 152 if (matcher_id == condition_set_id_to_event_matcher_id_.end()) {
153 NOTREACHED() << "id not found in condition set map (" << id_key << ")"; 153 NOTREACHED() << "id not found in condition set map (" << id_key << ")";
154 continue; 154 continue;
155 } 155 }
156 MatcherID id = matcher_id->second; 156 MatcherID id = matcher_id->second;
157 EventMatcherMap::const_iterator matcher_entry = matcher_map.find(id); 157 EventMatcherMap::const_iterator matcher_entry = matcher_map.find(id);
158 if (matcher_entry == matcher_map.end()) { 158 if (matcher_entry == matcher_map.end()) {
159 // Matcher must be for a different event. 159 // Matcher must be for a different event.
160 continue; 160 continue;
161 } 161 }
162 const EventMatcher* event_matcher = matcher_entry->second->event_matcher(); 162 const EventMatcher* event_matcher = matcher_entry->second->event_matcher();
163 // The context that installed the event listener should be the same context 163 // The context that installed the event listener should be the same context
164 // as the one where the event listener is called. 164 // as the one where the event listener is called.
165 if (routing_id != MSG_ROUTING_NONE && 165 if (routing_id != MSG_ROUTING_NONE &&
166 event_matcher->GetRoutingID() != routing_id) { 166 event_matcher->GetRoutingID() != routing_id) {
167 continue; 167 continue;
168 } 168 }
169 if (event_matcher->MatchNonURLCriteria(event_info)) { 169 if (event_matcher->MatchNonURLCriteria(event_info)) {
170 CHECK(!event_matcher->HasURLFilters() || event_info.has_url()); 170 CHECK(!event_matcher->HasURLFilters() || event_info.url);
171 matchers.insert(id); 171 matchers.insert(id);
172 } 172 }
173 } 173 }
174 174
175 return matchers; 175 return matchers;
176 } 176 }
177 177
178 int EventFilter::GetMatcherCountForEventForTesting( 178 int EventFilter::GetMatcherCountForEventForTesting(
179 const std::string& name) const { 179 const std::string& name) const {
180 EventMatcherMultiMap::const_iterator it = event_matchers_.find(name); 180 EventMatcherMultiMap::const_iterator it = event_matchers_.find(name);
181 return it != event_matchers_.end() ? it->second.size() : 0; 181 return it != event_matchers_.end() ? it->second.size() : 0;
182 } 182 }
183 183
184 } // namespace extensions 184 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/guest_view/extensions_guest_view_manager_delegate.cc ('k') | extensions/common/event_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698