| OLD | NEW |
| 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 #include "chrome/common/extensions/manifest_handler.h" | 5 #include "chrome/common/extensions/manifest_handler.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/linked_ptr.h" |
| 11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 12 #include "chrome/common/extensions/manifest.h" | 13 #include "chrome/common/extensions/manifest.h" |
| 13 | 14 |
| 14 namespace extensions { | 15 namespace extensions { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 class ManifestHandlerRegistry { | 19 class ManifestHandlerRegistry { |
| 19 public: | 20 public: |
| 20 ManifestHandlerRegistry() : is_sorted_(false) { | 21 ManifestHandlerRegistry() : is_sorted_(false) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // circular dependencies. | 130 // circular dependencies. |
| 130 CHECK(unsorted_handlers.size() == 0) << "Extension manifest handlers have " | 131 CHECK(unsorted_handlers.size() == 0) << "Extension manifest handlers have " |
| 131 << "circular dependencies!"; | 132 << "circular dependencies!"; |
| 132 | 133 |
| 133 is_sorted_ = true; | 134 is_sorted_ = true; |
| 134 } | 135 } |
| 135 | 136 |
| 136 static base::LazyInstance<ManifestHandlerRegistry> g_registry = | 137 static base::LazyInstance<ManifestHandlerRegistry> g_registry = |
| 137 LAZY_INSTANCE_INITIALIZER; | 138 LAZY_INSTANCE_INITIALIZER; |
| 138 | 139 |
| 139 static base::LazyInstance<std::vector<std::string> > g_empty_string_vector = | |
| 140 LAZY_INSTANCE_INITIALIZER; | |
| 141 | |
| 142 } // namespace | 140 } // namespace |
| 143 | 141 |
| 144 ManifestHandler::ManifestHandler() { | 142 ManifestHandler::ManifestHandler() { |
| 145 } | 143 } |
| 146 | 144 |
| 147 ManifestHandler::~ManifestHandler() { | 145 ManifestHandler::~ManifestHandler() { |
| 148 } | 146 } |
| 149 | 147 |
| 150 bool ManifestHandler::AlwaysParseForType(Manifest::Type type) { | 148 bool ManifestHandler::AlwaysParseForType(Manifest::Type type) const { |
| 151 return false; | 149 return false; |
| 152 } | 150 } |
| 153 | 151 |
| 154 const std::vector<std::string>& ManifestHandler::PrerequisiteKeys() { | 152 const std::vector<std::string> ManifestHandler::PrerequisiteKeys() const { |
| 155 return g_empty_string_vector.Get(); | 153 return std::vector<std::string>(); |
| 154 } |
| 155 |
| 156 void ManifestHandler::Register() { |
| 157 linked_ptr<ManifestHandler> this_linked(this); |
| 158 const std::vector<std::string> keys = Keys(); |
| 159 for (size_t i = 0; i < keys.size(); ++i) |
| 160 g_registry.Get().RegisterManifestHandler(keys[i], this_linked); |
| 156 } | 161 } |
| 157 | 162 |
| 158 // static | 163 // static |
| 159 void ManifestHandler::Register(const std::string& key, | 164 void ManifestHandler::ClearRegistryForTesting() { |
| 160 linked_ptr<ManifestHandler> handler) { | 165 g_registry.Get().ClearForTesting(); |
| 161 g_registry.Get().RegisterManifestHandler(key, handler); | |
| 162 } | 166 } |
| 163 | 167 |
| 164 // static | 168 // static |
| 165 bool ManifestHandler::ParseExtension(Extension* extension, string16* error) { | 169 bool ManifestHandler::ParseExtension(Extension* extension, string16* error) { |
| 166 return g_registry.Get().ParseExtension(extension, error); | 170 return g_registry.Get().ParseExtension(extension, error); |
| 167 } | 171 } |
| 168 | 172 |
| 169 // static | 173 // static |
| 170 void ManifestHandler::ClearRegistryForTesting() { | 174 const std::vector<std::string> ManifestHandler::SingleKey( |
| 171 g_registry.Get().ClearForTesting(); | 175 const std::string& key) { |
| 176 return std::vector<std::string>(1, key); |
| 172 } | 177 } |
| 173 | 178 |
| 174 } // namespace extensions | 179 } // namespace extensions |
| OLD | NEW |