Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/component_updater/origin_trials_component_installer.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/path_service.h" | |
| 11 #include "chrome/common/chrome_switches.h" | |
| 12 #include "components/component_updater/component_updater_paths.h" | |
| 13 | |
| 14 // The client-side configuration for the origin trial framework can be | |
| 15 // overridden by an installed component named 'OriginTrials' (extension id | |
| 16 // kfoklmclfodeliojeaekpoflbkkhojea. This component currently consists of just a | |
| 17 // manifest.json file, which can contain a custom key named 'origin-trials'. The | |
| 18 // value of this key is a dictionary: | |
| 19 // | |
| 20 // { | |
| 21 // "public-key": "<base64-encoding of replacement public key>", | |
| 22 // "disabled-features": [<list of features to disable>], | |
| 23 // "revoked-tokens": "<base64-encoded data>" | |
| 24 // } | |
| 25 // | |
| 26 // TODO(iclelland): Implement support for revoked tokens and disabled features. | |
| 27 // | |
| 28 // If the component is not present in the user data directory, the default | |
| 29 // configuration will be used. | |
| 30 | |
| 31 namespace component_updater { | |
| 32 | |
| 33 namespace { | |
| 34 | |
| 35 // Extension id is kfoklmclfodeliojeaekpoflbkkhojea | |
| 36 const uint8_t kSha256Hash[] = { | |
| 37 0xa5, 0xea, 0xbc, 0x2b, 0x5e, 0x34, 0xb8, 0xe9, | |
| 38 0x40, 0x4a, 0xfe, 0x5b, 0x1a, 0xa7, 0xe9, 0x40, | |
| 39 0xa8, 0xc5, 0xef, 0xa1, 0x9e, 0x20, 0x5a, 0x39, | |
| 40 0x73, 0x98, 0x98, 0x0f, 0x7a, 0x76, 0x62, 0xfa | |
| 41 }; | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 bool OriginTrialsComponentInstallerTraits::VerifyInstallation( | |
| 46 const base::DictionaryValue& manifest, | |
| 47 const base::FilePath& install_dir) const { | |
| 48 // Test if the "origin-trials" key is present in the manifest. | |
| 49 return manifest.HasKey("origin-trials"); | |
| 50 } | |
| 51 | |
| 52 bool OriginTrialsComponentInstallerTraits::CanAutoUpdate() const { | |
| 53 return true; | |
| 54 } | |
| 55 | |
| 56 bool OriginTrialsComponentInstallerTraits::RequiresNetworkEncryption() const { | |
| 57 return true; | |
| 58 } | |
| 59 | |
| 60 bool OriginTrialsComponentInstallerTraits::OnCustomInstall( | |
| 61 const base::DictionaryValue& manifest, | |
| 62 const base::FilePath& install_dir) { | |
| 63 return true; // nothing to do! | |
|
Sorin Jianu
2016/04/13 21:17:47
Comment is not needed. Please start with capital l
iclelland
2016/04/14 14:30:08
Removed.
| |
| 64 } | |
| 65 | |
| 66 void OriginTrialsComponentInstallerTraits::ComponentReady( | |
| 67 const base::Version& version, | |
| 68 const base::FilePath& install_dir, | |
| 69 std::unique_ptr<base::DictionaryValue> manifest) { | |
| 70 // Read the public key from the manifest and set the command line. | |
| 71 std::string override_public_key; | |
| 72 if (manifest->GetString("origin-trials.public-key", &override_public_key)) { | |
| 73 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 74 command_line->AppendSwitchASCII(switches::kOriginTrialPublicKey, | |
| 75 override_public_key); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 base::FilePath OriginTrialsComponentInstallerTraits::GetBaseDirectory() const { | |
| 80 base::FilePath result; | |
| 81 PathService::Get(DIR_ORIGIN_TRIAL_KEYS, &result); | |
| 82 return result; | |
| 83 } | |
| 84 | |
| 85 void OriginTrialsComponentInstallerTraits::GetHash( | |
| 86 std::vector<uint8_t>* hash) const { | |
| 87 if (!hash) | |
| 88 return; | |
| 89 hash->assign(kSha256Hash, | |
| 90 kSha256Hash + arraysize(kSha256Hash)); | |
| 91 } | |
| 92 | |
| 93 std::string OriginTrialsComponentInstallerTraits::GetName() const { | |
| 94 return "Origin Trials"; | |
| 95 } | |
| 96 | |
| 97 std::string OriginTrialsComponentInstallerTraits::GetAp() const { | |
| 98 // No additional parameters required; return empty string. | |
|
Sorin Jianu
2016/04/13 21:17:47
Comment is not needed, especially the part that fo
iclelland
2016/04/14 14:30:07
Removed.
| |
| 99 return std::string(); | |
| 100 } | |
| 101 | |
| 102 void RegisterOriginTrialsComponent(ComponentUpdateService* cus, | |
| 103 const base::FilePath& user_data_dir) { | |
| 104 VLOG(1) << "Registering origin trials component."; | |
|
Sorin Jianu
2016/04/13 21:17:47
Maybe use a DVLOG if this is needed for debugging,
iclelland
2016/04/14 14:30:07
Also removed.
| |
| 105 | |
| 106 scoped_ptr<ComponentInstallerTraits> traits( | |
| 107 new OriginTrialsComponentInstallerTraits()); | |
| 108 // |cus| will take ownership of |installer| during installer->Register(cus). | |
| 109 DefaultComponentInstaller* installer = | |
| 110 new DefaultComponentInstaller(std::move(traits)); | |
| 111 installer->Register(cus, base::Closure()); | |
| 112 } | |
| 113 | |
| 114 } // namespace component_updater | |
| OLD | NEW |