Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / common / event_matcher.cc
blob8ae022a00e8845bcb749813c3e973bf847932649
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
3 // found in the LICENSE file.
5 #include "extensions/common/event_matcher.h"
7 #include "extensions/common/event_filtering_info.h"
9 namespace {
10 const char kUrlFiltersKey[] = "url";
13 namespace extensions {
15 const char kEventFilterServiceTypeKey[] = "serviceType";
17 EventMatcher::EventMatcher(scoped_ptr<base::DictionaryValue> filter,
18 int routing_id)
19 : filter_(filter.Pass()),
20 routing_id_(routing_id) {
23 EventMatcher::~EventMatcher() {
26 bool EventMatcher::MatchNonURLCriteria(
27 const EventFilteringInfo& event_info) const {
28 if (event_info.has_instance_id()) {
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();
37 int EventMatcher::GetURLFilterCount() const {
38 base::ListValue* url_filters = NULL;
39 if (filter_->GetList(kUrlFiltersKey, &url_filters))
40 return url_filters->GetSize();
41 return 0;
44 bool EventMatcher::GetURLFilter(int i, base::DictionaryValue** url_filter_out) {
45 base::ListValue* url_filters = NULL;
46 if (filter_->GetList(kUrlFiltersKey, &url_filters)) {
47 return url_filters->GetDictionary(i, url_filter_out);
49 return false;
52 int EventMatcher::HasURLFilters() const {
53 return GetURLFilterCount() != 0;
56 std::string EventMatcher::GetServiceTypeFilter() const {
57 std::string service_type_filter;
58 filter_->GetStringASCII(kEventFilterServiceTypeKey, &service_type_filter);
59 return service_type_filter;
62 int EventMatcher::GetInstanceID() const {
63 int instance_id = 0;
64 filter_->GetInteger("instanceId", &instance_id);
65 return instance_id;
68 int EventMatcher::GetRoutingID() const {
69 return routing_id_;
72 } // namespace extensions