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

Side by Side Diff: chrome/browser/extensions/component_loader.cc

Issue 11572036: Do not load extension system in the Profile import process. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rollback to patchset 10 Created 8 years 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
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 #include "chrome/browser/extensions/component_loader.h" 5 #include "chrome/browser/extensions/component_loader.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 pref_change_registrar_.Add( 81 pref_change_registrar_.Add(
82 prefs::kEnterpriseWebStoreURL, 82 prefs::kEnterpriseWebStoreURL,
83 base::Bind(&ComponentLoader::AddOrReloadEnterpriseWebStore, 83 base::Bind(&ComponentLoader::AddOrReloadEnterpriseWebStore,
84 base::Unretained(this))); 84 base::Unretained(this)));
85 } 85 }
86 86
87 ComponentLoader::~ComponentLoader() { 87 ComponentLoader::~ComponentLoader() {
88 ClearAllRegistered(); 88 ClearAllRegistered();
89 } 89 }
90 90
91 void ComponentLoader::LoadAll() { 91 void ComponentLoader::BulkLoadAll() {
92 for (RegisteredComponentExtensions::iterator it = 92 for (RegisteredComponentExtensions::iterator it =
93 component_extensions_.begin(); 93 component_extensions_.begin();
94 it != component_extensions_.end(); ++it) { 94 it != component_extensions_.end(); ++it) {
95 Load(*it); 95 Load(*it, false);
96 } 96 }
97 } 97 }
98 98
99 void ComponentLoader::BulkLoadDeferBackgroundPages() {
100 for (RegisteredComponentExtensions::iterator it =
101 component_extensions_.begin();
102 it != component_extensions_.end(); ++it) {
103 Load(*it, true);
104 }
105 }
106
107 void ComponentLoader::BulkLoadDeferred() {
108 for (DeferredAtLoadExtensions::iterator it =
109 deferred_at_load_extensions.begin();
110 it != deferred_at_load_extensions.end(); ++it) {
111 extension_service_->AddComponentExtension(*it);
112 }
113 deferred_at_load_extensions.clear();
114 }
115
99 DictionaryValue* ComponentLoader::ParseManifest( 116 DictionaryValue* ComponentLoader::ParseManifest(
100 const std::string& manifest_contents) const { 117 const std::string& manifest_contents) const {
101 JSONStringValueSerializer serializer(manifest_contents); 118 JSONStringValueSerializer serializer(manifest_contents);
102 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); 119 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL));
103 120
104 if (!manifest.get() || !manifest->IsType(Value::TYPE_DICTIONARY)) { 121 if (!manifest.get() || !manifest->IsType(Value::TYPE_DICTIONARY)) {
105 LOG(ERROR) << "Failed to parse extension manifest."; 122 LOG(ERROR) << "Failed to parse extension manifest.";
106 return NULL; 123 return NULL;
107 } 124 }
108 // Transfer ownership to the caller. 125 // Transfer ownership to the caller.
(...skipping 26 matching lines...) Expand all
135 if (manifest) 152 if (manifest)
136 return Add(manifest, root_directory); 153 return Add(manifest, root_directory);
137 return ""; 154 return "";
138 } 155 }
139 156
140 std::string ComponentLoader::Add(const DictionaryValue* parsed_manifest, 157 std::string ComponentLoader::Add(const DictionaryValue* parsed_manifest,
141 const FilePath& root_directory) { 158 const FilePath& root_directory) {
142 ComponentExtensionInfo info(parsed_manifest, root_directory); 159 ComponentExtensionInfo info(parsed_manifest, root_directory);
143 component_extensions_.push_back(info); 160 component_extensions_.push_back(info);
144 if (extension_service_->is_ready()) 161 if (extension_service_->is_ready())
145 Load(info); 162 Load(info, false);
146 return info.extension_id; 163 return info.extension_id;
147 } 164 }
148 165
149 std::string ComponentLoader::AddOrReplace(const FilePath& path) { 166 std::string ComponentLoader::AddOrReplace(const FilePath& path) {
150 FilePath absolute_path = path; 167 FilePath absolute_path = path;
151 file_util::AbsolutePath(&absolute_path); 168 file_util::AbsolutePath(&absolute_path);
152 std::string error; 169 std::string error;
153 scoped_ptr<DictionaryValue> manifest( 170 scoped_ptr<DictionaryValue> manifest(
154 extension_file_util::LoadManifest(absolute_path, &error)); 171 extension_file_util::LoadManifest(absolute_path, &error));
155 if (!manifest.get()) { 172 if (!manifest.get()) {
156 LOG(ERROR) << "Could not load extension from '" << 173 LOG(ERROR) << "Could not load extension from '" <<
157 absolute_path.value() << "'. " << error; 174 absolute_path.value() << "'. " << error;
158 return NULL; 175 return NULL;
159 } 176 }
160 Remove(GenerateId(manifest.get(), absolute_path)); 177 Remove(GenerateId(manifest.get(), absolute_path));
161 178
162 return Add(manifest.release(), absolute_path); 179 return Add(manifest.release(), absolute_path);
163 } 180 }
164 181
165 void ComponentLoader::Reload(const std::string& extension_id) { 182 void ComponentLoader::Reload(const std::string& extension_id) {
166 for (RegisteredComponentExtensions::iterator it = 183 for (RegisteredComponentExtensions::iterator it =
167 component_extensions_.begin(); it != component_extensions_.end(); 184 component_extensions_.begin(); it != component_extensions_.end();
168 ++it) { 185 ++it) {
169 if (it->extension_id == extension_id) { 186 if (it->extension_id == extension_id) {
170 Load(*it); 187 Load(*it, false);
171 break; 188 break;
172 } 189 }
173 } 190 }
174 } 191 }
175 192
176 const Extension* ComponentLoader::Load(const ComponentExtensionInfo& info) { 193 void ComponentLoader::Load(const ComponentExtensionInfo& info,
194 bool defer_if_has_background_page) {
177 // TODO(abarth): We should REQUIRE_MODERN_MANIFEST_VERSION once we've updated 195 // TODO(abarth): We should REQUIRE_MODERN_MANIFEST_VERSION once we've updated
178 // our component extensions to the new manifest version. 196 // our component extensions to the new manifest version.
179 int flags = Extension::REQUIRE_KEY; 197 int flags = Extension::REQUIRE_KEY;
180 198
181 std::string error; 199 std::string error;
182 200
183 scoped_refptr<const Extension> extension(Extension::Create( 201 scoped_refptr<const Extension> extension(Extension::Create(
184 info.root_directory, 202 info.root_directory,
185 Extension::COMPONENT, 203 Extension::COMPONENT,
186 *info.manifest, 204 *info.manifest,
187 flags, 205 flags,
188 &error)); 206 &error));
189 if (!extension.get()) { 207 if (!extension.get()) {
190 LOG(ERROR) << error; 208 LOG(ERROR) << error;
191 return NULL; 209 return;
192 } 210 }
211
193 CHECK_EQ(info.extension_id, extension->id()) << extension->name(); 212 CHECK_EQ(info.extension_id, extension->id()) << extension->name();
194 extension_service_->AddComponentExtension(extension); 213 if (extension->has_background_page() && defer_if_has_background_page) {
195 return extension; 214 deferred_at_load_extensions.push_back(extension);
215 } else {
216 extension_service_->AddComponentExtension(extension);
217 }
196 } 218 }
197 219
198 void ComponentLoader::RemoveAll() { 220 void ComponentLoader::RemoveAll() {
199 RegisteredComponentExtensions::iterator it = component_extensions_.begin(); 221 RegisteredComponentExtensions::iterator it = component_extensions_.begin();
200 for (; it != component_extensions_.end(); ++it) 222 for (; it != component_extensions_.end(); ++it)
201 UnloadComponent(&(*it)); 223 UnloadComponent(&(*it));
202 224
203 component_extensions_.clear(); 225 component_extensions_.clear();
204 } 226 }
205 227
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { 452 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) {
431 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, 453 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL,
432 std::string() /* default_value */, 454 std::string() /* default_value */,
433 PrefService::UNSYNCABLE_PREF); 455 PrefService::UNSYNCABLE_PREF);
434 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, 456 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName,
435 std::string() /* default_value */, 457 std::string() /* default_value */,
436 PrefService::UNSYNCABLE_PREF); 458 PrefService::UNSYNCABLE_PREF);
437 } 459 }
438 460
439 } // namespace extensions 461 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/component_loader.h ('k') | chrome/browser/extensions/component_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698