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

Side by Side Diff: chrome/common/extensions/manifest_handler.h

Issue 14694010: Consolidate manifest handler registration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_
6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ 6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 // Call Parse on all registered manifest handlers that should parse 69 // Call Parse on all registered manifest handlers that should parse
70 // this extension. 70 // this extension.
71 static bool ParseExtension(Extension* extension, string16* error); 71 static bool ParseExtension(Extension* extension, string16* error);
72 72
73 // Call Validate on all registered manifest handlers for this extension. 73 // Call Validate on all registered manifest handlers for this extension.
74 static bool ValidateExtension(const Extension* extension, 74 static bool ValidateExtension(const Extension* extension,
75 std::string* error, 75 std::string* error,
76 std::vector<InstallWarning>* warnings); 76 std::vector<InstallWarning>* warnings);
77 77
78 // Reset the manifest handler registry to an empty state. Useful for
79 // unit tests.
80 static void ClearRegistryForTesting();
81
82 protected: 78 protected:
83 // A convenience method for handlers that only register for 1 key, 79 // A convenience method for handlers that only register for 1 key,
84 // so that they can define keys() { return SingleKey(kKey); } 80 // so that they can define keys() { return SingleKey(kKey); }
85 static const std::vector<std::string> SingleKey(const std::string& key); 81 static const std::vector<std::string> SingleKey(const std::string& key);
86 82
87 private: 83 private:
88 // The keys to register us for (in Register). 84 // The keys to register us for (in Register).
89 virtual const std::vector<std::string> Keys() const = 0; 85 virtual const std::vector<std::string> Keys() const = 0;
90 }; 86 };
91 87
92 // The global registry for manifest handlers. 88 // The global registry for manifest handlers.
93 class ManifestHandlerRegistry { 89 class ManifestHandlerRegistry {
94 private: 90 private:
95 friend class ManifestHandler; 91 friend class ManifestHandler;
96 friend class ScopedTestingManifestHandlerRegistry; 92 friend class ScopedTestingManifestHandlerRegistry;
97 friend struct base::DefaultLazyInstanceTraits<ManifestHandlerRegistry>; 93 friend struct base::DefaultLazyInstanceTraits<ManifestHandlerRegistry>;
98 94
99 ManifestHandlerRegistry(); 95 ManifestHandlerRegistry();
100 ~ManifestHandlerRegistry(); 96 ~ManifestHandlerRegistry();
101 97
102 void RegisterManifestHandler(const std::string& key, 98 void RegisterManifestHandler(const std::string& key,
103 linked_ptr<ManifestHandler> handler); 99 linked_ptr<ManifestHandler> handler);
104 bool ParseExtension(Extension* extension, string16* error); 100 bool ParseExtension(Extension* extension, string16* error);
105 bool ValidateExtension(const Extension* extension, 101 bool ValidateExtension(const Extension* extension,
106 std::string* error, 102 std::string* error,
107 std::vector<InstallWarning>* warnings); 103 std::vector<InstallWarning>* warnings);
108 104
109 void ClearForTesting();
110 // Overrides the current global ManifestHandlerRegistry with 105 // Overrides the current global ManifestHandlerRegistry with
111 // |registry|, returning the current one. 106 // |registry|, returning the current one.
112 static ManifestHandlerRegistry* SetForTesting( 107 static ManifestHandlerRegistry* SetForTesting(
113 ManifestHandlerRegistry* new_registry); 108 ManifestHandlerRegistry* new_registry);
114 109
115 typedef std::map<std::string, linked_ptr<ManifestHandler> > 110 typedef std::map<std::string, linked_ptr<ManifestHandler> >
116 ManifestHandlerMap; 111 ManifestHandlerMap;
117 typedef std::map<ManifestHandler*, int> ManifestHandlerPriorityMap; 112 typedef std::map<ManifestHandler*, int> ManifestHandlerPriorityMap;
118 113
119 // Puts the manifest handlers in order such that each handler comes after 114 // Puts the manifest handlers in order such that each handler comes after
120 // any handlers for their PrerequisiteKeys. If there is no handler for 115 // any handlers for their PrerequisiteKeys. If there is no handler for
121 // a prerequisite key, that dependency is simply ignored. 116 // a prerequisite key, that dependency is simply ignored.
122 // CHECKs that there are no manifest handlers with circular dependencies. 117 // CHECKs that there are no manifest handlers with circular dependencies.
123 void SortManifestHandlers(); 118 void SortManifestHandlers();
124 119
125 // All registered manifest handlers. 120 // All registered manifest handlers.
126 ManifestHandlerMap handlers_; 121 ManifestHandlerMap handlers_;
127 122
128 // The priority for each manifest handler. Handlers with lower priority 123 // The priority for each manifest handler. Handlers with lower priority
129 // values are evaluated first. 124 // values are evaluated first.
130 ManifestHandlerPriorityMap priority_map_; 125 ManifestHandlerPriorityMap priority_map_;
131 bool is_sorted_; 126 bool is_sorted_;
132 }; 127 };
133 128
134 } // namespace extensions 129 } // namespace extensions
135 130
136 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_ 131 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_HANDLER_H_
OLDNEW
« no previous file with comments | « chrome/common/extensions/features/base_feature_provider_unittest.cc ('k') | chrome/common/extensions/manifest_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698