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/strings/string_util.h" | |
| 11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 12 #include "components/component_updater/component_updater_paths.h" | 13 #include "components/component_updater/component_updater_paths.h" |
| 13 | 14 |
| 14 // The client-side configuration for the origin trial framework can be | 15 // The client-side configuration for the origin trial framework can be |
| 15 // overridden by an installed component named 'OriginTrials' (extension id | 16 // overridden by an installed component named 'OriginTrials' (extension id |
| 16 // kfoklmclfodeliojeaekpoflbkkhojea. This component currently consists of just a | 17 // kfoklmclfodeliojeaekpoflbkkhojea. This component currently consists of just a |
| 17 // manifest.json file, which can contain a custom key named 'origin-trials'. The | 18 // manifest.json file, which can contain a custom key named 'origin-trials'. The |
| 18 // value of this key is a dictionary: | 19 // value of this key is a dictionary: |
| 19 // | 20 // |
| 20 // { | 21 // { |
| 21 // "public-key": "<base64-encoding of replacement public key>", | 22 // "public-key": "<base64-encoding of replacement public key>", |
| 22 // "disabled-features": [<list of features to disable>], | 23 // "disabled-features": [<list of features to disable>], |
| 23 // "revoked-tokens": "<base64-encoded data>" | 24 // "revoked-tokens": "<base64-encoded data>" |
| 24 // } | 25 // } |
| 25 // | 26 // |
| 26 // TODO(iclelland): Implement support for revoked tokens and disabled features. | 27 // TODO(iclelland): Implement support for revoked tokens. |
| 27 // | 28 // |
| 28 // If the component is not present in the user data directory, the default | 29 // If the component is not present in the user data directory, the default |
| 29 // configuration will be used. | 30 // configuration will be used. |
| 30 | 31 |
| 31 namespace component_updater { | 32 namespace component_updater { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 // Extension id is kfoklmclfodeliojeaekpoflbkkhojea | 36 // Extension id is kfoklmclfodeliojeaekpoflbkkhojea |
| 36 const uint8_t kSha256Hash[] = {0xa5, 0xea, 0xbc, 0x2b, 0x5e, 0x34, 0xb8, 0xe9, | 37 const uint8_t kSha256Hash[] = {0xa5, 0xea, 0xbc, 0x2b, 0x5e, 0x34, 0xb8, 0xe9, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 65 const base::Version& version, | 66 const base::Version& version, |
| 66 const base::FilePath& install_dir, | 67 const base::FilePath& install_dir, |
| 67 std::unique_ptr<base::DictionaryValue> manifest) { | 68 std::unique_ptr<base::DictionaryValue> manifest) { |
| 68 // Read the public key from the manifest and set the command line. | 69 // Read the public key from the manifest and set the command line. |
| 69 std::string override_public_key; | 70 std::string override_public_key; |
| 70 if (manifest->GetString("origin-trials.public-key", &override_public_key)) { | 71 if (manifest->GetString("origin-trials.public-key", &override_public_key)) { |
| 71 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 72 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 72 command_line->AppendSwitchASCII(switches::kOriginTrialPublicKey, | 73 command_line->AppendSwitchASCII(switches::kOriginTrialPublicKey, |
| 73 override_public_key); | 74 override_public_key); |
| 74 } | 75 } |
| 76 base::ListValue* override_disabled_feature_list; | |
| 77 if (manifest->GetList("origin-trials.disabled-features", | |
| 78 &override_disabled_feature_list)) { | |
| 79 std::string disabled_feature; | |
| 80 std::vector<std::string> disabled_features; | |
| 81 for (const auto& item : *override_disabled_feature_list) { | |
| 82 if (item->GetAsString(&disabled_feature)) { | |
| 83 disabled_features.push_back(disabled_feature); | |
| 84 } | |
| 85 } | |
| 86 if (!disabled_features.empty()) { | |
| 87 std::string override_disabled_features = | |
| 88 base::JoinString(disabled_features, "|"); | |
| 89 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 90 command_line->AppendSwitchASCII(switches::kOriginTrialDisabledFeatures, | |
| 91 override_disabled_features); | |
|
waffles
2016/05/27 17:10:06
Hm, are you sure this will run in time? ComponentR
iclelland
2016/05/30 18:54:06
That's a good question -- It appears to be run in
iclelland
2016/05/31 14:50:13
So the StartupTaskRunner in BrowserMainLoop is blo
| |
| 92 } | |
| 93 } | |
| 75 } | 94 } |
| 76 | 95 |
| 77 base::FilePath OriginTrialsComponentInstallerTraits::GetRelativeInstallDir() | 96 base::FilePath OriginTrialsComponentInstallerTraits::GetRelativeInstallDir() |
| 78 const { | 97 const { |
| 79 return base::FilePath(FILE_PATH_LITERAL("OriginTrials")); | 98 return base::FilePath(FILE_PATH_LITERAL("OriginTrials")); |
| 80 } | 99 } |
| 81 | 100 |
| 82 void OriginTrialsComponentInstallerTraits::GetHash( | 101 void OriginTrialsComponentInstallerTraits::GetHash( |
| 83 std::vector<uint8_t>* hash) const { | 102 std::vector<uint8_t>* hash) const { |
| 84 if (!hash) | 103 if (!hash) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 98 const base::FilePath& user_data_dir) { | 117 const base::FilePath& user_data_dir) { |
| 99 std::unique_ptr<ComponentInstallerTraits> traits( | 118 std::unique_ptr<ComponentInstallerTraits> traits( |
| 100 new OriginTrialsComponentInstallerTraits()); | 119 new OriginTrialsComponentInstallerTraits()); |
| 101 // |cus| will take ownership of |installer| during installer->Register(cus). | 120 // |cus| will take ownership of |installer| during installer->Register(cus). |
| 102 DefaultComponentInstaller* installer = | 121 DefaultComponentInstaller* installer = |
| 103 new DefaultComponentInstaller(std::move(traits)); | 122 new DefaultComponentInstaller(std::move(traits)); |
| 104 installer->Register(cus, base::Closure()); | 123 installer->Register(cus, base::Closure()); |
| 105 } | 124 } |
| 106 | 125 |
| 107 } // namespace component_updater | 126 } // namespace component_updater |
| OLD | NEW |