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

Side by Side Diff: chrome/browser/extensions/api/declarative/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: Fix memory leaks Created 8 years, 9 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_RULES_REGISTRY_H__ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/ref_counted.h"
13 #include "chrome/common/extensions/api/experimental.declarative.h"
14 #include "content/public/browser/browser_thread.h"
15
12 namespace base { 16 namespace base {
13 class DictionaryValue; 17 class DictionaryValue;
14 } 18 }
15 19
16 namespace extensions { 20 namespace extensions {
17 21
22 class RulesRegistry;
23
24 // Traits that describe how RulesRegistry should be deleted. This just deletes
25 // the RulesRegistry on its owner thread.
26 struct RulesRegistryDeleteTraits {
27 public:
28 static void Destruct(const RulesRegistry* rules_registry);
29 };
30
18 // Interface for rule registries. 31 // Interface for rule registries.
19 class RulesRegistry { 32 //
33 // All functions except GetOwnerThread() are only called on the thread
34 // indicated by GetOwnerThread(). The object is destroyed on the owner thread.
35 class RulesRegistry
36 : public base::RefCountedThreadSafe<RulesRegistry,
37 RulesRegistryDeleteTraits> {
20 public: 38 public:
21 virtual ~RulesRegistry() {} 39 typedef extensions::api::experimental::Rule Rule;
22 40
23 // Registers |rules|, owned by |extension_id| to this RulesRegistry. 41 // Registers |rules|, owned by |extension_id| to this RulesRegistry.
24 // If a concrete RuleRegistry does not support some of the rules, 42 // If a concrete RuleRegistry does not support some of the rules,
25 // it may ignore them. 43 // it may ignore them.
26 // 44 //
27 // |rules| is a list of Rule instances following the definition of the 45 // |rules| is a list of Rule instances following the definition of the
28 // declarative extension APIs. It is guaranteed that each rule in |rules| has 46 // declarative extension APIs. It is guaranteed that each rule in |rules| has
29 // a unique name within the scope of |extension_id| that has not been 47 // a unique name within the scope of |extension_id| that has not been
30 // registered before, unless it has been removed again. 48 // registered before, unless it has been removed again.
31 // The ownership of rules remains with the caller. 49 // The ownership of rules remains with the caller.
32 // 50 //
33 // Returns an empty string if the function is successful or an error 51 // Returns an empty string if the function is successful or an error
34 // message otherwise. 52 // message otherwise.
35 // 53 //
36 // IMPORTANT: This function is atomic. Either all rules that are deemed 54 // IMPORTANT: This function is atomic. Either all rules that are deemed
37 // relevant are added or none. 55 // relevant are added or none.
38 virtual std::string AddRules( 56 virtual std::string AddRules(
39 const std::string& extension_id, 57 const std::string& extension_id,
40 const std::vector<base::DictionaryValue*>& rules) = 0; 58 const std::vector<linked_ptr<Rule> >& rules) = 0;
41 59
42 // Unregisters all rules listed in |rule_identifiers| and owned by 60 // Unregisters all rules listed in |rule_identifiers| and owned by
43 // |extension_id| from this RulesRegistry. 61 // |extension_id| from this RulesRegistry.
44 // Some or all IDs in |rule_identifiers| may not affect this RulesRegistry. 62 // Some or all IDs in |rule_identifiers| may not affect this RulesRegistry.
45 // 63 //
46 // Returns an empty string if the function is successful or an error 64 // Returns an empty string if the function is successful or an error
47 // message otherwise. 65 // message otherwise.
48 // 66 //
49 // IMPORTANT: This function is atomic. Either all rules that are deemed 67 // IMPORTANT: This function is atomic. Either all rules that are deemed
50 // relevant are removed or none. 68 // relevant are removed or none.
51 virtual std::string RemoveRules( 69 virtual std::string RemoveRules(
52 const std::string& extension_id, 70 const std::string& extension_id,
53 const std::vector<std::string>& rule_identifiers) = 0; 71 const std::vector<std::string>& rule_identifiers) = 0;
54 72
55 // Same as RemoveAllRules but acts on all rules owned by |extension_id|. 73 // Same as RemoveAllRules but acts on all rules owned by |extension_id|.
56 virtual std::string RemoveAllRules(const std::string& extension_id) = 0; 74 virtual std::string RemoveAllRules(const std::string& extension_id) = 0;
57 75
58 // Returns all rules listed in |rule_identifiers| and owned by |extension_id| 76 // Returns all rules listed in |rule_identifiers| and owned by |extension_id|
59 // registered in this RuleRegistry. 77 // registered in this RuleRegistry.
60 // 78 //
61 // The returned rules are stored in |out|. Ownership is passed to the caller. 79 // The returned rules are stored in |out|. Ownership is passed to the caller.
62 // 80 //
63 // Returns an empty string if the function is successful or an error 81 // Returns an empty string if the function is successful or an error
64 // message otherwise. 82 // message otherwise.
65 virtual std::string GetRules(const std::string& extension_id, 83 virtual std::string GetRules(const std::string& extension_id,
66 const std::vector<std::string>& rule_identifiers, 84 const std::vector<std::string>& rule_identifiers,
67 std::vector<base::DictionaryValue*>* out) = 0; 85 std::vector<linked_ptr<Rule> >* out) = 0;
68 86
69 // Same as GetRules but returns all rules owned by |extension_id|. 87 // Same as GetRules but returns all rules owned by |extension_id|.
70 virtual std::string GetAllRules(const std::string& extension_id, 88 virtual std::string GetAllRules(const std::string& extension_id,
71 std::vector<base::DictionaryValue*>* out) = 0; 89 std::vector<linked_ptr<Rule> >* out) = 0;
72 90
73 // Called to notify the RulesRegistry that an extension has been unloaded 91 // Called to notify the RulesRegistry that an extension has been unloaded
74 // and all rules of this extension need to be removed. 92 // and all rules of this extension need to be removed.
75 virtual void OnExtensionUnloaded(const std::string& extension_id) = 0; 93 virtual void OnExtensionUnloaded(const std::string& extension_id) = 0;
94
95 // Returns the ID of the thread on which the rules registry lives.
96 // It must be safe to call this function from any thread.
97 virtual content::BrowserThread::ID GetOwnerThread() const = 0;
98
99 protected:
100 friend struct RulesRegistryDeleteTraits;
101 friend class base::DeleteHelper<RulesRegistry>;
102 virtual ~RulesRegistry() {}
76 }; 103 };
77 104
78 } // namespace extensions 105 } // namespace extensions
79 106
80 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__ 107 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698