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

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

Issue 2140093002: STH Set: Delay loading until after start-up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed comment Created 4 years, 5 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
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/sth_set_component_installer.h" 5 #include "chrome/browser/component_updater/sth_set_component_installer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/json/json_reader.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/path_service.h" 15 #include "base/path_service.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "base/version.h" 18 #include "base/version.h"
18 #include "chrome/browser/net/sth_distributor_provider.h" 19 #include "chrome/browser/net/sth_distributor_provider.h"
20 #include "chrome/common/chrome_features.h"
19 #include "components/component_updater/component_updater_paths.h" 21 #include "components/component_updater/component_updater_paths.h"
20 #include "components/safe_json/safe_json_parser.h" 22 #include "components/safe_json/safe_json_parser.h"
23 #include "components/variations/variations_associated_data.h"
21 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
22 #include "crypto/sha2.h" 25 #include "crypto/sha2.h"
23 #include "net/cert/ct_log_response_parser.h" 26 #include "net/cert/ct_log_response_parser.h"
24 #include "net/cert/signed_tree_head.h" 27 #include "net/cert/signed_tree_head.h"
25 #include "net/cert/sth_distributor.h" 28 #include "net/cert/sth_distributor.h"
26 #include "net/cert/sth_observer.h" 29 #include "net/cert/sth_observer.h"
27 30
28 using component_updater::ComponentUpdateService; 31 using component_updater::ComponentUpdateService;
29 32
30 namespace { 33 namespace {
(...skipping 13 matching lines...) Expand all
44 // The extension id is: ojjgnpkioondelmggbekfhllhdaimnho 47 // The extension id is: ojjgnpkioondelmggbekfhllhdaimnho
45 const uint8_t kPublicKeySHA256[32] = { 48 const uint8_t kPublicKeySHA256[32] = {
46 0xe9, 0x96, 0xdf, 0xa8, 0xee, 0xd3, 0x4b, 0xc6, 0x61, 0x4a, 0x57, 49 0xe9, 0x96, 0xdf, 0xa8, 0xee, 0xd3, 0x4b, 0xc6, 0x61, 0x4a, 0x57,
47 0xbb, 0x73, 0x08, 0xcd, 0x7e, 0x51, 0x9b, 0xcc, 0x69, 0x08, 0x41, 50 0xbb, 0x73, 0x08, 0xcd, 0x7e, 0x51, 0x9b, 0xcc, 0x69, 0x08, 0x41,
48 0xe1, 0x96, 0x9f, 0x7c, 0xb1, 0x73, 0xef, 0x16, 0x80, 0x0a}; 51 0xe1, 0x96, 0x9f, 0x7c, 0xb1, 0x73, 0xef, 0x16, 0x80, 0x0a};
49 52
50 const char kSTHSetFetcherManifestName[] = "Signed Tree Heads"; 53 const char kSTHSetFetcherManifestName[] = "Signed Tree Heads";
51 54
52 STHSetComponentInstallerTraits::STHSetComponentInstallerTraits( 55 STHSetComponentInstallerTraits::STHSetComponentInstallerTraits(
53 net::ct::STHObserver* sth_observer) 56 net::ct::STHObserver* sth_observer)
54 : sth_observer_(sth_observer) {} 57 : sth_observer_(sth_observer), weak_ptr_factory_(this) {}
55 58
56 STHSetComponentInstallerTraits::~STHSetComponentInstallerTraits() {} 59 STHSetComponentInstallerTraits::~STHSetComponentInstallerTraits() {}
57 60
58 bool STHSetComponentInstallerTraits::CanAutoUpdate() const { 61 bool STHSetComponentInstallerTraits::CanAutoUpdate() const {
59 return true; 62 return true;
60 } 63 }
61 64
62 // Public data is delivered via this component, no need for encryption. 65 // Public data is delivered via this component, no need for encryption.
63 bool STHSetComponentInstallerTraits::RequiresNetworkEncryption() const { 66 bool STHSetComponentInstallerTraits::RequiresNetworkEncryption() const {
64 return false; 67 return false;
65 } 68 }
66 69
67 bool STHSetComponentInstallerTraits::OnCustomInstall( 70 bool STHSetComponentInstallerTraits::OnCustomInstall(
68 const base::DictionaryValue& manifest, 71 const base::DictionaryValue& manifest,
69 const base::FilePath& install_dir) { 72 const base::FilePath& install_dir) {
70 return true; // Nothing custom here. 73 return true; // Nothing custom here.
71 } 74 }
72 75
73 void STHSetComponentInstallerTraits::ComponentReady( 76 void STHSetComponentInstallerTraits::ComponentReady(
74 const base::Version& version, 77 const base::Version& version,
75 const base::FilePath& install_dir, 78 const base::FilePath& install_dir,
76 std::unique_ptr<base::DictionaryValue> manifest) { 79 std::unique_ptr<base::DictionaryValue> manifest) {
77 if (!content::BrowserThread::PostBlockingPoolTask( 80 const base::Closure load_sths_closure = base::Bind(
78 FROM_HERE, 81 &STHSetComponentInstallerTraits::LoadSTHsFromDisk,
79 base::Bind(&STHSetComponentInstallerTraits::LoadSTHsFromDisk, 82 weak_ptr_factory_.GetWeakPtr(), GetInstalledPath(install_dir), version);
80 base::Unretained(this), GetInstalledPath(install_dir), 83
81 version))) { 84 if (variations::GetVariationParamValueByFeature(features::kSTHSetComponent,
82 NOTREACHED(); 85 "delay_load") != "no") {
86 DVLOG(1) << "Delaying STHSet load until after start-up.";
87 content::BrowserThread::PostAfterStartupTask(
88 FROM_HERE, content::BrowserThread::GetBlockingPool(),
89 load_sths_closure);
90 } else {
91 DVLOG(1) << "Loading STHSet during start-up.";
92 content::BrowserThread::PostBlockingPoolTask(FROM_HERE, load_sths_closure);
83 } 93 }
84 } 94 }
85 95
86 // Called during startup and installation before ComponentReady(). 96 // Called during startup and installation before ComponentReady().
87 bool STHSetComponentInstallerTraits::VerifyInstallation( 97 bool STHSetComponentInstallerTraits::VerifyInstallation(
88 const base::DictionaryValue& manifest, 98 const base::DictionaryValue& manifest,
89 const base::FilePath& install_dir) const { 99 const base::FilePath& install_dir) const {
90 return base::PathExists(GetInstalledPath(install_dir)); 100 return base::PathExists(GetInstalledPath(install_dir));
91 } 101 }
92 102
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 const std::string log_id(reinterpret_cast<const char*>(&decoding_output[0]), 148 const std::string log_id(reinterpret_cast<const char*>(&decoding_output[0]),
139 decoding_output.size()); 149 decoding_output.size());
140 150
141 std::string json_sth; 151 std::string json_sth;
142 if (!base::ReadFileToString(sth_file_path, &json_sth)) { 152 if (!base::ReadFileToString(sth_file_path, &json_sth)) {
143 DVLOG(1) << "Failed reading from " << sth_file_path.value(); 153 DVLOG(1) << "Failed reading from " << sth_file_path.value();
144 continue; 154 continue;
145 } 155 }
146 156
147 DVLOG(1) << "STH: Successfully read: " << json_sth; 157 DVLOG(1) << "STH: Successfully read: " << json_sth;
148 safe_json::SafeJsonParser::Parse( 158
149 json_sth, 159 if (variations::GetVariationParamValueByFeature(
150 base::Bind(&STHSetComponentInstallerTraits::OnJsonParseSuccess, 160 features::kSTHSetComponent, "oop_json_parsing") != "yes") {
151 base::Unretained(this), log_id), 161 int error_code = 0;
152 base::Bind(&STHSetComponentInstallerTraits::OnJsonParseError, 162 std::string error_message;
153 base::Unretained(this), log_id)); 163 std::unique_ptr<base::Value> parsed_json =
164 base::JSONReader::ReadAndReturnError(json_sth, base::JSON_PARSE_RFC,
165 &error_code, &error_message);
166
167 if (error_code == base::JSONReader::JSON_NO_ERROR) {
168 OnJsonParseSuccess(log_id, std::move(parsed_json));
169 } else {
170 OnJsonParseError(log_id, error_message);
171 }
172 } else {
173 safe_json::SafeJsonParser::Parse(
174 json_sth,
175 base::Bind(&STHSetComponentInstallerTraits::OnJsonParseSuccess,
176 weak_ptr_factory_.GetWeakPtr(), log_id),
177 base::Bind(&STHSetComponentInstallerTraits::OnJsonParseError,
178 weak_ptr_factory_.GetWeakPtr(), log_id));
179 }
154 } 180 }
155 } 181 }
156 182
157 void STHSetComponentInstallerTraits::OnJsonParseSuccess( 183 void STHSetComponentInstallerTraits::OnJsonParseSuccess(
158 const std::string& log_id, 184 const std::string& log_id,
159 std::unique_ptr<base::Value> parsed_json) { 185 std::unique_ptr<base::Value> parsed_json) {
160 net::ct::SignedTreeHead signed_tree_head; 186 net::ct::SignedTreeHead signed_tree_head;
161 DVLOG(1) << "STH parsing success for log: " 187 DVLOG(1) << "STH parsing success for log: "
162 << base::HexEncode(log_id.data(), log_id.length()); 188 << base::HexEncode(log_id.data(), log_id.length());
163 if (!net::ct::FillSignedTreeHead(*(parsed_json.get()), &signed_tree_head)) { 189 if (!net::ct::FillSignedTreeHead(*(parsed_json.get()), &signed_tree_head)) {
(...skipping 27 matching lines...) Expand all
191 217
192 std::unique_ptr<ComponentInstallerTraits> traits( 218 std::unique_ptr<ComponentInstallerTraits> traits(
193 new STHSetComponentInstallerTraits(distributor)); 219 new STHSetComponentInstallerTraits(distributor));
194 // |cus| will take ownership of |installer| during installer->Register(cus). 220 // |cus| will take ownership of |installer| during installer->Register(cus).
195 DefaultComponentInstaller* installer = 221 DefaultComponentInstaller* installer =
196 new DefaultComponentInstaller(std::move(traits)); 222 new DefaultComponentInstaller(std::move(traits));
197 installer->Register(cus, base::Closure()); 223 installer->Register(cus, base::Closure());
198 } 224 }
199 225
200 } // namespace component_updater 226 } // namespace component_updater
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/sth_set_component_installer.h ('k') | content/public/browser/browser_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698