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

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

Issue 23437015: Initial chrome.mdns API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable test for WinDbg Created 7 years, 3 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
« no previous file with comments | « extensions/common/event_matcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_matcher.h" 5 #include "extensions/common/event_matcher.h"
6 6
7 #include "extensions/common/event_filtering_info.h" 7 #include "extensions/common/event_filtering_info.h"
8 8
9 namespace { 9 namespace {
10 const char kUrlFiltersKey[] = "url"; 10 const char kUrlFiltersKey[] = "url";
11 } 11 }
12 12
13 namespace extensions { 13 namespace extensions {
14 14
15 const char kEventFilterServiceTypeKey[] = "serviceType";
16
15 EventMatcher::EventMatcher(scoped_ptr<base::DictionaryValue> filter, 17 EventMatcher::EventMatcher(scoped_ptr<base::DictionaryValue> filter,
16 int routing_id) 18 int routing_id)
17 : filter_(filter.Pass()), 19 : filter_(filter.Pass()),
18 routing_id_(routing_id) { 20 routing_id_(routing_id) {
19 } 21 }
20 22
21 EventMatcher::~EventMatcher() { 23 EventMatcher::~EventMatcher() {
22 } 24 }
23 25
24 bool EventMatcher::MatchNonURLCriteria( 26 bool EventMatcher::MatchNonURLCriteria(
25 const EventFilteringInfo& event_info) const { 27 const EventFilteringInfo& event_info) const {
26 if (!event_info.has_instance_id()) 28 if (event_info.has_instance_id()) {
27 return true; 29 return event_info.instance_id() == GetInstanceID();
30 }
28 31
29 return event_info.instance_id() == GetInstanceID(); 32 const std::string& service_type_filter = GetServiceTypeFilter();
33 return service_type_filter.empty() ||
34 service_type_filter == event_info.service_type();
30 } 35 }
31 36
32 int EventMatcher::GetURLFilterCount() const { 37 int EventMatcher::GetURLFilterCount() const {
33 base::ListValue* url_filters = NULL; 38 base::ListValue* url_filters = NULL;
34 if (filter_->GetList(kUrlFiltersKey, &url_filters)) 39 if (filter_->GetList(kUrlFiltersKey, &url_filters))
35 return url_filters->GetSize(); 40 return url_filters->GetSize();
36 return 0; 41 return 0;
37 } 42 }
38 43
39 bool EventMatcher::GetURLFilter(int i, base::DictionaryValue** url_filter_out) { 44 bool EventMatcher::GetURLFilter(int i, base::DictionaryValue** url_filter_out) {
40 base::ListValue* url_filters = NULL; 45 base::ListValue* url_filters = NULL;
41 if (filter_->GetList(kUrlFiltersKey, &url_filters)) { 46 if (filter_->GetList(kUrlFiltersKey, &url_filters)) {
42 return url_filters->GetDictionary(i, url_filter_out); 47 return url_filters->GetDictionary(i, url_filter_out);
43 } 48 }
44 return false; 49 return false;
45 } 50 }
46 51
47 int EventMatcher::HasURLFilters() const { 52 int EventMatcher::HasURLFilters() const {
48 return GetURLFilterCount() != 0; 53 return GetURLFilterCount() != 0;
49 } 54 }
50 55
56 std::string EventMatcher::GetServiceTypeFilter() const {
57 std::string service_type_filter;
58 filter_->GetStringASCII(kEventFilterServiceTypeKey, &service_type_filter);
59 return service_type_filter;
60 }
61
51 int EventMatcher::GetInstanceID() const { 62 int EventMatcher::GetInstanceID() const {
52 int instance_id = 0; 63 int instance_id = 0;
53 filter_->GetInteger("instanceId", &instance_id); 64 filter_->GetInteger("instanceId", &instance_id);
54 return instance_id; 65 return instance_id;
55 } 66 }
56 67
57 int EventMatcher::GetRoutingID() const { 68 int EventMatcher::GetRoutingID() const {
58 return routing_id_; 69 return routing_id_;
59 } 70 }
60 71
61 } // namespace extensions 72 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/event_matcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698