| OLD | NEW |
| 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 Loading... |
| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } | 287 } |
| 288 #endif // NDEBUG | 288 #endif // NDEBUG |
| 289 | 289 |
| 290 void ComponentLoader::AddOrReloadEnterpriseWebStore() { | 290 void ComponentLoader::AddOrReloadEnterpriseWebStore() { |
| 291 FilePath path(FILE_PATH_LITERAL("enterprise_web_store")); | 291 FilePath path(FILE_PATH_LITERAL("enterprise_web_store")); |
| 292 | 292 |
| 293 // Remove the extension if it was already loaded. | 293 // Remove the extension if it was already loaded. |
| 294 Remove(path); | 294 Remove(path); |
| 295 | 295 |
| 296 std::string enterprise_webstore_url = | 296 std::string enterprise_webstore_url = |
| 297 prefs_->GetString(prefs::kEnterpriseWebStoreURL); | 297 profile_prefs_->GetString(prefs::kEnterpriseWebStoreURL); |
| 298 | 298 |
| 299 // Load the extension only if the URL preference is set. | 299 // Load the extension only if the URL preference is set. |
| 300 if (!enterprise_webstore_url.empty()) { | 300 if (!enterprise_webstore_url.empty()) { |
| 301 std::string manifest_contents = | 301 std::string manifest_contents = |
| 302 ResourceBundle::GetSharedInstance().GetRawDataResource( | 302 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 303 IDR_ENTERPRISE_WEBSTORE_MANIFEST).as_string(); | 303 IDR_ENTERPRISE_WEBSTORE_MANIFEST).as_string(); |
| 304 | 304 |
| 305 // The manifest is missing some values that are provided by policy. | 305 // The manifest is missing some values that are provided by policy. |
| 306 DictionaryValue* manifest = ParseManifest(manifest_contents); | 306 DictionaryValue* manifest = ParseManifest(manifest_contents); |
| 307 if (manifest) { | 307 if (manifest) { |
| 308 std::string name = prefs_->GetString(prefs::kEnterpriseWebStoreName); | 308 std::string name = |
| 309 profile_prefs_->GetString(prefs::kEnterpriseWebStoreName); |
| 309 manifest->SetString("app.launch.web_url", enterprise_webstore_url); | 310 manifest->SetString("app.launch.web_url", enterprise_webstore_url); |
| 310 manifest->SetString("name", name); | 311 manifest->SetString("name", name); |
| 311 Add(manifest, path); | 312 Add(manifest, path); |
| 312 } | 313 } |
| 313 } | 314 } |
| 314 } | 315 } |
| 315 | 316 |
| 316 void ComponentLoader::AddChromeApp() { | 317 void ComponentLoader::AddChromeApp() { |
| 317 #if defined(USE_ASH) | 318 #if defined(USE_ASH) |
| 318 std::string manifest_contents = | 319 std::string manifest_contents = |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) { | 442 void ComponentLoader::UnloadComponent(ComponentExtensionInfo* component) { |
| 442 delete component->manifest; | 443 delete component->manifest; |
| 443 if (extension_service_->is_ready()) { | 444 if (extension_service_->is_ready()) { |
| 444 extension_service_-> | 445 extension_service_-> |
| 445 UnloadExtension(component->extension_id, | 446 UnloadExtension(component->extension_id, |
| 446 extension_misc::UNLOAD_REASON_DISABLE); | 447 extension_misc::UNLOAD_REASON_DISABLE); |
| 447 } | 448 } |
| 448 } | 449 } |
| 449 | 450 |
| 450 // static | 451 // static |
| 451 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { | 452 void ComponentLoader::RegisterUserPrefs(PrefServiceSyncable* prefs) { |
| 452 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, | 453 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, |
| 453 std::string() /* default_value */, | 454 std::string() /* default_value */, |
| 454 PrefService::UNSYNCABLE_PREF); | 455 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 455 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, | 456 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, |
| 456 std::string() /* default_value */, | 457 std::string() /* default_value */, |
| 457 PrefService::UNSYNCABLE_PREF); | 458 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 458 } | 459 } |
| 459 | 460 |
| 460 } // namespace extensions | 461 } // namespace extensions |
| OLD | NEW |