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

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: resolve possible database conflicts in the browser process 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::LoadAll(bool defer_extensions_with_background_pages) {
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, defer_extensions_with_background_pages);
96 } 96 }
97 } 97 }
98 98
99 void ComponentLoader::LoadAllDeferred() {
100 for (DeferredAtLoadExtensions::iterator it =
101 deferred_at_load_extensions.begin();
102 it != deferred_at_load_extensions.end(); ++it) {
103 extension_service_->AddComponentExtension(*it);
104 }
105 deferred_at_load_extensions.clear();
106 }
107
99 DictionaryValue* ComponentLoader::ParseManifest( 108 DictionaryValue* ComponentLoader::ParseManifest(
100 const std::string& manifest_contents) const { 109 const std::string& manifest_contents) const {
101 JSONStringValueSerializer serializer(manifest_contents); 110 JSONStringValueSerializer serializer(manifest_contents);
102 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); 111 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL));
103 112
104 if (!manifest.get() || !manifest->IsType(Value::TYPE_DICTIONARY)) { 113 if (!manifest.get() || !manifest->IsType(Value::TYPE_DICTIONARY)) {
105 LOG(ERROR) << "Failed to parse extension manifest."; 114 LOG(ERROR) << "Failed to parse extension manifest.";
106 return NULL; 115 return NULL;
107 } 116 }
108 // Transfer ownership to the caller. 117 // Transfer ownership to the caller.
(...skipping 26 matching lines...) Expand all
135 if (manifest) 144 if (manifest)
136 return Add(manifest, root_directory); 145 return Add(manifest, root_directory);
137 return ""; 146 return "";
138 } 147 }
139 148
140 std::string ComponentLoader::Add(const DictionaryValue* parsed_manifest, 149 std::string ComponentLoader::Add(const DictionaryValue* parsed_manifest,
141 const FilePath& root_directory) { 150 const FilePath& root_directory) {
142 ComponentExtensionInfo info(parsed_manifest, root_directory); 151 ComponentExtensionInfo info(parsed_manifest, root_directory);
143 component_extensions_.push_back(info); 152 component_extensions_.push_back(info);
144 if (extension_service_->is_ready()) 153 if (extension_service_->is_ready())
145 Load(info); 154 Load(info, false);
146 return info.extension_id; 155 return info.extension_id;
147 } 156 }
148 157
149 std::string ComponentLoader::AddOrReplace(const FilePath& path) { 158 std::string ComponentLoader::AddOrReplace(const FilePath& path) {
150 FilePath absolute_path = path; 159 FilePath absolute_path = path;
151 file_util::AbsolutePath(&absolute_path); 160 file_util::AbsolutePath(&absolute_path);
152 std::string error; 161 std::string error;
153 scoped_ptr<DictionaryValue> manifest( 162 scoped_ptr<DictionaryValue> manifest(
154 extension_file_util::LoadManifest(absolute_path, &error)); 163 extension_file_util::LoadManifest(absolute_path, &error));
155 if (!manifest.get()) { 164 if (!manifest.get()) {
156 LOG(ERROR) << "Could not load extension from '" << 165 LOG(ERROR) << "Could not load extension from '" <<
157 absolute_path.value() << "'. " << error; 166 absolute_path.value() << "'. " << error;
158 return NULL; 167 return NULL;
159 } 168 }
160 Remove(GenerateId(manifest.get(), absolute_path)); 169 Remove(GenerateId(manifest.get(), absolute_path));
161 170
162 return Add(manifest.release(), absolute_path); 171 return Add(manifest.release(), absolute_path);
163 } 172 }
164 173
165 void ComponentLoader::Reload(const std::string& extension_id) { 174 void ComponentLoader::Reload(const std::string& extension_id) {
166 for (RegisteredComponentExtensions::iterator it = 175 for (RegisteredComponentExtensions::iterator it =
167 component_extensions_.begin(); it != component_extensions_.end(); 176 component_extensions_.begin(); it != component_extensions_.end();
168 ++it) { 177 ++it) {
169 if (it->extension_id == extension_id) { 178 if (it->extension_id == extension_id) {
170 Load(*it); 179 Load(*it, false);
171 break; 180 break;
172 } 181 }
173 } 182 }
174 } 183 }
175 184
176 const Extension* ComponentLoader::Load(const ComponentExtensionInfo& info) { 185 void ComponentLoader::Load(const ComponentExtensionInfo& info,
186 bool defer_if_has_background_page) {
177 // TODO(abarth): We should REQUIRE_MODERN_MANIFEST_VERSION once we've updated 187 // TODO(abarth): We should REQUIRE_MODERN_MANIFEST_VERSION once we've updated
178 // our component extensions to the new manifest version. 188 // our component extensions to the new manifest version.
179 int flags = Extension::REQUIRE_KEY; 189 int flags = Extension::REQUIRE_KEY;
180 190
181 std::string error; 191 std::string error;
182 192
183 scoped_refptr<const Extension> extension(Extension::Create( 193 scoped_refptr<const Extension> extension(Extension::Create(
184 info.root_directory, 194 info.root_directory,
185 Extension::COMPONENT, 195 Extension::COMPONENT,
186 *info.manifest, 196 *info.manifest,
187 flags, 197 flags,
188 &error)); 198 &error));
189 if (!extension.get()) { 199 if (!extension.get()) {
190 LOG(ERROR) << error; 200 LOG(ERROR) << error;
191 return NULL; 201 return;
192 } 202 }
203
193 CHECK_EQ(info.extension_id, extension->id()) << extension->name(); 204 CHECK_EQ(info.extension_id, extension->id()) << extension->name();
194 extension_service_->AddComponentExtension(extension); 205 if (extension->has_background_page() && defer_if_has_background_page) {
195 return extension; 206 deferred_at_load_extensions.push_back(extension);
207 } else {
208 extension_service_->AddComponentExtension(extension);
209 }
196 } 210 }
197 211
198 void ComponentLoader::RemoveAll() { 212 void ComponentLoader::RemoveAll() {
199 RegisteredComponentExtensions::iterator it = component_extensions_.begin(); 213 RegisteredComponentExtensions::iterator it = component_extensions_.begin();
200 for (; it != component_extensions_.end(); ++it) 214 for (; it != component_extensions_.end(); ++it)
201 UnloadComponent(&(*it)); 215 UnloadComponent(&(*it));
202 216
203 component_extensions_.clear(); 217 component_extensions_.clear();
204 } 218 }
205 219
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { 444 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) {
431 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, 445 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL,
432 std::string() /* default_value */, 446 std::string() /* default_value */,
433 PrefService::UNSYNCABLE_PREF); 447 PrefService::UNSYNCABLE_PREF);
434 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, 448 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName,
435 std::string() /* default_value */, 449 std::string() /* default_value */,
436 PrefService::UNSYNCABLE_PREF); 450 PrefService::UNSYNCABLE_PREF);
437 } 451 }
438 452
439 } // namespace extensions 453 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698