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

Side by Side Diff: chrome/browser/extensions/api/declarative/substring_set_matcher.h

Issue 9390018: Implementation of a Matching strategy for URLs in the Declarative WebRequest API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MSVC does not support EXPECT_NE on iterators Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/extensions/api/declarative/substring_set_matcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_
7 #pragma once
8
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
13
14 #include "base/basictypes.h"
15
16 namespace extensions {
17
18 // An individual pattern of the SubstringSetMatcher. A pattern consists of
19 // a string (interpreted as individual bytes, no character encoding) and an
20 // identifier.
21 // Each pattern that matches a string emits its ID to the caller of
22 // SubstringSetMatcher::Match(). This helps the caller to figure out what
23 // patterns matched a string. All patterns registered to a SubstringSetMatcher
24 // need to contain unique IDs.
25 class SubstringPattern {
26 public:
27 typedef int ID;
28
29 SubstringPattern(const std::string& pattern, ID id);
30 ~SubstringPattern();
31 const std::string& pattern() const { return pattern_; }
32 ID id() const { return id_; }
33
34 bool operator<(const SubstringPattern& rhs) const;
35
36 private:
37 std::string pattern_;
38 ID id_;
39
40 DISALLOW_COPY_AND_ASSIGN(SubstringPattern);
41 };
42
43 // Class that store a set of string patterns and can find for a string S,
44 // which string patterns occur in S.
45 class SubstringSetMatcher {
46 public:
47 SubstringSetMatcher();
48 ~SubstringSetMatcher();
49
50 // Registers all |patterns|. The ownership remains with the caller.
51 // The same pattern cannot be registered twice and each pattern needs to have
52 // a unique ID.
53 // Ownership of the patterns remains with the caller.
54 void RegisterPatterns(const std::vector<const SubstringPattern*>& patterns);
55
56 // Unregisters the passed |patterns|.
57 void UnregisterPatterns(const std::vector<const SubstringPattern*>& patterns);
58
59 // Analogous to RegisterPatterns and UnregisterPatterns but executes both
60 // operations in one step, which may be cheaper in the execution.
61 void RegisterAndUnregisterPatterns(
62 const std::vector<const SubstringPattern*>& to_register,
63 const std::vector<const SubstringPattern*>& to_unregister);
64
65 // Matches |text| against all registered SubstringPatterns. Stores the IDs
66 // of matching patterns in |matches|. |matches| is not cleared before adding
67 // to it.
68 bool Match(const std::string& text,
69 std::set<SubstringPattern::ID>* matches) const;
70
71 private:
72 typedef std::map<SubstringPattern::ID, const SubstringPattern*>
73 SubstringPatternSet;
74 SubstringPatternSet patterns_;
75
76 DISALLOW_COPY_AND_ASSIGN(SubstringSetMatcher);
77 };
78
79 } // namespace extensions
80
81 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/declarative/substring_set_matcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698