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

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

Issue 9422003: Migrate Declarative API bindings to new JSON objects generated by JSON compiler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pacify clang 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_H_ _ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_H_ _
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_H_ _ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY_H_ _
7 #pragma once 7 #pragma once
8 8
9 #include "chrome/browser/extensions/api/declarative/rules_registry.h" 9 #include "chrome/browser/extensions/api/declarative/rules_registry.h"
10 10
11 #include <map> 11 #include <map>
12 #include <set> 12 #include <set>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 16
17 namespace extensions { 17 namespace extensions {
18 18
19 // Wrapper class for RulesRegistry objects that takes care that all optional 19 // Wrapper class for RulesRegistry objects that takes care that all optional
20 // fields of rules are filled with valid values. 20 // fields of rules are filled with valid values.
21 class InitializingRulesRegistry : public RulesRegistry { 21 class InitializingRulesRegistry : public RulesRegistry {
22 public: 22 public:
23 explicit InitializingRulesRegistry(scoped_ptr<RulesRegistry> delegate); 23 explicit InitializingRulesRegistry(scoped_ptr<RulesRegistry> delegate);
24 virtual ~InitializingRulesRegistry(); 24 virtual ~InitializingRulesRegistry();
25 25
26 // Implementation for RulesRegistry: 26 // Implementation for RulesRegistry:
27 virtual std::string AddRules( 27 virtual std::string AddRules(
28 const std::string& extension_id, 28 const std::string& extension_id,
29 const std::vector<base::DictionaryValue*>& rules) OVERRIDE; 29 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules) OVERRIDE;
30 virtual std::string RemoveRules( 30 virtual std::string RemoveRules(
31 const std::string& extension_id, 31 const std::string& extension_id,
32 const std::vector<std::string>& rule_identifiers) OVERRIDE; 32 const std::vector<std::string>& rule_identifiers) OVERRIDE;
33 virtual std::string RemoveAllRules( 33 virtual std::string RemoveAllRules(
34 const std::string& extension_id) OVERRIDE; 34 const std::string& extension_id) OVERRIDE;
35 virtual std::string GetRules( 35 virtual std::string GetRules(
36 const std::string& extension_id, 36 const std::string& extension_id,
37 const std::vector<std::string>& rule_identifiers, 37 const std::vector<std::string>& rule_identifiers,
38 std::vector<base::DictionaryValue*>* out) OVERRIDE; 38 std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE;
39 virtual std::string GetAllRules( 39 virtual std::string GetAllRules(
40 const std::string& extension_id, 40 const std::string& extension_id,
41 std::vector<base::DictionaryValue*>* out) OVERRIDE; 41 std::vector<linked_ptr<RulesRegistry::Rule> >* out) OVERRIDE;
42 virtual void OnExtensionUnloaded(const std::string& extension_id) OVERRIDE; 42 virtual void OnExtensionUnloaded(const std::string& extension_id) OVERRIDE;
43 virtual content::BrowserThread::ID GetOwnerThread() OVERRIDE;
43 44
44 private: 45 private:
45 // Returns whether any existing rule is registered with identifier |rule_id| 46 // Returns whether any existing rule is registered with identifier |rule_id|
46 // for extension |extension_id|. 47 // for extension |extension_id|.
47 bool IsUniqueId(const std::string& extension_id, 48 bool IsUniqueId(const std::string& extension_id,
48 const std::string& rule_id) const; 49 const std::string& rule_id) const;
49 50
50 // Creates an ID that is unique within the scope of|extension_id|. 51 // Creates an ID that is unique within the scope of|extension_id|.
51 std::string GenerateUniqueId(std::string extension_id); 52 std::string GenerateUniqueId(std::string extension_id);
52 53
53 // Verifies that all |rules| have unique IDs or initializes them with 54 // Verifies that all |rules| have unique IDs or initializes them with
54 // unique IDs if they don't have one. In case of duplicate IDs, this function 55 // unique IDs if they don't have one. In case of duplicate IDs, this function
55 // returns a non-empty error message. 56 // returns a non-empty error message.
56 std::string CheckAndFillInOptionalRules( 57 std::string CheckAndFillInOptionalRules(
57 const std::string& extension_id, 58 const std::string& extension_id,
58 const std::vector<base::DictionaryValue*>& rules); 59 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules);
59 60
60 // Initializes the priority fields in case they have not been set. 61 // Initializes the priority fields in case they have not been set.
61 void FillInOptionalPriorities( 62 void FillInOptionalPriorities(
62 const std::vector<base::DictionaryValue*>& rules); 63 const std::vector<linked_ptr<RulesRegistry::Rule> >& rules);
63 64
64 // Removes all |identifiers| of |extension_id| from |used_rule_identifiers_|. 65 // Removes all |identifiers| of |extension_id| from |used_rule_identifiers_|.
65 void RemoveUsedRuleIdentifiers(const std::string& extension_id, 66 void RemoveUsedRuleIdentifiers(const std::string& extension_id,
66 const std::vector<std::string>& identifiers); 67 const std::vector<std::string>& identifiers);
67 68
68 // Same as RemoveUsedRuleIdentifiers but operates on all rules of 69 // Same as RemoveUsedRuleIdentifiers but operates on all rules of
69 // |extension_id|. 70 // |extension_id|.
70 void RemoveAllUsedRuleIdentifiers(const std::string& extension_id); 71 void RemoveAllUsedRuleIdentifiers(const std::string& extension_id);
71 72
72 scoped_ptr<RulesRegistry> delegate_; 73 scoped_ptr<RulesRegistry> delegate_;
73 74
74 typedef std::map<std::string, std::set<std::string> > RuleIdentifiersMap; 75 typedef std::map<std::string, std::set<std::string> > RuleIdentifiersMap;
75 RuleIdentifiersMap used_rule_identifiers_; 76 RuleIdentifiersMap used_rule_identifiers_;
76 int last_generated_rule_identifier_id_; 77 int last_generated_rule_identifier_id_;
77 }; 78 };
78 79
79 } // namespace extensions 80 } // namespace extensions
80 81
81 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY _H__ 82 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_INITIALIZING_RULES_REGISTRY _H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698