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