Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Side by Side Diff: chrome/browser/component_updater/origin_trials_component_installer.cc

Issue 1887743003: Allow the component updater framework to control Origin Trials. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ef-finch
Patch Set: Rebase and fix missed scoped_ptr -> unique_ptr conversion Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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[] = {0xa5, 0xea, 0xbc, 0x2b, 0x5e, 0x34, 0xb8, 0xe9,
37 0x40, 0x4a, 0xfe, 0x5b, 0x1a, 0xa7, 0xe9, 0x40,
38 0xa8, 0xc5, 0xef, 0xa1, 0x9e, 0x20, 0x5a, 0x39,
39 0x73, 0x98, 0x98, 0x0f, 0x7a, 0x76, 0x62, 0xfa};
40
41 } // namespace
42
43 bool OriginTrialsComponentInstallerTraits::VerifyInstallation(
44 const base::DictionaryValue& manifest,
45 const base::FilePath& install_dir) const {
46 // Test if the "origin-trials" key is present in the manifest.
47 return manifest.HasKey("origin-trials");
48 }
49
50 bool OriginTrialsComponentInstallerTraits::CanAutoUpdate() const {
51 return true;
52 }
53
54 bool OriginTrialsComponentInstallerTraits::RequiresNetworkEncryption() const {
55 return true;
56 }
57
58 bool OriginTrialsComponentInstallerTraits::OnCustomInstall(
59 const base::DictionaryValue& manifest,
60 const base::FilePath& install_dir) {
61 return true;
62 }
63
64 void OriginTrialsComponentInstallerTraits::ComponentReady(
65 const base::Version& version,
66 const base::FilePath& install_dir,
67 std::unique_ptr<base::DictionaryValue> manifest) {
68 // Read the public key from the manifest and set the command line.
69 std::string override_public_key;
70 if (manifest->GetString("origin-trials.public-key", &override_public_key)) {
71 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
72 command_line->AppendSwitchASCII(switches::kOriginTrialPublicKey,
73 override_public_key);
74 }
75 }
76
77 base::FilePath OriginTrialsComponentInstallerTraits::GetBaseDirectory() const {
78 base::FilePath result;
79 PathService::Get(DIR_ORIGIN_TRIAL_KEYS, &result);
80 return result;
81 }
82
83 void OriginTrialsComponentInstallerTraits::GetHash(
84 std::vector<uint8_t>* hash) const {
85 if (!hash)
86 return;
87 hash->assign(kSha256Hash, kSha256Hash + arraysize(kSha256Hash));
88 }
89
90 std::string OriginTrialsComponentInstallerTraits::GetName() const {
91 return "Origin Trials";
92 }
93
94 std::string OriginTrialsComponentInstallerTraits::GetAp() const {
95 return std::string();
96 }
97
98 void RegisterOriginTrialsComponent(ComponentUpdateService* cus,
99 const base::FilePath& user_data_dir) {
100 std::unique_ptr<ComponentInstallerTraits> traits(
101 new OriginTrialsComponentInstallerTraits());
102 // |cus| will take ownership of |installer| during installer->Register(cus).
103 DefaultComponentInstaller* installer =
104 new DefaultComponentInstaller(std::move(traits));
105 installer->Register(cus, base::Closure());
106 }
107
108 } // namespace component_updater
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/origin_trials_component_installer.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698