Import cobalt 25.master.0.1034729
diff --git a/components/client_update_protocol/METADATA b/components/client_update_protocol/METADATA
index c79225f..e692baa 100644
--- a/components/client_update_protocol/METADATA
+++ b/components/client_update_protocol/METADATA
@@ -1,3 +1,5 @@
+name: "client_update_protocol"
+
third_party {
identifier {
type: "ChromiumVersion"
diff --git a/components/client_update_protocol/ecdsa.cc b/components/client_update_protocol/ecdsa.cc
index 53b7e90..03e4c90 100644
--- a/components/client_update_protocol/ecdsa.cc
+++ b/components/client_update_protocol/ecdsa.cc
@@ -49,7 +49,7 @@
// Remove the weak prefix, then remove the begin and the end quotes.
const char kWeakETagPrefix[] = "W/";
if (etag_header_value.starts_with(kWeakETagPrefix))
- etag_header_value.remove_prefix(base::size(kWeakETagPrefix) - 1);
+ etag_header_value.remove_prefix(std::size(kWeakETagPrefix) - 1);
if (etag_header_value.size() >= 2 && etag_header_value.starts_with("\"") &&
etag_header_value.ends_with("\"")) {
etag_header_value.remove_prefix(1);
diff --git a/components/client_update_protocol/ecdsa.h b/components/client_update_protocol/ecdsa.h
index 24e4171..2a86767 100644
--- a/components/client_update_protocol/ecdsa.h
+++ b/components/client_update_protocol/ecdsa.h
@@ -11,6 +11,7 @@
#include <string>
#include <vector>
+#include "base/macros.h"
#include "base/strings/string_piece.h"
namespace client_update_protocol {
diff --git a/components/crash/core/common/crash_key_base_support.cc b/components/crash/core/common/crash_key_base_support.cc
index f9f2cd6..5eac128 100644
--- a/components/crash/core/common/crash_key_base_support.cc
+++ b/components/crash/core/common/crash_key_base_support.cc
@@ -34,6 +34,9 @@
case base::debug::CrashKeySize::Size256: \
operation_prefix BaseCrashKeyString<256> operation_suffix; \
break; \
+ case base::debug::CrashKeySize::Size1024: \
+ operation_prefix BaseCrashKeyString<1024> operation_suffix; \
+ break; \
}
class CrashKeyBaseSupport : public base::debug::CrashKeyImplementation {
@@ -60,6 +63,34 @@
reinterpret_cast<, *>(crash_key)->impl.Clear());
}
+ void OutputCrashKeysToStream(std::ostream& out) override {
+#if !defined(STARBOARD)
+ // TODO(lukasza): If phasing out breakpad takes a long time, then consider
+ // a better way to abstract away difference between crashpad and breakpad.
+ // For example, maybe the code below should be moved into
+ // third_party/crashpad/crashpad/client and exposed (in an abstract,
+ // implementation-agnostic way) via CrashKeyString. This would allow
+ // avoiding using the BUILDFLAG(...) macros here.
+
+ auto* annotations = crashpad::AnnotationList::Get();
+ if (!annotations || annotations->begin() == annotations->end())
+ return;
+
+ out << "Crash keys:\n";
+ for (const crashpad::Annotation* annotation : *annotations) {
+ if (!annotation->is_set())
+ continue;
+
+ if (annotation->type() != crashpad::Annotation::Type::kString)
+ continue;
+ base::StringPiece value(static_cast<const char*>(annotation->value()),
+ annotation->size());
+
+ out << " \"" << annotation->name() << "\" = \"" << value << "\"\n";
+ }
+#endif
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(CrashKeyBaseSupport);
};
diff --git a/components/crash/core/common/crash_keys.cc b/components/crash/core/common/crash_keys.cc
index bbb0af7..e953d81 100644
--- a/components/crash/core/common/crash_keys.cc
+++ b/components/crash/core/common/crash_keys.cc
@@ -130,7 +130,7 @@
ScopedPrinterInfo::ScopedPrinterInfo(base::StringPiece data) {
std::vector<base::StringPiece> info = base::SplitStringPiece(
data, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- for (size_t i = 0; i < arraysize(printer_info_keys); ++i) {
+ for (size_t i = 0; i < std::size(printer_info_keys); ++i) {
if (i < info.size())
printer_info_keys[i].Set(info[i]);
else
diff --git a/components/crash/core/common/crash_keys.h b/components/crash/core/common/crash_keys.h
index 20eb442..ed28d87 100644
--- a/components/crash/core/common/crash_keys.h
+++ b/components/crash/core/common/crash_keys.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/strings/string_piece.h"
+#include "base/macros.h"
namespace base {
class CommandLine;
diff --git a/components/crx_file/BUILD.gn b/components/crx_file/BUILD.gn
index 074de4c..0614a14 100644
--- a/components/crx_file/BUILD.gn
+++ b/components/crx_file/BUILD.gn
@@ -35,7 +35,7 @@
action("crx_file_download_test_data") {
install_content = true
- script = "//tools/download_from_gcs.py"
+ script = "//cobalt/tools/download_from_gcs.py"
sha_sources = []
foreach(sha1_file, sha1_files) {
diff --git a/components/crx_file/METADATA b/components/crx_file/METADATA
index 533568b..a809aef 100644
--- a/components/crx_file/METADATA
+++ b/components/crx_file/METADATA
@@ -1,3 +1,5 @@
+name: "crx_file"
+
third_party {
identifier {
type: "ChromiumVersion"
diff --git a/components/crx_file/crx_verifier.cc b/components/crx_file/crx_verifier.cc
index b3c58ef..7cb72b5 100644
--- a/components/crx_file/crx_verifier.cc
+++ b/components/crx_file/crx_verifier.cc
@@ -15,6 +15,7 @@
#include "base/callback.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
+#include "base/logging.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "components/crx_file/crx3.pb.h"
@@ -108,8 +109,7 @@
const VerifierCollection& verifiers) {
uint8_t buffer[1 << 12] = {};
size_t len = 0;
- while ((len = ReadAndHashBuffer(buffer, base::size(buffer), file, hash)) >
- 0) {
+ while ((len = ReadAndHashBuffer(buffer, std::size(buffer), file, hash)) > 0) {
for (auto& verifier : verifiers)
verifier->VerifyUpdate(base::make_span(buffer, len));
}
@@ -129,8 +129,8 @@
uint8_t buffer[1 << 12] = {};
while (remaining_bytes > 0) {
- size_t len = remaining_bytes >= base::size(buffer) ? base::size(buffer)
- : remaining_bytes;
+ size_t len = remaining_bytes >= std::size(buffer) ? std::size(buffer)
+ : remaining_bytes;
ReadAndHashBufferFromString(buffer, len, it, hash);
remaining_bytes -= len;
@@ -211,7 +211,7 @@
std::vector<uint8_t> publisher_key(std::begin(kPublisherKeyHash),
std::end(kPublisherKeyHash));
- base::Optional<std::vector<uint8_t>> publisher_test_key;
+ absl::optional<std::vector<uint8_t>> publisher_test_key;
if (accept_publisher_test_key) {
publisher_test_key.emplace(std::begin(kPublisherTestKeyHash),
std::end(kPublisherTestKeyHash));
@@ -333,7 +333,7 @@
std::vector<uint8_t> publisher_key(std::begin(kPublisherKeyHash),
std::end(kPublisherKeyHash));
- base::Optional<std::vector<uint8_t>> publisher_test_key;
+ absl::optional<std::vector<uint8_t>> publisher_test_key;
if (accept_publisher_test_key) {
publisher_test_key.emplace(std::begin(kPublisherTestKeyHash),
std::end(kPublisherTestKeyHash));
@@ -592,7 +592,7 @@
ReadAndHashLittleEndianUInt32FromString(&it, file_hash.get());
VerifierResult result;
if (version == 2)
- SB_LOG(WARNING) << "The string is in CRX2 format, which is deprecated and "
+ LOG(WARNING) << "The string is in CRX2 format, which is deprecated and "
<< "will not be supported in M78+";
if (format == VerifierFormat::CRX2_OR_CRX3 &&
(version == 2 || (diff && version == 0))) {
diff --git a/components/crx_file/id_util.cc b/components/crx_file/id_util.cc
index d896ab4..a6250c1 100644
--- a/components/crx_file/id_util.cc
+++ b/components/crx_file/id_util.cc
@@ -7,7 +7,7 @@
#include <stdint.h>
#include "base/files/file_path.h"
-#include "base/sha1.h"
+#include "base/hash/sha1.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
diff --git a/components/metrics/child_call_stack_profile_collector_unittest.cc b/components/metrics/child_call_stack_profile_collector_unittest.cc
index 24cc30e..b5a611e 100644
--- a/components/metrics/child_call_stack_profile_collector_unittest.cc
+++ b/components/metrics/child_call_stack_profile_collector_unittest.cc
@@ -9,8 +9,8 @@
#include <vector>
#include "base/bind.h"
-#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
+#include "base/task/sequenced_task_runner.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/components/metrics/clean_exit_beacon.cc b/components/metrics/clean_exit_beacon.cc
index 74aefd8..b154f26 100644
--- a/components/metrics/clean_exit_beacon.cc
+++ b/components/metrics/clean_exit_beacon.cc
@@ -19,7 +19,7 @@
namespace metrics {
-CleanExitBeacon::CleanExitBeacon(const base::string16& backup_registry_key,
+CleanExitBeacon::CleanExitBeacon(const std::wstring& backup_registry_key,
PrefService* local_state)
: local_state_(local_state),
initial_value_(local_state->GetBoolean(prefs::kStabilityExitedCleanly)),
diff --git a/components/metrics/clean_exit_beacon.h b/components/metrics/clean_exit_beacon.h
index 0043596..dc44198 100644
--- a/components/metrics/clean_exit_beacon.h
+++ b/components/metrics/clean_exit_beacon.h
@@ -6,7 +6,6 @@
#define COMPONENTS_METRICS_CLEAN_EXIT_BEACON_H_
#include "base/macros.h"
-#include "base/strings/string16.h"
#include "base/time/time.h"
class PrefRegistrySimple;
@@ -23,7 +22,7 @@
// On Windows, |backup_registry_key| is used to store a backup of the beacon.
// It is ignored on other platforms.
CleanExitBeacon(
- const base::string16& backup_registry_key,
+ const std::wstring& backup_registry_key,
PrefService* local_state);
~CleanExitBeacon();
@@ -53,7 +52,7 @@
// time of construction. It notes a timestamp from the previous browser
// session when the browser was known to be alive.
const base::Time initial_browser_last_live_timestamp_;
- const base::string16 backup_registry_key_;
+ const std::wstring backup_registry_key_;
DISALLOW_COPY_AND_ASSIGN(CleanExitBeacon);
};
diff --git a/components/metrics/cloned_install_detector.cc b/components/metrics/cloned_install_detector.cc
index 3839744..806f046 100644
--- a/components/metrics/cloned_install_detector.cc
+++ b/components/metrics/cloned_install_detector.cc
@@ -10,11 +10,10 @@
#include "base/bind.h"
#include "base/location.h"
+#include "base/task/thread_pool.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/metrics_hashes.h"
-#include "base/single_thread_task_runner.h"
-#include "base/task/post_task.h"
-#include "base/task_runner_util.h"
+#include "base/task/single_thread_task_runner.h"
#include "components/metrics/machine_id_provider.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
@@ -54,13 +53,16 @@
}
void ClonedInstallDetector::CheckForClonedInstall(PrefService* local_state) {
- base::PostTaskWithTraitsAndReplyWithResult(
+ if (!MachineIdProvider::HasId())
+ return;
+
+ base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE,
{base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN},
- base::Bind(&MachineIdProvider::GetMachineId),
- base::Bind(&ClonedInstallDetector::SaveMachineId,
- weak_ptr_factory_.GetWeakPtr(), local_state));
+ base::BindOnce(&MachineIdProvider::GetMachineId),
+ base::BindOnce(&ClonedInstallDetector::SaveMachineId,
+ weak_ptr_factory_.GetWeakPtr(), local_state));
}
void ClonedInstallDetector::SaveMachineId(PrefService* local_state,
diff --git a/components/metrics/daily_event.cc b/components/metrics/daily_event.cc
index befc2eb..6df1cdd 100644
--- a/components/metrics/daily_event.cc
+++ b/components/metrics/daily_event.cc
@@ -6,6 +6,7 @@
#include <utility>
+#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
diff --git a/components/metrics/data_use_tracker.cc b/components/metrics/data_use_tracker.cc
index 61be02f..ec096eb 100644
--- a/components/metrics/data_use_tracker.cc
+++ b/components/metrics/data_use_tracker.cc
@@ -91,14 +91,14 @@
int message_size) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- DictionaryPrefUpdate pref_updater(local_state_, pref_name);
+ ScopedDictPrefUpdate pref_updater(local_state_, pref_name);
int todays_traffic = 0;
std::string todays_key = GetCurrentMeasurementDateAsString();
- const base::DictionaryValue* user_pref_dict =
+ const base::Value::Dict* user_pref_dict =
local_state_->GetDictionary(pref_name);
- user_pref_dict->GetInteger(todays_key, &todays_traffic);
- pref_updater->SetInteger(todays_key, todays_traffic + message_size);
+ todays_traffic = user_pref_dict->FindInt(todays_key).value_or(0);
+ pref_updater->Set(todays_key, todays_traffic + message_size);
}
void DataUseTracker::RemoveExpiredEntries() {
@@ -110,20 +110,20 @@
void DataUseTracker::RemoveExpiredEntriesForPref(const std::string& pref_name) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- const base::DictionaryValue* user_pref_dict =
+ const base::Value::Dict* user_pref_dict =
local_state_->GetDictionary(pref_name);
const base::Time current_date = GetCurrentMeasurementDate();
const base::Time week_ago = current_date - base::TimeDelta::FromDays(7);
- base::DictionaryValue user_pref_new_dict;
- for (base::DictionaryValue::Iterator it(*user_pref_dict); !it.IsAtEnd();
- it.Advance()) {
+ base::Value::Dict user_pref_new_dict;
+ for (const auto it : *user_pref_dict) {
base::Time key_date;
- if (base::Time::FromUTCString(it.key().c_str(), &key_date) &&
- key_date > week_ago)
- user_pref_new_dict.Set(it.key(), it.value().CreateDeepCopy());
+ if (base::Time::FromUTCString(it.first.c_str(), &key_date) &&
+ key_date > week_ago) {
+ user_pref_new_dict.Set(it.first, it.second.Clone());
+ }
}
- local_state_->Set(pref_name, user_pref_new_dict);
+ local_state_->SetDict(pref_name, std::move(user_pref_new_dict));
}
// Note: We compute total data use regardless of what is the current date. In
@@ -134,12 +134,10 @@
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
int total_data_use = 0;
- const base::DictionaryValue* pref_dict =
+ const base::Value::Dict* pref_dict =
local_state_->GetDictionary(pref_name);
- for (base::DictionaryValue::Iterator it(*pref_dict); !it.IsAtEnd();
- it.Advance()) {
- int value = 0;
- it.value().GetAsInteger(&value);
+ for (const auto it : *pref_dict) {
+ int value = it.second.GetIfInt().value_or(0);
total_data_use += value;
}
return total_data_use;
diff --git a/components/metrics/drive_metrics_provider.h b/components/metrics/drive_metrics_provider.h
index 1da73ce..5a89b6a 100644
--- a/components/metrics/drive_metrics_provider.h
+++ b/components/metrics/drive_metrics_provider.h
@@ -5,7 +5,7 @@
#ifndef COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_
#define COMPONENTS_METRICS_DRIVE_METRICS_PROVIDER_H_
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
diff --git a/components/metrics/environment_recorder.cc b/components/metrics/environment_recorder.cc
index 6391f61..7b6d926 100644
--- a/components/metrics/environment_recorder.cc
+++ b/components/metrics/environment_recorder.cc
@@ -5,7 +5,7 @@
#include "components/metrics/environment_recorder.h"
#include "base/base64.h"
-#include "base/sha1.h"
+#include "base/hash/sha1.h"
#include "base/strings/string_number_conversions.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
diff --git a/components/metrics/expired_histogram_util.cc b/components/metrics/expired_histogram_util.cc
index 17844e7..388773d 100644
--- a/components/metrics/expired_histogram_util.cc
+++ b/components/metrics/expired_histogram_util.cc
@@ -20,7 +20,7 @@
} // namespace
-void EnableExpiryChecker(const uint64_t* expired_histograms_hashes,
+void EnableExpiryChecker(const uint32_t* expired_histograms_hashes,
size_t num_expired_histograms) {
DCHECK(base::FeatureList::GetInstance());
if (base::FeatureList::IsEnabled(kExpiredHistogramLogicFeature)) {
diff --git a/components/metrics/expired_histogram_util.h b/components/metrics/expired_histogram_util.h
index cf6c455..d0e25e7 100644
--- a/components/metrics/expired_histogram_util.h
+++ b/components/metrics/expired_histogram_util.h
@@ -13,7 +13,7 @@
// Enables histogram expiry checker if it is enabled by field trial. Histogram
// expiry is disbaled by default so that unit tests don't fail unexpectedly when
// a histogram expires.
-void EnableExpiryChecker(const uint64_t* expired_histograms_hashes,
+void EnableExpiryChecker(const uint32_t* expired_histograms_hashes,
size_t num_expired_histograms);
} // namespace metrics
diff --git a/components/metrics/expired_histograms_checker.cc b/components/metrics/expired_histograms_checker.cc
index d1d3ecb..fd0dc1c 100644
--- a/components/metrics/expired_histograms_checker.cc
+++ b/components/metrics/expired_histograms_checker.cc
@@ -15,7 +15,7 @@
namespace metrics {
ExpiredHistogramsChecker::ExpiredHistogramsChecker(
- const uint64_t* array,
+ const uint32_t* array,
size_t size,
const std::string& whitelist_str)
: array_(array), size_(size) {
@@ -24,7 +24,7 @@
ExpiredHistogramsChecker::~ExpiredHistogramsChecker() {}
-bool ExpiredHistogramsChecker::ShouldRecord(uint64_t histogram_hash) const {
+bool ExpiredHistogramsChecker::ShouldRecord(uint32_t histogram_hash) const {
// If histogram is whitelisted then it should always be recorded.
if (base::ContainsKey(whitelist_, histogram_hash))
return true;
diff --git a/components/metrics/expired_histograms_checker.h b/components/metrics/expired_histograms_checker.h
index b3ca4a7..1111d1d 100644
--- a/components/metrics/expired_histograms_checker.h
+++ b/components/metrics/expired_histograms_checker.h
@@ -21,13 +21,13 @@
// Takes sorted in nondecreasing order array of histogram hashes, its size and
// list of whitelisted histogram names concatenated as a comma-separated
// string.
- ExpiredHistogramsChecker(const uint64_t* array,
+ ExpiredHistogramsChecker(const uint32_t* array,
size_t size,
const std::string& whitelist_str);
~ExpiredHistogramsChecker() override;
// Checks if the given |histogram_hash| corresponds to an expired histogram.
- bool ShouldRecord(uint64_t histogram_hash) const override;
+ bool ShouldRecord(uint32_t histogram_hash) const override;
private:
// Initializes the |whitelist_| array of histogram hashes that should be
@@ -35,13 +35,13 @@
void InitWhitelist(const std::string& whitelist_str);
// Array of expired histogram hashes.
- const uint64_t* const array_;
+ const uint32_t* const array_;
// Size of the |array_|.
const size_t size_;
// List of expired histogram hashes that should be recorded.
- std::set<uint64_t> whitelist_;
+ std::set<uint32_t> whitelist_;
DISALLOW_COPY_AND_ASSIGN(ExpiredHistogramsChecker);
};
diff --git a/components/metrics/file_metrics_provider.cc b/components/metrics/file_metrics_provider.cc
index a94bb07..25fe6f2 100644
--- a/components/metrics/file_metrics_provider.cc
+++ b/components/metrics/file_metrics_provider.cc
@@ -20,7 +20,7 @@
#include "base/strings/string_piece.h"
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
-#include "base/task_runner.h"
+#include "base/task/task_runner.h"
#include "base/time/time.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_service.h"
diff --git a/components/metrics/file_metrics_provider.h b/components/metrics/file_metrics_provider.h
index 7465d93..167224b 100644
--- a/components/metrics/file_metrics_provider.h
+++ b/components/metrics/file_metrics_provider.h
@@ -9,7 +9,7 @@
#include <memory>
#include <string>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
diff --git a/components/metrics/machine_id_provider.h b/components/metrics/machine_id_provider.h
index b7a2704..f9853f7 100644
--- a/components/metrics/machine_id_provider.h
+++ b/components/metrics/machine_id_provider.h
@@ -29,7 +29,8 @@
static std::string GetMachineId();
private:
- DISALLOW_IMPLICIT_CONSTRUCTORS(MachineIdProvider);
+ MachineIdProvider() = delete;
+ MachineIdProvider(const MachineIdProvider&) = delete;
};
} // namespace metrics
diff --git a/components/metrics/metrics_log.cc b/components/metrics/metrics_log.cc
index 971b98a..82e97f9 100644
--- a/components/metrics/metrics_log.cc
+++ b/components/metrics/metrics_log.cc
@@ -11,6 +11,7 @@
#include "base/build_time.h"
#include "base/cpu.h"
+#include "base/logging.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_flattener.h"
#include "base/metrics/histogram_functions.h"
@@ -20,7 +21,7 @@
#include "base/metrics/metrics_hashes.h"
#include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h"
-#include "base/sys_info.h"
+#include "base/system/sys_info.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/metrics/delegating_provider.h"
diff --git a/components/metrics/metrics_log_store_unittest.cc b/components/metrics/metrics_log_store_unittest.cc
index 50b78c7..b6168cf 100644
--- a/components/metrics/metrics_log_store_unittest.cc
+++ b/components/metrics/metrics_log_store_unittest.cc
@@ -29,7 +29,7 @@
const char* pref = log_type == MetricsLog::INITIAL_STABILITY_LOG
? prefs::kMetricsInitialLogs
: prefs::kMetricsOngoingLogs;
- return pref_service_.GetList(pref)->GetSize();
+ return pref_service_.GetList(pref)->size();
}
TestMetricsServiceClient client_;
diff --git a/components/metrics/metrics_log_unittest.cc b/components/metrics/metrics_log_unittest.cc
index bddc0fc..abc53de 100644
--- a/components/metrics/metrics_log_unittest.cc
+++ b/components/metrics/metrics_log_unittest.cc
@@ -16,7 +16,7 @@
#include "base/metrics/sample_vector.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
-#include "base/sys_info.h"
+#include "base/system/sys_info.h"
#include "base/time/time.h"
#include "components/metrics/delegating_provider.h"
#include "components/metrics/environment_recorder.h"
diff --git a/components/metrics/metrics_service.cc b/components/metrics/metrics_service.cc
index ba636e0..2ecb0ed 100644
--- a/components/metrics/metrics_service.cc
+++ b/components/metrics/metrics_service.cc
@@ -138,9 +138,8 @@
#include "base/metrics/histogram_samples.h"
#include "base/metrics/persistent_histogram_allocator.h"
#include "base/metrics/statistics_recorder.h"
-#include "base/single_thread_task_runner.h"
+#include "base/task/single_thread_task_runner.h"
#include "base/strings/string_piece.h"
-#include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/metrics/environment_recorder.h"
@@ -278,7 +277,7 @@
}
void MetricsService::StartUpdatingLastLiveTimestamp() {
- base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&MetricsService::UpdateLastLiveTimestampTask,
self_ptr_factory_.GetWeakPtr()),
@@ -558,7 +557,7 @@
IncrementLongPrefsValue(prefs::kUninstallLaunchCount);
}
-void MetricsService::OnUserAction(const std::string& action) {
+void MetricsService::OnUserAction(const std::string& action, base::TimeTicks) {
log_manager_.current_log()->RecordUserAction(action);
HandleIdleSinceLastTransmission(false);
}
@@ -622,25 +621,25 @@
<< initialization_delay_secs;
}
}
- base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&MetricsService::StartInitTask,
self_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(initialization_delay_secs));
- base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&MetricsService::PrepareProviderMetricsTask,
self_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(2 * initialization_delay_secs));
#else
- base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&MetricsService::StartInitTask,
self_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(kInitializationDelaySeconds));
- base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&MetricsService::PrepareProviderMetricsTask,
self_ptr_factory_.GetWeakPtr()),
@@ -923,7 +922,7 @@
bool found = PrepareProviderMetricsLog();
base::TimeDelta next_check = found ? base::TimeDelta::FromSeconds(5)
: base::TimeDelta::FromMinutes(15);
- base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&MetricsService::PrepareProviderMetricsTask,
self_ptr_factory_.GetWeakPtr()),
diff --git a/components/metrics/metrics_service.h b/components/metrics/metrics_service.h
index 6471314..8bd5ba6 100644
--- a/components/metrics/metrics_service.h
+++ b/components/metrics/metrics_service.h
@@ -225,7 +225,7 @@
// state should be INIT_TASK_SCHEDULED.
void FinishedInitTask();
- void OnUserAction(const std::string& action);
+ void OnUserAction(const std::string& action, base::TimeTicks);
// Get the amount of uptime since this process started and since the last
// call to this function. Also updates the cumulative uptime metric (stored
diff --git a/components/metrics/metrics_service_client.h b/components/metrics/metrics_service_client.h
index c1bc828..6b0baee 100644
--- a/components/metrics/metrics_service_client.h
+++ b/components/metrics/metrics_service_client.h
@@ -11,7 +11,6 @@
#include <string>
#include "base/callback.h"
-#include "base/strings/string16.h"
#include "base/time/time.h"
#include "components/metrics/metrics_log_uploader.h"
#include "components/metrics/metrics_reporting_default_state.h"
diff --git a/components/metrics/metrics_service_unittest.cc b/components/metrics/metrics_service_unittest.cc
index f10b79a..3f7215a 100644
--- a/components/metrics/metrics_service_unittest.cc
+++ b/components/metrics/metrics_service_unittest.cc
@@ -16,8 +16,8 @@
#include "base/metrics/statistics_recorder.h"
#include "base/metrics/user_metrics.h"
#include "base/stl_util.h"
-#include "base/strings/string16.h"
#include "base/test/scoped_feature_list.h"
+#include "base/test/task_environment.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread_task_runner_handle.h"
@@ -82,10 +82,9 @@
class MetricsServiceTest : public testing::Test {
public:
MetricsServiceTest()
- : task_runner_(new base::TestSimpleTaskRunner),
- task_runner_handle_(task_runner_),
- enabled_state_provider_(new TestEnabledStateProvider(false, false)) {
- base::SetRecordActionTaskRunner(task_runner_);
+ : enabled_state_provider_(new TestEnabledStateProvider(false, false)) {
+ base::SetRecordActionTaskRunner(
+ task_environment_.GetMainThreadTaskRunner());
MetricsService::RegisterPrefs(testing_local_state_.registry());
}
@@ -99,7 +98,7 @@
// stability state from prefs after tests have a chance to initialize it.
if (!metrics_state_manager_) {
metrics_state_manager_ = MetricsStateManager::Create(
- GetLocalState(), enabled_state_provider_.get(), base::string16(),
+ GetLocalState(), enabled_state_provider_.get(), std::wstring(),
base::Bind(&StoreNoClientInfoBackup), base::Bind(&ReturnNoBackup));
}
return metrics_state_manager_.get();
@@ -143,9 +142,9 @@
}
protected:
- scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
- base::ThreadTaskRunnerHandle task_runner_handle_;
base::test::ScopedFeatureList feature_list_;
+ base::test::TaskEnvironment task_environment_{
+ base::test::TaskEnvironment::TimeSource::MOCK_TIME};
private:
std::unique_ptr<TestEnabledStateProvider> enabled_state_provider_;
@@ -354,6 +353,8 @@
EXPECT_TRUE(test_provider->init_called());
}
+// TODO: b/323391538 Re-enable these tests after updating metrics component.
+#if !defined(STARBOARD)
TEST_F(MetricsServiceTest, SplitRotation) {
TestMetricsServiceClient client;
TestMetricsService service(GetMetricsStateManager(), &client,
@@ -445,5 +446,6 @@
updated_last_live_time,
GetLocalState()->GetTime(prefs::kStabilityBrowserLastLiveTimeStamp));
}
+#endif // defined(STARBOARD)
} // namespace metrics
diff --git a/components/metrics/metrics_state_manager.cc b/components/metrics/metrics_state_manager.cc
index f4515c9..6a15a89 100644
--- a/components/metrics/metrics_state_manager.cc
+++ b/components/metrics/metrics_state_manager.cc
@@ -133,7 +133,7 @@
MetricsStateManager::MetricsStateManager(
PrefService* local_state,
EnabledStateProvider* enabled_state_provider,
- const base::string16& backup_registry_key,
+ const std::wstring& backup_registry_key,
const StoreClientInfoCallback& store_client_info,
const LoadClientInfoCallback& retrieve_client_info)
: local_state_(local_state),
@@ -257,7 +257,7 @@
UpdateEntropySourceReturnedValue(ENTROPY_SOURCE_HIGH);
const std::string high_entropy_source =
- client_id_ + base::IntToString(low_entropy_source_value);
+ client_id_ + std::to_string(low_entropy_source_value);
return std::unique_ptr<const base::FieldTrial::EntropyProvider>(
new variations::SHA1EntropyProvider(high_entropy_source));
}
@@ -285,7 +285,7 @@
std::unique_ptr<MetricsStateManager> MetricsStateManager::Create(
PrefService* local_state,
EnabledStateProvider* enabled_state_provider,
- const base::string16& backup_registry_key,
+ const std::wstring& backup_registry_key,
const StoreClientInfoCallback& store_client_info,
const LoadClientInfoCallback& retrieve_client_info) {
std::unique_ptr<MetricsStateManager> result;
diff --git a/components/metrics/metrics_state_manager.h b/components/metrics/metrics_state_manager.h
index a1a15b3..0ed6ad3 100644
--- a/components/metrics/metrics_state_manager.h
+++ b/components/metrics/metrics_state_manager.h
@@ -12,7 +12,6 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/metrics/field_trial.h"
-#include "base/strings/string16.h"
#include "components/metrics/clean_exit_beacon.h"
#include "components/metrics/client_info.h"
@@ -96,7 +95,7 @@
static std::unique_ptr<MetricsStateManager> Create(
PrefService* local_state,
EnabledStateProvider* enabled_state_provider,
- const base::string16& backup_registry_key,
+ const std::wstring& backup_registry_key,
const StoreClientInfoCallback& store_client_info,
const LoadClientInfoCallback& load_client_info);
@@ -131,7 +130,7 @@
// that it is later retrievable by |load_client_info|.
MetricsStateManager(PrefService* local_state,
EnabledStateProvider* enabled_state_provider,
- const base::string16& backup_registry_key,
+ const std::wstring& backup_registry_key,
const StoreClientInfoCallback& store_client_info,
const LoadClientInfoCallback& load_client_info);
diff --git a/components/metrics/metrics_state_manager_unittest.cc b/components/metrics/metrics_state_manager_unittest.cc
index 0e1f148..0244458 100644
--- a/components/metrics/metrics_state_manager_unittest.cc
+++ b/components/metrics/metrics_state_manager_unittest.cc
@@ -13,7 +13,6 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/macros.h"
-#include "base/strings/string16.h"
#include "base/test/metrics/histogram_tester.h"
#include "components/metrics/client_info.h"
#include "components/metrics/metrics_log.h"
@@ -38,7 +37,7 @@
std::unique_ptr<MetricsStateManager> CreateStateManager() {
return MetricsStateManager::Create(
- &prefs_, enabled_state_provider_.get(), base::string16(),
+ &prefs_, enabled_state_provider_.get(), std::wstring(),
base::Bind(&MetricsStateManagerTest::MockStoreClientInfoBackup,
base::Unretained(this)),
base::Bind(&MetricsStateManagerTest::LoadFakeClientInfoBackup,
@@ -177,7 +176,9 @@
state_manager->GetLowEntropySource();
EXPECT_FALSE(low_entropy_pref->IsDefaultValue());
- EXPECT_TRUE(low_entropy_pref->GetValue()->GetAsInteger(&low_entropy_value));
+ auto low_entropy_value_optional = low_entropy_pref->GetValue()->GetIfInt();
+ EXPECT_TRUE(low_entropy_value_optional.has_value());
+ low_entropy_value = low_entropy_value_optional.value();
}
// Now, set a dummy value in the permuted entropy cache pref and verify that
diff --git a/components/metrics/metrics_upload_scheduler.cc b/components/metrics/metrics_upload_scheduler.cc
index b7b7364..5992ead 100644
--- a/components/metrics/metrics_upload_scheduler.cc
+++ b/components/metrics/metrics_upload_scheduler.cc
@@ -61,7 +61,6 @@
MetricsUploadScheduler::MetricsUploadScheduler(
const base::Closure& upload_callback)
: MetricsScheduler(upload_callback),
- unsent_logs_interval_(GetUnsentLogsInterval()),
initial_backoff_interval_(GetInitialBackoffInterval()),
backoff_interval_(initial_backoff_interval_) {}
@@ -76,13 +75,13 @@
backoff_interval_ = BackOffUploadInterval(backoff_interval_);
} else {
backoff_interval_ = initial_backoff_interval_;
- TaskDone(unsent_logs_interval_);
+ TaskDone(GetUnsentLogsInterval());
}
}
void MetricsUploadScheduler::StopAndUploadCancelled() {
Stop();
- TaskDone(unsent_logs_interval_);
+ TaskDone(GetUnsentLogsInterval());
}
void MetricsUploadScheduler::UploadOverDataUsageCap() {
diff --git a/components/metrics/metrics_upload_scheduler.h b/components/metrics/metrics_upload_scheduler.h
index a97b7cb..f04a76e 100644
--- a/components/metrics/metrics_upload_scheduler.h
+++ b/components/metrics/metrics_upload_scheduler.h
@@ -34,9 +34,6 @@
void UploadOverDataUsageCap();
private:
- // Time to wait between uploads on success.
- const base::TimeDelta unsent_logs_interval_;
-
// Initial time to wait between upload retry attempts.
const base::TimeDelta initial_backoff_interval_;
diff --git a/components/metrics/net/net_metrics_log_uploader.cc b/components/metrics/net/net_metrics_log_uploader.cc
index 0d937ce..23730af 100644
--- a/components/metrics/net/net_metrics_log_uploader.cc
+++ b/components/metrics/net/net_metrics_log_uploader.cc
@@ -14,7 +14,7 @@
#include "net/base/load_flags.h"
#include "net/base/url_util.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
-#include "net/url_request/url_fetcher.h"
+#include "cobalt/network/custom/url_fetcher.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "third_party/metrics_proto/reporting_info.pb.h"
diff --git a/components/metrics/net/network_metrics_provider.cc b/components/metrics/net/network_metrics_provider.cc
index d175648..193bd84 100644
--- a/components/metrics/net/network_metrics_provider.cc
+++ b/components/metrics/net/network_metrics_provider.cc
@@ -10,7 +10,7 @@
#include <vector>
#include "base/bind_helpers.h"
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/sparse_histogram.h"
diff --git a/components/metrics/net/network_metrics_provider.h b/components/metrics/net/network_metrics_provider.h
index 3b9932f..f0c0905 100644
--- a/components/metrics/net/network_metrics_provider.h
+++ b/components/metrics/net/network_metrics_provider.h
@@ -10,7 +10,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_base.h"
-#include "base/sequenced_task_runner.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/threading/thread_checker.h"
#include "components/metrics/metrics_provider.h"
#include "components/metrics/net/wifi_access_point_info_provider.h"
diff --git a/components/metrics/persisted_logs.cc b/components/metrics/persisted_logs.cc
index 74d1ca7..c789d99 100644
--- a/components/metrics/persisted_logs.cc
+++ b/components/metrics/persisted_logs.cc
@@ -9,9 +9,9 @@
#include <utility>
#include "base/base64.h"
-#include "base/md5.h"
+#include "base/hash/md5.h"
#include "base/metrics/histogram_macros.h"
-#include "base/sha1.h"
+#include "base/hash/sha1.h"
#include "base/strings/string_number_conversions.h"
#include "base/timer/elapsed_timer.h"
#include "components/metrics/persisted_logs_metrics.h"
@@ -41,6 +41,16 @@
return result;
}
+bool GetString(const base::Value::Dict& dict,
+ base::StringPiece key,
+ std::string& out) {
+ const std::string* value = dict.FindString(key);
+ if (!value)
+ return false;
+ out = *value;
+ return true;
+}
+
} // namespace
void PersistedLogs::LogInfo::Init(PersistedLogsMetrics* metrics,
@@ -125,8 +135,8 @@
}
void PersistedLogs::PersistUnsentLogs() const {
- ListPrefUpdate update(local_state_, pref_name_);
- WriteLogsToPrefList(update.Get());
+ ScopedListPrefUpdate update(local_state_, pref_name_);
+ WriteLogsToPrefList(&update.Get());
}
void PersistedLogs::LoadPersistedUnsentLogs() {
@@ -136,7 +146,7 @@
void PersistedLogs::StoreLog(const std::string& log_data) {
list_.push_back(LogInfo());
list_.back().Init(metrics_.get(), log_data,
- base::Int64ToString(base::Time::Now().ToTimeT()));
+ std::to_string(base::Time::Now().ToTimeT()));
}
void PersistedLogs::Purge() {
@@ -147,22 +157,22 @@
local_state_->ClearPref(pref_name_);
}
-void PersistedLogs::ReadLogsFromPrefList(const base::ListValue& list_value) {
+void PersistedLogs::ReadLogsFromPrefList(const base::Value::List& list_value) {
if (list_value.empty()) {
metrics_->RecordLogReadStatus(PersistedLogsMetrics::LIST_EMPTY);
return;
}
- const size_t log_count = list_value.GetSize();
+ const size_t log_count = list_value.size();
DCHECK(list_.empty());
list_.resize(log_count);
for (size_t i = 0; i < log_count; ++i) {
- const base::DictionaryValue* dict;
- if (!list_value.GetDictionary(i, &dict) ||
- !dict->GetString(kLogDataKey, &list_[i].compressed_log_data) ||
- !dict->GetString(kLogHashKey, &list_[i].hash)) {
+ const base::Value::Dict* dict = list_value[i].GetIfDict();
+ std::unique_ptr<LogInfo> info = std::make_unique<LogInfo>();
+ if (!dict || !GetString(*dict, kLogDataKey, info->compressed_log_data) ||
+ !GetString(*dict, kLogHashKey, info->hash)) {
list_.clear();
metrics_->RecordLogReadStatus(
PersistedLogsMetrics::LOG_STRING_CORRUPTION);
@@ -176,14 +186,14 @@
// older logs.
// NOTE: Should be added to the check with other fields once migration is
// over.
- dict->GetString(kLogTimestampKey, &list_[i].timestamp);
+ GetString(*dict, kLogTimestampKey, list_[i].timestamp);
}
metrics_->RecordLogReadStatus(PersistedLogsMetrics::RECALL_SUCCESS);
}
-void PersistedLogs::WriteLogsToPrefList(base::ListValue* list_value) const {
- list_value->Clear();
+void PersistedLogs::WriteLogsToPrefList(base::Value::List* list_value) const {
+ list_value->clear();
// Keep the most recent logs which are smaller than |max_log_size_|.
// We keep at least |min_log_bytes_| and |min_log_count_| of logs before
@@ -212,12 +222,11 @@
dropped_logs_num++;
continue;
}
- std::unique_ptr<base::DictionaryValue> dict_value(
- new base::DictionaryValue);
- dict_value->SetString(kLogHashKey, EncodeToBase64(list_[i].hash));
- dict_value->SetString(kLogDataKey,
- EncodeToBase64(list_[i].compressed_log_data));
- dict_value->SetString(kLogTimestampKey, list_[i].timestamp);
+
+ base::Value::Dict dict_value;
+ dict_value.Set(kLogHashKey, EncodeToBase64(list_[i].hash));
+ dict_value.Set(kLogDataKey, EncodeToBase64(list_[i].compressed_log_data));
+ dict_value.Set(kLogTimestampKey, list_[i].timestamp);
list_value->Append(std::move(dict_value));
}
if (dropped_logs_num > 0)
diff --git a/components/metrics/persisted_logs.h b/components/metrics/persisted_logs.h
index f95b820..ab5f0a5 100644
--- a/components/metrics/persisted_logs.h
+++ b/components/metrics/persisted_logs.h
@@ -67,10 +67,10 @@
private:
// Writes the list to the ListValue.
- void WriteLogsToPrefList(base::ListValue* list) const;
+ void WriteLogsToPrefList(base::Value::List* list) const;
// Reads the list from the ListValue.
- void ReadLogsFromPrefList(const base::ListValue& list);
+ void ReadLogsFromPrefList(const base::Value::List& list);
// An object for recording UMA metrics.
std::unique_ptr<PersistedLogsMetrics> metrics_;
diff --git a/components/metrics/persistent_system_profile.cc b/components/metrics/persistent_system_profile.cc
index fa35a44..af623c0 100644
--- a/components/metrics/persistent_system_profile.cc
+++ b/components/metrics/persistent_system_profile.cc
@@ -337,7 +337,7 @@
pickler.WriteString(group);
WriteToAll(kFieldTrialInfo,
- base::StringPiece(static_cast<const char*>(pickler.data()),
+ base::StringPiece(pickler.data_as_char(),
pickler.size()));
}
diff --git a/components/metrics/persistent_system_profile.h b/components/metrics/persistent_system_profile.h
index 6c854a9..5a851b8 100644
--- a/components/metrics/persistent_system_profile.h
+++ b/components/metrics/persistent_system_profile.h
@@ -10,6 +10,7 @@
#include "base/strings/string_piece.h"
#include "base/threading/thread_checker.h"
#include "third_party/metrics_proto/system_profile.pb.h"
+#include "base/macros.h"
namespace base {
template <typename T>
diff --git a/components/metrics/public/cpp/call_stack_profile_struct_traits_unittest.cc b/components/metrics/public/cpp/call_stack_profile_struct_traits_unittest.cc
index 236d619..6e472db 100644
--- a/components/metrics/public/cpp/call_stack_profile_struct_traits_unittest.cc
+++ b/components/metrics/public/cpp/call_stack_profile_struct_traits_unittest.cc
@@ -5,7 +5,7 @@
#include <utility>
#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/metrics/public/interfaces/call_stack_profile_collector_test.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/components/metrics/reporting_service_unittest.cc b/components/metrics/reporting_service_unittest.cc
index fb838cb..76e4dda 100644
--- a/components/metrics/reporting_service_unittest.cc
+++ b/components/metrics/reporting_service_unittest.cc
@@ -12,7 +12,7 @@
#include "base/bind.h"
#include "base/macros.h"
-#include "base/sha1.h"
+#include "base/hash/sha1.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/metrics/log_store.h"
@@ -88,8 +88,7 @@
class ReportingServiceTest : public testing::Test {
public:
ReportingServiceTest()
- : task_runner_(new base::TestSimpleTaskRunner),
- task_runner_handle_(task_runner_) {
+ : task_runner_(new base::TestSimpleTaskRunner) {
ReportingService::RegisterPrefs(testing_local_state_.registry());
}
@@ -99,7 +98,6 @@
protected:
scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
- base::ThreadTaskRunnerHandle task_runner_handle_;
TestMetricsServiceClient client_;
private:
@@ -110,6 +108,8 @@
} // namespace
+// TODO: b/323391538 Re-enable these tests after updating metrics component.
+#if !defined(STARBOARD)
TEST_F(ReportingServiceTest, BasicTest) {
TestReportingService service(&client_, GetLocalState());
service.AddLog("log1");
@@ -138,5 +138,6 @@
EXPECT_EQ(0U, task_runner_->NumPendingTasks());
EXPECT_FALSE(client_.uploader()->is_uploading());
}
+#endif // defined(STARBOARD)
} // namespace metrics
diff --git a/components/metrics/serialization/serialization_utils.cc b/components/metrics/serialization/serialization_utils.cc
index 7214b5d..6abee21 100644
--- a/components/metrics/serialization/serialization_utils.cc
+++ b/components/metrics/serialization/serialization_utils.cc
@@ -103,15 +103,15 @@
const std::string& name = parts[0];
const std::string& value = parts[1];
- if (base::LowerCaseEqualsASCII(name, "crash"))
+ if (base::EqualsCaseInsensitiveASCII(name, "crash"))
return MetricSample::CrashSample(value);
- if (base::LowerCaseEqualsASCII(name, "histogram"))
+ if (base::EqualsCaseInsensitiveASCII(name, "histogram"))
return MetricSample::ParseHistogram(value);
- if (base::LowerCaseEqualsASCII(name, "linearhistogram"))
+ if (base::EqualsCaseInsensitiveASCII(name, "linearhistogram"))
return MetricSample::ParseLinearHistogram(value);
- if (base::LowerCaseEqualsASCII(name, "sparsehistogram"))
+ if (base::EqualsCaseInsensitiveASCII(name, "sparsehistogram"))
return MetricSample::ParseSparseHistogram(value);
- if (base::LowerCaseEqualsASCII(name, "useraction"))
+ if (base::EqualsCaseInsensitiveASCII(name, "useraction"))
return MetricSample::UserActionSample(value);
DLOG(ERROR) << "invalid event type: " << name << ", value: " << value;
return std::unique_ptr<MetricSample>();
diff --git a/components/metrics/single_sample_metrics_factory_impl_unittest.cc b/components/metrics/single_sample_metrics_factory_impl_unittest.cc
index 7362085..f275b8b 100644
--- a/components/metrics/single_sample_metrics_factory_impl_unittest.cc
+++ b/components/metrics/single_sample_metrics_factory_impl_unittest.cc
@@ -4,9 +4,9 @@
#include "components/metrics/single_sample_metrics_factory_impl.h"
-#include "base/message_loop/message_loop.h"
#include "base/metrics/dummy_histogram.h"
#include "base/run_loop.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/threading/thread.h"
diff --git a/components/metrics_services_manager/metrics_services_manager.cc b/components/metrics_services_manager/metrics_services_manager.cc
index 9406017..874a984 100644
--- a/components/metrics_services_manager/metrics_services_manager.cc
+++ b/components/metrics_services_manager/metrics_services_manager.cc
@@ -6,6 +6,7 @@
#include <utility>
+#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "components/metrics/metrics_service.h"
diff --git a/components/metrics_services_manager/metrics_services_manager_client.h b/components/metrics_services_manager/metrics_services_manager_client.h
index adb3730..d19273a 100644
--- a/components/metrics_services_manager/metrics_services_manager_client.h
+++ b/components/metrics_services_manager/metrics_services_manager_client.h
@@ -7,7 +7,7 @@
#include <memory>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/metrics/field_trial.h"
namespace metrics {
diff --git a/components/nacl/common/BUILD.gn b/components/nacl/common/BUILD.gn
new file mode 100644
index 0000000..7f8e28b
--- /dev/null
+++ b/components/nacl/common/BUILD.gn
@@ -0,0 +1,5 @@
+import("//build/buildflag_header.gni")
+buildflag_header("buildflags") {
+ header = "buildflags.h"
+ flags = [ "IS_MINIMAL_TOOLCHAIN=false" ]
+}
diff --git a/components/prefs/BUILD.gn b/components/prefs/BUILD.gn
index d625cc5..ee349a0 100644
--- a/components/prefs/BUILD.gn
+++ b/components/prefs/BUILD.gn
@@ -56,10 +56,7 @@
configs += [ ":prefs_config" ]
- deps = [
- "//base",
- "//base/util/values:values_util",
- ]
+ deps = [ "//base" ]
}
source_set("test_support") {
diff --git a/components/prefs/METADATA b/components/prefs/METADATA
index d7757ae..48c0ec2 100644
--- a/components/prefs/METADATA
+++ b/components/prefs/METADATA
@@ -1,3 +1,5 @@
+name: "chrome_prefs"
+
third_party {
identifier {
type: "ChromiumVersion"
diff --git a/components/prefs/command_line_pref_store.cc b/components/prefs/command_line_pref_store.cc
index 79fc10c..bd3e1f1 100644
--- a/components/prefs/command_line_pref_store.cc
+++ b/components/prefs/command_line_pref_store.cc
@@ -7,6 +7,7 @@
#include <memory>
#include <string>
+#include "base/logging.h"
#include "base/files/file_path.h"
#include "base/strings/string_number_conversions.h"
@@ -22,7 +23,7 @@
for (size_t i = 0; i < size; ++i) {
if (command_line_->HasSwitch(string_switch[i].switch_name)) {
SetValue(string_switch[i].preference_path,
- std::make_unique<base::Value>(command_line_->GetSwitchValueASCII(
+ base::Value(command_line_->GetSwitchValueASCII(
string_switch[i].switch_name)),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
@@ -35,7 +36,7 @@
for (size_t i = 0; i < size; ++i) {
if (command_line_->HasSwitch(path_switch[i].switch_name)) {
SetValue(path_switch[i].preference_path,
- std::make_unique<base::Value>(
+ base::Value(
command_line_->GetSwitchValuePath(path_switch[i].switch_name)
.value()),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
@@ -58,7 +59,7 @@
continue;
}
SetValue(integer_switch[i].preference_path,
- std::make_unique<base::Value>(int_value),
+ base::Value(int_value),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
}
@@ -70,7 +71,7 @@
for (size_t i = 0; i < size; ++i) {
if (command_line_->HasSwitch(boolean_switch_map[i].switch_name)) {
SetValue(boolean_switch_map[i].preference_path,
- std::make_unique<base::Value>(boolean_switch_map[i].set_value),
+ base::Value(boolean_switch_map[i].set_value),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
}
diff --git a/components/prefs/default_pref_store.cc b/components/prefs/default_pref_store.cc
index d8d13ec..92cfc3a 100644
--- a/components/prefs/default_pref_store.cc
+++ b/components/prefs/default_pref_store.cc
@@ -17,8 +17,8 @@
return prefs_.GetValue(key, result);
}
-std::unique_ptr<base::DictionaryValue> DefaultPrefStore::GetValues() const {
- return prefs_.AsDictionaryValue();
+base::Value::Dict DefaultPrefStore::GetValues() const {
+ return prefs_.AsDict();
}
void DefaultPrefStore::AddObserver(PrefStore::Observer* observer) {
@@ -30,7 +30,7 @@
}
bool DefaultPrefStore::HasObservers() const {
- return observers_.might_have_observers();
+ return !observers_.empty();
}
void DefaultPrefStore::SetDefaultValue(const std::string& key, Value value) {
diff --git a/components/prefs/default_pref_store.h b/components/prefs/default_pref_store.h
index 17ba3ec..37db218 100644
--- a/components/prefs/default_pref_store.h
+++ b/components/prefs/default_pref_store.h
@@ -25,7 +25,7 @@
// PrefStore implementation:
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
diff --git a/components/prefs/in_memory_pref_store.cc b/components/prefs/in_memory_pref_store.cc
index 20d1eea..1aebddf 100644
--- a/components/prefs/in_memory_pref_store.cc
+++ b/components/prefs/in_memory_pref_store.cc
@@ -18,8 +18,8 @@
return prefs_.GetValue(key, value);
}
-std::unique_ptr<base::DictionaryValue> InMemoryPrefStore::GetValues() const {
- return prefs_.AsDictionaryValue();
+base::Value::Dict InMemoryPrefStore::GetValues() const {
+ return prefs_.AsDict();
}
bool InMemoryPrefStore::GetMutableValue(const std::string& key,
@@ -36,7 +36,7 @@
}
bool InMemoryPrefStore::HasObservers() const {
- return observers_.might_have_observers();
+ return !observers_.empty();
}
bool InMemoryPrefStore::IsInitializationComplete() const {
@@ -44,18 +44,18 @@
}
void InMemoryPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
- DCHECK(value);
- if (prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value))))
+ DCHECK(!value.is_none());
+ if (prefs_.SetValue(key, std::move(value)))
ReportValueChanged(key, flags);
}
void InMemoryPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
- uint32_t flags) {
- DCHECK(value);
- prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value)));
+ base::Value value,
+ uint32_t flags) {
+ DCHECK(!value.is_none());
+ prefs_.SetValue(key, std::move(value));
}
void InMemoryPrefStore::RemoveValue(const std::string& key, uint32_t flags) {
diff --git a/components/prefs/in_memory_pref_store.h b/components/prefs/in_memory_pref_store.h
index c623adb..7e20c01 100644
--- a/components/prefs/in_memory_pref_store.h
+++ b/components/prefs/in_memory_pref_store.h
@@ -26,7 +26,7 @@
// PrefStore implementation.
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
@@ -36,10 +36,10 @@
bool GetMutableValue(const std::string& key, base::Value** result) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override;
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool ReadOnly() const override;
diff --git a/components/prefs/json_pref_store.cc b/components/prefs/json_pref_store.cc
index 9fb45fa..ce678ba 100644
--- a/components/prefs/json_pref_store.cc
+++ b/components/prefs/json_pref_store.cc
@@ -9,6 +9,7 @@
#include <algorithm>
#include <utility>
+#include "base/logging.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
@@ -19,11 +20,9 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram.h"
-#include "base/sequenced_task_runner.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
-#include "base/task_runner_util.h"
-#include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/default_clock.h"
#include "base/values.h"
#include "components/prefs/pref_filter.h"
@@ -84,8 +83,7 @@
// TODO(erikkay) if we keep this error checking for very long, we may
// want to differentiate between recent and long ago errors.
bool bad_existed = base::PathExists(bad);
- base::CopyFile(path, bad);
- base::DeleteFile(path, false);
+ base::Move(path, bad);
return bad_existed ? PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT
: PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE;
}
@@ -139,7 +137,6 @@
scoped_refptr<base::SequencedTaskRunner> file_task_runner)
: path_(pref_filename),
file_task_runner_(std::move(file_task_runner)),
- prefs_(new base::DictionaryValue()),
read_only_(false),
writer_(pref_filename, file_task_runner_),
pref_filter_(std::move(pref_filter)),
@@ -155,8 +152,12 @@
const base::Value** result) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- base::Value* tmp = nullptr;
- if (!prefs_->Get(key, &tmp))
+#if defined(STARBOARD)
+ const base::Value* tmp = prefs_.Find(key);
+#else
+ const base::Value* tmp = prefs_.FindByDottedPath(key);
+#endif
+ if (!tmp)
return false;
if (result)
@@ -164,8 +165,8 @@
return true;
}
-std::unique_ptr<base::DictionaryValue> JsonPrefStore::GetValues() const {
- return prefs_->CreateDeepCopy();
+base::Value::Dict JsonPrefStore::GetValues() const {
+ return prefs_.Clone();
}
void JsonPrefStore::AddObserver(PrefStore::Observer* observer) {
@@ -183,7 +184,7 @@
bool JsonPrefStore::HasObservers() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- return observers_.might_have_observers();
+ return !observers_.empty();
}
bool JsonPrefStore::IsInitializationComplete() const {
@@ -196,42 +197,54 @@
base::Value** result) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- return prefs_->Get(key, result);
+#if defined(STARBOARD)
+ base::Value* tmp = prefs_.Find(key);
+#else
+ base::Value* tmp = prefs_.FindByDottedPath(key);
+#endif
+ if (!tmp)
+ return false;
+
+ if (result)
+ *result = tmp;
+ return true;
}
void JsonPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- DCHECK(value);
- base::Value* old_value = nullptr;
- prefs_->Get(key, &old_value);
- if (!old_value || !value->Equals(old_value)) {
#if defined(STARBOARD)
- // Value::DictionaryValue::Set creates a nested dictionary treating a URL
- // key as a path, SetKey avoids this.
- prefs_->SetKey(key, base::Value::FromUniquePtrValue(std::move(value)));
+ base::Value* old_value = prefs_.Find(key);
#else
- prefs_->Set(key, std::move(value));
+ base::Value* old_value = prefs_.FindByDottedPath(key);
+#endif
+ if (!old_value || value != *old_value) {
+#if defined(STARBOARD)
+ prefs_.Set(key, std::move(value));
+#else
+ prefs_.SetByDottedPath(key, std::move(value));
#endif
ReportValueChanged(key, flags);
}
}
void JsonPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- DCHECK(value);
- base::Value* old_value = nullptr;
- prefs_->Get(key, &old_value);
- if (!old_value || !value->Equals(old_value)) {
#if defined(STARBOARD)
- prefs_->SetKey(key, base::Value::FromUniquePtrValue(std::move(value)));
+ base::Value* old_value = prefs_.Find(key);
#else
- prefs_->Set(key, std::move(value));
+ base::Value* old_value = prefs_.FindByDottedPath(key);
+#endif
+ if (!old_value || value != *old_value) {
+#if defined(STARBOARD)
+ prefs_.Set(key, std::move(value));
+#else
+ prefs_.SetByDottedPath(key, std::move(value));
#endif
ScheduleWrite(flags);
}
@@ -240,7 +253,11 @@
void JsonPrefStore::RemoveValue(const std::string& key, uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- if (prefs_->RemovePath({key})) {
+#if defined(STARBOARD)
+ if (prefs_.Remove(key)) {
+#else
+ if (prefs_.RemoveByDottedPath(key)) {
+#endif
ReportValueChanged(key, flags);
}
}
@@ -249,7 +266,11 @@
uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- prefs_->RemovePath({key});
+#if defined(STARBOARD)
+ prefs_.Remove(key);
+#else
+ prefs_.RemoveByDottedPath(key);
+#endif
ScheduleWrite(flags);
}
@@ -280,9 +301,9 @@
error_delegate_.reset(error_delegate);
// Weakly binds the read task so that it doesn't kick in during shutdown.
- base::PostTaskAndReplyWithResult(
- file_task_runner_.get(), FROM_HERE, base::Bind(&ReadPrefsFromDisk, path_),
- base::Bind(&JsonPrefStore::OnFileRead, AsWeakPtr()));
+ file_task_runner_->PostTaskAndReplyWithResult(
+ FROM_HERE, base::BindOnce(&ReadPrefsFromDisk, path_),
+ base::BindOnce(&JsonPrefStore::OnFileRead, AsWeakPtr()));
}
void JsonPrefStore::CommitPendingWrite(
@@ -330,6 +351,16 @@
ScheduleWrite(flags);
}
+void JsonPrefStore::PerformPreserializationTasks() {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ pending_lossy_write_ = false;
+ if (pref_filter_) {
+ OnWriteCallbackPair callbacks = pref_filter_->FilterSerializeData(prefs_);
+ if (!callbacks.first.is_null() || !callbacks.second.is_null())
+ RegisterOnNextWriteSynchronousCallbacks(std::move(callbacks));
+ }
+}
+
void JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback(
bool write_success) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -366,7 +397,7 @@
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(on_next_successful_write_reply_.is_null());
- on_next_successful_write_reply_ = on_next_successful_write_reply;
+ on_next_successful_write_reply_ = std::move(on_next_successful_write_reply);
// If there are pending callbacks, avoid erasing them; the reply will be used
// as we set |on_next_successful_write_reply_|. Otherwise, setup a reply with
@@ -374,12 +405,13 @@
if (!has_pending_write_reply_) {
has_pending_write_reply_ = true;
writer_.RegisterOnNextWriteCallbacks(
- base::Closure(),
+ base::OnceClosure(),
base::Bind(
&PostWriteCallback, base::Callback<void(bool success)>(),
- base::Bind(&JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
- AsWeakPtr()),
- base::SequencedTaskRunnerHandle::Get()));
+ base::Bind(
+ &JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
+ AsWeakPtr()),
+ base::SequencedTaskRunner::GetCurrentDefault()));
}
}
@@ -390,12 +422,13 @@
has_pending_write_reply_ = true;
writer_.RegisterOnNextWriteCallbacks(
- callbacks.first,
+ std::move(callbacks.first),
base::Bind(
- &PostWriteCallback, callbacks.second,
- base::Bind(&JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
- AsWeakPtr()),
- base::SequencedTaskRunnerHandle::Get()));
+ &PostWriteCallback, std::move(callbacks.second),
+ base::Bind(
+ &JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
+ AsWeakPtr()),
+ base::SequencedTaskRunner::GetCurrentDefault()));
}
void JsonPrefStore::ClearMutableValues() {
@@ -412,8 +445,7 @@
DCHECK(read_result);
- std::unique_ptr<base::DictionaryValue> unfiltered_prefs(
- new base::DictionaryValue);
+ base::Value::Dict unfiltered_prefs;
read_error_ = read_result->error;
@@ -430,8 +462,8 @@
break;
case PREF_READ_ERROR_NONE:
DCHECK(read_result->value);
- unfiltered_prefs.reset(
- static_cast<base::DictionaryValue*>(read_result->value.release()));
+ DCHECK(read_result->value->is_dict());
+ unfiltered_prefs = std::move(*read_result->value).TakeDict();
break;
case PREF_READ_ERROR_NO_FILE:
// If the file just doesn't exist, maybe this is first run. In any case
@@ -468,31 +500,32 @@
CommitPendingWrite();
}
-bool JsonPrefStore::SerializeData(std::string* output) {
+absl::optional<std::string> JsonPrefStore::SerializeData() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
pending_lossy_write_ = false;
if (pref_filter_) {
OnWriteCallbackPair callbacks =
- pref_filter_->FilterSerializeData(prefs_.get());
+ pref_filter_->FilterSerializeData(prefs_);
if (!callbacks.first.is_null() || !callbacks.second.is_null())
RegisterOnNextWriteSynchronousCallbacks(callbacks);
}
- JSONStringValueSerializer serializer(output);
+ std::string output;
+ JSONStringValueSerializer serializer(&output);
// Not pretty-printing prefs shrinks pref file size by ~30%. To obtain
// readable prefs for debugging purposes, you can dump your prefs into any
// command-line or online JSON pretty printing tool.
serializer.set_pretty_print(false);
- bool success = serializer.Serialize(*prefs_);
+ bool success = serializer.Serialize(prefs_);
DCHECK(success);
- return success;
+ return output;
}
void JsonPrefStore::FinalizeFileRead(
bool initialization_successful,
- std::unique_ptr<base::DictionaryValue> prefs,
+ base::Value::Dict prefs,
bool schedule_write) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
diff --git a/components/prefs/json_pref_store.h b/components/prefs/json_pref_store.h
index e29e3b5..566eefd 100644
--- a/components/prefs/json_pref_store.h
+++ b/components/prefs/json_pref_store.h
@@ -11,7 +11,7 @@
#include <set>
#include <string>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/files/important_file_writer.h"
@@ -20,7 +20,8 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/sequence_checker.h"
-#include "base/task/post_task.h"
+#include "base/task/thread_pool.h"
+#include "base/values.h"
#include "components/prefs/persistent_pref_store.h"
#include "components/prefs/pref_filter.h"
#include "components/prefs/prefs_export.h"
@@ -67,14 +68,14 @@
JsonPrefStore(const base::FilePath& pref_filename,
std::unique_ptr<PrefFilter> pref_filter = nullptr,
scoped_refptr<base::SequencedTaskRunner> file_task_runner =
- base::CreateSequencedTaskRunnerWithTraits(
+ base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN}));
// PrefStore overrides:
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
@@ -83,10 +84,10 @@
// PersistentPrefStore overrides:
bool GetMutableValue(const std::string& key, base::Value** result) override;
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool ReadOnly() const override;
@@ -125,6 +126,10 @@
~JsonPrefStore() override;
+ // Perform pre-serialization bookkeeping common to either serialization flow
+ // (main thread or background thread).
+ void PerformPreserializationTasks();
+
// If |write_success| is true, runs |on_next_successful_write_|.
// Otherwise, re-registers |on_next_successful_write_|.
void RunOrScheduleNextSuccessfulWriteCallback(bool write_success);
@@ -152,7 +157,7 @@
void OnFileRead(std::unique_ptr<ReadResult> read_result);
// ImportantFileWriter::DataSerializer overrides:
- bool SerializeData(std::string* output) override;
+ absl::optional<std::string> SerializeData() override;
// This method is called after the JSON file has been read and the result has
// potentially been intercepted and modified by |pref_filter_|.
@@ -162,7 +167,7 @@
// (typically because the |pref_filter_| has already altered the |prefs|) --
// this will be ignored if this store is read-only.
void FinalizeFileRead(bool initialization_successful,
- std::unique_ptr<base::DictionaryValue> prefs,
+ base::Value::Dict prefs,
bool schedule_write);
// Schedule a write with the file writer as long as |flags| doesn't contain
@@ -172,7 +177,7 @@
const base::FilePath path_;
const scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
- std::unique_ptr<base::DictionaryValue> prefs_;
+ base::Value::Dict prefs_;
bool read_only_;
diff --git a/components/prefs/json_pref_store_unittest.cc b/components/prefs/json_pref_store_unittest.cc
index de878aa..f2da53b 100644
--- a/components/prefs/json_pref_store_unittest.cc
+++ b/components/prefs/json_pref_store_unittest.cc
@@ -72,7 +72,7 @@
std::unique_ptr<base::DictionaryValue> pref_store_contents) override;
void FilterUpdate(const std::string& path) override {}
OnWriteCallbackPair FilterSerializeData(
- base::DictionaryValue* pref_store_contents) override {
+ base::Value::Dict& pref_store_contents) override {
return on_write_callback_pair_;
}
void OnStoreDeletionFromDisk() override {}
diff --git a/components/prefs/json_read_only_pref_store.cc b/components/prefs/json_read_only_pref_store.cc
index 9c50844..5a960ba 100644
--- a/components/prefs/json_read_only_pref_store.cc
+++ b/components/prefs/json_read_only_pref_store.cc
@@ -11,16 +11,15 @@
#include "base/bind.h"
#include "base/callback.h"
+#include "base/logging.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram.h"
-#include "base/sequenced_task_runner.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
-#include "base/task_runner_util.h"
-#include "base/threading/sequenced_task_runner_handle.h"
#include "base/values.h"
#include "components/prefs/pref_filter.h"
@@ -78,8 +77,7 @@
// TODO(erikkay) if we keep this error checking for very long, we may
// want to differentiate between recent and long ago errors.
bool bad_existed = base::PathExists(bad);
- base::CopyFile(path, bad);
- base::DeleteFile(path, false);
+ base::Move(path, bad);
return bad_existed ? PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT
: PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE;
}
@@ -133,7 +131,6 @@
scoped_refptr<base::SequencedTaskRunner> file_task_runner)
: path_(pref_filename),
file_task_runner_(std::move(file_task_runner)),
- prefs_(new base::DictionaryValue()),
pref_filter_(std::move(pref_filter)),
initialized_(false),
filtering_in_progress_(false),
@@ -145,8 +142,8 @@
const base::Value** result) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- base::Value* tmp = nullptr;
- if (!prefs_->Get(key, &tmp))
+ const base::Value* tmp = prefs_.FindByDottedPath(key);
+ if (!tmp)
return false;
if (result)
@@ -154,9 +151,9 @@
return true;
}
-std::unique_ptr<base::DictionaryValue> JsonReadOnlyPrefStore::GetValues()
+base::Value::Dict JsonReadOnlyPrefStore::GetValues()
const {
- return prefs_->CreateDeepCopy();
+ return prefs_.Clone();
}
void JsonReadOnlyPrefStore::AddObserver(PrefStore::Observer* observer) {
@@ -173,8 +170,7 @@
bool JsonReadOnlyPrefStore::HasObservers() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
-
- return observers_.might_have_observers();
+ return !observers_.empty();
}
bool JsonReadOnlyPrefStore::IsInitializationComplete() const {
@@ -187,17 +183,23 @@
base::Value** result) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- return prefs_->Get(key, result);
+ base::Value* tmp = prefs_.FindByDottedPath(key);
+ if (!tmp)
+ return false;
+
+ if (result)
+ *result = tmp;
+ return true;
}
void JsonReadOnlyPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
NOTIMPLEMENTED();
}
void JsonReadOnlyPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
NOTIMPLEMENTED();
}
@@ -232,9 +234,9 @@
error_delegate_.reset(error_delegate);
// Weakly binds the read task so that it doesn't kick in during shutdown.
- base::PostTaskAndReplyWithResult(
- file_task_runner_.get(), FROM_HERE, base::Bind(&ReadPrefsFromDisk, path_),
- base::Bind(&JsonReadOnlyPrefStore::OnFileRead, AsWeakPtr()));
+ file_task_runner_->PostTaskAndReplyWithResult(
+ FROM_HERE, base::BindOnce(&ReadPrefsFromDisk, path_),
+ base::BindOnce(&JsonReadOnlyPrefStore::OnFileRead, AsWeakPtr()));
}
void JsonReadOnlyPrefStore::CommitPendingWrite(
@@ -267,8 +269,7 @@
DCHECK(read_result);
- std::unique_ptr<base::DictionaryValue> unfiltered_prefs(
- new base::DictionaryValue);
+ base::Value::Dict unfiltered_prefs;
read_error_ = read_result->error;
@@ -284,8 +285,8 @@
break;
case PREF_READ_ERROR_NONE:
DCHECK(read_result->value);
- unfiltered_prefs.reset(
- static_cast<base::DictionaryValue*>(read_result->value.release()));
+ DCHECK(read_result->value->is_dict());
+ unfiltered_prefs = std::move(*read_result->value).TakeDict();
break;
case PREF_READ_ERROR_NO_FILE:
@@ -306,10 +307,10 @@
if (pref_filter_) {
filtering_in_progress_ = true;
- const PrefFilter::PostFilterOnLoadCallback post_filter_on_load_callback(
- base::Bind(&JsonReadOnlyPrefStore::FinalizeFileRead, AsWeakPtr(),
- initialization_successful));
- pref_filter_->FilterOnLoad(post_filter_on_load_callback,
+ PrefFilter::PostFilterOnLoadCallback post_filter_on_load_callback(
+ base::BindOnce(&JsonReadOnlyPrefStore::FinalizeFileRead, AsWeakPtr(),
+ initialization_successful));
+ pref_filter_->FilterOnLoad(std::move(post_filter_on_load_callback),
std::move(unfiltered_prefs));
} else {
FinalizeFileRead(initialization_successful, std::move(unfiltered_prefs),
@@ -319,7 +320,7 @@
void JsonReadOnlyPrefStore::FinalizeFileRead(
bool initialization_successful,
- std::unique_ptr<base::DictionaryValue> prefs,
+ base::Value::Dict prefs,
bool schedule_write) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
diff --git a/components/prefs/json_read_only_pref_store.h b/components/prefs/json_read_only_pref_store.h
index 4577c01..a2c2190 100644
--- a/components/prefs/json_read_only_pref_store.h
+++ b/components/prefs/json_read_only_pref_store.h
@@ -11,14 +11,15 @@
#include <set>
#include <string>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/sequence_checker.h"
-#include "base/task/post_task.h"
+#include "base/task/thread_pool.h"
+#include "base/values.h"
#include "components/prefs/persistent_pref_store.h"
#include "components/prefs/pref_filter.h"
#include "components/prefs/prefs_export.h"
@@ -45,14 +46,14 @@
const base::FilePath& pref_filename,
std::unique_ptr<PrefFilter> pref_filter = nullptr,
scoped_refptr<base::SequencedTaskRunner> file_task_runner =
- base::CreateSequencedTaskRunnerWithTraits(
- {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
- base::TaskShutdownBehavior::BLOCK_SHUTDOWN}));
+ base::ThreadPool::CreateSequencedTaskRunner(
+ {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
+ base::TaskShutdownBehavior::BLOCK_SHUTDOWN}));
// PrefStore overrides:
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
@@ -61,10 +62,10 @@
// PersistentPrefStore overrides:
bool GetMutableValue(const std::string& key, base::Value** result) override;
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool ReadOnly() const override;
@@ -104,13 +105,13 @@
// (typically because the |pref_filter_| has already altered the |prefs|) --
// this will be ignored if this store is read-only.
void FinalizeFileRead(bool initialization_successful,
- std::unique_ptr<base::DictionaryValue> prefs,
+ base::Value::Dict prefs,
bool schedule_write);
const base::FilePath path_;
const scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
- std::unique_ptr<base::DictionaryValue> prefs_;
+ base::Value::Dict prefs_;
std::unique_ptr<PrefFilter> pref_filter_;
base::ObserverList<PrefStore::Observer, true>::Unchecked observers_;
diff --git a/components/prefs/mock_pref_change_callback.h b/components/prefs/mock_pref_change_callback.h
index 9c0aeec..1581237 100644
--- a/components/prefs/mock_pref_change_callback.h
+++ b/components/prefs/mock_pref_change_callback.h
@@ -28,7 +28,7 @@
return value == NULL;
if (!value)
return actual_value == NULL;
- return value->Equals(actual_value);
+ return value == actual_value;
}
// A mock for testing preference notifications and easy setup of expectations.
diff --git a/components/prefs/overlay_user_pref_store.cc b/components/prefs/overlay_user_pref_store.cc
index 0baa6c4..ec6c048 100644
--- a/components/prefs/overlay_user_pref_store.cc
+++ b/components/prefs/overlay_user_pref_store.cc
@@ -63,7 +63,7 @@
}
bool OverlayUserPrefStore::HasObservers() const {
- return observers_.might_have_observers();
+ return !observers_.empty();
}
bool OverlayUserPrefStore::IsInitializationComplete() const {
@@ -83,7 +83,7 @@
return persistent_user_pref_store_->GetValue(key, result);
}
-std::unique_ptr<base::DictionaryValue> OverlayUserPrefStore::GetValues() const {
+base::Value::Dict OverlayUserPrefStore::GetValues() const {
auto values = ephemeral_user_pref_store_->GetValues();
auto persistent_values = persistent_user_pref_store_->GetValues();
@@ -92,10 +92,9 @@
// overwritten by the content of |persistent_user_pref_store_| (the persistent
// store).
for (const auto& key : persistent_names_set_) {
- std::unique_ptr<base::Value> out_value;
- persistent_values->Remove(key, &out_value);
+ absl::optional<base::Value> out_value = persistent_values.Extract(key);
if (out_value) {
- values->Set(key, std::move(out_value));
+ values.Set(key, std::move(*out_value));
}
}
return values;
@@ -116,14 +115,14 @@
return false;
ephemeral_user_pref_store_->SetValue(
- key, persistent_value->CreateDeepCopy(),
+ key, persistent_value->Clone(),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
ephemeral_user_pref_store_->GetMutableValue(key, result);
return true;
}
void OverlayUserPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
if (ShallBeStoredInPersistent(key)) {
persistent_user_pref_store_->SetValue(key, std::move(value), flags);
@@ -138,7 +137,7 @@
}
void OverlayUserPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
if (ShallBeStoredInPersistent(key)) {
persistent_user_pref_store_->SetValueSilently(key, std::move(value), flags);
diff --git a/components/prefs/overlay_user_pref_store.h b/components/prefs/overlay_user_pref_store.h
index 9b7c95a..35eb9c5 100644
--- a/components/prefs/overlay_user_pref_store.h
+++ b/components/prefs/overlay_user_pref_store.h
@@ -42,15 +42,15 @@
bool IsInitializationComplete() const override;
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
// Methods of PersistentPrefStore.
bool GetMutableValue(const std::string& key, base::Value** result) override;
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool ReadOnly() const override;
diff --git a/components/prefs/persistent_pref_store.cc b/components/prefs/persistent_pref_store.cc
index 9086c1e..656f9ef 100644
--- a/components/prefs/persistent_pref_store.cc
+++ b/components/prefs/persistent_pref_store.cc
@@ -6,7 +6,7 @@
#include <utility>
-#include "base/threading/sequenced_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
void PersistentPrefStore::CommitPendingWrite(
base::OnceClosure reply_callback,
@@ -21,7 +21,7 @@
std::move(synchronous_done_callback).Run();
if (reply_callback) {
- base::SequencedTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(FROM_HERE,
std::move(reply_callback));
}
}
diff --git a/components/prefs/pref_filter.h b/components/prefs/pref_filter.h
index 3d52136..8e7384b 100644
--- a/components/prefs/pref_filter.h
+++ b/components/prefs/pref_filter.h
@@ -9,13 +9,10 @@
#include <string>
#include <utility>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
+#include "base/values.h"
#include "components/prefs/prefs_export.h"
-namespace base {
-class DictionaryValue;
-} // namespace base
-
// Filters preferences as they are loaded from disk or updated at runtime.
// Currently supported only by JsonPrefStore.
class COMPONENTS_PREFS_EXPORT PrefFilter {
@@ -29,8 +26,7 @@
// builder. |schedule_write| indicates whether a write should be immediately
// scheduled (typically because the |prefs| were pre-modified).
using PostFilterOnLoadCallback =
- base::Callback<void(std::unique_ptr<base::DictionaryValue> prefs,
- bool schedule_write)>;
+ base::OnceCallback<void(base::Value::Dict prefs, bool schedule_write)>;
virtual ~PrefFilter() {}
@@ -43,7 +39,7 @@
// to external users (see SegregatedPrefStore::ReadPrefs() for an example).
virtual void FilterOnLoad(
const PostFilterOnLoadCallback& post_filter_on_load_callback,
- std::unique_ptr<base::DictionaryValue> pref_store_contents) = 0;
+ base::Value::Dict pref_store_contents) = 0;
// Receives notification when a pref store value is changed, before Observers
// are notified.
@@ -57,7 +53,7 @@
// invoked synchronously after the next write (from the I/O TaskRunner so they
// must not be bound to thread-unsafe member state).
virtual OnWriteCallbackPair FilterSerializeData(
- base::DictionaryValue* pref_store_contents) = 0;
+ base::Value::Dict& pref_store_contents) = 0;
// Cleans preference data that may have been saved outside of the store.
virtual void OnStoreDeletionFromDisk() = 0;
diff --git a/components/prefs/pref_member.cc b/components/prefs/pref_member.cc
index a8fa12c..08bb7bf 100644
--- a/components/prefs/pref_member.cc
+++ b/components/prefs/pref_member.cc
@@ -6,11 +6,10 @@
#include <utility>
+#include "base/json/values_util.h"
#include "base/callback.h"
-#include "base/callback_helpers.h"
+#include "base/functional/callback_helpers.h"
#include "base/location.h"
-#include "base/threading/sequenced_task_runner_handle.h"
-#include "base/value_conversions.h"
#include "components/prefs/pref_service.h"
using base::SequencedTaskRunner;
@@ -71,10 +70,9 @@
DCHECK(pref);
if (!internal())
CreateInternal();
- internal()->UpdateValue(pref->GetValue()->DeepCopy(),
- pref->IsManaged(),
- pref->IsUserModifiable(),
- callback);
+ internal()->UpdateValue(
+ base::Value::ToUniquePtrValue(pref->GetValue()->Clone()).release(),
+ pref->IsManaged(), pref->IsUserModifiable(), callback);
}
void PrefMemberBase::VerifyPref() const {
@@ -89,7 +87,7 @@
}
PrefMemberBase::Internal::Internal()
- : owning_task_runner_(base::SequencedTaskRunnerHandle::Get()),
+ : owning_task_runner_(base::SequencedTaskRunner::GetCurrentDefault()),
is_managed_(false),
is_user_modifiable_(false) {}
PrefMemberBase::Internal::~Internal() { }
@@ -129,15 +127,15 @@
std::vector<std::string>* string_vector) {
if (!value.is_list())
return false;
- const base::ListValue* list = static_cast<const base::ListValue*>(&value);
+ const base::Value::List* list = value.GetIfList();
std::vector<std::string> local_vector;
for (auto it = list->begin(); it != list->end(); ++it) {
- std::string string_value;
- if (!it->GetAsString(&string_value))
+ const std::string* string_value = it->GetIfString();
+ if (string_value == nullptr) {
return false;
-
- local_vector.push_back(string_value);
+ }
+ local_vector.push_back(*string_value);
}
string_vector->swap(local_vector);
@@ -154,7 +152,10 @@
template <>
bool PrefMember<bool>::Internal::UpdateValueInternal(
const base::Value& value) const {
- return value.GetAsBoolean(&value_);
+ absl::optional<bool> temp = value.GetIfBool();
+ if (value.is_bool())
+ value_ = value.GetBool();
+ return value.is_bool();;
}
template <>
@@ -165,7 +166,10 @@
template <>
bool PrefMember<int>::Internal::UpdateValueInternal(
const base::Value& value) const {
- return value.GetAsInteger(&value_);
+ absl::optional<int> temp = value.GetIfInt();
+ if (value.is_int())
+ value_ = value.GetInt();
+ return value.is_int();
}
template <>
@@ -174,9 +178,11 @@
}
template <>
-bool PrefMember<double>::Internal::UpdateValueInternal(const base::Value& value)
- const {
- return value.GetAsDouble(&value_);
+bool PrefMember<double>::Internal::UpdateValueInternal(
+ const base::Value& value) const {
+ if (value.is_double() || value.is_int())
+ value_ = value.GetDouble();
+ return value.is_double() || value.is_int();
}
template <>
@@ -186,9 +192,10 @@
template <>
bool PrefMember<std::string>::Internal::UpdateValueInternal(
- const base::Value& value)
- const {
- return value.GetAsString(&value_);
+ const base::Value& value) const {
+ if (value.is_string())
+ value_ = value.GetString();
+ return value.is_string();
}
template <>
@@ -198,17 +205,22 @@
template <>
bool PrefMember<base::FilePath>::Internal::UpdateValueInternal(
- const base::Value& value)
- const {
- return base::GetValueAsFilePath(value, &value_);
+ const base::Value& value) const {
+ absl::optional<base::FilePath> path = base::ValueToFilePath(value);
+ if (!path)
+ return false;
+ value_ = *path;
+ return true;
}
template <>
void PrefMember<std::vector<std::string> >::UpdatePref(
const std::vector<std::string>& value) {
- base::ListValue list_value;
- list_value.AppendStrings(value);
- prefs()->Set(pref_name(), list_value);
+ base::Value::List list_value;
+ for (const std::string& val : value)
+ list_value.Append(val);
+
+ prefs()->SetList(pref_name(), std::move(list_value));
}
template <>
diff --git a/components/prefs/pref_member.h b/components/prefs/pref_member.h
index f2166e6..4d9dc97 100644
--- a/components/prefs/pref_member.h
+++ b/components/prefs/pref_member.h
@@ -28,12 +28,13 @@
#include <vector>
#include "base/bind.h"
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/files/file_path.h"
+#include "base/callback.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/sequenced_task_runner.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/values.h"
#include "components/prefs/pref_observer.h"
#include "components/prefs/prefs_export.h"
diff --git a/components/prefs/pref_registry_simple.cc b/components/prefs/pref_registry_simple.cc
index bab05dd..f4bbc47 100644
--- a/components/prefs/pref_registry_simple.cc
+++ b/components/prefs/pref_registry_simple.cc
@@ -57,7 +57,7 @@
void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path,
uint32_t flags) {
- RegisterPreference(path, base::Value(base::Value::Type::DICTIONARY), flags);
+ RegisterPreference(path, base::Value(base::Value::Type::DICT), flags);
}
void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path,
diff --git a/components/prefs/pref_service.cc b/components/prefs/pref_service.cc
index f9a5088..9f0da31 100644
--- a/components/prefs/pref_service.cc
+++ b/components/prefs/pref_service.cc
@@ -8,6 +8,7 @@
#include <map>
#include <utility>
+#include "base/optional.h"
#include "base/bind.h"
#include "base/debug/alias.h"
#include "base/debug/dump_without_crashing.h"
@@ -16,13 +17,12 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram.h"
-#include "base/single_thread_task_runner.h"
+#include "base/task/single_thread_task_runner.h"
#include "base/stl_util.h"
+#include "base/json/values_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h"
-#include "base/util/values/values_util.h"
-#include "base/value_conversions.h"
#include "build/build_config.h"
#include "components/prefs/default_pref_store.h"
#include "components/prefs/pref_notifier_impl.h"
@@ -69,16 +69,17 @@
if (!pref_store)
return;
auto values = pref_store->GetValues();
- for (const auto& item : values->DictItems()) {
+ for (base::Value::Dict::iterator it = values.begin(); it != values.end();
+ ++it) {
// If the key already presents, skip it as a store with higher precedence
// already sets the entry.
- if (pref_changed_map->find(item.first) != pref_changed_map->end())
+ if (pref_changed_map->find(it->first) != pref_changed_map->end())
continue;
const PrefService::Preference* pref =
- pref_service->FindPreference(item.first);
+ pref_service->FindPreference(it->first);
if (!pref)
continue;
- pref_changed_map->emplace(item.first, *(pref->GetValue()) != item.second);
+ pref_changed_map->emplace(it->first, *(pref->GetValue()) != it->second);
}
}
@@ -164,9 +165,7 @@
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return result;
- bool rv = value->GetAsBoolean(&result);
- DCHECK(rv);
- return result;
+ return (*value).GetBool();
}
int PrefService::GetInteger(const std::string& path) const {
@@ -177,9 +176,7 @@
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return result;
- bool rv = value->GetAsInteger(&result);
- DCHECK(rv);
- return result;
+ return (*value).GetInt();
}
double PrefService::GetDouble(const std::string& path) const {
@@ -190,9 +187,7 @@
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return result;
- bool rv = value->GetAsDouble(&result);
- DCHECK(rv);
- return result;
+ return (*value).GetDouble();
}
std::string PrefService::GetString(const std::string& path) const {
@@ -203,9 +198,7 @@
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return result;
- bool rv = value->GetAsString(&result);
- DCHECK(rv);
- return result;
+ return (*value).GetString();
}
base::FilePath PrefService::GetFilePath(const std::string& path) const {
@@ -216,9 +209,9 @@
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return base::FilePath(result);
- bool rv = base::GetValueAsFilePath(*value, &result);
+ absl::optional<base::FilePath> rv = base::ValueToFilePath(value);
DCHECK(rv);
- return result;
+ return *rv;
}
bool PrefService::HasPrefPath(const std::string& path) const {
@@ -234,18 +227,18 @@
callback.Run(it.first, *GetPreferenceValue(it.first));
}
-std::unique_ptr<base::DictionaryValue> PrefService::GetPreferenceValues(
+base::Value::Dict PrefService::GetPreferenceValues(
IncludeDefaults include_defaults) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- std::unique_ptr<base::DictionaryValue> out(new base::DictionaryValue);
+ base::Value::Dict out;
for (const auto& it : *pref_registry_) {
if (include_defaults == INCLUDE_DEFAULTS) {
- out->Set(it.first, GetPreferenceValue(it.first)->CreateDeepCopy());
+ out.Set(it.first, GetPreferenceValue(it.first)->Clone());
} else {
const Preference* pref = FindPreference(it.first);
if (pref->IsDefaultValue())
continue;
- out->Set(it.first, pref->GetValue()->CreateDeepCopy());
+ out.Set(it.first, pref->GetValue()->Clone());
}
}
return out;
@@ -320,18 +313,18 @@
return value;
}
-const base::DictionaryValue* PrefService::GetDictionary(
+const base::Value::Dict* PrefService::GetDictionary(
const std::string& path) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return nullptr;
- if (value->type() != base::Value::Type::DICTIONARY) {
+ if (value->type() != base::Value::Type::DICT) {
NOTREACHED();
return nullptr;
}
- return static_cast<const base::DictionaryValue*>(value);
+ return value->GetIfDict();
}
const base::Value* PrefService::GetUserPrefValue(
@@ -374,7 +367,7 @@
return value;
}
-const base::ListValue* PrefService::GetList(const std::string& path) const {
+const base::Value::List* PrefService::GetList(const std::string& path) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const base::Value* value = GetPreferenceValueChecked(path);
@@ -384,7 +377,7 @@
NOTREACHED();
return nullptr;
}
- return static_cast<const base::ListValue*>(value);
+ return value->GetIfList();
}
void PrefService::AddPrefObserver(const std::string& path, PrefObserver* obs) {
@@ -471,46 +464,52 @@
}
void PrefService::Set(const std::string& path, const base::Value& value) {
- SetUserPrefValue(path, value.CreateDeepCopy());
+ SetUserPrefValue(path, value.Clone());
+}
+
+void PrefService::SetList(const std::string& path, const base::Value::List& value) {
+ SetUserPrefValue(path, base::Value(value.Clone()));
+}
+
+void PrefService::SetDict(const std::string& path, const base::Value::Dict& value) {
+ SetUserPrefValue(path, base::Value(value.Clone()));
}
void PrefService::SetBoolean(const std::string& path, bool value) {
- SetUserPrefValue(path, std::make_unique<base::Value>(value));
+ SetUserPrefValue(path, base::Value(value));
}
void PrefService::SetInteger(const std::string& path, int value) {
- SetUserPrefValue(path, std::make_unique<base::Value>(value));
+ SetUserPrefValue(path, base::Value(value));
}
void PrefService::SetDouble(const std::string& path, double value) {
- SetUserPrefValue(path, std::make_unique<base::Value>(value));
+ SetUserPrefValue(path, base::Value(value));
}
void PrefService::SetString(const std::string& path, const std::string& value) {
- SetUserPrefValue(path, std::make_unique<base::Value>(value));
+ SetUserPrefValue(path, base::Value(value));
}
void PrefService::SetFilePath(const std::string& path,
const base::FilePath& value) {
- SetUserPrefValue(
- path, base::Value::ToUniquePtrValue(base::CreateFilePathValue(value)));
+ SetUserPrefValue(path, base::FilePathToValue(value));
}
void PrefService::SetInt64(const std::string& path, int64_t value) {
- SetUserPrefValue(path,
- base::Value::ToUniquePtrValue(util::Int64ToValue(value)));
+ SetUserPrefValue(path, base::Int64ToValue(value));
}
int64_t PrefService::GetInt64(const std::string& path) const {
const base::Value* value = GetPreferenceValueChecked(path);
- base::Optional<int64_t> integer = util::ValueToInt64(value);
+ absl::optional<int64_t> integer = base::ValueToInt64(value);
DCHECK(integer);
return integer.value_or(0);
}
void PrefService::SetUint64(const std::string& path, uint64_t value) {
SetUserPrefValue(path,
- std::make_unique<base::Value>(base::NumberToString(value)));
+ base::Value(base::NumberToString(value)));
}
uint64_t PrefService::GetUint64(const std::string& path) const {
@@ -520,8 +519,8 @@
if (!value)
return 0;
std::string result("0");
- bool rv = value->GetAsString(&result);
- DCHECK(rv);
+ if (!(*value).is_string())
+ return 0;
uint64_t val;
base::StringToUint64(result, &val);
@@ -530,31 +529,31 @@
void PrefService::SetTime(const std::string& path, base::Time value) {
SetUserPrefValue(path,
- base::Value::ToUniquePtrValue(util::TimeToValue(value)));
+ base::Value(base::TimeToValue(value)));
}
base::Time PrefService::GetTime(const std::string& path) const {
const base::Value* value = GetPreferenceValueChecked(path);
- base::Optional<base::Time> time = util::ValueToTime(value);
+ absl::optional<base::Time> time = base::ValueToTime(value);
DCHECK(time);
return time.value_or(base::Time());
}
void PrefService::SetTimeDelta(const std::string& path, base::TimeDelta value) {
SetUserPrefValue(
- path, base::Value::ToUniquePtrValue(util::TimeDeltaToValue(value)));
+ path, base::Value(base::TimeDeltaToValue(value)));
}
base::TimeDelta PrefService::GetTimeDelta(const std::string& path) const {
const base::Value* value = GetPreferenceValueChecked(path);
- base::Optional<base::TimeDelta> time_delta = util::ValueToTimeDelta(value);
+ absl::optional<base::TimeDelta> time_delta = base::ValueToTimeDelta(value);
DCHECK(time_delta);
return time_delta.value_or(base::TimeDelta());
}
base::Value* PrefService::GetMutableUserPref(const std::string& path,
base::Value::Type type) {
- CHECK(type == base::Value::Type::DICTIONARY ||
+ CHECK(type == base::Value::Type::DICT ||
type == base::Value::Type::LIST);
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -590,7 +589,7 @@
DEBUG_ALIAS_FOR_CSTR(path_copy, path.c_str(), 1024);
base::debug::DumpWithoutCrashing();
}
- user_pref_store_->SetValueSilently(path, default_value->CreateDeepCopy(),
+ user_pref_store_->SetValueSilently(path, default_value->Clone(),
GetWriteFlags(pref));
user_pref_store_->GetMutableValue(path, &value);
return value;
@@ -610,7 +609,7 @@
}
void PrefService::SetUserPrefValue(const std::string& path,
- std::unique_ptr<base::Value> new_value) {
+ base::Value new_value) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const Preference* pref = FindPreference(path);
@@ -618,10 +617,10 @@
NOTREACHED() << "Trying to write an unregistered pref: " << path;
return;
}
- if (pref->GetType() != new_value->type()) {
+ if (pref->GetType() != new_value.type()) {
NOTREACHED() << "Trying to set pref " << path << " of type "
<< pref->GetType() << " to value of type "
- << new_value->type();
+ << new_value.type();
return;
}
diff --git a/components/prefs/pref_service.h b/components/prefs/pref_service.h
index 9580b48..7019c7e 100644
--- a/components/prefs/pref_service.h
+++ b/components/prefs/pref_service.h
@@ -222,8 +222,8 @@
// Note that |path| must point to a registered preference. In that case, these
// functions will never return NULL.
const base::Value* Get(const std::string& path) const;
- const base::DictionaryValue* GetDictionary(const std::string& path) const;
- const base::ListValue* GetList(const std::string& path) const;
+ const base::Value::Dict* GetDictionary(const std::string& path) const;
+ const base::Value::List* GetList(const std::string& path) const;
// Removes a user pref and restores the pref to its default value.
void ClearPref(const std::string& path);
@@ -234,6 +234,8 @@
// Set(), but to modify the value of a dictionary or list use either
// ListPrefUpdate or DictionaryPrefUpdate from scoped_user_pref_update.h.
void Set(const std::string& path, const base::Value& value);
+ void SetList(const std::string& path, const base::Value::List& value);
+ void SetDict(const std::string& path, const base::Value::Dict& value);
void SetBoolean(const std::string& path, bool value);
void SetInteger(const std::string& path, int value);
void SetDouble(const std::string& path, double value);
@@ -295,7 +297,7 @@
// If INCLUDE_DEFAULTS is requested, preferences set to their default values
// will be included. Otherwise, these will be omitted from the returned
// dictionary.
- std::unique_ptr<base::DictionaryValue> GetPreferenceValues(
+ base::Value::Dict GetPreferenceValues(
IncludeDefaults include_defaults) const;
bool ReadOnly() const;
@@ -429,7 +431,7 @@
// Sets the value for this pref path in the user pref store and informs the
// PrefNotifier of the change.
void SetUserPrefValue(const std::string& path,
- std::unique_ptr<base::Value> new_value);
+ base::Value new_value);
// Load preferences from storage, attempting to diagnose and handle errors.
// This should only be called from the constructor.
diff --git a/components/prefs/pref_service_factory.cc b/components/prefs/pref_service_factory.cc
index cc8e52d..f1c5436 100644
--- a/components/prefs/pref_service_factory.cc
+++ b/components/prefs/pref_service_factory.cc
@@ -8,7 +8,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
-#include "base/sequenced_task_runner.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/prefs/default_pref_store.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_filter.h"
diff --git a/components/prefs/pref_store.h b/components/prefs/pref_store.h
index 5f5f092..e7e07fb 100644
--- a/components/prefs/pref_store.h
+++ b/components/prefs/pref_store.h
@@ -10,12 +10,9 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/values.h"
#include "components/prefs/prefs_export.h"
-namespace base {
-class DictionaryValue;
-class Value;
-}
// This is an abstract interface for reading and writing from/to a persistent
// preference store, used by PrefService. An implementation using a JSON file
@@ -55,7 +52,7 @@
const base::Value** result) const = 0;
// Get all the values. Never returns a null pointer.
- virtual std::unique_ptr<base::DictionaryValue> GetValues() const = 0;
+ virtual base::Value::Dict GetValues() const = 0;
protected:
friend class base::RefCounted<PrefStore>;
diff --git a/components/prefs/pref_value_map.cc b/components/prefs/pref_value_map.cc
index b932eef..eb13555 100644
--- a/components/prefs/pref_value_map.cc
+++ b/components/prefs/pref_value_map.cc
@@ -82,7 +82,11 @@
bool PrefValueMap::GetBoolean(const std::string& key,
bool* value) const {
const base::Value* stored_value = nullptr;
- return GetValue(key, &stored_value) && stored_value->GetAsBoolean(value);
+ if (GetValue(key, &stored_value) && stored_value->is_bool()) {
+ *value = stored_value->GetBool();
+ return true;
+ }
+ return false;
}
void PrefValueMap::SetBoolean(const std::string& key, bool value) {
@@ -92,7 +96,11 @@
bool PrefValueMap::GetString(const std::string& key,
std::string* value) const {
const base::Value* stored_value = nullptr;
- return GetValue(key, &stored_value) && stored_value->GetAsString(value);
+ if (GetValue(key, &stored_value) && stored_value->is_string()) {
+ *value = stored_value->GetString();
+ return true;
+ }
+ return false;
}
void PrefValueMap::SetString(const std::string& key,
@@ -102,7 +110,11 @@
bool PrefValueMap::GetInteger(const std::string& key, int* value) const {
const base::Value* stored_value = nullptr;
- return GetValue(key, &stored_value) && stored_value->GetAsInteger(value);
+ if (GetValue(key, &stored_value) && stored_value->is_int()) {
+ *value = stored_value->GetInt();
+ return true;
+ }
+ return false;
}
void PrefValueMap::SetInteger(const std::string& key, const int value) {
@@ -132,7 +144,7 @@
while (this_pref != this_prefs.end() && other_pref != other_prefs.end()) {
const int diff = this_pref->first.compare(other_pref->first);
if (diff == 0) {
- if (!this_pref->second->Equals(other_pref->second))
+ if (*this_pref->second != *other_pref->second)
differing_keys->push_back(this_pref->first);
++this_pref;
++other_pref;
@@ -152,10 +164,10 @@
differing_keys->push_back(other_pref->first);
}
-std::unique_ptr<base::DictionaryValue> PrefValueMap::AsDictionaryValue() const {
- auto dictionary = std::make_unique<base::DictionaryValue>();
+base::Value::Dict PrefValueMap::AsDict() const {
+ base::Value::Dict dictionary;
for (const auto& value : prefs_)
- dictionary->Set(value.first, value.second.CreateDeepCopy());
+ dictionary.SetByDottedPath(value.first, value.second.Clone());
return dictionary;
}
diff --git a/components/prefs/pref_value_map.h b/components/prefs/pref_value_map.h
index 6a9b4b6..92f9386 100644
--- a/components/prefs/pref_value_map.h
+++ b/components/prefs/pref_value_map.h
@@ -11,13 +11,9 @@
#include <vector>
#include "base/macros.h"
+#include "base/values.h"
#include "components/prefs/prefs_export.h"
-namespace base {
-class DictionaryValue;
-class Value;
-}
-
// A generic string to value map used by the PrefStore implementations.
class COMPONENTS_PREFS_EXPORT PrefValueMap {
public:
@@ -83,8 +79,8 @@
void GetDifferingKeys(const PrefValueMap* other,
std::vector<std::string>* differing_keys) const;
- // Copies the map into a dictionary value.
- std::unique_ptr<base::DictionaryValue> AsDictionaryValue() const;
+ // Copies the map into a Value::Dict.
+ base::Value::Dict AsDict() const;
private:
Map prefs_;
diff --git a/components/prefs/scoped_user_pref_update.cc b/components/prefs/scoped_user_pref_update.cc
index 27d56af..3e36c63 100644
--- a/components/prefs/scoped_user_pref_update.cc
+++ b/components/prefs/scoped_user_pref_update.cc
@@ -42,3 +42,11 @@
}
} // namespace subtle
+
+base::Value::Dict& ScopedDictPrefUpdate::Get() {
+ return GetValueOfType(base::Value::Type::DICT)->GetDict();
+}
+
+base::Value::List& ScopedListPrefUpdate::Get() {
+ return GetValueOfType(base::Value::Type::LIST)->GetList();
+}
diff --git a/components/prefs/scoped_user_pref_update.h b/components/prefs/scoped_user_pref_update.h
index 7de6bfb..8c283f4 100644
--- a/components/prefs/scoped_user_pref_update.h
+++ b/components/prefs/scoped_user_pref_update.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -10,7 +10,7 @@
#include <string>
-#include "base/macros.h"
+#include "base/memory/raw_ptr.h"
#include "base/sequence_checker.h"
#include "base/values.h"
#include "components/prefs/pref_service.h"
@@ -18,11 +18,6 @@
class PrefService;
-namespace base {
-class DictionaryValue;
-class ListValue;
-}
-
namespace subtle {
// Base class for ScopedUserPrefUpdateTemplate that contains the parts
@@ -32,6 +27,10 @@
// and getting access to PrefService::GetMutableUserPref and
// PrefService::ReportUserPrefChanged.
class COMPONENTS_PREFS_EXPORT ScopedUserPrefUpdateBase {
+ public:
+ ScopedUserPrefUpdateBase(const ScopedUserPrefUpdateBase&) = delete;
+ ScopedUserPrefUpdateBase& operator=(const ScopedUserPrefUpdateBase&) = delete;
+
protected:
ScopedUserPrefUpdateBase(PrefService* service, const std::string& path);
@@ -47,64 +46,85 @@
void Notify();
// Weak pointer.
- PrefService* service_;
+ raw_ptr<PrefService> service_;
// Path of the preference being updated.
std::string path_;
// Cache of value from user pref store (set between Get() and Notify() calls).
- base::Value* value_;
+ raw_ptr<base::Value> value_;
SEQUENCE_CHECKER(sequence_checker_);
-
- DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdateBase);
};
} // namespace subtle
-// Class to support modifications to DictionaryValues and ListValues while
-// guaranteeing that PrefObservers are notified of changed values.
+// Class to support modifications to base::Value::Dicts while guaranteeing
+// that PrefObservers are notified of changed values.
//
// This class may only be used on the UI thread as it requires access to the
// PrefService.
-template <typename T, base::Value::Type type_enum_value>
-class ScopedUserPrefUpdate : public subtle::ScopedUserPrefUpdateBase {
+class COMPONENTS_PREFS_EXPORT ScopedDictPrefUpdate
+ : public subtle::ScopedUserPrefUpdateBase {
public:
- ScopedUserPrefUpdate(PrefService* service, const std::string& path)
+ // The underlying dictionary must not be removed from `service` during
+ // the lifetime of the created ScopedDictPrefUpdate.
+ ScopedDictPrefUpdate(PrefService* service, const std::string& path)
: ScopedUserPrefUpdateBase(service, path) {}
- // Triggers an update notification if Get() was called.
- virtual ~ScopedUserPrefUpdate() {}
+ ScopedDictPrefUpdate(const ScopedDictPrefUpdate&) = delete;
+ ScopedDictPrefUpdate& operator=(const ScopedDictPrefUpdate&) = delete;
- // Returns a mutable |T| instance that
+ // Triggers an update notification if Get() was called.
+ virtual ~ScopedDictPrefUpdate() = default;
+
+ // Returns a mutable `base::Value::Dict` instance that
// - is already in the user pref store, or
// - is (silently) created and written to the user pref store if none existed
// before.
//
- // Calling Get() implies that an update notification is necessary at
- // destruction time.
+ // Calling Get() will result in an update notification automatically
+ // being triggered at destruction time.
//
// The ownership of the return value remains with the user pref store.
- // Virtual so it can be overriden in subclasses that transform the value
- // before returning it (for example to return a subelement of a dictionary).
- virtual T* Get() {
- return static_cast<T*>(GetValueOfType(type_enum_value));
- }
+ base::Value::Dict& Get();
- T& operator*() {
- return *Get();
- }
+ base::Value::Dict& operator*() { return Get(); }
- T* operator->() {
- return Get();
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdate);
+ base::Value::Dict* operator->() { return &Get(); }
};
-typedef ScopedUserPrefUpdate<base::DictionaryValue,
- base::Value::Type::DICTIONARY>
- DictionaryPrefUpdate;
-typedef ScopedUserPrefUpdate<base::ListValue, base::Value::Type::LIST>
- ListPrefUpdate;
+// Class to support modifications to base::Value::Lists while guaranteeing
+// that PrefObservers are notified of changed values.
+//
+// This class may only be used on the UI thread as it requires access to the
+// PrefService.
+class COMPONENTS_PREFS_EXPORT ScopedListPrefUpdate
+ : public subtle::ScopedUserPrefUpdateBase {
+ public:
+ // The underlying list must not be removed from `service` during
+ // the lifetime of the created ScopedListPrefUpdate.
+ ScopedListPrefUpdate(PrefService* service, const std::string& path)
+ : ScopedUserPrefUpdateBase(service, path) {}
+
+ ScopedListPrefUpdate(const ScopedListPrefUpdate&) = delete;
+ ScopedListPrefUpdate& operator=(const ScopedListPrefUpdate&) = delete;
+
+ // Triggers an update notification if Get() was called.
+ virtual ~ScopedListPrefUpdate() = default;
+
+ // Returns a mutable `base::Value::List` instance that
+ // - is already in the user pref store, or
+ // - is (silently) created and written to the user pref store if none existed
+ // before.
+ //
+ // Calling Get() will result in an update notification automatically
+ // being triggered at destruction time.
+ //
+ // The ownership of the return value remains with the user pref store.
+ base::Value::List& Get();
+
+ base::Value::List& operator*() { return Get(); }
+
+ base::Value::List* operator->() { return &Get(); }
+};
#endif // COMPONENTS_PREFS_SCOPED_USER_PREF_UPDATE_H_
diff --git a/components/prefs/testing_pref_service.h b/components/prefs/testing_pref_service.h
index f10e0cb..f0b05fa 100644
--- a/components/prefs/testing_pref_service.h
+++ b/components/prefs/testing_pref_service.h
@@ -220,7 +220,7 @@
SetPref(TestingPrefStore* pref_store,
const std::string& path,
std::unique_ptr<base::Value> value) {
- pref_store->SetValue(path, std::move(value),
+ pref_store->SetValue(path, base::Value(std::move(*value)),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
diff --git a/components/prefs/testing_pref_store.cc b/components/prefs/testing_pref_store.cc
index 4380407..a5da9b7 100644
--- a/components/prefs/testing_pref_store.cc
+++ b/components/prefs/testing_pref_store.cc
@@ -8,7 +8,6 @@
#include <utility>
#include "base/json/json_writer.h"
-#include "base/threading/sequenced_task_runner_handle.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -26,8 +25,8 @@
return prefs_.GetValue(key, value);
}
-std::unique_ptr<base::DictionaryValue> TestingPrefStore::GetValues() const {
- return prefs_.AsDictionaryValue();
+base::Value::Dict TestingPrefStore::GetValues() const {
+ return prefs_.AsDict();
}
bool TestingPrefStore::GetMutableValue(const std::string& key,
@@ -44,7 +43,7 @@
}
bool TestingPrefStore::HasObservers() const {
- return observers_.might_have_observers();
+ return !observers_.empty();
}
bool TestingPrefStore::IsInitializationComplete() const {
@@ -52,21 +51,19 @@
}
void TestingPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
- DCHECK(value);
- if (prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value)))) {
+ if (prefs_.SetValue(key, base::Value(std::move(value)))) {
committed_ = false;
NotifyPrefValueChanged(key);
}
}
void TestingPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
- DCHECK(value);
- CheckPrefIsSerializable(key, *value);
- if (prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value))))
+ CheckPrefIsSerializable(key, value);
+ if (prefs_.SetValue(key, base::Value(std::move(value))))
committed_ = false;
}
@@ -139,15 +136,15 @@
void TestingPrefStore::SetString(const std::string& key,
const std::string& value) {
- SetValue(key, std::make_unique<base::Value>(value), DEFAULT_PREF_WRITE_FLAGS);
+ SetValue(key, base::Value(value), DEFAULT_PREF_WRITE_FLAGS);
}
void TestingPrefStore::SetInteger(const std::string& key, int value) {
- SetValue(key, std::make_unique<base::Value>(value), DEFAULT_PREF_WRITE_FLAGS);
+ SetValue(key, base::Value(value), DEFAULT_PREF_WRITE_FLAGS);
}
void TestingPrefStore::SetBoolean(const std::string& key, bool value) {
- SetValue(key, std::make_unique<base::Value>(value), DEFAULT_PREF_WRITE_FLAGS);
+ SetValue(key, base::Value(value), DEFAULT_PREF_WRITE_FLAGS);
}
bool TestingPrefStore::GetString(const std::string& key,
@@ -156,7 +153,11 @@
if (!prefs_.GetValue(key, &stored_value) || !stored_value)
return false;
- return stored_value->GetAsString(value);
+ if (value && stored_value->is_string()) {
+ *value = stored_value->GetString();
+ return true;
+ }
+ return stored_value->is_string();
}
bool TestingPrefStore::GetInteger(const std::string& key, int* value) const {
@@ -164,7 +165,11 @@
if (!prefs_.GetValue(key, &stored_value) || !stored_value)
return false;
- return stored_value->GetAsInteger(value);
+ if (value && stored_value->is_int()) {
+ *value = stored_value->GetInt();
+ return true;
+ }
+ return stored_value->is_int();
}
bool TestingPrefStore::GetBoolean(const std::string& key, bool* value) const {
@@ -172,7 +177,11 @@
if (!prefs_.GetValue(key, &stored_value) || !stored_value)
return false;
- return stored_value->GetAsBoolean(value);
+ if (value && stored_value->is_bool()) {
+ *value = stored_value->GetBool();
+ return true;
+ }
+ return stored_value->is_bool();
}
void TestingPrefStore::SetBlockAsyncRead(bool block_async_read) {
diff --git a/components/prefs/testing_pref_store.h b/components/prefs/testing_pref_store.h
index 499b094..233294b 100644
--- a/components/prefs/testing_pref_store.h
+++ b/components/prefs/testing_pref_store.h
@@ -25,7 +25,7 @@
// Overriden from PrefStore.
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
@@ -35,10 +35,10 @@
bool GetMutableValue(const std::string& key, base::Value** result) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override;
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool ReadOnly() const override;
diff --git a/components/prefs/value_map_pref_store.cc b/components/prefs/value_map_pref_store.cc
index 79c2017..7305a28 100644
--- a/components/prefs/value_map_pref_store.cc
+++ b/components/prefs/value_map_pref_store.cc
@@ -17,8 +17,8 @@
return prefs_.GetValue(key, value);
}
-std::unique_ptr<base::DictionaryValue> ValueMapPrefStore::GetValues() const {
- return prefs_.AsDictionaryValue();
+base::Value::Dict ValueMapPrefStore::GetValues() const {
+ return prefs_.AsDict();
}
void ValueMapPrefStore::AddObserver(PrefStore::Observer* observer) {
@@ -30,14 +30,13 @@
}
bool ValueMapPrefStore::HasObservers() const {
- return observers_.might_have_observers();
+ return !observers_.empty();
}
void ValueMapPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
- DCHECK(value);
- if (prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value)))) {
+ if (prefs_.SetValue(key, std::move(value))) {
for (Observer& observer : observers_)
observer.OnPrefValueChanged(key);
}
@@ -62,10 +61,9 @@
}
void ValueMapPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
- DCHECK(value);
- prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value)));
+ prefs_.SetValue(key, std::move(value));
}
ValueMapPrefStore::~ValueMapPrefStore() {}
diff --git a/components/prefs/value_map_pref_store.h b/components/prefs/value_map_pref_store.h
index f0de0cd..7fff0f8 100644
--- a/components/prefs/value_map_pref_store.h
+++ b/components/prefs/value_map_pref_store.h
@@ -25,20 +25,20 @@
// PrefStore overrides:
bool GetValue(const std::string& key,
const base::Value** value) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
// WriteablePrefStore overrides:
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool GetMutableValue(const std::string& key, base::Value** value) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
protected:
diff --git a/components/prefs/writeable_pref_store.h b/components/prefs/writeable_pref_store.h
index 9a69c7c..9d5d281 100644
--- a/components/prefs/writeable_pref_store.h
+++ b/components/prefs/writeable_pref_store.h
@@ -38,7 +38,7 @@
// Sets a |value| for |key| in the store. |value| must be non-NULL. |flags| is
// a bitmask of PrefWriteFlags.
virtual void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) = 0;
// Removes the value for |key|.
@@ -73,7 +73,7 @@
// tests rely on the number of notifications generated. |flags| is a bitmask
// of PrefWriteFlags.
virtual void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) = 0;
protected:
diff --git a/components/ukm/ukm_recorder_impl.h b/components/ukm/ukm_recorder_impl.h
index 7f3084f..83859ee 100644
--- a/components/ukm/ukm_recorder_impl.h
+++ b/components/ukm/ukm_recorder_impl.h
@@ -12,7 +12,7 @@
#include <unordered_set>
#include <vector>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/containers/flat_map.h"
#include "base/sequence_checker.h"
#include "base/strings/string_piece.h"
diff --git a/components/update_client/BUILD.gn b/components/update_client/BUILD.gn
index 8e2133b..798367d 100644
--- a/components/update_client/BUILD.gn
+++ b/components/update_client/BUILD.gn
@@ -121,6 +121,12 @@
"unzip/unzip_impl_cobalt.h",
]
+ if (cobalt_pending_clean_up) {
+ sources -= [
+ "net/url_request_post_interceptor.cc",
+ ]
+ }
+
deps = [
":update_client",
"//base",
@@ -202,13 +208,22 @@
"utils_unittest.cc",
]
+ if (cobalt_pending_clean_up) {
+ sources -= [
+ "crx_downloader_unittest.cc",
+ "ping_manager_unittest.cc",
+ "update_checker_unittest.cc",
+ ]
+ }
+
deps = [
":test_support",
":update_client",
":update_client_test_files",
+ "//chrome/updater",
"//cobalt/base",
+ "//cobalt/network",
"//cobalt/test:run_all_unittests",
- "//cobalt/updater",
"//components/crx_file",
"//components/prefs",
"//components/prefs:test_support",
@@ -233,8 +248,8 @@
deps = [
":update_client",
+ "//chrome/updater",
"//cobalt/base",
- "//cobalt/updater",
"//components/crx_file",
"//components/prefs",
"//components/prefs:test_support",
diff --git a/components/update_client/METADATA b/components/update_client/METADATA
index a61e644..a3526dc 100644
--- a/components/update_client/METADATA
+++ b/components/update_client/METADATA
@@ -1,3 +1,5 @@
+name: "chrome_update_client"
+
third_party {
identifier {
type: "ChromiumVersion"
diff --git a/components/update_client/action_runner.cc b/components/update_client/action_runner.cc
index 2df16f5..b456f13 100644
--- a/components/update_client/action_runner.cc
+++ b/components/update_client/action_runner.cc
@@ -14,8 +14,8 @@
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/logging.h"
-#include "base/task/post_task.h"
-#include "base/threading/sequenced_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
+#include "base/task/thread_pool.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "components/crx_file/crx_verifier.h"
@@ -59,18 +59,18 @@
ActionRunner::ActionRunner(const Component& component)
: is_per_user_install_(component.config()->IsPerUserInstall()),
component_(component),
- main_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
+ main_task_runner_(base::SequencedTaskRunner::GetCurrentDefault()) {}
ActionRunner::~ActionRunner() {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void ActionRunner::Run(Callback run_complete) {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
run_complete_ = std::move(run_complete);
- base::CreateSequencedTaskRunnerWithTraits(kTaskTraits)
+ base::ThreadPool::CreateSequencedTaskRunner(kTaskTraits)
->PostTask(
FROM_HERE,
base::BindOnce(&ActionRunner::RunOnTaskRunner, base::Unretained(this),
@@ -116,7 +116,7 @@
}
unpack_path_ = result.unpack_path;
- base::SequencedTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(&ActionRunner::RunCommand, base::Unretained(this),
MakeCommandLine(result.unpack_path)));
diff --git a/components/update_client/action_runner.h b/components/update_client/action_runner.h
index ee41890..8383553 100644
--- a/components/update_client/action_runner.h
+++ b/components/update_client/action_runner.h
@@ -15,7 +15,7 @@
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
+#include "base/sequence_checker.h"
#include "build/build_config.h"
#include "components/update_client/component_unpacker.h"
@@ -59,14 +59,14 @@
const Component& component_;
// Used to post callbacks to the main thread.
- scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
+ scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
// Contains the unpack path for the component associated with the run action.
base::FilePath unpack_path_;
Callback run_complete_;
- THREAD_CHECKER(thread_checker_);
+ SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(ActionRunner);
};
diff --git a/components/update_client/cobalt_slot_management.cc b/components/update_client/cobalt_slot_management.cc
index afca111..0ebece9 100644
--- a/components/update_client/cobalt_slot_management.cc
+++ b/components/update_client/cobalt_slot_management.cc
@@ -20,8 +20,9 @@
#include <vector>
#include "base/files/file_util.h"
+#include "base/logging.h"
#include "base/values.h"
-#include "cobalt/updater/utils.h"
+#include "chrome/updater/util.h"
#include "components/update_client/utils.h"
#include "starboard/configuration_constants.h"
#include "starboard/file.h"
diff --git a/components/update_client/cobalt_slot_management_test.cc b/components/update_client/cobalt_slot_management_test.cc
index 6790005..47e3434 100644
--- a/components/update_client/cobalt_slot_management_test.cc
+++ b/components/update_client/cobalt_slot_management_test.cc
@@ -20,8 +20,8 @@
#include <vector>
#include "base/strings/string_util.h"
+#include "base/time/time.h"
#include "starboard/common/file.h"
-#include "starboard/common/time.h"
#include "starboard/extension/free_space.h"
#include "starboard/loader_app/app_key_files.h"
#include "starboard/loader_app/drain_file.h"
@@ -206,7 +206,7 @@
// In order to be higher ranked, the other app's drain file needs to be older
// but not expired.
int64_t current_time_us =
- starboard::PosixTimeToWindowsTime(starboard::CurrentPosixTime());
+ base::Time::Now().ToDeltaSinceWindowsEpoch().InMicroseconds();
starboard::loader_app::ScopedDrainFile racing_drain_file(
slot_path, kTestAppKey2,
current_time_us - (kDrainFileMaximumAgeUsec / 2));
diff --git a/components/update_client/component.cc b/components/update_client/component.cc
index 1549649..f88f384 100644
--- a/components/update_client/component.cc
+++ b/components/update_client/component.cc
@@ -12,9 +12,10 @@
#include "base/files/scoped_temp_dir.h"
#include "base/location.h"
#include "base/logging.h"
-#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
-#include "base/task/post_task.h"
+#include "base/task/bind_post_task.h"
+#include "base/task/sequenced_task_runner.h"
+#include "base/task/thread_pool.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
#include "components/update_client/action_runner.h"
@@ -77,17 +78,17 @@
void(ErrorCategory error_category, int error_code, int extra_code1)>;
void InstallComplete(
- scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
+ scoped_refptr<base::SequencedTaskRunner> main_task_runner,
InstallOnBlockingTaskRunnerCompleteCallback callback,
const base::FilePath& unpack_path,
const CrxInstaller::Result& result) {
#if defined(STARBOARD)
LOG(INFO) << "InstallComplete";
#endif
- base::PostTaskWithTraits(
+ base::ThreadPool::PostTask(
FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()},
base::BindOnce(
- [](scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
+ [](scoped_refptr<base::SequencedTaskRunner> main_task_runner,
InstallOnBlockingTaskRunnerCompleteCallback callback,
const base::FilePath& unpack_path,
const CrxInstaller::Result& result) {
@@ -111,7 +112,7 @@
}
void InstallOnBlockingTaskRunner(
- scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
+ scoped_refptr<base::SequencedTaskRunner> main_task_runner,
const base::FilePath& unpack_path,
const std::string& public_key,
#if defined(STARBOARD)
@@ -195,7 +196,7 @@
}
void UnpackCompleteOnBlockingTaskRunner(
- scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
+ scoped_refptr<base::SequencedTaskRunner> main_task_runner,
#if defined(IN_MEMORY_UPDATES)
const base::FilePath& installation_dir,
#else
@@ -247,7 +248,7 @@
return;
}
- base::PostTaskWithTraits(
+ base::ThreadPool::PostTask(
FROM_HERE, kTaskTraits,
base::BindOnce(&InstallOnBlockingTaskRunner, main_task_runner,
result.unpack_path, result.public_key,
@@ -261,7 +262,7 @@
}
void StartInstallOnBlockingTaskRunner(
- scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
+ scoped_refptr<base::SequencedTaskRunner> main_task_runner,
const std::vector<uint8_t>& pk_hash,
#if defined(IN_MEMORY_UPDATES)
const base::FilePath& installation_dir,
@@ -350,7 +351,7 @@
}
void Component::Handle(CallbackHandleComplete callback_handle_complete) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(state_);
#if defined(STARBOARD)
LOG(INFO) << "Component::Handle";
@@ -363,14 +364,14 @@
#if defined(STARBOARD)
void Component::Cancel() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
is_cancelled_ = true;
state_->Cancel();
}
#endif
void Component::ChangeState(std::unique_ptr<State> next_state) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "Component::ChangeState next_state="
<< ((next_state)? next_state->state_name(): "nullptr");
@@ -382,12 +383,12 @@
else
is_handled_ = true;
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, std::move(callback_handle_complete_));
}
CrxUpdateItem Component::GetCrxUpdateItem() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
CrxUpdateItem crx_update_item;
crx_update_item.state = state_->state();
@@ -405,7 +406,7 @@
}
void Component::SetParseResult(const ProtocolParser::Result& result) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(0, update_check_error_);
@@ -436,7 +437,7 @@
}
void Component::Uninstall(const base::Version& version, int reason) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(ComponentState::kNew, state());
@@ -454,7 +455,7 @@
const base::Optional<ProtocolParser::Result>& result,
ErrorCategory error_category,
int error) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(ComponentState::kChecking, state());
error_category_ = error_category;
@@ -462,7 +463,7 @@
if (result)
SetParseResult(result.value());
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, std::move(update_check_complete_));
}
@@ -473,12 +474,12 @@
update_context_.config->EnabledBackgroundDownloader();
}
-void Component::AppendEvent(base::Value event) {
+void Component::AppendEvent(base::Value::Dict event) {
events_.push_back(std::move(event));
}
void Component::NotifyObservers(UpdateClient::Observer::Events event) const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
if (!is_cancelled_) {
@@ -492,7 +493,7 @@
}
base::TimeDelta Component::GetUpdateDuration() const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (update_begin_.is_null())
return base::TimeDelta();
@@ -504,98 +505,98 @@
return std::min(update_cost, max_update_delay);
}
-base::Value Component::MakeEventUpdateComplete() const {
- base::Value event(base::Value::Type::DICTIONARY);
- event.SetKey("eventtype", base::Value(3));
- event.SetKey(
+base::Value::Dict Component::MakeEventUpdateComplete() const {
+ base::Value::Dict event;
+ event.Set("eventtype", base::Value(3));
+ event.Set(
"eventresult",
base::Value(static_cast<int>(state() == ComponentState::kUpdated)));
if (error_category() != ErrorCategory::kNone)
- event.SetKey("errorcat", base::Value(static_cast<int>(error_category())));
+ event.Set("errorcat", base::Value(static_cast<int>(error_category())));
if (error_code())
- event.SetKey("errorcode", base::Value(error_code()));
+ event.Set("errorcode", base::Value(error_code()));
if (extra_code1())
- event.SetKey("extracode1", base::Value(extra_code1()));
+ event.Set("extracode1", base::Value(extra_code1()));
if (HasDiffUpdate(*this)) {
const int diffresult = static_cast<int>(!diff_update_failed());
- event.SetKey("diffresult", base::Value(diffresult));
+ event.Set("diffresult", base::Value(diffresult));
}
if (diff_error_category() != ErrorCategory::kNone) {
const int differrorcat = static_cast<int>(diff_error_category());
- event.SetKey("differrorcat", base::Value(differrorcat));
+ event.Set("differrorcat", base::Value(differrorcat));
}
if (diff_error_code())
- event.SetKey("differrorcode", base::Value(diff_error_code()));
+ event.Set("differrorcode", base::Value(diff_error_code()));
if (diff_extra_code1())
- event.SetKey("diffextracode1", base::Value(diff_extra_code1()));
+ event.Set("diffextracode1", base::Value(diff_extra_code1()));
if (!previous_fp().empty())
- event.SetKey("previousfp", base::Value(previous_fp()));
+ event.Set("previousfp", base::Value(previous_fp()));
if (!next_fp().empty())
- event.SetKey("nextfp", base::Value(next_fp()));
+ event.Set("nextfp", base::Value(next_fp()));
DCHECK(previous_version().IsValid());
- event.SetKey("previousversion", base::Value(previous_version().GetString()));
+ event.Set("previousversion", base::Value(previous_version().GetString()));
if (next_version().IsValid())
- event.SetKey("nextversion", base::Value(next_version().GetString()));
+ event.Set("nextversion", base::Value(next_version().GetString()));
return event;
}
-base::Value Component::MakeEventDownloadMetrics(
+base::Value::Dict Component::MakeEventDownloadMetrics(
const CrxDownloader::DownloadMetrics& dm) const {
- base::Value event(base::Value::Type::DICTIONARY);
- event.SetKey("eventtype", base::Value(14));
- event.SetKey("eventresult", base::Value(static_cast<int>(dm.error == 0)));
- event.SetKey("downloader", base::Value(DownloaderToString(dm.downloader)));
+ base::Value::Dict event;
+ event.Set("eventtype", base::Value(14));
+ event.Set("eventresult", base::Value(static_cast<int>(dm.error == 0)));
+ event.Set("downloader", base::Value(DownloaderToString(dm.downloader)));
if (dm.error)
- event.SetKey("errorcode", base::Value(dm.error));
- event.SetKey("url", base::Value(dm.url.spec()));
+ event.Set("errorcode", base::Value(dm.error));
+ event.Set("url", base::Value(dm.url.spec()));
// -1 means that the byte counts are not known.
if (dm.total_bytes != -1 && dm.total_bytes < kProtocolMaxInt)
- event.SetKey("total", base::Value(static_cast<double>(dm.total_bytes)));
+ event.Set("total", base::Value(static_cast<double>(dm.total_bytes)));
if (dm.downloaded_bytes != -1 && dm.total_bytes < kProtocolMaxInt) {
- event.SetKey("downloaded",
+ event.Set("downloaded",
base::Value(static_cast<double>(dm.downloaded_bytes)));
}
if (dm.download_time_ms && dm.total_bytes < kProtocolMaxInt) {
- event.SetKey("download_time_ms",
+ event.Set("download_time_ms",
base::Value(static_cast<double>(dm.download_time_ms)));
}
DCHECK(previous_version().IsValid());
- event.SetKey("previousversion", base::Value(previous_version().GetString()));
+ event.Set("previousversion", base::Value(previous_version().GetString()));
if (next_version().IsValid())
- event.SetKey("nextversion", base::Value(next_version().GetString()));
+ event.Set("nextversion", base::Value(next_version().GetString()));
return event;
}
-base::Value Component::MakeEventUninstalled() const {
+base::Value::Dict Component::MakeEventUninstalled() const {
DCHECK(state() == ComponentState::kUninstalled);
- base::Value event(base::Value::Type::DICTIONARY);
- event.SetKey("eventtype", base::Value(4));
- event.SetKey("eventresult", base::Value(1));
+ base::Value::Dict event;
+ event.Set("eventtype", base::Value(4));
+ event.Set("eventresult", base::Value(1));
if (extra_code1())
- event.SetKey("extracode1", base::Value(extra_code1()));
+ event.Set("extracode1", base::Value(extra_code1()));
DCHECK(previous_version().IsValid());
- event.SetKey("previousversion", base::Value(previous_version().GetString()));
+ event.Set("previousversion", base::Value(previous_version().GetString()));
DCHECK(next_version().IsValid());
- event.SetKey("nextversion", base::Value(next_version().GetString()));
+ event.Set("nextversion", base::Value(next_version().GetString()));
return event;
}
-base::Value Component::MakeEventActionRun(bool succeeded,
+base::Value::Dict Component::MakeEventActionRun(bool succeeded,
int error_code,
int extra_code1) const {
- base::Value event(base::Value::Type::DICTIONARY);
- event.SetKey("eventtype", base::Value(42));
- event.SetKey("eventresult", base::Value(static_cast<int>(succeeded)));
+ base::Value::Dict event;
+ event.Set("eventtype", base::Value(42));
+ event.Set("eventresult", base::Value(static_cast<int>(succeeded)));
if (error_code)
- event.SetKey("errorcode", base::Value(error_code));
+ event.Set("errorcode", base::Value(error_code));
if (extra_code1)
- event.SetKey("extracode1", base::Value(extra_code1));
+ event.Set("extracode1", base::Value(extra_code1));
return event;
}
-std::vector<base::Value> Component::GetEvents() const {
- std::vector<base::Value> events;
+std::vector<base::Value::Dict> Component::GetEvents() const {
+ std::vector<base::Value::Dict> events;
for (const auto& event : events_)
events.push_back(event.Clone());
return events;
@@ -607,7 +608,7 @@
Component::State::~State() {}
void Component::State::Handle(CallbackNextState callback_next_state) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "Component::State::Handle";
#endif
@@ -619,29 +620,29 @@
#if defined(STARBOARD)
void Component::State::Cancel() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Further work may be needed to ensure cancellation during any state results
// in a clear result and no memory leaks.
}
#endif
void Component::State::TransitionState(std::unique_ptr<State> next_state) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(next_state);
#if defined(STARBOARD)
LOG(INFO) << "Component::State::TransitionState next_state="
<< ((next_state)? next_state->state_name(): "nullptr");
#endif
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback_next_state_), std::move(next_state)));
}
void Component::State::EndState() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback_next_state_), nullptr));
}
@@ -649,11 +650,11 @@
: State(component, ComponentState::kNew) {}
Component::StateNew::~StateNew() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void Component::StateNew::DoHandle() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = State::component();
@@ -675,7 +676,7 @@
: State(component, ComponentState::kChecking) {}
Component::StateChecking::~StateChecking() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
// Unlike how other states are handled, this function does not change the
@@ -685,7 +686,7 @@
// together but the state machine defines the transitions for one component
// at a time.
void Component::StateChecking::DoHandle() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = State::component();
DCHECK(component.crx_component());
@@ -698,18 +699,18 @@
}
void Component::StateChecking::UpdateCheckComplete() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = State::component();
#if defined(STARBOARD)
auto& config = component.update_context_.config;
auto metadata = component.update_context_.update_checker->GetPersistedData();
if (metadata != nullptr) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&PersistedData::SetUpdaterChannel,
base::Unretained(metadata), component.id_,
config->GetChannel()));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&PersistedData::SetLatestChannel,
base::Unretained(metadata),
config->GetChannel()));
@@ -741,11 +742,11 @@
: State(component, ComponentState::kUpdateError) {}
Component::StateUpdateError::~StateUpdateError() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void Component::StateUpdateError::DoHandle() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = State::component();
@@ -771,11 +772,11 @@
: State(component, ComponentState::kCanUpdate) {}
Component::StateCanUpdate::~StateCanUpdate() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void Component::StateCanUpdate::DoHandle() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = State::component();
DCHECK(component.crx_component());
@@ -814,11 +815,11 @@
: State(component, ComponentState::kUpToDate) {}
Component::StateUpToDate::~StateUpToDate() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void Component::StateUpToDate::DoHandle() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = State::component();
DCHECK(component.crx_component());
@@ -831,18 +832,18 @@
: State(component, ComponentState::kDownloadingDiff) {}
Component::StateDownloadingDiff::~StateDownloadingDiff() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
#if defined(STARBOARD)
void Component::StateDownloadingDiff::Cancel() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
crx_downloader_->CancelDownload();
}
#endif
void Component::StateDownloadingDiff::DoHandle() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(IN_MEMORY_UPDATES)
auto& component = Component::State::component();
@@ -881,7 +882,7 @@
// times due to how the CRX downloader switches between different downloaders
// and fallback urls.
void Component::StateDownloadingDiff::DownloadProgress(const std::string& id) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
component().NotifyObservers(Events::COMPONENT_UPDATE_DOWNLOADING);
}
@@ -889,7 +890,7 @@
void Component::StateDownloadingDiff::DownloadComplete(
const std::string& id,
const CrxDownloader::Result& download_result) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = Component::State::component();
for (const auto& download_metrics : crx_downloader_->download_metrics())
@@ -925,18 +926,18 @@
: State(component, ComponentState::kDownloading) {}
Component::StateDownloading::~StateDownloading() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
#if defined(STARBOARD)
void Component::StateDownloading::Cancel() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
crx_downloader_->CancelDownload();
}
#endif
void Component::StateDownloading::DoHandle() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(IN_MEMORY_UPDATES)
auto& component = Component::State::component();
@@ -975,7 +976,7 @@
// times due to how the CRX downloader switches between different downloaders
// and fallback urls.
void Component::StateDownloading::DownloadProgress(const std::string& id) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
component().NotifyObservers(Events::COMPONENT_UPDATE_DOWNLOADING);
}
@@ -983,7 +984,7 @@
void Component::StateDownloading::DownloadComplete(
const std::string& id,
const CrxDownloader::Result& download_result) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = Component::State::component();
@@ -1020,11 +1021,11 @@
: State(component, ComponentState::kUpdatingDiff) {}
Component::StateUpdatingDiff::~StateUpdatingDiff() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void Component::StateUpdatingDiff::DoHandle() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(IN_MEMORY_UPDATES)
auto& component = Component::State::component();
@@ -1037,12 +1038,12 @@
component.NotifyObservers(Events::COMPONENT_UPDATE_READY);
- base::CreateSequencedTaskRunnerWithTraits(kTaskTraits)
+ base::ThreadPool::CreateSequencedTaskRunner(kTaskTraits)
->PostTask(
FROM_HERE,
base::BindOnce(
&update_client::StartInstallOnBlockingTaskRunner,
- base::ThreadTaskRunnerHandle::Get(),
+ base::SequencedTaskRunner::GetCurrentDefault(),
component.crx_component()->pk_hash,
#if defined(IN_MEMORY_UPDATES)
component.installation_dir_,
@@ -1066,7 +1067,7 @@
void Component::StateUpdatingDiff::InstallComplete(ErrorCategory error_category,
int error_code,
int extra_code1) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = Component::State::component();
@@ -1097,14 +1098,14 @@
: State(component, ComponentState::kUpdating) {}
Component::StateUpdating::~StateUpdating() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void Component::StateUpdating::DoHandle() {
#if defined(STARBOARD)
LOG(INFO) << "Component::StateUpdating::DoHandle()";
#endif
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(IN_MEMORY_UPDATES)
auto& component = Component::State::component();
@@ -1117,11 +1118,11 @@
component.NotifyObservers(Events::COMPONENT_UPDATE_READY);
- base::CreateSequencedTaskRunnerWithTraits(kTaskTraits)
+ base::ThreadPool::CreateSequencedTaskRunner(kTaskTraits)
->PostTask(FROM_HERE,
base::BindOnce(
&update_client::StartInstallOnBlockingTaskRunner,
- base::ThreadTaskRunnerHandle::Get(),
+ base::SequencedTaskRunner::GetCurrentDefault(),
component.crx_component()->pk_hash,
#if defined(IN_MEMORY_UPDATES)
component.installation_dir_,
@@ -1145,7 +1146,7 @@
void Component::StateUpdating::InstallComplete(ErrorCategory error_category,
int error_code,
int extra_code1) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = Component::State::component();
@@ -1170,15 +1171,15 @@
Component::StateUpdated::StateUpdated(Component* component)
: State(component, ComponentState::kUpdated) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
Component::StateUpdated::~StateUpdated() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void Component::StateUpdated::DoHandle() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = State::component();
DCHECK(component.crx_component());
@@ -1194,15 +1195,15 @@
Component::StateUninstalled::StateUninstalled(Component* component)
: State(component, ComponentState::kUninstalled) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
Component::StateUninstalled::~StateUninstalled() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void Component::StateUninstalled::DoHandle() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = State::component();
DCHECK(component.crx_component());
@@ -1216,11 +1217,11 @@
: State(component, ComponentState::kRun) {}
Component::StateRun::~StateRun() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void Component::StateRun::DoHandle() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const auto& component = State::component();
DCHECK(component.crx_component());
@@ -1233,7 +1234,7 @@
void Component::StateRun::ActionRunComplete(bool succeeded,
int error_code,
int extra_code1) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto& component = State::component();
diff --git a/components/update_client/component.h b/components/update_client/component.h
index d5d9e43..b763f7d 100644
--- a/components/update_client/component.h
+++ b/components/update_client/component.h
@@ -11,13 +11,14 @@
#include <utility>
#include <vector>
+#include "base/values.h"
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/optional.h"
-#include "base/threading/thread_checker.h"
+#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "base/version.h"
#include "components/update_client/crx_downloader.h"
@@ -127,10 +128,10 @@
std::string session_id() const;
- const std::vector<base::Value>& events() const { return events_; }
+ const std::vector<base::Value::Dict>& events() const { return events_; }
// Returns a clone of the component events.
- std::vector<base::Value> GetEvents() const;
+ std::vector<base::Value::Dict> GetEvents() const;
private:
#if defined(STARBOARD)
@@ -218,7 +219,7 @@
Component& component() { return component_; }
const Component& component() const { return component_; }
- base::ThreadChecker thread_checker_;
+ SEQUENCE_CHECKER(sequence_checker_);
const ComponentState state_;
@@ -422,7 +423,7 @@
// by a downloader which can do bandwidth throttling on the client side.
bool CanDoBackgroundDownload() const;
- void AppendEvent(base::Value event);
+ void AppendEvent(base::Value::Dict event);
// Changes the component state and notifies the caller of the |Handle|
// function that the handling of this component state is complete.
@@ -435,15 +436,15 @@
// These functions return a specific event. Each data member of the event is
// represented as a key-value pair in a dictionary value.
- base::Value MakeEventUpdateComplete() const;
- base::Value MakeEventDownloadMetrics(
+ base::Value::Dict MakeEventUpdateComplete() const;
+ base::Value::Dict MakeEventDownloadMetrics(
const CrxDownloader::DownloadMetrics& download_metrics) const;
- base::Value MakeEventUninstalled() const;
- base::Value MakeEventActionRun(bool succeeded,
+ base::Value::Dict MakeEventUninstalled() const;
+ base::Value::Dict MakeEventActionRun(bool succeeded,
int error_code,
int extra_code1) const;
- base::ThreadChecker thread_checker_;
+ SEQUENCE_CHECKER(sequence_checker_);
const std::string id_;
base::Optional<CrxComponent> crx_component_;
@@ -513,7 +514,7 @@
int diff_extra_code1_ = 0;
// Contains the events which are therefore serialized in the requests.
- std::vector<base::Value> events_;
+ std::vector<base::Value::Dict> events_;
CallbackHandleComplete callback_handle_complete_;
std::unique_ptr<State> state_;
diff --git a/components/update_client/component_patcher.cc b/components/update_client/component_patcher.cc
index ba81f1d..93f5ec4 100644
--- a/components/update_client/component_patcher.cc
+++ b/components/update_client/component_patcher.cc
@@ -14,7 +14,7 @@
#include "base/json/json_file_value_serializer.h"
#include "base/location.h"
#include "base/memory/weak_ptr.h"
-#include "base/threading/sequenced_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/values.h"
#include "components/update_client/component_patcher_operation.h"
#include "components/update_client/patcher.h"
@@ -27,19 +27,20 @@
// Deserialize the commands file (present in delta update packages). The top
// level must be a list.
-base::ListValue* ReadCommands(const base::FilePath& unpack_path) {
+absl::optional<base::Value::List> ReadCommands(
+ const base::FilePath& unpack_path) {
const base::FilePath commands =
unpack_path.Append(FILE_PATH_LITERAL("commands.json"));
if (!base::PathExists(commands))
- return nullptr;
+ return absl::nullopt;
JSONFileValueDeserializer deserializer(commands);
std::unique_ptr<base::Value> root =
deserializer.Deserialize(nullptr, nullptr);
return (root.get() && root->is_list())
- ? static_cast<base::ListValue*>(root.release())
- : nullptr;
+ ? absl::make_optional(std::move(*root).TakeList())
+ : absl::nullopt;
}
} // namespace
@@ -58,13 +59,13 @@
void ComponentPatcher::Start(Callback callback) {
callback_ = std::move(callback);
- base::SequencedTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&ComponentPatcher::StartPatching,
scoped_refptr<ComponentPatcher>(this)));
}
void ComponentPatcher::StartPatching() {
- commands_.reset(ReadCommands(input_dir_));
+ commands_ = ReadCommands(input_dir_);
if (!commands_) {
DonePatching(UnpackerError::kDeltaBadCommands, 0);
} else {
@@ -78,15 +79,14 @@
DonePatching(UnpackerError::kNone, 0);
return;
}
- const base::DictionaryValue* command_args;
- if (!next_command_->GetAsDictionary(&command_args)) {
+ if (!next_command_->is_dict()) {
DonePatching(UnpackerError::kDeltaBadCommands, 0);
return;
}
+ const base::Value::Dict& command_args = next_command_->GetDict();
- std::string operation;
- if (command_args->GetString(kOp, &operation)) {
- current_operation_ = CreateDeltaUpdateOp(operation, patcher_);
+ if (const std::string* operation = command_args.FindString(kOp)) {
+ current_operation_ = CreateDeltaUpdateOp(*operation, patcher_);
}
if (!current_operation_) {
@@ -111,7 +111,7 @@
void ComponentPatcher::DonePatching(UnpackerError error, int extended_error) {
current_operation_ = nullptr;
- base::SequencedTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback_), error, extended_error));
}
diff --git a/components/update_client/component_patcher.h b/components/update_client/component_patcher.h
index e31a812..8352cb1 100644
--- a/components/update_client/component_patcher.h
+++ b/components/update_client/component_patcher.h
@@ -29,7 +29,7 @@
#include <memory>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/values.h"
@@ -91,8 +91,8 @@
scoped_refptr<CrxInstaller> installer_;
scoped_refptr<Patcher> patcher_;
Callback callback_;
- std::unique_ptr<base::ListValue> commands_;
- base::ListValue::const_iterator next_command_;
+ absl::optional<base::Value::List> commands_;
+ base::Value::List::const_iterator next_command_;
scoped_refptr<DeltaUpdateOp> current_operation_;
DISALLOW_COPY_AND_ASSIGN(ComponentPatcher);
diff --git a/components/update_client/component_patcher_operation.cc b/components/update_client/component_patcher_operation.cc
index fe5411d..509652e 100644
--- a/components/update_client/component_patcher_operation.cc
+++ b/components/update_client/component_patcher_operation.cc
@@ -13,8 +13,7 @@
#include "base/files/memory_mapped_file.h"
#include "base/location.h"
#include "base/strings/string_number_conversions.h"
-#include "base/task/post_task.h"
-#include "base/threading/sequenced_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/courgette/courgette.h"
#include "components/courgette/third_party/bsdiff/bsdiff.h"
#include "components/update_client/patcher.h"
@@ -59,21 +58,22 @@
DeltaUpdateOp::~DeltaUpdateOp() {
}
-void DeltaUpdateOp::Run(const base::DictionaryValue* command_args,
+void DeltaUpdateOp::Run(const base::Value::Dict& command_args,
const base::FilePath& input_dir,
const base::FilePath& unpack_dir,
scoped_refptr<CrxInstaller> installer,
ComponentPatcher::Callback callback) {
callback_ = std::move(callback);
- std::string output_rel_path;
- if (!command_args->GetString(kOutput, &output_rel_path) ||
- !command_args->GetString(kSha256, &output_sha256_)) {
+ const std::string* output_rel_path = command_args.FindString(kOutput);
+ const std::string* sha256_value = command_args.FindString(kSha256);
+ if (!output_rel_path || !sha256_value) {
DoneRunning(UnpackerError::kDeltaBadCommands, 0);
return;
}
+ output_sha256_ = *sha256_value;
output_abs_path_ =
- unpack_dir.Append(base::FilePath::FromUTF8Unsafe(output_rel_path));
+ unpack_dir.Append(base::FilePath::FromUTF8Unsafe(*output_rel_path));
UnpackerError parse_result =
DoParseArguments(command_args, input_dir, installer);
if (parse_result != UnpackerError::kNone) {
@@ -96,7 +96,7 @@
void DeltaUpdateOp::DoneRunning(UnpackerError error, int extended_error) {
if (error == UnpackerError::kNone)
error = CheckHash();
- base::SequencedTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback_), error, extended_error));
}
@@ -121,14 +121,14 @@
}
UnpackerError DeltaUpdateOpCopy::DoParseArguments(
- const base::DictionaryValue* command_args,
+ const base::Value::Dict& command_args,
const base::FilePath& input_dir,
scoped_refptr<CrxInstaller> installer) {
- std::string input_rel_path;
- if (!command_args->GetString(kInput, &input_rel_path))
+ const std::string* input_rel_path = command_args.FindString(kInput);
+ if (!input_rel_path)
return UnpackerError::kDeltaBadCommands;
- if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_))
+ if (!installer->GetInstalledFile(*input_rel_path, &input_abs_path_))
return UnpackerError::kDeltaMissingExistingFile;
return UnpackerError::kNone;
@@ -148,15 +148,15 @@
}
UnpackerError DeltaUpdateOpCreate::DoParseArguments(
- const base::DictionaryValue* command_args,
+ const base::Value::Dict& command_args,
const base::FilePath& input_dir,
scoped_refptr<CrxInstaller> installer) {
- std::string patch_rel_path;
- if (!command_args->GetString(kPatch, &patch_rel_path))
+ const std::string* patch_rel_path = command_args.FindString(kPatch);
+ if (!patch_rel_path)
return UnpackerError::kDeltaBadCommands;
patch_abs_path_ =
- input_dir.Append(base::FilePath::FromUTF8Unsafe(patch_rel_path));
+ input_dir.Append(base::FilePath::FromUTF8Unsafe(*patch_rel_path));
return UnpackerError::kNone;
}
@@ -182,20 +182,19 @@
}
UnpackerError DeltaUpdateOpPatch::DoParseArguments(
- const base::DictionaryValue* command_args,
+ const base::Value::Dict& command_args,
const base::FilePath& input_dir,
scoped_refptr<CrxInstaller> installer) {
- std::string patch_rel_path;
- std::string input_rel_path;
- if (!command_args->GetString(kPatch, &patch_rel_path) ||
- !command_args->GetString(kInput, &input_rel_path))
+ const std::string* patch_rel_path = command_args.FindString(kPatch);
+ const std::string* input_rel_path = command_args.FindString(kInput);
+ if (!patch_rel_path || !input_rel_path)
return UnpackerError::kDeltaBadCommands;
- if (!installer->GetInstalledFile(input_rel_path, &input_abs_path_))
+ if (!installer->GetInstalledFile(*input_rel_path, &input_abs_path_))
return UnpackerError::kDeltaMissingExistingFile;
patch_abs_path_ =
- input_dir.Append(base::FilePath::FromUTF8Unsafe(patch_rel_path));
+ input_dir.Append(base::FilePath::FromUTF8Unsafe(*patch_rel_path));
return UnpackerError::kNone;
}
diff --git a/components/update_client/component_patcher_operation.h b/components/update_client/component_patcher_operation.h
index 0649ff9..546e14b 100644
--- a/components/update_client/component_patcher_operation.h
+++ b/components/update_client/component_patcher_operation.h
@@ -36,7 +36,7 @@
// Parses, runs, and verifies the operation. Calls |callback| with the
// result of the operation. The callback is called using |task_runner|.
- void Run(const base::DictionaryValue* command_args,
+ void Run(const base::Value::Dict& command_args,
const base::FilePath& input_dir,
const base::FilePath& unpack_dir,
scoped_refptr<CrxInstaller> installer,
@@ -57,7 +57,7 @@
// arguments. DoParseArguments returns DELTA_OK on success; any other code
// represents failure.
virtual UnpackerError DoParseArguments(
- const base::DictionaryValue* command_args,
+ const base::Value::Dict& command_args,
const base::FilePath& input_dir,
scoped_refptr<CrxInstaller> installer) = 0;
@@ -88,7 +88,7 @@
// Overrides of DeltaUpdateOp.
UnpackerError DoParseArguments(
- const base::DictionaryValue* command_args,
+ const base::Value::Dict& command_args,
const base::FilePath& input_dir,
scoped_refptr<CrxInstaller> installer) override;
@@ -112,7 +112,7 @@
// Overrides of DeltaUpdateOp.
UnpackerError DoParseArguments(
- const base::DictionaryValue* command_args,
+ const base::Value::Dict& command_args,
const base::FilePath& input_dir,
scoped_refptr<CrxInstaller> installer) override;
@@ -137,7 +137,7 @@
// Overrides of DeltaUpdateOp.
UnpackerError DoParseArguments(
- const base::DictionaryValue* command_args,
+ const base::Value::Dict& command_args,
const base::FilePath& input_dir,
scoped_refptr<CrxInstaller> installer) override;
diff --git a/components/update_client/component_unpacker.cc b/components/update_client/component_unpacker.cc
index 6a1db54..e77146a 100644
--- a/components/update_client/component_unpacker.cc
+++ b/components/update_client/component_unpacker.cc
@@ -19,7 +19,7 @@
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
-#include "base/threading/sequenced_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/crx_file/crx_verifier.h"
#include "components/update_client/component_patcher.h"
#include "components/update_client/patcher.h"
@@ -159,13 +159,13 @@
}
patcher_ = base::MakeRefCounted<ComponentPatcher>(
unpack_diff_path_, unpack_path_, installer_, patcher_tool_);
- base::SequencedTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(&ComponentPatcher::Start, patcher_,
base::BindOnce(&ComponentUnpacker::EndPatching,
scoped_refptr<ComponentUnpacker>(this))));
} else {
- base::SequencedTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&ComponentUnpacker::EndPatching,
scoped_refptr<ComponentUnpacker>(this),
UnpackerError::kNone, 0));
@@ -197,7 +197,7 @@
result.public_key = public_key_;
}
- base::SequencedTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback_), result));
}
diff --git a/components/update_client/component_unpacker_unittest.cc b/components/update_client/component_unpacker_unittest.cc
index dabe4bf..9a4f280 100644
--- a/components/update_client/component_unpacker_unittest.cc
+++ b/components/update_client/component_unpacker_unittest.cc
@@ -16,8 +16,7 @@
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
-#include "base/task/post_task.h"
-#include "base/test/scoped_task_environment.h"
+#include "base/test/task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/crx_file/crx_verifier.h"
#include "components/update_client/component_unpacker.h"
@@ -78,9 +77,9 @@
protected:
void RunThreads();
- base::test::ScopedTaskEnvironment scoped_task_environment_;
- const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_ =
- base::ThreadTaskRunnerHandle::Get();
+ base::test::TaskEnvironment scoped_task_environment_;
+ const scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner_ =
+ base::SequencedTaskRunner::GetCurrentDefault();
base::RunLoop runloop_;
base::OnceClosure quit_closure_ = runloop_.QuitClosure();
diff --git a/components/update_client/configurator.h b/components/update_client/configurator.h
index f55a325..3932b8d 100644
--- a/components/update_client/configurator.h
+++ b/components/update_client/configurator.h
@@ -10,7 +10,7 @@
#include <tuple>
#include <vector>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/containers/flat_map.h"
#include "base/memory/ref_counted.h"
diff --git a/components/update_client/crx_downloader.cc b/components/update_client/crx_downloader.cc
index 76ce53e..b40925e 100644
--- a/components/update_client/crx_downloader.cc
+++ b/components/update_client/crx_downloader.cc
@@ -10,9 +10,9 @@
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/logging.h"
-#include "base/task/post_task.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/task/task_traits.h"
-#include "base/threading/thread_task_runner_handle.h"
+#include "base/task/thread_pool.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include "components/update_client/background_downloader_win.h"
@@ -60,7 +60,7 @@
}
CrxDownloader::CrxDownloader(std::unique_ptr<CrxDownloader> successor)
- : main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
+ : main_task_runner_(base::SequencedTaskRunner::GetCurrentDefault()),
successor_(std::move(successor)) {
#if defined(STARBOARD)
LOG(INFO) << "CrxDownloader::CrxDownloader";
@@ -119,7 +119,7 @@
std::string* dst,
#endif
DownloadCallback download_callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(IN_MEMORY_UPDATES)
CHECK(dst != nullptr);
#endif
@@ -166,12 +166,12 @@
bool is_handled,
const Result& result,
const DownloadMetrics& download_metrics) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "CrxDownloader::OnDownloadComplete";
#endif
if (!result.error)
- base::PostTaskWithTraits(
+ base::ThreadPool::PostTask(
FROM_HERE, kTaskTraits,
base::BindOnce(&CrxDownloader::VerifyResponse, base::Unretained(this),
is_handled, result, download_metrics));
@@ -183,7 +183,7 @@
}
void CrxDownloader::OnDownloadProgress() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (progress_callback_.is_null())
return;
@@ -241,7 +241,7 @@
bool is_handled,
const Result& result,
const DownloadMetrics& download_metrics) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_NE(0, result.error);
#if !defined(IN_MEMORY_UPDATES)
DCHECK(result.response.empty());
diff --git a/components/update_client/crx_downloader.h b/components/update_client/crx_downloader.h
index 6263a41..9d311b9 100644
--- a/components/update_client/crx_downloader.h
+++ b/components/update_client/crx_downloader.h
@@ -15,8 +15,8 @@
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/single_thread_task_runner.h"
-#include "base/threading/thread_checker.h"
+#include "base/sequence_checker.h"
+#include "base/task/sequenced_task_runner.h"
#include "url/gurl.h"
#if defined(STARBOARD)
@@ -170,7 +170,7 @@
// Returns the url which is currently being downloaded from.
GURL url() const;
- scoped_refptr<base::SingleThreadTaskRunner> main_task_runner() const {
+ scoped_refptr<base::SequencedTaskRunner> main_task_runner() const {
return main_task_runner_;
}
@@ -192,10 +192,10 @@
const Result& result,
const DownloadMetrics& download_metrics);
- base::ThreadChecker thread_checker_;
+ SEQUENCE_CHECKER(sequence_checker_);
// Used to post callbacks to the main thread.
- scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
+ scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
std::vector<GURL> urls_;
diff --git a/components/update_client/crx_downloader_unittest.cc b/components/update_client/crx_downloader_unittest.cc
index 5b48093..e5dccb7 100644
--- a/components/update_client/crx_downloader_unittest.cc
+++ b/components/update_client/crx_downloader_unittest.cc
@@ -13,9 +13,9 @@
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
#include "base/run_loop.h"
-#include "base/test/bind_test_util.h"
-#include "base/test/scoped_task_environment.h"
-#include "base/threading/thread_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
+#include "base/test/bind.h"
+#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "components/update_client/net/network_chromium.h"
#include "components/update_client/update_client_errors.h"
@@ -107,7 +107,7 @@
static const int kExpectedContext = 0xaabb;
private:
- base::test::ScopedTaskEnvironment scoped_task_environment_;
+ base::test::TaskEnvironment task_environment_;
#if defined(STARBOARD)
scoped_refptr<net::TestURLRequestContextGetter> context_;
#else
@@ -129,11 +129,11 @@
crx_context_(0),
num_download_complete_calls_(0),
num_progress_calls_(0),
- scoped_task_environment_(
- base::test::ScopedTaskEnvironment::MainThreadType::IO),
+ task_environment_(
+ base::test::TaskEnvironment::MainThreadType::IO),
#if defined(STARBOARD)
context_(base::MakeRefCounted<net::TestURLRequestContextGetter>(
- base::ThreadTaskRunnerHandle::Get())) {
+ base::SequencedTaskRunner::GetCurrentDefault())) {
}
CrxDownloaderTest::~CrxDownloaderTest() {
@@ -162,7 +162,8 @@
crx_downloader_->set_progress_callback(progress_callback_);
get_interceptor_ = std::make_unique<GetInterceptor>(
- base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get());
+ base::SequencedTaskRunner::GetCurrentDefault(),
+ base::SequencedTaskRunner::GetCurrentDefault());
#else
crx_downloader_ = CrxDownloader::Create(
false, base::MakeRefCounted<NetworkFetcherChromiumFactory>(
@@ -228,7 +229,7 @@
}
void CrxDownloaderTest::RunThreadsUntilIdle() {
- scoped_task_environment_.RunUntilIdle();
+ task_environment_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
}
diff --git a/components/update_client/net/network_impl_cobalt.cc b/components/update_client/net/network_impl_cobalt.cc
index 853d2de..a64a61d 100644
--- a/components/update_client/net/network_impl_cobalt.cc
+++ b/components/update_client/net/network_impl_cobalt.cc
@@ -19,11 +19,13 @@
#include "base/bind.h"
#include "base/callback.h"
-#include "base/callback_helpers.h"
+#include "base/functional/callback_helpers.h"
+#include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h"
#include "cobalt/base/polymorphic_downcast.h"
#include "cobalt/loader/url_fetcher_string_writer.h"
#include "components/update_client/net/network_cobalt.h"
+#include "net/base/net_errors.h"
namespace {
@@ -183,25 +185,26 @@
void NetworkFetcherCobaltImpl::OnURLFetchComplete(
const net::URLFetcher* source) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
- const net::URLRequestStatus& status = source->GetStatus();
+ LOG(INFO) << "cobalt::updater::NetworkFetcher::OnURLFetchComplete";
+ const net::Error status = source->GetStatus();
const int response_code = source->GetResponseCode();
if (url_fetcher_type_ == kUrlFetcherTypePostRequest) {
- OnPostRequestComplete(source, status.error());
+ OnPostRequestComplete(source, status);
#if defined(IN_MEMORY_UPDATES)
} else if (url_fetcher_type_ == kUrlFetcherTypeDownloadToString) {
- OnDownloadToStringComplete(source, status.error());
+ OnDownloadToStringComplete(source, status);
}
#else
} else if (url_fetcher_type_ == kUrlFetcherTypeDownloadToFile) {
- OnDownloadToFileComplete(source, status.error());
+ OnDownloadToFileComplete(source, status);
}
#endif
- if (!status.is_success() || !IsResponseCodeSuccess(response_code)) {
- std::string msg(base::StringPrintf(
- "NetworkFetcher error on %s : %s, response code %d",
- source->GetURL().spec().c_str(),
- net::ErrorToString(status.error()).c_str(), response_code));
+ if (status != net::OK || !IsResponseCodeSuccess(response_code)) {
+ std::string msg(
+ base::StringPrintf("NetworkFetcher error on %s : %s, response code %d",
+ source->GetURL().spec().c_str(),
+ net::ErrorToString(status).c_str(), response_code));
return HandleError(msg).InvalidateThis();
}
url_fetcher_.reset();
@@ -230,9 +233,9 @@
// Request mode is kCORSModeOmitCredentials.
const uint32 kDisableCookiesAndCacheLoadFlags =
net::LOAD_NORMAL | net::LOAD_DO_NOT_SAVE_COOKIES |
- net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA |
net::LOAD_DISABLE_CACHE;
url_fetcher_->SetLoadFlags(kDisableCookiesAndCacheLoadFlags);
+ url_fetcher_->SetAllowCredentials(false);
url_fetcher_->SetAutomaticallyRetryOnNetworkChanges(
kMaxRetriesOnNetworkChange);
diff --git a/components/update_client/net/network_impl_cobalt.h b/components/update_client/net/network_impl_cobalt.h
index d6181ad..e9ffe8e 100644
--- a/components/update_client/net/network_impl_cobalt.h
+++ b/components/update_client/net/network_impl_cobalt.h
@@ -24,9 +24,9 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/threading/thread_checker.h"
+#include "cobalt/network/custom/url_fetcher_delegate.h"
#include "cobalt/network/network_module.h"
#include "components/update_client/network.h"
-#include "net/url_request/url_fetcher_delegate.h"
namespace base {
diff --git a/components/update_client/net/url_loader_post_interceptor.cc b/components/update_client/net/url_loader_post_interceptor.cc
index 11a2af8..6ddd2c5 100644
--- a/components/update_client/net/url_loader_post_interceptor.cc
+++ b/components/update_client/net/url_loader_post_interceptor.cc
@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/test/bind_test_util.h"
#include "components/update_client/test_configurator.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
@@ -120,7 +121,7 @@
void URLLoaderPostInterceptor::Resume() {
is_paused_ = false;
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindLambdaForTesting([&]() {
if (!pending_expectations_.size())
return;
@@ -182,7 +183,7 @@
const std::string response_body(expectation.second.response_body);
if (url_job_request_ready_callback_) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, std::move(url_job_request_ready_callback_));
}
diff --git a/components/update_client/net/url_request_post_interceptor.cc b/components/update_client/net/url_request_post_interceptor.cc
index e5a539f..e562f51 100644
--- a/components/update_client/net/url_request_post_interceptor.cc
+++ b/components/update_client/net/url_request_post_interceptor.cc
@@ -10,7 +10,7 @@
#include "base/files/file_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/sequenced_task_runner.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/strings/stringprintf.h"
#include "components/update_client/test_configurator.h"
#include "net/base/upload_bytes_element_reader.h"
@@ -20,7 +20,6 @@
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_filter.h"
#include "net/url_request/url_request_interceptor.h"
-#include "net/url_request/url_request_simple_job.h"
#include "net/url_request/url_request_test_util.h"
namespace update_client {
diff --git a/components/update_client/network.h b/components/update_client/network.h
index b6b179d..ec83785 100644
--- a/components/update_client/network.h
+++ b/components/update_client/network.h
@@ -10,7 +10,7 @@
#include <memory>
#include <string>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
diff --git a/components/update_client/patcher.h b/components/update_client/patcher.h
index 1316d26..dcf3805 100644
--- a/components/update_client/patcher.h
+++ b/components/update_client/patcher.h
@@ -5,7 +5,7 @@
#ifndef COMPONENTS_UPDATE_CLIENT_PATCHER_H_
#define COMPONENTS_UPDATE_CLIENT_PATCHER_H_
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
diff --git a/components/update_client/persisted_data.cc b/components/update_client/persisted_data.cc
index bf922fd..bf68388 100644
--- a/components/update_client/persisted_data.cc
+++ b/components/update_client/persisted_data.cc
@@ -27,44 +27,40 @@
activity_data_service_(activity_data_service) {}
PersistedData::~PersistedData() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
int PersistedData::GetInt(const std::string& id,
const std::string& key,
int fallback) const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// We assume ids do not contain '.' characters.
DCHECK_EQ(std::string::npos, id.find('.'));
if (!pref_service_)
return fallback;
- const base::DictionaryValue* dict =
+ const base::Value::Dict* dict =
pref_service_->GetDictionary(kPersistedDataPreference);
if (!dict)
return fallback;
- int result = 0;
- return dict->GetInteger(
- base::StringPrintf("apps.%s.%s", id.c_str(), key.c_str()), &result)
- ? result
- : fallback;
+ absl::optional<int> result = dict->FindInt(
+ base::StringPrintf("apps.%s.%s", id.c_str(), key.c_str()));
+ return result.value_or(fallback);
}
std::string PersistedData::GetString(const std::string& id,
const std::string& key) const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// We assume ids do not contain '.' characters.
DCHECK_EQ(std::string::npos, id.find('.'));
if (!pref_service_)
return std::string();
- const base::DictionaryValue* dict =
+ const base::Value::Dict* dict =
pref_service_->GetDictionary(kPersistedDataPreference);
if (!dict)
return std::string();
- std::string result;
- return dict->GetString(
- base::StringPrintf("apps.%s.%s", id.c_str(), key.c_str()), &result)
- ? result
- : std::string();
+ const std::string* result = dict->FindString(
+ base::StringPrintf("apps.%s.%s", id.c_str(), key.c_str()));
+ return result != nullptr ? *result : std::string();
}
int PersistedData::GetDateLastRollCall(const std::string& id) const {
@@ -88,14 +84,12 @@
return GetString(id, "updaterchannel");
}
std::string PersistedData::GetLatestChannel() const {
- const base::DictionaryValue* dict =
+ const base::Value::Dict* dict =
pref_service_->GetDictionary(kPersistedDataPreference);
if (!dict)
return std::string();
- std::string result;
- return dict->GetString("latestchannel", &result)
- ? result
- : std::string();
+ const std::string* result = dict->FindString("latestchannel");
+ return result != nullptr ? *result : std::string();
}
#endif
@@ -113,30 +107,30 @@
void PersistedData::SetDateLastRollCall(const std::vector<std::string>& ids,
int datenum) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!pref_service_ || datenum < 0)
return;
- DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
+ ScopedDictPrefUpdate update(pref_service_, kPersistedDataPreference);
for (const auto& id : ids) {
// We assume ids do not contain '.' characters.
DCHECK_EQ(std::string::npos, id.find('.'));
- update->SetInteger(base::StringPrintf("apps.%s.dlrc", id.c_str()), datenum);
- update->SetString(base::StringPrintf("apps.%s.pf", id.c_str()),
+ update->Set(base::StringPrintf("apps.%s.dlrc", id.c_str()), datenum);
+ update->Set(base::StringPrintf("apps.%s.pf", id.c_str()),
base::GenerateGUID());
}
}
void PersistedData::SetDateLastActive(const std::vector<std::string>& ids,
int datenum) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!pref_service_ || datenum < 0)
return;
- DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
+ ScopedDictPrefUpdate update(pref_service_, kPersistedDataPreference);
for (const auto& id : ids) {
if (GetActiveBit(id)) {
// We assume ids do not contain '.' characters.
DCHECK_EQ(std::string::npos, id.find('.'));
- update->SetInteger(base::StringPrintf("apps.%s.dla", id.c_str()),
+ update->Set(base::StringPrintf("apps.%s.dla", id.c_str()),
datenum);
activity_data_service_->ClearActiveBit(id);
}
@@ -146,11 +140,11 @@
void PersistedData::SetString(const std::string& id,
const std::string& key,
const std::string& value) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!pref_service_)
return;
- DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
- update->SetString(base::StringPrintf("apps.%s.%s", id.c_str(), key.c_str()),
+ ScopedDictPrefUpdate update(pref_service_, kPersistedDataPreference);
+ update->Set(base::StringPrintf("apps.%s.%s", id.c_str(), key.c_str()),
value);
}
@@ -164,11 +158,11 @@
SetString(id, "updaterchannel", channel);
}
void PersistedData::SetLatestChannel(const std::string& channel) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!pref_service_)
return;
- DictionaryPrefUpdate update(pref_service_, kPersistedDataPreference);
- update->SetString("latestchannel", channel);
+ ScopedDictPrefUpdate update(pref_service_, kPersistedDataPreference);
+ update->Set("latestchannel", channel);
}
#endif
@@ -192,14 +186,14 @@
}
int PersistedData::GetDaysSinceLastRollCall(const std::string& id) const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return activity_data_service_
? activity_data_service_->GetDaysSinceLastRollCall(id)
: kDaysUnknown;
}
int PersistedData::GetDaysSinceLastActive(const std::string& id) const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return activity_data_service_
? activity_data_service_->GetDaysSinceLastActive(id)
: kDaysUnknown;
diff --git a/components/update_client/persisted_data.h b/components/update_client/persisted_data.h
index 6a35594..715cb2b 100644
--- a/components/update_client/persisted_data.h
+++ b/components/update_client/persisted_data.h
@@ -9,7 +9,7 @@
#include <vector>
#include "base/macros.h"
-#include "base/threading/thread_checker.h"
+#include "base/sequence_checker.h"
#include "base/values.h"
class PrefRegistrySimple;
@@ -133,7 +133,7 @@
const std::string& key,
const std::string& value);
- base::ThreadChecker thread_checker_;
+ SEQUENCE_CHECKER(sequence_checker_);
PrefService* pref_service_;
ActivityDataService* activity_data_service_;
diff --git a/components/update_client/ping_manager.cc b/components/update_client/ping_manager.cc
index a2486ef..811b3ac 100644
--- a/components/update_client/ping_manager.cc
+++ b/components/update_client/ping_manager.cc
@@ -15,7 +15,7 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
-#include "base/threading/thread_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/update_client/component.h"
#include "components/update_client/configurator.h"
#include "components/update_client/protocol_definition.h"
@@ -58,7 +58,7 @@
const std::string& response,
int retry_after_sec);
- THREAD_CHECKER(thread_checker_);
+ SEQUENCE_CHECKER(sequence_checker_);
const scoped_refptr<Configurator> config_;
Callback callback_;
@@ -70,18 +70,18 @@
PingSender::PingSender(scoped_refptr<Configurator> config) : config_(config) {}
PingSender::~PingSender() {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void PingSender::SendPing(const Component& component, Callback callback) {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "PingSender::SendPing";
#endif
if (component.events().empty()) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), kErrorNoEvents, ""));
return;
}
@@ -93,7 +93,7 @@
RemoveUnsecureUrls(&urls);
if (urls.empty()) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), kErrorNoUrl, ""));
return;
}
@@ -129,7 +129,7 @@
void PingSender::SendPingComplete(int error,
const std::string& response,
int retry_after_sec) {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::move(callback_).Run(error, response);
}
@@ -154,14 +154,14 @@
#endif
PingManager::~PingManager() {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "PingManager::~PingManager";
#endif
}
void PingManager::SendPing(const Component& component, Callback callback) {
- DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "PingManager::SendPing";
diff --git a/components/update_client/ping_manager.h b/components/update_client/ping_manager.h
index d049788..822a0ae 100644
--- a/components/update_client/ping_manager.h
+++ b/components/update_client/ping_manager.h
@@ -7,10 +7,10 @@
#include <string>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
+#include "base/sequence_checker.h"
namespace update_client {
@@ -44,7 +44,7 @@
private:
friend class base::RefCountedThreadSafe<PingManager>;
- THREAD_CHECKER(thread_checker_);
+ SEQUENCE_CHECKER(sequence_checker_);
const scoped_refptr<Configurator> config_;
#if defined(STARBOARD)
diff --git a/components/update_client/ping_manager_unittest.cc b/components/update_client/ping_manager_unittest.cc
index fe349f9..7dc3ec0 100644
--- a/components/update_client/ping_manager_unittest.cc
+++ b/components/update_client/ping_manager_unittest.cc
@@ -16,8 +16,8 @@
#include "base/json/json_reader.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/test/scoped_task_environment.h"
-#include "base/threading/thread_task_runner_handle.h"
#include "base/version.h"
#include "components/update_client/component.h"
#include "components/update_client/protocol_definition.h"
@@ -118,8 +118,8 @@
TEST_P(PingManagerTest, SendPing) {
#if defined(STARBOARD)
- auto interceptor_factory =
- std::make_unique<InterceptorFactory>(base::ThreadTaskRunnerHandle::Get());
+ auto interceptor_factory = std::make_unique<InterceptorFactory>(
+ base::SequencedTaskRunner::GetCurrentDefault());
auto interceptor = interceptor_factory->CreateInterceptor();
#else
auto interceptor = std::make_unique<URLLoaderPostInterceptor>(
diff --git a/components/update_client/protocol_definition.h b/components/update_client/protocol_definition.h
index aaacc76..0e0a536 100644
--- a/components/update_client/protocol_definition.h
+++ b/components/update_client/protocol_definition.h
@@ -113,7 +113,7 @@
base::Optional<Ping> ping;
// Progress/result pings.
- base::Optional<std::vector<base::Value>> events;
+ absl::optional<std::vector<base::Value::Dict>> events;
private:
DISALLOW_COPY_AND_ASSIGN(App);
diff --git a/components/update_client/protocol_parser.cc b/components/update_client/protocol_parser.cc
index 7f280c5..457a2cb 100644
--- a/components/update_client/protocol_parser.cc
+++ b/components/update_client/protocol_parser.cc
@@ -1,8 +1,11 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/update_client/protocol_parser.h"
+
+#include <string>
+
#include "base/strings/stringprintf.h"
namespace update_client {
@@ -31,6 +34,20 @@
default;
ProtocolParser::Result::Manifest::Package::~Package() = default;
+ProtocolParser::Result::Data::Data() = default;
+ProtocolParser::Result::Data::Data(const Data& other) = default;
+ProtocolParser::Result::Data& ProtocolParser::Result::Data::operator=(
+ const Data&) = default;
+ProtocolParser::Result::Data::Data(const std::string& status,
+ const std::string& name,
+ const std::string& install_data_index,
+ const std::string& text)
+ : status(status),
+ name(name),
+ install_data_index(install_data_index),
+ text(text) {}
+ProtocolParser::Result::Data::~Data() = default;
+
void ProtocolParser::ParseError(const char* details, ...) {
va_list args;
va_start(args, details);
diff --git a/components/update_client/protocol_parser.h b/components/update_client/protocol_parser.h
index 471fd6d..12e1d00 100644
--- a/components/update_client/protocol_parser.h
+++ b/components/update_client/protocol_parser.h
@@ -1,4 +1,4 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,7 +11,6 @@
#include <string>
#include <vector>
-#include "base/macros.h"
#include "url/gurl.h"
namespace update_client {
@@ -48,6 +47,39 @@
std::string version;
std::string browser_min_version;
std::vector<Package> packages;
+
+ // A path within the CRX archive to an executable to run as part of the
+ // update. The executable is typically an application installer.
+ std::string run;
+
+ // Command-line arguments for the binary specified by |run|.
+ std::string arguments;
+ };
+
+ // Optional `data` element.
+ struct Data {
+ Data();
+ Data(const Data& other);
+ Data& operator=(const Data&);
+ Data(const std::string& status,
+ const std::string& name,
+ const std::string& install_data_index,
+ const std::string& text);
+ ~Data();
+
+ // "ok" if the server could successfully find a match for the `data`
+ // element in the update request, or an error string otherwise.
+ std::string status;
+
+ // If `status` is "ok", this contains the `name`. The only value supported
+ // for `name` by the server currently is "install".
+ std::string name;
+
+ // The `install_data_index` specified by the update check.
+ std::string install_data_index;
+
+ // The server data corresponding to the `name`/`install_data_index pair`.
+ std::string text;
};
Result();
@@ -59,6 +91,11 @@
// The updatecheck response status.
std::string status;
+ // App-specific additions in the updatecheck response, including the
+ // mandatory '_' prefix (which prevents collision with formal protocol
+ // elements).
+ std::map<std::string, std::string> custom_attributes;
+
// The list of fallback urls, for full and diff updates respectively.
// These urls are base urls; they don't include the filename.
std::vector<GURL> crx_urls;
@@ -76,8 +113,31 @@
static const char kCohortName[];
// Contains the run action returned by the server as part of an update
- // check response.
+ // check response. This indicates the need to trigger the execution of
+ // something bound to a component which is already installed.
std::string action_run;
+
+ // Contains the data responses corresponding to the data elements specified
+ // in the update request.
+ std::vector<Data> data;
+ };
+
+ struct SystemRequirements {
+ std::string platform; // For example, "win".
+
+ // Expected host processor architecture that the app is compatible with.
+ // `arch` can be a single entry, or multiple entries separated with `,`.
+ // Entries prefixed with a `-` (negative entries) indicate non-compatible
+ // hosts.
+ //
+ // Examples:
+ // * `arch` == "x86".
+ // * `arch` == "x64".
+ // * `arch` == "x86,x64,-arm64": the app will fail installation if the
+ // underlying host is arm64.
+ std::string arch;
+
+ std::string min_os_version; // major.minor.
};
static const int kNoDaystart = -1;
@@ -91,11 +151,16 @@
// This will be >= 0, or kNoDaystart if the <daystart> tag was not present.
int daystart_elapsed_days = kNoDaystart;
+
+ SystemRequirements system_requirements;
std::vector<Result> list;
};
static std::unique_ptr<ProtocolParser> Create();
+ ProtocolParser(const ProtocolParser&) = delete;
+ ProtocolParser& operator=(const ProtocolParser&) = delete;
+
virtual ~ProtocolParser();
// Parses an update response string into Result data. Returns a bool
@@ -119,8 +184,6 @@
Results results_;
std::string errors_;
-
- DISALLOW_COPY_AND_ASSIGN(ProtocolParser);
};
} // namespace update_client
diff --git a/components/update_client/protocol_parser_json.cc b/components/update_client/protocol_parser_json.cc
index eb022e4..9858ba0 100644
--- a/components/update_client/protocol_parser_json.cc
+++ b/components/update_client/protocol_parser_json.cc
@@ -1,35 +1,46 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/update_client/protocol_parser_json.h"
+#include <string>
#include <utility>
+#include "base/check.h"
#include "base/json/json_reader.h"
+#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "base/version.h"
#include "components/update_client/protocol_definition.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
namespace update_client {
namespace {
-bool ParseManifest(const base::Value& manifest_node,
+std::string GetValueString(const base::Value::Dict& node, const char* key) {
+ const std::string* value = node.FindString(key);
+ return value ? *value : std::string();
+}
+
+bool ParseManifest(const base::Value& manifest_node_val,
ProtocolParser::Result* result,
std::string* error) {
- if (!manifest_node.is_dict()) {
+ if (!manifest_node_val.is_dict()) {
*error = "'manifest' is not a dictionary.";
+ return false;
}
- const auto* version = manifest_node.FindKey("version");
- if (!version || !version->is_string()) {
+ const base::Value::Dict& manifest_node = manifest_node_val.GetDict();
+ const std::string* version = manifest_node.FindString("version");
+ if (!version) {
*error = "Missing version for manifest.";
return false;
}
- result->manifest.version = version->GetString();
+ result->manifest.version = *version;
if (!base::Version(result->manifest.version).IsValid()) {
*error =
base::StrCat({"Invalid version: '", result->manifest.version, "'."});
@@ -37,9 +48,10 @@
}
// Get the optional minimum browser version.
- const auto* browser_min_version = manifest_node.FindKey("prodversionmin");
- if (browser_min_version && browser_min_version->is_string()) {
- result->manifest.browser_min_version = browser_min_version->GetString();
+ const std::string* browser_min_version =
+ manifest_node.FindString("prodversionmin");
+ if (browser_min_version) {
+ result->manifest.browser_min_version = *browser_min_version;
if (!base::Version(result->manifest.browser_min_version).IsValid()) {
*error = base::StrCat({"Invalid prodversionmin: '",
result->manifest.browser_min_version, "'."});
@@ -47,58 +59,51 @@
}
}
- const auto* packages_node = manifest_node.FindKey("packages");
- if (!packages_node || !packages_node->is_dict()) {
+ result->manifest.run = GetValueString(manifest_node, "run");
+ result->manifest.arguments = GetValueString(manifest_node, "arguments");
+
+ const base::Value::Dict* packages_node = manifest_node.FindDict("packages");
+ if (!packages_node) {
*error = "Missing packages in manifest or 'packages' is not a dictionary.";
return false;
}
- const auto* package_node = packages_node->FindKey("package");
- if (!package_node || !package_node->is_list()) {
+ const base::Value::List* package_node = packages_node->FindList("package");
+ if (!package_node) {
*error = "Missing package in packages.";
return false;
}
- for (const auto& package : package_node->GetList()) {
- if (!package.is_dict()) {
+ for (const auto& package_val : *package_node) {
+ if (!package_val.is_dict()) {
*error = "'package' is not a dictionary.";
return false;
}
+ const base::Value::Dict& package = package_val.GetDict();
ProtocolParser::Result::Manifest::Package p;
- const auto* name = package.FindKey("name");
- if (!name || !name->is_string()) {
+ const std::string* name = package.FindString("name");
+ if (!name) {
*error = "Missing name for package.";
return false;
}
- p.name = name->GetString();
+ p.name = *name;
- const auto* namediff = package.FindKey("namediff");
- if (namediff && namediff->is_string())
- p.namediff = namediff->GetString();
+ p.namediff = GetValueString(package, "namediff");
+ p.fingerprint = GetValueString(package, "fp");
+ p.hash_sha256 = GetValueString(package, "hash_sha256");
+ p.hashdiff_sha256 = GetValueString(package, "hashdiff_sha256");
- const auto* fingerprint = package.FindKey("fp");
- if (fingerprint && fingerprint->is_string())
- p.fingerprint = fingerprint->GetString();
-
- const auto* hash_sha256 = package.FindKey("hash_sha256");
- if (hash_sha256 && hash_sha256->is_string())
- p.hash_sha256 = hash_sha256->GetString();
-
- const auto* size = package.FindKey("size");
- if (size && (size->is_int() || size->is_double())) {
- const auto val = size->GetDouble();
+ const absl::optional<double> size = package.FindDouble("size");
+ if (size) {
+ const double val = size.value();
if (0 <= val && val < kProtocolMaxInt)
- p.size = size->GetDouble();
+ p.size = val;
}
- const auto* hashdiff_sha256 = package.FindKey("hashdiff_sha256");
- if (hashdiff_sha256 && hashdiff_sha256->is_string())
- p.hashdiff_sha256 = hashdiff_sha256->GetString();
-
- const auto* sizediff = package.FindKey("sizediff");
- if (sizediff && (sizediff->is_int() || sizediff->is_double())) {
- const auto val = sizediff->GetDouble();
+ const absl::optional<double> sizediff = package.FindDouble("sizediff");
+ if (sizediff) {
+ const double val = sizediff.value();
if (0 <= val && val < kProtocolMaxInt)
- p.sizediff = sizediff->GetDouble();
+ p.sizediff = val;
}
result->manifest.packages.push_back(std::move(p));
@@ -112,46 +117,51 @@
if (!actions_node.is_dict())
return;
- const auto* action_node = actions_node.FindKey("action");
- if (!action_node || !action_node->is_list())
+ const base::Value::List* action_node =
+ actions_node.GetDict().FindList("action");
+ if (!action_node) {
return;
+ }
- const auto& action_list = action_node->GetList();
+ const base::Value::List& action_list = *action_node;
if (action_list.empty() || !action_list[0].is_dict())
return;
- const auto* run = action_list[0].FindKey("run");
- if (run && run->is_string())
- result->action_run = run->GetString();
+ result->action_run = GetValueString(action_list[0].GetDict(), "run");
}
-bool ParseUrls(const base::Value& urls_node,
+bool ParseUrls(const base::Value& urls_node_val,
ProtocolParser::Result* result,
std::string* error) {
- if (!urls_node.is_dict()) {
+ if (!urls_node_val.is_dict()) {
*error = "'urls' is not a dictionary.";
return false;
}
- const auto* url_node = urls_node.FindKey("url");
- if (!url_node || !url_node->is_list()) {
+ const base::Value::Dict& urls_node = urls_node_val.GetDict();
+ const base::Value::List* url_node = urls_node.FindList("url");
+ if (!url_node) {
*error = "Missing url on urls.";
return false;
}
- for (const auto& url : url_node->GetList()) {
- if (!url.is_dict())
+ for (const base::Value& url_val : *url_node) {
+ if (!url_val.is_dict()) {
continue;
- const auto* codebase = url.FindKey("codebase");
- if (codebase && codebase->is_string()) {
- GURL crx_url(codebase->GetString());
- if (crx_url.is_valid())
- result->crx_urls.push_back(std::move(crx_url));
}
- const auto* codebasediff = url.FindKey("codebasediff");
- if (codebasediff && codebasediff->is_string()) {
- GURL crx_diffurl(codebasediff->GetString());
- if (crx_diffurl.is_valid())
+ const base::Value::Dict& url = url_val.GetDict();
+ const std::string* codebase = url.FindString("codebase");
+ if (codebase) {
+ GURL crx_url(*codebase);
+ if (crx_url.is_valid()) {
+ result->crx_urls.push_back(std::move(crx_url));
+ }
+ }
+ const std::string* codebasediff = url.FindString("codebasediff");
+ if (codebasediff) {
+ GURL crx_diffurl(*codebasediff);
+ if (crx_diffurl.is_valid()) {
result->crx_diffurls.push_back(std::move(crx_diffurl));
+ }
}
}
@@ -164,33 +174,53 @@
return true;
}
-bool ParseUpdateCheck(const base::Value& updatecheck_node,
+void ParseData(const base::Value& data_node_val,
+ ProtocolParser::Result* result) {
+ if (!data_node_val.is_dict()) {
+ return;
+ }
+ const base::Value::Dict& data_node = data_node_val.GetDict();
+
+ result->data.emplace_back(
+ GetValueString(data_node, "status"), GetValueString(data_node, "name"),
+ GetValueString(data_node, "index"), GetValueString(data_node, "#text"));
+}
+
+bool ParseUpdateCheck(const base::Value& updatecheck_node_val,
ProtocolParser::Result* result,
std::string* error) {
- if (!updatecheck_node.is_dict()) {
+ if (!updatecheck_node_val.is_dict()) {
*error = "'updatecheck' is not a dictionary.";
return false;
}
- const auto* status = updatecheck_node.FindKey("status");
- if (!status || !status->is_string()) {
+ const base::Value::Dict& updatecheck_node = updatecheck_node_val.GetDict();
+
+ for (auto kv : updatecheck_node) {
+ if (kv.first.front() == '_' && kv.second.is_string()) {
+ result->custom_attributes[kv.first] = kv.second.GetString();
+ }
+ }
+
+ const std::string* status = updatecheck_node.FindString("status");
+ if (!status) {
*error = "Missing status on updatecheck node";
return false;
}
- result->status = status->GetString();
+ result->status = *status;
if (result->status == "noupdate") {
- const auto* actions_node = updatecheck_node.FindKey("actions");
+ const auto* actions_node = updatecheck_node.Find("actions");
if (actions_node)
ParseActions(*actions_node, result);
return true;
}
if (result->status == "ok") {
- const auto* actions_node = updatecheck_node.FindKey("actions");
+ const auto* actions_node = updatecheck_node.Find("actions");
if (actions_node)
ParseActions(*actions_node, result);
- const auto* urls_node = updatecheck_node.FindKey("urls");
+ const auto* urls_node = updatecheck_node.Find("urls");
if (!urls_node) {
*error = "Missing urls on updatecheck.";
return false;
@@ -199,7 +229,7 @@
if (!ParseUrls(*urls_node, result, error))
return false;
- const auto* manifest_node = updatecheck_node.FindKey("manifest");
+ const auto* manifest_node = updatecheck_node.Find("manifest");
if (!manifest_node) {
*error = "Missing manifest on updatecheck.";
return false;
@@ -212,23 +242,26 @@
return false;
}
-bool ParseApp(const base::Value& app_node,
+bool ParseApp(const base::Value& app_node_val,
ProtocolParser::Result* result,
std::string* error) {
- if (!app_node.is_dict()) {
+ if (!app_node_val.is_dict()) {
*error = "'app' is not a dictionary.";
return false;
}
+ const base::Value::Dict& app_node = app_node_val.GetDict();
for (const auto* cohort_key :
{ProtocolParser::Result::kCohort, ProtocolParser::Result::kCohortHint,
ProtocolParser::Result::kCohortName}) {
- const auto* cohort_value = app_node.FindKey(cohort_key);
- if (cohort_value && cohort_value->is_string())
- result->cohort_attrs[cohort_key] = cohort_value->GetString();
+ const std::string* cohort_value = app_node.FindString(cohort_key);
+ if (cohort_value) {
+ result->cohort_attrs[cohort_key] = *cohort_value;
+ }
}
- const auto* appid = app_node.FindKey("appid");
- if (appid && appid->is_string())
- result->extension_id = appid->GetString();
+ const std::string* appid = app_node.FindString("appid");
+ if (appid) {
+ result->extension_id = *appid;
+ }
if (result->extension_id.empty()) {
*error = "Missing appid on app node";
return false;
@@ -238,9 +271,9 @@
// If the status is one of the defined app status error literals, then return
// it in the result as if it were an updatecheck status, then stop parsing,
// and return success.
- const auto* status = app_node.FindKey("status");
- if (status && status->is_string()) {
- result->status = status->GetString();
+ const std::string* status = app_node.FindString("status");
+ if (status) {
+ result->status = *status;
if (result->status == "restricted" ||
result->status == "error-unknownApplication" ||
result->status == "error-invalidAppId")
@@ -254,8 +287,15 @@
}
}
- DCHECK(result->status.empty() || result->status == "ok");
- const auto* updatecheck_node = app_node.FindKey("updatecheck");
+ CHECK(result->status.empty() || result->status == "ok");
+
+ if (const base::Value::List* data_node = app_node.FindList("data")) {
+ base::ranges::for_each(*data_node, [&result](const base::Value& data) {
+ ParseData(data, result);
+ });
+ }
+
+ const auto* updatecheck_node = app_node.Find("updatecheck");
if (!updatecheck_node) {
*error = "Missing updatecheck on app.";
return false;
@@ -268,7 +308,7 @@
bool ProtocolParserJSON::DoParse(const std::string& response_json,
Results* results) {
- DCHECK(results);
+ CHECK(results);
if (response_json.empty()) {
ParseError("Empty JSON.");
@@ -282,9 +322,9 @@
ParseError("Missing secure JSON prefix.");
return false;
}
- const auto doc = base::JSONReader::Read(
- {response_json.begin() + std::char_traits<char>::length(kJSONPrefix),
- response_json.end()});
+ const auto doc = base::JSONReader::Read(base::MakeStringPiece(
+ response_json.begin() + std::char_traits<char>::length(kJSONPrefix),
+ response_json.end()));
if (!doc) {
ParseError("JSON read error.");
return false;
@@ -293,35 +333,58 @@
ParseError("JSON document is not a dictionary.");
return false;
}
- const auto* response_node = doc->FindKey("response");
- if (!response_node || !response_node->is_dict()) {
+ const base::Value::Dict* response_node = doc->GetDict().FindDict("response");
+ if (!response_node) {
ParseError("Missing 'response' element or 'response' is not a dictionary.");
return false;
}
- const auto* protocol = response_node->FindKey("protocol");
- if (!protocol || !protocol->is_string()) {
+ const std::string* protocol = response_node->FindString("protocol");
+ if (!protocol) {
ParseError("Missing/non-string protocol.");
return false;
}
- if (protocol->GetString() != kProtocolVersion) {
+ if (*protocol != kProtocolVersion) {
ParseError("Incorrect protocol. (expected '%s', found '%s')",
- kProtocolVersion, protocol->GetString().c_str());
+ kProtocolVersion, protocol->c_str());
return false;
}
- const auto* daystart_node = response_node->FindKey("daystart");
- if (daystart_node && daystart_node->is_dict()) {
- const auto* elapsed_seconds = daystart_node->FindKey("elapsed_seconds");
- if (elapsed_seconds && elapsed_seconds->is_int())
- results->daystart_elapsed_seconds = elapsed_seconds->GetInt();
- const auto* elapsed_days = daystart_node->FindKey("elapsed_days");
- if (elapsed_days && elapsed_days->is_int())
- results->daystart_elapsed_days = elapsed_days->GetInt();
+ const base::Value::Dict* daystart_node = response_node->FindDict("daystart");
+ if (daystart_node) {
+ const absl::optional<int> elapsed_seconds =
+ daystart_node->FindInt("elapsed_seconds");
+ if (elapsed_seconds) {
+ results->daystart_elapsed_seconds = elapsed_seconds.value();
+ }
+ const absl::optional<int> elapsed_days =
+ daystart_node->FindInt("elapsed_days");
+ if (elapsed_days) {
+ results->daystart_elapsed_days = elapsed_days.value();
+ }
}
- const auto* app_node = response_node->FindKey("app");
- if (app_node && app_node->is_list()) {
- for (const auto& app : app_node->GetList()) {
+ const base::Value::Dict* systemrequirements_node =
+ response_node->FindDict("systemrequirements");
+ if (systemrequirements_node) {
+ const std::string* platform =
+ systemrequirements_node->FindString("platform");
+ if (platform) {
+ results->system_requirements.platform = *platform;
+ }
+ const std::string* arch = systemrequirements_node->FindString("arch");
+ if (arch) {
+ results->system_requirements.arch = *arch;
+ }
+ const std::string* min_os_version =
+ systemrequirements_node->FindString("min_os_version");
+ if (min_os_version) {
+ results->system_requirements.min_os_version = *min_os_version;
+ }
+ }
+
+ const base::Value::List* app_node = response_node->FindList("app");
+ if (app_node) {
+ for (const auto& app : *app_node) {
Result result;
std::string error;
if (ParseApp(app, &result, &error))
diff --git a/components/update_client/protocol_parser_json.h b/components/update_client/protocol_parser_json.h
index 71f96f4..c195017 100644
--- a/components/update_client/protocol_parser_json.h
+++ b/components/update_client/protocol_parser_json.h
@@ -1,4 +1,4 @@
-// Copyright 2018 The Chromium Authors. All rights reserved.
+// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,7 +7,6 @@
#include <string>
-#include "base/macros.h"
#include "components/update_client/protocol_parser.h"
namespace update_client {
@@ -18,11 +17,12 @@
public:
ProtocolParserJSON() = default;
+ ProtocolParserJSON(const ProtocolParserJSON&) = delete;
+ ProtocolParserJSON& operator=(const ProtocolParserJSON&) = delete;
+
private:
// Overrides for ProtocolParser.
bool DoParse(const std::string& response_json, Results* results) override;
-
- DISALLOW_COPY_AND_ASSIGN(ProtocolParserJSON);
};
} // namespace update_client
diff --git a/components/update_client/protocol_serializer.cc b/components/update_client/protocol_serializer.cc
index 4453d8e..4e299df 100644
--- a/components/update_client/protocol_serializer.cc
+++ b/components/update_client/protocol_serializer.cc
@@ -13,7 +13,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
-#include "base/sys_info.h"
+#include "base/system/sys_info.h"
#include "base/version.h"
#include "build/build_config.h"
#include "components/update_client/activity_data_service.h"
@@ -138,7 +138,7 @@
#endif
if (updater_state_attributes) {
- request.updater = base::make_optional<protocol_request::Updater>();
+ request.updater = absl::make_optional<protocol_request::Updater>();
auto it = updater_state_attributes->find("name");
if (it != updater_state_attributes->end())
request.updater->name = it->second;
@@ -182,7 +182,7 @@
protocol_request::App MakeProtocolApp(
const std::string& app_id,
const base::Version& version,
- base::Optional<std::vector<base::Value>> events) {
+ absl::optional<std::vector<base::Value::Dict>> events) {
protocol_request::App app;
app.app_id = app_id;
app.version = version.GetString();
diff --git a/components/update_client/protocol_serializer.h b/components/update_client/protocol_serializer.h
index 47c212a..0a3b731 100644
--- a/components/update_client/protocol_serializer.h
+++ b/components/update_client/protocol_serializer.h
@@ -47,7 +47,7 @@
protocol_request::App MakeProtocolApp(
const std::string& app_id,
const base::Version& version,
- base::Optional<std::vector<base::Value>> events);
+ absl::optional<std::vector<base::Value::Dict>> events);
protocol_request::App MakeProtocolApp(
const std::string& app_id,
diff --git a/components/update_client/protocol_serializer_json.cc b/components/update_client/protocol_serializer_json.cc
index 89fd7c0..e128cbe 100644
--- a/components/update_client/protocol_serializer_json.cc
+++ b/components/update_client/protocol_serializer_json.cc
@@ -19,157 +19,166 @@
std::string ProtocolSerializerJSON::Serialize(
const protocol_request::Request& request) const {
- Value root_node(Value::Type::DICTIONARY);
- auto* request_node =
- root_node.SetKey("request", Value(Value::Type::DICTIONARY));
- request_node->SetKey("protocol", Value(request.protocol_version));
- request_node->SetKey("dedup", Value("cr"));
- request_node->SetKey("acceptformat", Value("crx2,crx3"));
+ base::Value::Dict root_node;
+ base::Value::Dict request_node;
+ request_node.Set("protocol", request.protocol_version);
+ request_node.Set("dedup", "cr");
+ request_node.Set("acceptformat", Value("crx2,crx3"));
if (!request.additional_attributes.empty()) {
for (const auto& attr : request.additional_attributes)
- request_node->SetKey(attr.first, Value(attr.second));
+ request_node.Set(attr.first, attr.second);
}
- request_node->SetKey("sessionid", Value(request.session_id));
- request_node->SetKey("requestid", Value(request.request_id));
- request_node->SetKey("@updater", Value(request.updatername));
- request_node->SetKey("prodversion", Value(request.updaterversion));
- request_node->SetKey("updaterversion", Value(request.prodversion));
- request_node->SetKey("lang", Value(request.lang));
- request_node->SetKey("@os", Value(request.operating_system));
- request_node->SetKey("arch", Value(request.arch));
- request_node->SetKey("nacl_arch", Value(request.nacl_arch));
-#if defined(OS_WIN)
+ request_node.Set("sessionid", request.session_id);
+ request_node.Set("requestid", request.request_id);
+ request_node.Set("@updater", request.updatername);
+ request_node.Set("prodversion", request.prodversion);
+ request_node.Set("updaterversion", request.updaterversion);
+ request_node.Set("@os", request.operating_system);
+#if defined(STARBOARD)
+ // Upstream sets the lang in app_nodes, but we want it in request_node until
+ // we fully update //components/update_client.
+ request_node.Set("lang", request.lang);
+#endif
+ request_node.Set("arch", request.lang);
+ request_node.Set("nacl_arch", request.nacl_arch);
+#if BUILDFLAG(IS_WIN)
if (request.is_wow64)
- request_node->SetKey("wow64", Value(request.is_wow64));
-#endif // OS_WIN
+ request_node.Set("wow64", request.is_wow64);
+#endif // BUILDFLAG(IS_WIN)
if (!request.updaterchannel.empty())
- request_node->SetKey("updaterchannel", Value(request.updaterchannel));
+ request_node.Set("updaterchannel", request.updaterchannel);
if (!request.prodchannel.empty())
- request_node->SetKey("prodchannel", Value(request.prodchannel));
+ request_node.Set("prodchannel", request.prodchannel);
if (!request.dlpref.empty())
- request_node->SetKey("dlpref", Value(request.dlpref));
- if (request.domain_joined) {
- request_node->SetKey(UpdaterState::kIsEnterpriseManaged,
- Value(*request.domain_joined));
- }
+ request_node.Set("dlpref", request.dlpref);
+ if (request.domain_joined)
+ request_node.Set("domainjoined", *request.domain_joined);
// HW platform information.
- auto* hw_node = request_node->SetKey("hw", Value(Value::Type::DICTIONARY));
- hw_node->SetKey("physmemory", Value(static_cast<int>(request.hw.physmemory)));
+ base::Value::Dict hw_node;
+ hw_node.Set("physmemory", static_cast<int>(request.hw.physmemory));
+ request_node.Set("hw", std::move(hw_node));
// OS version and platform information.
- auto* os_node = request_node->SetKey("os", Value(Value::Type::DICTIONARY));
- os_node->SetKey("platform", Value(request.os.platform));
- os_node->SetKey("arch", Value(request.os.arch));
+ base::Value::Dict os_node;
+ os_node.Set("platform", request.os.platform);
+ os_node.Set("arch", request.os.arch);
if (!request.os.version.empty())
- os_node->SetKey("version", Value(request.os.version));
+ os_node.Set("version", request.os.version);
if (!request.os.service_pack.empty())
- os_node->SetKey("sp", Value(request.os.service_pack));
+ os_node.Set("sp", request.os.service_pack);
+ request_node.Set("os", std::move(os_node));
#if defined(GOOGLE_CHROME_BUILD)
if (request.updater) {
const auto& updater = *request.updater;
- auto* updater_node =
- request_node->SetKey("updater", Value(Value::Type::DICTIONARY));
- updater_node->SetKey("name", Value(updater.name));
- updater_node->SetKey("ismachine", Value(updater.is_machine));
- updater_node->SetKey("autoupdatecheckenabled",
- Value(updater.autoupdate_check_enabled));
- updater_node->SetKey("updatepolicy", Value(updater.update_policy));
+ base::Value::Dict updater_node;
+ updater_node.Set("name", updater.name);
+ updater_node.Set("ismachine", updater.is_machine);
+ updater_node.Set("autoupdatecheckenabled",
+ updater.autoupdate_check_enabled);
+ updater_node.Set("updatepolicy", updater.update_policy);
if (!updater.version.empty())
- updater_node->SetKey("version", Value(updater.version));
+ updater_node.Set("version", updater.version);
if (updater.last_checked)
- updater_node->SetKey("lastchecked", Value(*updater.last_checked));
+ updater_node.Set("lastchecked", *updater.last_checked);
if (updater.last_started)
- updater_node->SetKey("laststarted", Value(*updater.last_started));
+ updater_node.Set("laststarted", *updater.last_started);
+ request_node.Set("updater", std::move(updater_node));
}
#endif
- std::vector<Value> app_nodes;
+ base::Value::List app_nodes;
for (const auto& app : request.apps) {
- Value app_node(Value::Type::DICTIONARY);
- app_node.SetKey("appid", Value(app.app_id));
- app_node.SetKey("version", Value(app.version));
+ base::Value::Dict app_node;
+ app_node.Set("appid", app.app_id);
+ app_node.Set("version", app.version);
if (!app.brand_code.empty())
- app_node.SetKey("brand", Value(app.brand_code));
+ app_node.Set("brand", app.brand_code);
+#if !defined(STARBOARD)
+ if (!app.lang.empty())
+ app_node.Set("lang", app.lang);
+#endif
if (!app.install_source.empty())
- app_node.SetKey("installsource", Value(app.install_source));
+ app_node.Set("installsource", app.install_source);
if (!app.install_location.empty())
- app_node.SetKey("installedby", Value(app.install_location));
+ app_node.Set("installedby", app.install_location);
if (!app.cohort.empty())
- app_node.SetKey("cohort", Value(app.cohort));
+ app_node.Set("cohort", app.cohort);
if (!app.cohort_name.empty())
- app_node.SetKey("cohortname", Value(app.cohort_name));
+ app_node.Set("cohortname", app.cohort_name);
if (!app.cohort_hint.empty())
- app_node.SetKey("cohorthint", Value(app.cohort_hint));
+ app_node.Set("cohorthint", app.cohort_hint);
if (app.enabled)
- app_node.SetKey("enabled", Value(*app.enabled));
+ app_node.Set("enabled", *app.enabled);
if (app.disabled_reasons && !app.disabled_reasons->empty()) {
- std::vector<Value> disabled_nodes;
+ base::Value::List disabled_nodes;
for (const int disabled_reason : *app.disabled_reasons) {
- Value disabled_node(Value::Type::DICTIONARY);
- disabled_node.SetKey("reason", Value(disabled_reason));
- disabled_nodes.push_back(std::move(disabled_node));
+ base::Value::Dict disabled_node;
+ disabled_node.Set("reason", disabled_reason);
+ disabled_nodes.Append(std::move(disabled_node));
}
- app_node.SetKey("disabled", Value(disabled_nodes));
+ app_node.Set("disabled", std::move(disabled_nodes));
}
for (const auto& attr : app.installer_attributes)
- app_node.SetKey(attr.first, Value(attr.second));
+ app_node.Set(attr.first, attr.second);
if (app.update_check) {
- auto* update_check_node =
- app_node.SetKey("updatecheck", Value(Value::Type::DICTIONARY));
+ base::Value::Dict update_check_node;
if (app.update_check->is_update_disabled)
- update_check_node->SetKey("updatedisabled", Value(true));
+ update_check_node.Set("updatedisabled", true);
+ app_node.Set("updatecheck", std::move(update_check_node));
}
if (app.ping) {
const auto& ping = *app.ping;
- auto* ping_node = app_node.SetKey("ping", Value(Value::Type::DICTIONARY));
+ base::Value::Dict ping_node;
if (!ping.ping_freshness.empty())
- ping_node->SetKey("ping_freshness", Value(ping.ping_freshness));
+ ping_node.Set("ping_freshness", ping.ping_freshness);
// Output "ad" or "a" only if the this app has been seen 'active'.
if (ping.date_last_active) {
- ping_node->SetKey("ad", Value(*ping.date_last_active));
+ ping_node.Set("ad", *ping.date_last_active);
} else if (ping.days_since_last_active_ping) {
- ping_node->SetKey("a", Value(*ping.days_since_last_active_ping));
+ ping_node.Set("a", *ping.days_since_last_active_ping);
}
// Output "rd" if valid or "r" as a last resort roll call metric.
if (ping.date_last_roll_call)
- ping_node->SetKey("rd", Value(*ping.date_last_roll_call));
+ ping_node.Set("rd", *ping.date_last_roll_call);
else
- ping_node->SetKey("r", Value(ping.days_since_last_roll_call));
+ ping_node.Set("r", ping.days_since_last_roll_call);
+ app_node.Set("ping", std::move(ping_node));
}
if (!app.fingerprint.empty()) {
- std::vector<Value> package_nodes;
- Value package(Value::Type::DICTIONARY);
- package.SetKey("fp", Value(app.fingerprint));
- package_nodes.push_back(std::move(package));
- auto* packages_node =
- app_node.SetKey("packages", Value(Value::Type::DICTIONARY));
- packages_node->SetKey("package", Value(package_nodes));
+ base::Value::List package_nodes;
+ base::Value::Dict package;
+ package.Set("fp", app.fingerprint);
+ package_nodes.Append(std::move(package));
+ base::Value::Dict packages_node;
+ packages_node.Set("package", std::move(package_nodes));
+ app_node.Set("packages", std::move(packages_node));
}
if (app.events) {
- std::vector<Value> event_nodes;
+ base::Value::List event_nodes;
for (const auto& event : *app.events) {
- DCHECK(event.is_dict());
- DCHECK(!event.DictEmpty());
- event_nodes.push_back(event.Clone());
+ DCHECK(!event.empty());
+ event_nodes.Append(event.Clone());
}
- app_node.SetKey("event", Value(event_nodes));
+ app_node.Set("event", std::move(event_nodes));
}
- app_nodes.push_back(std::move(app_node));
+ app_nodes.Append(std::move(app_node));
}
if (!app_nodes.empty())
- request_node->SetKey("app", Value(std::move(app_nodes)));
+ request_node.Set("app", std::move(app_nodes));
+
+ root_node.Set("request", std::move(request_node));
std::string msg;
return base::JSONWriter::WriteWithOptions(
diff --git a/components/update_client/request_sender.cc b/components/update_client/request_sender.cc
index 2f3d878..e1f03cc 100644
--- a/components/update_client/request_sender.cc
+++ b/components/update_client/request_sender.cc
@@ -12,7 +12,7 @@
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/stringprintf.h"
-#include "base/threading/thread_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/client_update_protocol/ecdsa.h"
#include "components/update_client/configurator.h"
#include "components/update_client/network.h"
@@ -35,7 +35,7 @@
: config_(config) {}
RequestSender::~RequestSender() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void RequestSender::Send(
@@ -44,7 +44,7 @@
const std::string& request_body,
bool use_signing,
RequestSenderCallback request_sender_callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "RequestSender::Send";
#endif
@@ -74,7 +74,7 @@
void RequestSender::SendInternal() {
DCHECK(cur_url_ != urls_.end());
DCHECK(cur_url_->is_valid());
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
GURL url(*cur_url_);
@@ -89,7 +89,7 @@
network_fetcher_ = config_->GetNetworkFetcherFactory()->Create();
if (!network_fetcher_) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(&RequestSender::SendInternalComplete,
base::Unretained(this),
@@ -122,7 +122,7 @@
#endif
if (!error) {
if (!use_signing_) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(request_sender_callback_), 0,
response_body, retry_after_sec));
return;
@@ -131,7 +131,7 @@
DCHECK(use_signing_);
DCHECK(signer_);
if (signer_->ValidateResponse(response_body, response_etag)) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(request_sender_callback_), 0,
response_body, retry_after_sec));
return;
@@ -145,7 +145,7 @@
// A positive |retry_after_sec| is a hint from the server that the client
// should not send further request until the cooldown has expired.
if (retry_after_sec <= 0 && ++cur_url_ != urls_.end() &&
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&RequestSender::SendInternal,
base::Unretained(this)))) {
return;
@@ -166,7 +166,7 @@
int net_error,
const std::string& header_etag,
int64_t xheader_retry_after_sec) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "RequestSender::OnNetworkFetcherComplete";
#endif
@@ -187,7 +187,7 @@
if (original_url.SchemeIsCryptographic() && error > 0)
retry_after_sec = base::saturated_cast<int>(xheader_retry_after_sec);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&RequestSender::SendInternalComplete,
base::Unretained(this), error,
response_body ? *response_body : std::string(),
@@ -195,7 +195,7 @@
}
void RequestSender::HandleSendError(int error, int retry_after_sec) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(request_sender_callback_), error,
std::string(), retry_after_sec));
}
diff --git a/components/update_client/request_sender.h b/components/update_client/request_sender.h
index 1936047..2d5e711 100644
--- a/components/update_client/request_sender.h
+++ b/components/update_client/request_sender.h
@@ -15,7 +15,7 @@
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
+#include "base/sequence_checker.h"
#include "url/gurl.h"
namespace client_update_protocol {
@@ -92,7 +92,7 @@
// Helper function to handle a non-continuable error in Send.
void HandleSendError(int error, int retry_after_sec);
- base::ThreadChecker thread_checker_;
+ SEQUENCE_CHECKER(sequence_checker_);
const scoped_refptr<Configurator> config_;
diff --git a/components/update_client/request_sender_unittest.cc b/components/update_client/request_sender_unittest.cc
index 9bca3d0..de10f78 100644
--- a/components/update_client/request_sender_unittest.cc
+++ b/components/update_client/request_sender_unittest.cc
@@ -13,11 +13,11 @@
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
-#include "base/test/scoped_task_environment.h"
+#include "base/test/task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
#if defined(STARBOARD)
#include "components/update_client/net/url_request_post_interceptor.h"
-#include "net/url_request/url_fetcher.h"
+#include "cobalt/network/custom/url_fetcher.h"
#else
#include "components/update_client/net/url_loader_post_interceptor.h"
#endif
@@ -67,7 +67,7 @@
void Quit();
void RunThreads();
- base::test::ScopedTaskEnvironment scoped_task_environment_;
+ base::test::TaskEnvironment scoped_task_environment_;
scoped_refptr<TestConfigurator> config_;
std::unique_ptr<RequestSender> request_sender_;
@@ -94,7 +94,7 @@
RequestSenderTest::RequestSenderTest()
: scoped_task_environment_(
- base::test::ScopedTaskEnvironment::MainThreadType::IO) {}
+ base::test::TaskEnvironment::MainThreadType::IO) {}
RequestSenderTest::~RequestSenderTest() {}
@@ -103,8 +103,8 @@
request_sender_ = std::make_unique<RequestSender>(config_);
#if defined(STARBOARD)
- interceptor_factory_ =
- std::make_unique<InterceptorFactory>(base::ThreadTaskRunnerHandle::Get());
+ interceptor_factory_ = std::make_unique<InterceptorFactory>(
+ base::SequencedTaskRunner::GetCurrentDefault());
post_interceptor_1_ =
interceptor_factory_->CreateInterceptorForPath(kUrlPath1);
post_interceptor_2_ =
diff --git a/components/update_client/task_send_uninstall_ping.cc b/components/update_client/task_send_uninstall_ping.cc
index 018bb1d..f9bc629 100644
--- a/components/update_client/task_send_uninstall_ping.cc
+++ b/components/update_client/task_send_uninstall_ping.cc
@@ -7,7 +7,7 @@
#include "base/bind.h"
#include "base/location.h"
-#include "base/threading/thread_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/version.h"
#include "components/update_client/update_client.h"
#include "components/update_client/update_engine.h"
@@ -27,11 +27,11 @@
callback_(std::move(callback)) {}
TaskSendUninstallPing::~TaskSendUninstallPing() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void TaskSendUninstallPing::Run() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (id_.empty()) {
TaskComplete(Error::INVALID_ARGUMENT);
@@ -44,7 +44,7 @@
}
void TaskSendUninstallPing::Cancel() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
TaskComplete(Error::UPDATE_CANCELED);
}
@@ -54,9 +54,9 @@
}
void TaskSendUninstallPing::TaskComplete(Error error) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback_), scoped_refptr<Task>(this), error));
}
diff --git a/components/update_client/task_send_uninstall_ping.h b/components/update_client/task_send_uninstall_ping.h
index 9367b3d..83078cf 100644
--- a/components/update_client/task_send_uninstall_ping.h
+++ b/components/update_client/task_send_uninstall_ping.h
@@ -11,7 +11,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
+#include "base/sequence_checker.h"
#include "components/update_client/task.h"
#include "components/update_client/update_client.h"
@@ -53,7 +53,7 @@
// it has been canceled.
void TaskComplete(Error error);
- base::ThreadChecker thread_checker_;
+ SEQUENCE_CHECKER(sequence_checker_);
scoped_refptr<UpdateEngine> update_engine_;
const std::string id_;
const base::Version version_;
diff --git a/components/update_client/task_update.cc b/components/update_client/task_update.cc
index ea331b4..ad4c706 100644
--- a/components/update_client/task_update.cc
+++ b/components/update_client/task_update.cc
@@ -7,7 +7,8 @@
#include "base/bind.h"
#include "base/location.h"
-#include "base/threading/thread_task_runner_handle.h"
+#include "base/logging.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/update_client/update_client.h"
#include "components/update_client/update_engine.h"
@@ -33,14 +34,14 @@
}
TaskUpdate::~TaskUpdate() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "TaskUpdate::~TaskUpdate";
#endif
}
void TaskUpdate::Run() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "TaskUpdate::Run begin";
if(is_completed_) {
@@ -67,7 +68,7 @@
}
void TaskUpdate::Cancel() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "TaskUpdate::Cancel";
@@ -84,7 +85,7 @@
}
void TaskUpdate::TaskComplete(Error error) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "TaskUpdate::TaskComplete";
@@ -98,7 +99,7 @@
is_completed_ = true;
#endif
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback_),
scoped_refptr<TaskUpdate>(this), error));
}
diff --git a/components/update_client/task_update.h b/components/update_client/task_update.h
index 2697c35..2d4e45e 100644
--- a/components/update_client/task_update.h
+++ b/components/update_client/task_update.h
@@ -11,7 +11,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/threading/thread_checker.h"
+#include "base/sequence_checker.h"
#include "components/update_client/task.h"
#include "components/update_client/update_client.h"
@@ -51,7 +51,7 @@
// it has been canceled.
void TaskComplete(Error error);
- base::ThreadChecker thread_checker_;
+ SEQUENCE_CHECKER(sequence_checker_);
scoped_refptr<UpdateEngine> update_engine_;
const bool is_foreground_;
const std::vector<std::string> ids_;
diff --git a/components/update_client/unzipper.h b/components/update_client/unzipper.h
index 5d1e602..e7c87d5 100644
--- a/components/update_client/unzipper.h
+++ b/components/update_client/unzipper.h
@@ -5,7 +5,7 @@
#ifndef COMPONENTS_UPDATE_CLIENT_UNZIPPER_H_
#define COMPONENTS_UPDATE_CLIENT_UNZIPPER_H_
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
diff --git a/components/update_client/update_checker.cc b/components/update_client/update_checker.cc
index 8009af0..25942f7 100644
--- a/components/update_client/update_checker.cc
+++ b/components/update_client/update_checker.cc
@@ -17,13 +17,13 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
+#include "base/sequence_checker.h"
#include "base/strings/stringprintf.h"
-#include "base/task/post_task.h"
-#include "base/threading/thread_checker.h"
-#include "base/threading/thread_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
+#include "base/task/thread_pool.h"
#include "build/build_config.h"
#if defined(STARBOARD)
-#include "cobalt/updater/utils.h"
+#include "chrome/updater/util.h"
#include "components/update_client/cobalt_slot_management.h"
#endif
#include "components/update_client/component.h"
@@ -113,7 +113,7 @@
int error,
int retry_after_sec);
- base::ThreadChecker thread_checker_;
+ SEQUENCE_CHECKER(sequence_checker_);
const scoped_refptr<Configurator> config_;
PersistedData* metadata_ = nullptr;
@@ -134,7 +134,7 @@
}
UpdateCheckerImpl::~UpdateCheckerImpl() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "UpdateCheckerImpl::~UpdateCheckerImpl";
#endif
@@ -147,7 +147,7 @@
const base::flat_map<std::string, std::string>& additional_attributes,
bool enabled_component_updates,
UpdateCheckCallback update_check_callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "UpdateCheckerImpl::CheckForUpdates";
#endif
@@ -155,7 +155,7 @@
ids_checked_ = ids_checked;
update_check_callback_ = std::move(update_check_callback);
- base::PostTaskWithTraitsAndReply(
+ base::ThreadPool::PostTaskAndReply(
FROM_HERE, kTaskTraits,
base::BindOnce(&UpdateCheckerImpl::ReadUpdaterStateAttributes,
base::Unretained(this)),
@@ -187,7 +187,7 @@
const IdToComponentPtrMap& components,
const base::flat_map<std::string, std::string>& additional_attributes,
bool enabled_component_updates) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "UpdateCheckerImpl::CheckForUpdatesHelper";
#endif
@@ -334,7 +334,7 @@
int error,
const std::string& response,
int retry_after_sec) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (error) {
VLOG(1) << "RequestSender failed " << error;
@@ -358,7 +358,7 @@
void UpdateCheckerImpl::UpdateCheckSucceeded(
const ProtocolParser::Results& results,
int retry_after_sec) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const int daynum = results.daystart_elapsed_days;
if (daynum != ProtocolParser::kNoDaystart) {
@@ -377,20 +377,20 @@
metadata_->SetCohortHint(result.extension_id, entry->second);
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(std::move(update_check_callback_),
- base::make_optional<ProtocolParser::Results>(results),
+ absl::make_optional<ProtocolParser::Results>(results),
ErrorCategory::kNone, 0, retry_after_sec));
}
void UpdateCheckerImpl::UpdateCheckFailed(ErrorCategory error_category,
int error,
int retry_after_sec) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_NE(0, error);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(std::move(update_check_callback_), base::nullopt,
error_category, error, retry_after_sec));
diff --git a/components/update_client/update_checker_unittest.cc b/components/update_client/update_checker_unittest.cc
index b8e92fc..04f76ee 100644
--- a/components/update_client/update_checker_unittest.cc
+++ b/components/update_client/update_checker_unittest.cc
@@ -21,9 +21,9 @@
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/post_task.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/test/bind_test_util.h"
#include "base/test/scoped_task_environment.h"
-#include "base/threading/thread_task_runner_handle.h"
#include "base/version.h"
#include "build/build_config.h"
#include "components/prefs/testing_pref_service.h"
@@ -188,8 +188,8 @@
activity_data_service_.get());
#if defined(STARBOARD)
- interceptor_factory_ =
- std::make_unique<InterceptorFactory>(base::ThreadTaskRunnerHandle::Get());
+ interceptor_factory_ = std::make_unique<InterceptorFactory>(
+ base::SequencedTaskRunner::GetCurrentDefault());
post_interceptor_ = interceptor_factory_->CreateInterceptor();
#else
post_interceptor_ = std::make_unique<URLLoaderPostInterceptor>(
diff --git a/components/update_client/update_client.cc b/components/update_client/update_client.cc
index 8c5add0..8e9e90e 100644
--- a/components/update_client/update_client.cc
+++ b/components/update_client/update_client.cc
@@ -12,13 +12,14 @@
#include "base/bind.h"
#include "base/callback.h"
+#include "base/containers/contains.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/stl_util.h"
-#include "base/threading/thread_checker.h"
-#include "base/threading/thread_task_runner_handle.h"
+#include "base/sequence_checker.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/crx_file/crx_verifier.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/update_client/configurator.h"
@@ -73,7 +74,7 @@
base::Unretained(this)))) {}
UpdateClientImpl::~UpdateClientImpl() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(task_queue_.empty());
DCHECK(tasks_.empty());
@@ -89,7 +90,7 @@
void UpdateClientImpl::Install(const std::string& id,
CrxDataCallback crx_data_callback,
Callback callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (IsUpdating(id)) {
std::move(callback).Run(Error::UPDATE_IN_PROGRESS);
@@ -111,7 +112,7 @@
CrxDataCallback crx_data_callback,
bool is_foreground,
Callback callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto task = base::MakeRefCounted<TaskUpdate>(
update_engine_.get(), is_foreground, ids, std::move(crx_data_callback),
@@ -128,8 +129,8 @@
}
void UpdateClientImpl::RunTask(scoped_refptr<Task> task) {
- DCHECK(thread_checker_.CalledOnValidThread());
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&Task::Run, base::Unretained(task.get())));
tasks_.insert(task);
}
@@ -137,14 +138,14 @@
void UpdateClientImpl::OnTaskComplete(Callback callback,
scoped_refptr<Task> task,
Error error) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(task);
#if defined(STARBOARD)
LOG(INFO) << "UpdateClientImpl::OnTaskComplete";
#endif
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), error));
// Remove the task from the set of the running tasks. Only tasks handled by
@@ -164,18 +165,18 @@
}
void UpdateClientImpl::AddObserver(Observer* observer) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
observer_list_.AddObserver(observer);
}
void UpdateClientImpl::RemoveObserver(Observer* observer) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
observer_list_.RemoveObserver(observer);
}
void UpdateClientImpl::NotifyObservers(Observer::Events event,
const std::string& id) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
if (is_stopped_) {
LOG(WARNING) << "UpdateClientImpl::NotifyObservers: already stopped";
@@ -192,18 +193,18 @@
}
bool UpdateClientImpl::IsUpdating(const std::string& id) const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
for (const auto task : tasks_) {
const auto ids = task->GetIds();
- if (base::ContainsValue(ids, id)) {
+ if (base::Contains(ids, id)) {
return true;
}
}
for (const auto task : task_queue_) {
const auto ids = task->GetIds();
- if (base::ContainsValue(ids, id)) {
+ if (base::Contains(ids, id)) {
return true;
}
}
@@ -212,7 +213,7 @@
}
void UpdateClientImpl::Stop() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
is_stopped_ = true;
@@ -251,7 +252,7 @@
const base::Version& version,
int reason,
Callback callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
RunTask(base::MakeRefCounted<TaskSendUninstallPing>(
update_engine_.get(), id, version, reason,
diff --git a/components/update_client/update_client.h b/components/update_client/update_client.h
index 41b9ee2..81ada59 100644
--- a/components/update_client/update_client.h
+++ b/components/update_client/update_client.h
@@ -11,7 +11,7 @@
#include <string>
#include <vector>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/optional.h"
#include "base/version.h"
diff --git a/components/update_client/update_client_internal.h b/components/update_client/update_client_internal.h
index 2b6158c..b7691db 100644
--- a/components/update_client/update_client_internal.h
+++ b/components/update_client/update_client_internal.h
@@ -14,7 +14,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/observer_list.h"
-#include "base/threading/thread_checker.h"
+#include "base/sequence_checker.h"
#include "components/update_client/crx_downloader.h"
#include "components/update_client/update_checker.h"
#include "components/update_client/update_client.h"
@@ -61,7 +61,7 @@
void NotifyObservers(Observer::Events event, const std::string& id);
- base::ThreadChecker thread_checker_;
+ SEQUENCE_CHECKER(sequence_checker_);
// True if Stop method has been called.
bool is_stopped_ = false;
diff --git a/components/update_client/update_client_unittest.cc b/components/update_client/update_client_unittest.cc
index 866927b..4d6c78e 100644
--- a/components/update_client/update_client_unittest.cc
+++ b/components/update_client/update_client_unittest.cc
@@ -280,7 +280,7 @@
ProtocolParser::Results results;
results.list.push_back(result);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -451,7 +451,7 @@
EXPECT_FALSE(components.at(id)->is_foreground());
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -485,11 +485,11 @@
result.error = 0;
result.response = path;
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress,
base::Unretained(this)));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete,
base::Unretained(this), true, result,
download_metrics));
@@ -652,7 +652,7 @@
EXPECT_FALSE(components.at(id)->is_foreground());
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -686,11 +686,11 @@
result.error = 0;
result.response = path;
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress,
base::Unretained(this)));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete,
base::Unretained(this), true, result,
download_metrics));
@@ -860,7 +860,7 @@
EXPECT_FALSE(components.at(id)->is_foreground());
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -898,11 +898,11 @@
NOTREACHED();
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress,
base::Unretained(this)));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete,
base::Unretained(this), true, result,
download_metrics));
@@ -1189,7 +1189,7 @@
results.list.push_back(result);
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -1238,11 +1238,11 @@
NOTREACHED();
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress,
base::Unretained(this)));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete,
base::Unretained(this), true, result,
download_metrics));
@@ -1480,7 +1480,7 @@
NOTREACHED();
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -1532,11 +1532,11 @@
NOTREACHED();
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress,
base::Unretained(this)));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete,
base::Unretained(this), true, result,
download_metrics));
@@ -1754,7 +1754,7 @@
ProtocolParser::Results results;
results.list.push_back(result);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -1788,11 +1788,11 @@
result.error = 0;
result.response = path;
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress,
base::Unretained(this)));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete,
base::Unretained(this), true, result,
download_metrics));
@@ -2003,7 +2003,7 @@
NOTREACHED();
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -2065,11 +2065,11 @@
result.response = path;
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress,
base::Unretained(this)));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete,
base::Unretained(this), true, result,
download_metrics));
@@ -2222,7 +2222,7 @@
ProtocolParser::Results results;
results.list.push_back(result);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -2369,7 +2369,7 @@
// Verify that calling Install sets ondemand.
EXPECT_TRUE(components.at(id)->is_foreground());
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -2407,11 +2407,11 @@
NOTREACHED();
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress,
base::Unretained(this)));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete,
base::Unretained(this), true, result,
download_metrics));
@@ -2632,7 +2632,7 @@
// Verify that calling Install sets |is_foreground| for the component.
EXPECT_TRUE(components.at(id)->is_foreground());
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -2917,7 +2917,7 @@
ProtocolParser::Results results;
results.list.push_back(result);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, retry_after_sec));
}
@@ -3160,7 +3160,7 @@
results.list.push_back(result);
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -3198,11 +3198,11 @@
NOTREACHED();
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress,
base::Unretained(this)));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete,
base::Unretained(this), true, result,
download_metrics));
@@ -3328,7 +3328,7 @@
const std::string id = "jebgalgnebhfojomionfpkfelancnnkf";
EXPECT_EQ(id, ids_to_check.front());
EXPECT_EQ(1u, components.count(id));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(std::move(update_check_callback), base::nullopt,
ErrorCategory::kUpdateCheck, -1, 0));
@@ -3485,7 +3485,7 @@
const auto parser = ProtocolHandlerFactoryJSON().CreateParser();
EXPECT_TRUE(parser->Parse(update_response));
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(std::move(update_check_callback), parser->results(),
ErrorCategory::kNone, 0, 0));
@@ -3671,7 +3671,7 @@
ProtocolParser::Results results;
results.list.push_back(result);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
@@ -3709,7 +3709,7 @@
NOTREACHED();
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete,
base::Unretained(this), true, result,
download_metrics));
@@ -3833,7 +3833,7 @@
ProtocolParser::Results results;
results.list.push_back(result);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_check_callback), results,
ErrorCategory::kNone, 0, 0));
}
diff --git a/components/update_client/update_engine.cc b/components/update_client/update_engine.cc
index ffef9b3..57e6f9c 100644
--- a/components/update_client/update_engine.cc
+++ b/components/update_client/update_engine.cc
@@ -15,7 +15,7 @@
#include "base/optional.h"
#include "base/stl_util.h"
#include "base/strings/strcat.h"
-#include "base/threading/thread_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/prefs/pref_service.h"
#include "components/update_client/component.h"
#include "components/update_client/configurator.h"
@@ -77,7 +77,7 @@
}
UpdateEngine::~UpdateEngine() {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "UpdateEngine::~UpdateEngine";
#endif
@@ -96,14 +96,14 @@
base::OnceClosure& cancelation_closure) {
#endif
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "UpdateEngine::Update";
#endif
if (ids.empty()) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback), Error::INVALID_ARGUMENT));
return;
@@ -115,7 +115,7 @@
for (const auto& id : ids) {
VLOG(1) << "id:" << id;
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), Error::RETRY_LATER));
return;
}
@@ -163,7 +163,7 @@
}
if (update_context->components_to_check_for_updates.empty()) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&UpdateEngine::HandleComponent,
base::Unretained(this), update_context));
return;
@@ -178,7 +178,7 @@
void UpdateEngine::ComponentCheckingForUpdatesStart(
scoped_refptr<UpdateContext> update_context,
const std::string& id) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(update_context);
DCHECK_EQ(1u, update_context->components.count(id));
@@ -207,13 +207,13 @@
}
#endif
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&UpdateEngine::DoUpdateCheck,
base::Unretained(this), update_context));
}
void UpdateEngine::DoUpdateCheck(scoped_refptr<UpdateContext> update_context) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(update_context);
#if defined(STARBOARD)
@@ -238,7 +238,7 @@
ErrorCategory error_category,
int error,
int retry_after_sec) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(update_context);
#if defined(STARBOARD)
@@ -314,7 +314,7 @@
void UpdateEngine::ComponentCheckingForUpdatesComplete(
scoped_refptr<UpdateContext> update_context) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(update_context);
#if defined(STARBOARD)
@@ -327,14 +327,14 @@
return;
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&UpdateEngine::UpdateCheckComplete,
base::Unretained(this), update_context));
}
void UpdateEngine::UpdateCheckComplete(
scoped_refptr<UpdateContext> update_context) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(update_context);
#if defined(STARBOARD)
@@ -344,14 +344,14 @@
for (const auto& id : update_context->components_to_check_for_updates)
update_context->component_queue.push(id);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&UpdateEngine::HandleComponent,
base::Unretained(this), update_context));
}
void UpdateEngine::HandleComponent(
scoped_refptr<UpdateContext> update_context) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(update_context);
#if defined(STARBOARD)
@@ -365,7 +365,7 @@
? Error::UPDATE_CHECK_ERROR
: Error::NONE;
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(&UpdateEngine::UpdateComplete, base::Unretained(this),
update_context, error));
@@ -379,7 +379,7 @@
auto& next_update_delay = update_context->next_update_delay;
if (!next_update_delay.is_zero() && component->IsUpdateAvailable()) {
- base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&UpdateEngine::HandleComponent, base::Unretained(this),
update_context),
@@ -405,7 +405,7 @@
void UpdateEngine::HandleComponentComplete(
scoped_refptr<UpdateContext> update_context) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(update_context);
#if defined(STARBOARD)
@@ -441,7 +441,7 @@
queue.pop();
}
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&UpdateEngine::HandleComponent,
base::Unretained(this), update_context));
}
@@ -452,19 +452,19 @@
LOG(INFO) << "UpdateEngine::UpdateComplete";
#endif
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(update_context);
const auto num_erased = update_contexts_.erase(update_context->session_id);
DCHECK_EQ(1u, num_erased);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(update_context->callback), error));
}
bool UpdateEngine::GetUpdateState(const std::string& id,
CrxUpdateItem* update_item) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "UpdateEngine::GetUpdateState";
#endif
@@ -480,7 +480,7 @@
}
bool UpdateEngine::IsThrottled(bool is_foreground) const {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "UpdateEngine::IsThrottled";
#endif
@@ -520,7 +520,7 @@
const base::Version& version,
int reason,
Callback callback) {
- DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
#if defined(STARBOARD)
LOG(INFO) << "UpdateEngine::SendUninstallPing";
@@ -545,7 +545,7 @@
update_context->component_queue.push(id);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&UpdateEngine::HandleComponent,
base::Unretained(this), update_context));
}
diff --git a/components/update_client/update_engine.h b/components/update_client/update_engine.h
index 1bf1cd7..a536fe6 100644
--- a/components/update_client/update_engine.h
+++ b/components/update_client/update_engine.h
@@ -16,7 +16,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/optional.h"
-#include "base/threading/thread_checker.h"
+#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "components/update_client/component.h"
#include "components/update_client/crx_downloader.h"
@@ -115,7 +115,7 @@
const std::vector<std::string>& crx_component_ids);
#endif
- base::ThreadChecker thread_checker_;
+ SEQUENCE_CHECKER(sequence_checker_);
scoped_refptr<Configurator> config_;
UpdateChecker::Factory update_checker_factory_;
CrxDownloader::Factory crx_downloader_factory_;
diff --git a/components/update_client/update_query_params.cc b/components/update_client/update_query_params.cc
index 517abf8..3b5f808 100644
--- a/components/update_client/update_query_params.cc
+++ b/components/update_client/update_query_params.cc
@@ -6,7 +6,7 @@
#include "base/logging.h"
#include "base/strings/stringprintf.h"
-#include "base/sys_info.h"
+#include "base/system/sys_info.h"
#include "build/build_config.h"
#include "components/update_client/update_query_params_delegate.h"
diff --git a/components/update_client/url_fetcher_downloader.cc b/components/update_client/url_fetcher_downloader.cc
index b706ec4..b494946 100644
--- a/components/update_client/url_fetcher_downloader.cc
+++ b/components/update_client/url_fetcher_downloader.cc
@@ -12,11 +12,11 @@
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/logging.h"
-#include "base/sequenced_task_runner.h"
-#include "base/task/post_task.h"
+#include "base/task/sequenced_task_runner.h"
+#include "base/task/thread_pool.h"
#include "base/task/task_traits.h"
#if defined(STARBOARD)
-#include "cobalt/updater/updater_module.h"
+#include "chrome/updater/updater_module.h"
#endif
#include "components/update_client/network.h"
#include "components/update_client/utils.h"
@@ -105,7 +105,7 @@
return;
}
- base::SequencedTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&UrlFetcherDownloader::StartURLFetch,
#if defined(IN_MEMORY_UPDATES)
base::Unretained(this), url, dst));
@@ -137,7 +137,7 @@
updater_status_string_map.find(UpdaterStatus::kSlotLocked)->second));
// Use 15 sec delay to allow for other updaters/loaders to settle down.
- base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&UrlFetcherDownloader::ConfirmSlot, base::Unretained(this),
#if defined(IN_MEMORY_UPDATES)
@@ -174,7 +174,7 @@
ReportDownloadFailure(url);
return;
}
- base::SequencedTaskRunnerHandle::Get()->PostTask(
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(&UrlFetcherDownloader::SelectSlot,
#if defined(IN_MEMORY_UPDATES)
base::Unretained(this), url, dst));
diff --git a/components/update_client/utils.cc b/components/update_client/utils.cc
index d0c49f2..543df0f 100644
--- a/components/update_client/utils.cc
+++ b/components/update_client/utils.cc
@@ -41,14 +41,14 @@
}
bool DeleteFileAndEmptyParentDirectory(const base::FilePath& filepath) {
- if (!base::DeleteFile(filepath, false))
+ if (!base::DeleteFile(filepath))
return false;
const base::FilePath dirname(filepath.DirName());
if (!base::IsDirectoryEmpty(dirname))
return true;
- return base::DeleteFile(dirname, false);
+ return base::DeleteFile(dirname);
}
std::string GetCrxComponentID(const CrxComponent& component) {
@@ -212,21 +212,20 @@
// TODO(cpu): add a specific attribute check to a component json that the
// extension unpacker will reject, so that a component cannot be installed
// as an extension.
-std::unique_ptr<base::DictionaryValue> ReadManifest(
+base::Value::Dict ReadManifest(
const base::FilePath& unpack_path) {
base::FilePath manifest =
unpack_path.Append(FILE_PATH_LITERAL("manifest.json"));
if (!base::PathExists(manifest))
- return std::unique_ptr<base::DictionaryValue>();
+ return base::Value::Dict();
JSONFileValueDeserializer deserializer(manifest);
std::string error;
std::unique_ptr<base::Value> root = deserializer.Deserialize(nullptr, &error);
if (!root)
- return std::unique_ptr<base::DictionaryValue>();
+ return base::Value::Dict();
if (!root->is_dict())
- return std::unique_ptr<base::DictionaryValue>();
- return std::unique_ptr<base::DictionaryValue>(
- static_cast<base::DictionaryValue*>(root.release()));
+ return base::Value::Dict();
+ return std::move(root->GetDict());
}
} // namespace update_client
diff --git a/components/update_client/utils.h b/components/update_client/utils.h
index d64126b..887b3c2 100644
--- a/components/update_client/utils.h
+++ b/components/update_client/utils.h
@@ -10,8 +10,9 @@
#include <utility>
#include <vector>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/memory/ref_counted.h"
+#include "base/values.h"
#include "components/update_client/update_client.h"
class GURL;
@@ -79,7 +80,7 @@
base::OnceCallback<bool()> callback);
// Deserializes the CRX manifest. The top level must be a dictionary.
-std::unique_ptr<base::DictionaryValue> ReadManifest(
+base::Value::Dict ReadManifest(
const base::FilePath& unpack_path);
// Converts a custom, specific installer error (and optionally extended error)
diff --git a/components/variations/BUILD.gn b/components/variations/BUILD.gn
index 0dc84d8..d05dfc2 100644
--- a/components/variations/BUILD.gn
+++ b/components/variations/BUILD.gn
@@ -84,6 +84,10 @@
"proto/permuted_entropy_cache.proto",
"proto/study.proto",
"proto/variations_seed.proto",
+
+ # These can't be by compiled and aren't used in Cobalt.
+ "experiment_labels.cc",
+ "experiment_labels.h",
]
}
diff --git a/components/variations/active_field_trials.cc b/components/variations/active_field_trials.cc
index f18dfe1..90a07d0 100644
--- a/components/variations/active_field_trials.cc
+++ b/components/variations/active_field_trials.cc
@@ -26,8 +26,8 @@
DCHECK(name_group_ids->empty());
for (auto it = active_groups.begin(); it != active_groups.end(); ++it) {
name_group_ids->push_back(
- MakeActiveGroupId(it->trial_name + suffix.as_string(),
- it->group_name + suffix.as_string()));
+ MakeActiveGroupId(it->trial_name + std::string(suffix),
+ it->group_name + std::string(suffix)));
}
}
diff --git a/components/variations/child_process_field_trial_syncer.cc b/components/variations/child_process_field_trial_syncer.cc
index 0694ccf..79fabc2 100644
--- a/components/variations/child_process_field_trial_syncer.cc
+++ b/components/variations/child_process_field_trial_syncer.cc
@@ -7,6 +7,7 @@
#include <set>
#include <utility>
+#include "base/stl_util.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "components/variations/variations_crash_keys.h"
diff --git a/components/variations/child_process_field_trial_syncer_unittest.cc b/components/variations/child_process_field_trial_syncer_unittest.cc
index fbfe7ac..5bb1320 100644
--- a/components/variations/child_process_field_trial_syncer_unittest.cc
+++ b/components/variations/child_process_field_trial_syncer_unittest.cc
@@ -10,9 +10,9 @@
#include "base/base_switches.h"
#include "base/command_line.h"
-#include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h"
#include "base/run_loop.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/variations/variations_crash_keys.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/components/variations/entropy_provider.cc b/components/variations/entropy_provider.cc
index 897b4fa..2abc20c 100644
--- a/components/variations/entropy_provider.cc
+++ b/components/variations/entropy_provider.cc
@@ -10,7 +10,7 @@
#include "base/logging.h"
#include "base/rand_util.h"
-#include "base/sha1.h"
+#include "base/hash/sha1.h"
#include "base/strings/string_number_conversions.h"
#include "base/sys_byteorder.h"
#include "components/variations/hashing.h"
@@ -77,7 +77,7 @@
}
double SHA1EntropyProvider::GetEntropyForTrial(
- const std::string& trial_name,
+ base::StringPiece trial_name,
uint32_t randomization_seed) const {
// Given enough input entropy, SHA-1 will produce a uniformly random spread
// in its output space. In this case, the input entropy that is used is the
@@ -88,7 +88,7 @@
// distribution given the same |trial_name|. When using such a low entropy
// source, PermutedEntropyProvider should be used instead.
std::string input(entropy_source_);
- input.append(randomization_seed == 0 ? trial_name : base::UintToString(
+ input.append(randomization_seed == 0 ? trial_name : std::to_string(
randomization_seed));
unsigned char sha1_hash[base::kSHA1Length];
@@ -116,7 +116,7 @@
}
double PermutedEntropyProvider::GetEntropyForTrial(
- const std::string& trial_name,
+ base::StringPiece trial_name,
uint32_t randomization_seed) const {
if (randomization_seed == 0)
randomization_seed = HashName(trial_name);
diff --git a/components/variations/entropy_provider.h b/components/variations/entropy_provider.h
index 29001f1..a01bc22 100644
--- a/components/variations/entropy_provider.h
+++ b/components/variations/entropy_provider.h
@@ -54,7 +54,7 @@
~SHA1EntropyProvider() override;
// base::FieldTrial::EntropyProvider implementation:
- double GetEntropyForTrial(const std::string& trial_name,
+ double GetEntropyForTrial(base::StringPiece trial_name,
uint32_t randomization_seed) const override;
private:
@@ -77,7 +77,7 @@
~PermutedEntropyProvider() override;
// base::FieldTrial::EntropyProvider implementation:
- double GetEntropyForTrial(const std::string& trial_name,
+ double GetEntropyForTrial(base::StringPiece trial_name,
uint32_t randomization_seed) const override;
protected:
diff --git a/components/variations/experiment_labels.cc b/components/variations/experiment_labels.cc
index 1b0d85a..f4d9a02 100644
--- a/components/variations/experiment_labels.cc
+++ b/components/variations/experiment_labels.cc
@@ -18,18 +18,19 @@
namespace {
const char kVariationPrefix[] = "CrVar";
+constexpr base::WStringPiece kLabelSeparator = L";";
} // namespace
-base::string16 ExtractNonVariationLabels(const base::string16& labels) {
+base::WStringPiece ExtractNonVariationLabels(base::WStringPiece labels) {
// First, split everything by the label separator.
- std::vector<base::StringPiece16> entries = base::SplitStringPiece(
- labels, base::StringPiece16(&kExperimentLabelSeparator, 1),
+ std::vector<base::WStringPiece> entries = base::SplitStringPiece(
+ labels, kLabelSeparator,
base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
// For each label, keep the ones that do not look like a Variations label.
- base::string16 non_variation_labels;
- for (const base::StringPiece16& entry : entries) {
+ base::WStringPiece non_variation_labels;
+ for (const auto& entry : entries) {
if (entry.empty() ||
base::StartsWith(entry,
base::ASCIIToUTF16(kVariationPrefix),
diff --git a/components/variations/experiment_labels.h b/components/variations/experiment_labels.h
index cd10825..7e7aa7a 100644
--- a/components/variations/experiment_labels.h
+++ b/components/variations/experiment_labels.h
@@ -6,14 +6,14 @@
#define COMPONENTS_VARIATIONS_EXPERIMENT_LABELS_H_
#include "base/metrics/field_trial.h"
-#include "base/strings/string16.h"
+#include <string>
namespace variations {
// Takes the value of experiment_labels from the registry and returns a valid
// experiment_labels string value containing only the labels that are not
// associated with Chrome Variations.
-base::string16 ExtractNonVariationLabels(const base::string16& labels);
+std::u16string ExtractNonVariationLabels(const std::u16string& labels);
} // namespace variations
diff --git a/components/variations/hashing.cc b/components/variations/hashing.cc
index 3383201..8c82a82 100644
--- a/components/variations/hashing.cc
+++ b/components/variations/hashing.cc
@@ -6,7 +6,7 @@
#include <string.h>
-#include "base/sha1.h"
+#include "base/hash/sha1.h"
#include "base/sys_byteorder.h"
namespace variations {
diff --git a/components/variations/net/variations_http_headers.cc b/components/variations/net/variations_http_headers.cc
index 2227205..d28e6af 100644
--- a/components/variations/net/variations_http_headers.cc
+++ b/components/variations/net/variations_http_headers.cc
@@ -79,7 +79,7 @@
return true;
}
for (size_t i = 0; i < arraysize(kHostsToSetHeadersFor); ++i) {
- if (base::LowerCaseEqualsASCII(host, kHostsToSetHeadersFor[i]))
+ if (base::EqualsCaseInsensitiveASCII(host, kHostsToSetHeadersFor[i]))
return true;
}
diff --git a/components/variations/study_filtering.cc b/components/variations/study_filtering.cc
index 6f1e217..eba4484 100644
--- a/components/variations/study_filtering.cc
+++ b/components/variations/study_filtering.cc
@@ -9,6 +9,7 @@
#include <set>
+#include "base/containers/contains.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "components/variations/client_filterable_state.h"
@@ -60,10 +61,10 @@
// ignored. We do not expect both to be present for Chrome due to server-side
// checks.
if (filter.form_factor_size() > 0)
- return base::ContainsValue(filter.form_factor(), form_factor);
+ return base::Contains(filter.form_factor(), form_factor);
// Omit if we match the blacklist.
- return !base::ContainsValue(filter.exclude_form_factor(), form_factor);
+ return !base::Contains(filter.exclude_form_factor(), form_factor);
}
bool CheckStudyHardwareClass(const Study::Filter& filter,
@@ -100,10 +101,10 @@
// that this means this overrides the exclude_locale in case that ever occurs
// (which it shouldn't).
if (filter.locale_size() > 0)
- return base::ContainsValue(filter.locale(), locale);
+ return base::Contains(filter.locale(), locale);
// Omit if matches any of the exclude entries.
- return !base::ContainsValue(filter.exclude_locale(), locale);
+ return !base::Contains(filter.exclude_locale(), locale);
}
bool CheckStudyPlatform(const Study::Filter& filter, Study::Platform platform) {
@@ -170,10 +171,10 @@
// that this means this overrides the exclude_country in case that ever occurs
// (which it shouldn't).
if (filter.country_size() > 0)
- return base::ContainsValue(filter.country(), country);
+ return base::Contains(filter.country(), country);
// Omit if matches any of the exclude entries.
- return !base::ContainsValue(filter.exclude_country(), country);
+ return !base::Contains(filter.exclude_country(), country);
}
const std::string& GetClientCountryForStudy(
diff --git a/components/variations/synthetic_trial_registry_unittest.cc b/components/variations/synthetic_trial_registry_unittest.cc
index 403c134..eb4a7d6 100644
--- a/components/variations/synthetic_trial_registry_unittest.cc
+++ b/components/variations/synthetic_trial_registry_unittest.cc
@@ -6,9 +6,9 @@
#include <string>
-#include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h"
#include "base/strings/stringprintf.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/variations/active_field_trials.h"
#include "components/variations/hashing.h"
#include "components/variations/synthetic_trials_active_group_id_provider.h"
diff --git a/components/variations/variations_crash_keys.cc b/components/variations/variations_crash_keys.cc
index 91c477c..32016eb 100644
--- a/components/variations/variations_crash_keys.cc
+++ b/components/variations/variations_crash_keys.cc
@@ -7,6 +7,7 @@
#include <string>
#include "base/debug/leak_annotations.h"
+#include "base/metrics/field_trial_list_including_low_anonymity.h"
#include "base/sequence_checker.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
@@ -14,7 +15,7 @@
#include "components/crash/core/common/crash_key.h"
#include "components/variations/active_field_trials.h"
#include "components/variations/synthetic_trials.h"
-
+#include "base/task/sequenced_task_runner.h"
namespace variations {
namespace {
@@ -36,6 +37,8 @@
return base::StringPrintf("%x-%x,", active_group.name, active_group.group);
}
+}
+
class VariationsCrashKeys final : public base::FieldTrialList::Observer {
public:
VariationsCrashKeys();
@@ -88,12 +91,12 @@
}
UpdateCrashKeys();
- ui_thread_task_runner_ = base::SequencedTaskRunnerHandle::Get();
- base::FieldTrialList::SetSynchronousObserver(this);
+ ui_thread_task_runner_ = base::SequencedTaskRunner::GetCurrentDefault();
+ base::FieldTrialListIncludingLowAnonymity::AddObserver(this);
}
VariationsCrashKeys::~VariationsCrashKeys() {
- base::FieldTrialList::RemoveSynchronousObserver(this);
+ base::FieldTrialListIncludingLowAnonymity::RemoveObserver(this);
g_num_variations_crash_key.Clear();
g_variations_crash_key.Clear();
}
@@ -177,8 +180,6 @@
// there's no benefit in cleaning it up at exit.
VariationsCrashKeys* g_variations_crash_keys = nullptr;
-} // namespace
-
void InitCrashKeys() {
DCHECK(!g_variations_crash_keys);
g_variations_crash_keys = new VariationsCrashKeys();
diff --git a/components/variations/variations_crash_keys_unittest.cc b/components/variations/variations_crash_keys_unittest.cc
index 8d5f802..d74be81 100644
--- a/components/variations/variations_crash_keys_unittest.cc
+++ b/components/variations/variations_crash_keys_unittest.cc
@@ -6,9 +6,9 @@
#include <string>
-#include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h"
#include "base/run_loop.h"
+#include "base/task/sequenced_task_runner.h"
#include "build/build_config.h"
#include "components/crash/core/common/crash_key.h"
#include "components/variations/hashing.h"
diff --git a/components/variations/variations_experiment_util.cc b/components/variations/variations_experiment_util.cc
index 9cf78bb..25e1464 100644
--- a/components/variations/variations_experiment_util.cc
+++ b/components/variations/variations_experiment_util.cc
@@ -5,6 +5,7 @@
#include "components/variations/variations_experiment_util.h"
#include <vector>
+#include <string>
#include "base/logging.h"
#include "base/strings/stringprintf.h"
@@ -13,7 +14,7 @@
namespace variations {
-const base::char16 kExperimentLabelSeparator = ';';
+const base::WStringPiece kExperimentLabelSeparator = L";";
namespace {
@@ -24,7 +25,7 @@
} // namespace
-base::string16 BuildExperimentDateString(const base::Time& current_time) {
+::std::u16string BuildExperimentDateString(const base::Time& current_time) {
// The Google Update experiment_labels timestamp format is:
// "DAY, DD0 MON YYYY HH0:MI0:SE0 TZ"
// DAY = 3 character day of week,
diff --git a/components/variations/variations_experiment_util.h b/components/variations/variations_experiment_util.h
index c9c23f4..23c90fb 100644
--- a/components/variations/variations_experiment_util.h
+++ b/components/variations/variations_experiment_util.h
@@ -5,20 +5,20 @@
#ifndef COMPONENTS_VARIATIONS_VARIATIONS_EXPERIMENT_UTIL_H_
#define COMPONENTS_VARIATIONS_VARIATIONS_EXPERIMENT_UTIL_H_
-#include "base/strings/string16.h"
-
+#include <string>
+#include "base/basictypes.h"
+#include "base/strings/string_piece_forward.h"
namespace base {
class Time;
}
namespace variations {
-// The separator used to separate items in experiment labels.
-extern const base::char16 kExperimentLabelSeparator;
+extern const base::WStringPiece kExperimentLabelSeparator;
// Constructs a date string in the format understood by Google Update for the
// |current_time| plus one year.
-base::string16 BuildExperimentDateString(const base::Time& current_time);
+std::u16string BuildExperimentDateString(const base::Time& current_time);
} // namespace variations
diff --git a/components/variations/variations_http_header_provider.cc b/components/variations/variations_http_header_provider.cc
index 0b1e4c8..6565072 100644
--- a/components/variations/variations_http_header_provider.cc
+++ b/components/variations/variations_http_header_provider.cc
@@ -74,7 +74,7 @@
base::AutoLock scoped_lock(lock_);
for (const VariationIDEntry& entry : GetAllVariationIds()) {
if (entry.second == GOOGLE_WEB_PROPERTIES) {
- ids_string.append(base::IntToString(entry.first));
+ ids_string.append(std::to_string(entry.first));
ids_string.push_back(' ');
}
}
@@ -164,8 +164,8 @@
// Register for additional cache updates. This is done first to avoid a race
// that could cause registered FieldTrials to be missed.
- DCHECK(base::ThreadTaskRunnerHandle::IsSet());
- base::FieldTrialList::AddObserver(this);
+ bool success = base::FieldTrialList::AddObserver(this);
+ DCHECK(success);
base::TimeTicks before_time = base::TimeTicks::Now();
diff --git a/components/variations/variations_http_header_provider_unittest.cc b/components/variations/variations_http_header_provider_unittest.cc
index 4fad592..69d2597 100644
--- a/components/variations/variations_http_header_provider_unittest.cc
+++ b/components/variations/variations_http_header_provider_unittest.cc
@@ -7,9 +7,9 @@
#include <string>
#include "base/base64.h"
-#include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h"
#include "base/run_loop.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/variations/entropy_provider.h"
#include "components/variations/proto/client_variations.pb.h"
#include "components/variations/variations_associated_data.h"
diff --git a/components/variations/variations_id_collection.h b/components/variations/variations_id_collection.h
index 36c0ff2..d57a719 100644
--- a/components/variations/variations_id_collection.h
+++ b/components/variations/variations_id_collection.h
@@ -8,6 +8,7 @@
#include <set>
#include <string>
+#include "base/callback.h"
#include "base/macros.h"
#include "base/metrics/field_trial.h"
#include "components/variations/variations_associated_data.h"
diff --git a/components/variations/variations_id_collection_unittest.cc b/components/variations/variations_id_collection_unittest.cc
index 0ec36fc..6dfd1f5 100644
--- a/components/variations/variations_id_collection_unittest.cc
+++ b/components/variations/variations_id_collection_unittest.cc
@@ -7,8 +7,8 @@
#include <memory>
#include <vector>
-#include "base/message_loop/message_loop.h"
#include "base/metrics/field_trial.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/variations/variations_associated_data.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/components/variations/variations_request_scheduler_mobile_unittest.cc b/components/variations/variations_request_scheduler_mobile_unittest.cc
index 9d5f6b6..7dc1abb 100644
--- a/components/variations/variations_request_scheduler_mobile_unittest.cc
+++ b/components/variations/variations_request_scheduler_mobile_unittest.cc
@@ -5,7 +5,7 @@
#include "components/variations/variations_request_scheduler_mobile.h"
#include "base/bind.h"
-#include "base/message_loop/message_loop.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "components/variations/pref_names.h"
diff --git a/components/variations/variations_request_scheduler_unittest.cc b/components/variations/variations_request_scheduler_unittest.cc
index ca5d6fa..f315a0a 100644
--- a/components/variations/variations_request_scheduler_unittest.cc
+++ b/components/variations/variations_request_scheduler_unittest.cc
@@ -6,7 +6,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
-#include "base/message_loop/message_loop.h"
+#include "base/task/sequenced_task_runner.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace variations {
diff --git a/components/variations/variations_seed_processor.h b/components/variations/variations_seed_processor.h
index 140dc27..5e78665 100644
--- a/components/variations/variations_seed_processor.h
+++ b/components/variations/variations_seed_processor.h
@@ -10,7 +10,7 @@
#include <string>
#include <vector>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"