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" |
| 12 #include "chrome/browser/browser_process.h" |
11 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/pref_names.h" |
12 #include "components/component_updater/component_updater_paths.h" | 15 #include "components/component_updater/component_updater_paths.h" |
| 16 #include "components/prefs/pref_service.h" |
13 | 17 |
14 // The client-side configuration for the origin trial framework can be | 18 // The client-side configuration for the origin trial framework can be |
15 // overridden by an installed component named 'OriginTrials' (extension id | 19 // overridden by an installed component named 'OriginTrials' (extension id |
16 // kfoklmclfodeliojeaekpoflbkkhojea. This component currently consists of just a | 20 // kfoklmclfodeliojeaekpoflbkkhojea. This component currently consists of just a |
17 // 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 |
18 // value of this key is a dictionary: | 22 // value of this key is a dictionary: |
19 // | 23 // |
20 // { | 24 // { |
21 // "public-key": "<base64-encoding of replacement public key>", | 25 // "public-key": "<base64-encoding of replacement public key>", |
22 // "disabled-features": [<list of features to disable>], | 26 // "disabled-features": [<list of features to disable>], |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 bool OriginTrialsComponentInstallerTraits::OnCustomInstall( | 62 bool OriginTrialsComponentInstallerTraits::OnCustomInstall( |
59 const base::DictionaryValue& manifest, | 63 const base::DictionaryValue& manifest, |
60 const base::FilePath& install_dir) { | 64 const base::FilePath& install_dir) { |
61 return true; | 65 return true; |
62 } | 66 } |
63 | 67 |
64 void OriginTrialsComponentInstallerTraits::ComponentReady( | 68 void OriginTrialsComponentInstallerTraits::ComponentReady( |
65 const base::Version& version, | 69 const base::Version& version, |
66 const base::FilePath& install_dir, | 70 const base::FilePath& install_dir, |
67 std::unique_ptr<base::DictionaryValue> manifest) { | 71 std::unique_ptr<base::DictionaryValue> manifest) { |
68 // Read the public key from the manifest and set the command line. | 72 // 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 PrefService* local_state = g_browser_process->local_state(); |
69 std::string override_public_key; | 75 std::string override_public_key; |
70 if (manifest->GetString("origin-trials.public-key", &override_public_key)) { | 76 if (manifest->GetString("origin-trials.public-key", &override_public_key)) { |
71 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 77 local_state->Set(prefs::kOriginTrialPublicKey, |
72 command_line->AppendSwitchASCII(switches::kOriginTrialPublicKey, | 78 base::StringValue(override_public_key)); |
73 override_public_key); | |
74 } | 79 } |
75 } | 80 } |
76 | 81 |
77 base::FilePath OriginTrialsComponentInstallerTraits::GetRelativeInstallDir() | 82 base::FilePath OriginTrialsComponentInstallerTraits::GetRelativeInstallDir() |
78 const { | 83 const { |
79 return base::FilePath(FILE_PATH_LITERAL("OriginTrials")); | 84 return base::FilePath(FILE_PATH_LITERAL("OriginTrials")); |
80 } | 85 } |
81 | 86 |
82 void OriginTrialsComponentInstallerTraits::GetHash( | 87 void OriginTrialsComponentInstallerTraits::GetHash( |
83 std::vector<uint8_t>* hash) const { | 88 std::vector<uint8_t>* hash) const { |
(...skipping 14 matching lines...) Expand all Loading... |
98 const base::FilePath& user_data_dir) { | 103 const base::FilePath& user_data_dir) { |
99 std::unique_ptr<ComponentInstallerTraits> traits( | 104 std::unique_ptr<ComponentInstallerTraits> traits( |
100 new OriginTrialsComponentInstallerTraits()); | 105 new OriginTrialsComponentInstallerTraits()); |
101 // |cus| will take ownership of |installer| during installer->Register(cus). | 106 // |cus| will take ownership of |installer| during installer->Register(cus). |
102 DefaultComponentInstaller* installer = | 107 DefaultComponentInstaller* installer = |
103 new DefaultComponentInstaller(std::move(traits)); | 108 new DefaultComponentInstaller(std::move(traits)); |
104 installer->Register(cus, base::Closure()); | 109 installer->Register(cus, base::Closure()); |
105 } | 110 } |
106 | 111 |
107 } // namespace component_updater | 112 } // namespace component_updater |
OLD | NEW |