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

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

Powered by Google App Engine
This is Rietveld 408576698