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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/component_updater/sth_set_component_installer.cc
diff --git a/chrome/browser/component_updater/sth_set_component_installer.cc b/chrome/browser/component_updater/sth_set_component_installer.cc
index b6ced0134ef16a261d8719e72d851bbaeb5ac705..dc93cc38058e9e6b269015b8c796eeed1d11cb13 100644
--- a/chrome/browser/component_updater/sth_set_component_installer.cc
+++ b/chrome/browser/component_updater/sth_set_component_installer.cc
@@ -10,14 +10,17 @@
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
+#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "base/version.h"
#include "chrome/browser/net/sth_distributor_provider.h"
+#include "chrome/common/chrome_features.h"
#include "components/component_updater/component_updater_paths.h"
#include "components/safe_json/safe_json_parser.h"
+#include "components/variations/variations_associated_data.h"
#include "content/public/browser/browser_thread.h"
#include "crypto/sha2.h"
#include "net/cert/ct_log_response_parser.h"
@@ -51,7 +54,7 @@ const char kSTHSetFetcherManifestName[] = "Signed Tree Heads";
STHSetComponentInstallerTraits::STHSetComponentInstallerTraits(
net::ct::STHObserver* sth_observer)
- : sth_observer_(sth_observer) {}
+ : sth_observer_(sth_observer), weak_ptr_factory_(this) {}
STHSetComponentInstallerTraits::~STHSetComponentInstallerTraits() {}
@@ -74,12 +77,19 @@ void STHSetComponentInstallerTraits::ComponentReady(
const base::Version& version,
const base::FilePath& install_dir,
std::unique_ptr<base::DictionaryValue> manifest) {
- if (!content::BrowserThread::PostBlockingPoolTask(
- FROM_HERE,
- base::Bind(&STHSetComponentInstallerTraits::LoadSTHsFromDisk,
- base::Unretained(this), GetInstalledPath(install_dir),
- version))) {
- NOTREACHED();
+ const base::Closure load_sths_closure = base::Bind(
+ &STHSetComponentInstallerTraits::LoadSTHsFromDisk,
+ weak_ptr_factory_.GetWeakPtr(), GetInstalledPath(install_dir), version);
+
+ if (variations::GetVariationParamValueByFeature(features::kSTHSetComponent,
+ "delay_load") != "no") {
+ DVLOG(1) << "Delaying STHSet load until after start-up.";
+ content::BrowserThread::PostAfterStartupTask(
+ FROM_HERE, content::BrowserThread::GetBlockingPool(),
+ load_sths_closure);
+ } else {
+ DVLOG(1) << "Loading STHSet during start-up.";
+ content::BrowserThread::PostBlockingPoolTask(FROM_HERE, load_sths_closure);
}
}
@@ -145,12 +155,28 @@ void STHSetComponentInstallerTraits::LoadSTHsFromDisk(
}
DVLOG(1) << "STH: Successfully read: " << json_sth;
- safe_json::SafeJsonParser::Parse(
- json_sth,
- base::Bind(&STHSetComponentInstallerTraits::OnJsonParseSuccess,
- base::Unretained(this), log_id),
- base::Bind(&STHSetComponentInstallerTraits::OnJsonParseError,
- base::Unretained(this), log_id));
+
+ if (variations::GetVariationParamValueByFeature(
+ features::kSTHSetComponent, "oop_json_parsing") != "yes") {
+ int error_code = 0;
+ std::string error_message;
+ std::unique_ptr<base::Value> parsed_json =
+ base::JSONReader::ReadAndReturnError(json_sth, base::JSON_PARSE_RFC,
+ &error_code, &error_message);
+
+ if (error_code == base::JSONReader::JSON_NO_ERROR) {
+ OnJsonParseSuccess(log_id, std::move(parsed_json));
+ } else {
+ OnJsonParseError(log_id, error_message);
+ }
+ } else {
+ safe_json::SafeJsonParser::Parse(
+ json_sth,
+ base::Bind(&STHSetComponentInstallerTraits::OnJsonParseSuccess,
+ weak_ptr_factory_.GetWeakPtr(), log_id),
+ base::Bind(&STHSetComponentInstallerTraits::OnJsonParseError,
+ weak_ptr_factory_.GetWeakPtr(), log_id));
+ }
}
}
« 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