Chromium Code Reviews| 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..a97e53e9987ae747cf68e9688018f2f44c241b51 100644 |
| --- a/chrome/browser/component_updater/sth_set_component_installer.cc |
| +++ b/chrome/browser/component_updater/sth_set_component_installer.cc |
| @@ -10,14 +10,16 @@ |
| #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 +53,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 +76,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, |
| + "delayed_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 +154,18 @@ 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)); |
| + |
| + int error_code = 0; |
|
Alexei Svitkine (slow)
2016/07/13 19:25:01
Can you keep the old behavior based on variation p
Eran Messeri
2016/07/14 10:01:03
Done.
|
| + 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); |
| + } |
| } |
| } |