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

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: Cleanup 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
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 const std::string& pattern() const { return pattern_; }
31 ID id() const { return id_; }
32
33 bool operator<(const SubstringPattern& rhs) const;
34
35 private:
36 std::string pattern_;
37 ID id_;
38
39 DISALLOW_COPY_AND_ASSIGN(SubstringPattern);
40 };
41
42 // Class that store a set of string patterns and can find for a string S,
43 // which string patterns occur in S.
44 class SubstringSetMatcher {
45 public:
46 SubstringSetMatcher();
47 ~SubstringSetMatcher();
48
49 // Registers all |patterns|. The ownership remains with the caller.
50 // The same pattern cannot be registered twice and each pattern needs to have
51 // a unique ID.
52 // Ownership of the patterns remains with the caller.
53 void RegisterPatterns(const std::vector<const SubstringPattern*>& patterns);
54
55 // Unregisters the passed |patterns|.
56 void UnregisterPatterns(const std::vector<const SubstringPattern*>& patterns);
57
58 // Analogous to RegisterPatterns and UnregisterPatterns but executes both
59 // operations in one step, which may be cheaper in the execution.
60 void RegisterAndUnregisterPatterns(
61 const std::vector<const SubstringPattern*>& to_register,
62 const std::vector<const SubstringPattern*>& to_unregister);
63
64 // Matches |text| against all registered SubstringPatterns. Stores the IDs
65 // of matching patterns in |matches|.
66 bool Match(const std::string& text,
67 std::set<SubstringPattern::ID>* matches) const;
68
69 private:
70 typedef std::map<SubstringPattern::ID, const SubstringPattern*>
71 SubstringPatternSet;
72 SubstringPatternSet patterns_;
73
74 DISALLOW_COPY_AND_ASSIGN(SubstringSetMatcher);
75 };
76
77 } // namespace extensions
78
79 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_SUBSTRING_SET_MATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698