| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/component_updater/origin_trials_component_installer.h" | 5 #include "chrome/browser/component_updater/origin_trials_component_installer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "components/component_updater/component_updater_paths.h" | 15 #include "components/component_updater/component_updater_paths.h" |
| 16 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
| 17 #include "components/prefs/scoped_user_pref_update.h" |
| 17 | 18 |
| 18 // The client-side configuration for the origin trial framework can be | 19 // The client-side configuration for the origin trial framework can be |
| 19 // overridden by an installed component named 'OriginTrials' (extension id | 20 // overridden by an installed component named 'OriginTrials' (extension id |
| 20 // kfoklmclfodeliojeaekpoflbkkhojea. This component currently consists of just a | 21 // kfoklmclfodeliojeaekpoflbkkhojea. This component currently consists of just a |
| 21 // manifest.json file, which can contain a custom key named 'origin-trials'. The | 22 // manifest.json file, which can contain a custom key named 'origin-trials'. The |
| 22 // value of this key is a dictionary: | 23 // value of this key is a dictionary: |
| 23 // | 24 // |
| 24 // { | 25 // { |
| 25 // "public-key": "<base64-encoding of replacement public key>", | 26 // "public-key": "<base64-encoding of replacement public key>", |
| 26 // "disabled-features": [<list of features to disable>], | 27 // "disabled-features": [<list of features to disable>], |
| 27 // "revoked-tokens": "<base64-encoded data>" | 28 // "revoked-tokens": "<base64-encoded data>" |
| 28 // } | 29 // } |
| 29 // | 30 // |
| 30 // TODO(iclelland): Implement support for revoked tokens and disabled features. | 31 // TODO(iclelland): Implement support for revoked tokens. |
| 31 // | 32 // |
| 32 // If the component is not present in the user data directory, the default | 33 // If the component is not present in the user data directory, the default |
| 33 // configuration will be used. | 34 // configuration will be used. |
| 34 | 35 |
| 35 namespace component_updater { | 36 namespace component_updater { |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 // Extension id is kfoklmclfodeliojeaekpoflbkkhojea | 40 // Extension id is kfoklmclfodeliojeaekpoflbkkhojea |
| 40 const uint8_t kSha256Hash[] = {0xa5, 0xea, 0xbc, 0x2b, 0x5e, 0x34, 0xb8, 0xe9, | 41 const uint8_t kSha256Hash[] = {0xa5, 0xea, 0xbc, 0x2b, 0x5e, 0x34, 0xb8, 0xe9, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 70 const base::FilePath& install_dir, | 71 const base::FilePath& install_dir, |
| 71 std::unique_ptr<base::DictionaryValue> manifest) { | 72 std::unique_ptr<base::DictionaryValue> manifest) { |
| 72 // Read the public key from the manifest and set values in browser | 73 // Read the public key from the manifest and set values in browser |
| 73 // local_state. These will be used on the next browser restart. | 74 // local_state. These will be used on the next browser restart. |
| 74 PrefService* local_state = g_browser_process->local_state(); | 75 PrefService* local_state = g_browser_process->local_state(); |
| 75 std::string override_public_key; | 76 std::string override_public_key; |
| 76 if (manifest->GetString("origin-trials.public-key", &override_public_key)) { | 77 if (manifest->GetString("origin-trials.public-key", &override_public_key)) { |
| 77 local_state->Set(prefs::kOriginTrialPublicKey, | 78 local_state->Set(prefs::kOriginTrialPublicKey, |
| 78 base::StringValue(override_public_key)); | 79 base::StringValue(override_public_key)); |
| 79 } | 80 } |
| 81 base::ListValue* override_disabled_feature_list = nullptr; |
| 82 if (manifest->GetList("origin-trials.disabled-features", |
| 83 &override_disabled_feature_list)) { |
| 84 ListPrefUpdate update(local_state, prefs::kOriginTrialDisabledFeatures); |
| 85 update->Swap(override_disabled_feature_list); |
| 86 } |
| 80 } | 87 } |
| 81 | 88 |
| 82 base::FilePath OriginTrialsComponentInstallerTraits::GetRelativeInstallDir() | 89 base::FilePath OriginTrialsComponentInstallerTraits::GetRelativeInstallDir() |
| 83 const { | 90 const { |
| 84 return base::FilePath(FILE_PATH_LITERAL("OriginTrials")); | 91 return base::FilePath(FILE_PATH_LITERAL("OriginTrials")); |
| 85 } | 92 } |
| 86 | 93 |
| 87 void OriginTrialsComponentInstallerTraits::GetHash( | 94 void OriginTrialsComponentInstallerTraits::GetHash( |
| 88 std::vector<uint8_t>* hash) const { | 95 std::vector<uint8_t>* hash) const { |
| 89 if (!hash) | 96 if (!hash) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 103 const base::FilePath& user_data_dir) { | 110 const base::FilePath& user_data_dir) { |
| 104 std::unique_ptr<ComponentInstallerTraits> traits( | 111 std::unique_ptr<ComponentInstallerTraits> traits( |
| 105 new OriginTrialsComponentInstallerTraits()); | 112 new OriginTrialsComponentInstallerTraits()); |
| 106 // |cus| will take ownership of |installer| during installer->Register(cus). | 113 // |cus| will take ownership of |installer| during installer->Register(cus). |
| 107 DefaultComponentInstaller* installer = | 114 DefaultComponentInstaller* installer = |
| 108 new DefaultComponentInstaller(std::move(traits)); | 115 new DefaultComponentInstaller(std::move(traits)); |
| 109 installer->Register(cus, base::Closure()); | 116 installer->Register(cus, base::Closure()); |
| 110 } | 117 } |
| 111 | 118 |
| 112 } // namespace component_updater | 119 } // namespace component_updater |
| OLD | NEW |