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.
4
5#ifndef EXTENSIONS_COMMON_EVENT_MATCHER_H_
6#define EXTENSIONS_COMMON_EVENT_MATCHER_H_
7
8#include <memory>
9
10#include "base/macros.h"
11#include "base/values.h"
12
13namespace extensions {
14struct EventFilteringInfo;
15
16extern const char kEventFilterServiceTypeKey[];
17
18// Matches EventFilteringInfos against a set of criteria. This is intended to
19// be used by EventFilter which performs efficient URL matching across
20// potentially many EventMatchers itself. This is why this class only exposes
21// MatchNonURLCriteria() - URL matching is handled by EventFilter.
22class EventMatcher {
23 public:
24 EventMatcher(std::unique_ptr<base::DictionaryValue> filter, int routing_id);
25 ~EventMatcher();
26
27 // Returns true if |event_info| satisfies this matcher's criteria, not taking
28 // into consideration any URL criteria.
29 bool MatchNonURLCriteria(const EventFilteringInfo& event_info) const;
30
31 int GetURLFilterCount() const;
32 bool GetURLFilter(int i, base::DictionaryValue** url_filter_out);
33
34 int GetWindowTypeCount() const;
35 bool GetWindowType(int i, std::string* window_type_out) const;
36
37 std::string GetServiceTypeFilter() const;
38
39 bool HasURLFilters() const;
40
41 bool HasWindowTypes() const;
42
43 int GetInstanceID() const;
44
45 int GetRoutingID() const;
46
47 base::DictionaryValue* value() const {
48 return filter_.get();
49 }
50
51 private:
52 // Contains a dictionary that corresponds to a single event filter, eg:
53 //
54 // {url: [{hostSuffix: 'google.com'}]}
55 //
56 // The valid filter keys are event-specific.
57 const std::unique_ptr<base::DictionaryValue> filter_;
58
59 const int routing_id_;
60
61 DISALLOW_COPY_AND_ASSIGN(EventMatcher);
62};
63
64} // namespace extensions
65
66#endif // EXTENSIONS_COMMON_EVENT_MATCHER_H_
67