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

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

Issue 11570009: Split PrefService into PrefService, PrefServiceSimple and PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. 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 | 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 #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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 : manifest(manifest), 62 : manifest(manifest),
63 root_directory(directory) { 63 root_directory(directory) {
64 if (!root_directory.IsAbsolute()) { 64 if (!root_directory.IsAbsolute()) {
65 CHECK(PathService::Get(chrome::DIR_RESOURCES, &root_directory)); 65 CHECK(PathService::Get(chrome::DIR_RESOURCES, &root_directory));
66 root_directory = root_directory.Append(directory); 66 root_directory = root_directory.Append(directory);
67 } 67 }
68 extension_id = GenerateId(manifest, root_directory); 68 extension_id = GenerateId(manifest, root_directory);
69 } 69 }
70 70
71 ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service, 71 ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service,
72 PrefService* prefs, 72 PrefServiceBase* profile_prefs,
73 PrefService* local_state) 73 PrefServiceBase* local_state)
74 : prefs_(prefs), 74 : profile_prefs_(profile_prefs),
75 local_state_(local_state), 75 local_state_(local_state),
76 extension_service_(extension_service) { 76 extension_service_(extension_service) {
77 pref_change_registrar_.Init(prefs); 77 pref_change_registrar_.Init(profile_prefs);
78 78
79 // This pref is set by policy. We have to watch it for change because on 79 // This pref is set by policy. We have to watch it for change because on
80 // ChromeOS, policy isn't loaded until after the browser process is started. 80 // ChromeOS, policy isn't loaded until after the browser process is started.
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() {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 265 }
266 #endif // NDEBUG 266 #endif // NDEBUG
267 267
268 void ComponentLoader::AddOrReloadEnterpriseWebStore() { 268 void ComponentLoader::AddOrReloadEnterpriseWebStore() {
269 FilePath path(FILE_PATH_LITERAL("enterprise_web_store")); 269 FilePath path(FILE_PATH_LITERAL("enterprise_web_store"));
270 270
271 // Remove the extension if it was already loaded. 271 // Remove the extension if it was already loaded.
272 Remove(path); 272 Remove(path);
273 273
274 std::string enterprise_webstore_url = 274 std::string enterprise_webstore_url =
275 prefs_->GetString(prefs::kEnterpriseWebStoreURL); 275 profile_prefs_->GetString(prefs::kEnterpriseWebStoreURL);
276 276
277 // Load the extension only if the URL preference is set. 277 // Load the extension only if the URL preference is set.
278 if (!enterprise_webstore_url.empty()) { 278 if (!enterprise_webstore_url.empty()) {
279 std::string manifest_contents = 279 std::string manifest_contents =
280 ResourceBundle::GetSharedInstance().GetRawDataResource( 280 ResourceBundle::GetSharedInstance().GetRawDataResource(
281 IDR_ENTERPRISE_WEBSTORE_MANIFEST).as_string(); 281 IDR_ENTERPRISE_WEBSTORE_MANIFEST).as_string();
282 282
283 // The manifest is missing some values that are provided by policy. 283 // The manifest is missing some values that are provided by policy.
284 DictionaryValue* manifest = ParseManifest(manifest_contents); 284 DictionaryValue* manifest = ParseManifest(manifest_contents);
285 if (manifest) { 285 if (manifest) {
286 std::string name = prefs_->GetString(prefs::kEnterpriseWebStoreName); 286 std::string name =
287 profile_prefs_->GetString(prefs::kEnterpriseWebStoreName);
287 manifest->SetString("app.launch.web_url", enterprise_webstore_url); 288 manifest->SetString("app.launch.web_url", enterprise_webstore_url);
288 manifest->SetString("name", name); 289 manifest->SetString("name", name);
289 Add(manifest, path); 290 Add(manifest, path);
290 } 291 }
291 } 292 }
292 } 293 }
293 294
294 void ComponentLoader::AddChromeApp() { 295 void ComponentLoader::AddChromeApp() {
295 #if defined(USE_ASH) 296 #if defined(USE_ASH)
296 std::string manifest_contents = 297 std::string manifest_contents =
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) { 420 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) {
420 delete component->manifest; 421 delete component->manifest;
421 if (extension_service_->is_ready()) { 422 if (extension_service_->is_ready()) {
422 extension_service_-> 423 extension_service_->
423 UnloadExtension(component->extension_id, 424 UnloadExtension(component->extension_id,
424 extension_misc::UNLOAD_REASON_DISABLE); 425 extension_misc::UNLOAD_REASON_DISABLE);
425 } 426 }
426 } 427 }
427 428
428 // static 429 // static
429 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { 430 void ComponentLoader::RegisterUserPrefs(PrefServiceSyncable* prefs) {
430 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, 431 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL,
431 std::string() /* default_value */, 432 std::string() /* default_value */,
432 PrefService::UNSYNCABLE_PREF); 433 PrefServiceSyncable::UNSYNCABLE_PREF);
433 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, 434 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName,
434 std::string() /* default_value */, 435 std::string() /* default_value */,
435 PrefService::UNSYNCABLE_PREF); 436 PrefServiceSyncable::UNSYNCABLE_PREF);
436 } 437 }
437 438
438 } // namespace extensions 439 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698