summaryrefslogtreecommitdiff
path: root/chromium/components/sync_device_info
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/sync_device_info')
-rw-r--r--chromium/components/sync_device_info/BUILD.gn12
-rw-r--r--chromium/components/sync_device_info/DEPS1
-rw-r--r--chromium/components/sync_device_info/device_info.cc5
-rw-r--r--chromium/components/sync_device_info/device_info_prefs.cc37
-rw-r--r--chromium/components/sync_device_info/device_info_prefs_unittest.cc20
-rw-r--r--chromium/components/sync_device_info/device_info_sync_bridge.cc22
-rw-r--r--chromium/components/sync_device_info/device_info_sync_bridge.h2
-rw-r--r--chromium/components/sync_device_info/device_info_sync_bridge_unittest.cc6
-rw-r--r--chromium/components/sync_device_info/device_info_sync_client.h3
-rw-r--r--chromium/components/sync_device_info/fake_device_info_sync_service.h2
-rw-r--r--chromium/components/sync_device_info/local_device_info_util.cc16
-rw-r--r--chromium/components/sync_device_info/local_device_info_util.h5
-rw-r--r--chromium/components/sync_device_info/local_device_info_util_chromeos.cc31
-rw-r--r--chromium/components/sync_device_info/local_device_info_util_linux.cc27
14 files changed, 103 insertions, 86 deletions
diff --git a/chromium/components/sync_device_info/BUILD.gn b/chromium/components/sync_device_info/BUILD.gn
index ed4e2ae3cd3..8e23456aad1 100644
--- a/chromium/components/sync_device_info/BUILD.gn
+++ b/chromium/components/sync_device_info/BUILD.gn
@@ -54,11 +54,15 @@ static_library("sync_device_info") {
sources += [ "local_device_info_util_android.cc" ]
}
+ if (is_chromeos) {
+ sources += [ "local_device_info_util_chromeos.cc" ]
+ }
+
if (is_ios) {
sources += [ "local_device_info_util_ios.mm" ]
}
- if (is_linux || is_chromeos) {
+ if (is_linux) {
sources += [ "local_device_info_util_linux.cc" ]
}
@@ -78,8 +82,7 @@ static_library("sync_device_info") {
sources += [ "local_device_info_util_win.cc" ]
}
- if (is_chromeos_ash) {
- # Required by device_info_util_linux.cc on Chrome OS.
+ if (is_chromeos) {
deps += [
"//chromeos/constants",
"//chromeos/system",
@@ -100,7 +103,7 @@ static_library("test_support") {
public_deps = [ ":sync_device_info" ]
- deps = [ "//components/sync:test_support_model" ]
+ deps = [ "//components/sync:test_support" ]
}
source_set("unit_tests") {
@@ -124,7 +127,6 @@ source_set("unit_tests") {
"//build:chromeos_buildflags",
"//components/prefs:test_support",
"//components/sync:test_support",
- "//components/sync/invalidations:test_support",
"//components/version_info:version_string",
"//testing/gmock",
"//testing/gtest",
diff --git a/chromium/components/sync_device_info/DEPS b/chromium/components/sync_device_info/DEPS
index d016c1f9f98..766edb27883 100644
--- a/chromium/components/sync_device_info/DEPS
+++ b/chromium/components/sync_device_info/DEPS
@@ -5,6 +5,7 @@ include_rules = [
"+components/metrics",
"+components/prefs",
"+components/sync/base",
+ "+components/sync/engine",
"+components/sync/invalidations",
"+components/sync/model",
"+components/sync/protocol",
diff --git a/chromium/components/sync_device_info/device_info.cc b/chromium/components/sync_device_info/device_info.cc
index e551176f5ba..2b1a5edb54d 100644
--- a/chromium/components/sync_device_info/device_info.cc
+++ b/chromium/components/sync_device_info/device_info.cc
@@ -4,11 +4,6 @@
#include "components/sync_device_info/device_info.h"
-// device_info.h's size can impact build time. Try not to raise this limit
-// unless absolutely necessary. See
-// https://chromium.googlesource.com/chromium/src/+/HEAD/docs/wmax_tokens.md
-#pragma clang max_tokens_here 529500
-
#include <utility>
#include "base/values.h"
diff --git a/chromium/components/sync_device_info/device_info_prefs.cc b/chromium/components/sync_device_info/device_info_prefs.cc
index 3194c04bb0f..1d007371dd9 100644
--- a/chromium/components/sync_device_info/device_info_prefs.cc
+++ b/chromium/components/sync_device_info/device_info_prefs.cc
@@ -39,7 +39,7 @@ bool MatchesGuidInDictionary(const base::Value& dict,
if (!dict.is_dict()) {
return false;
}
- const std::string* v_cache_guid = dict.FindStringKey(kCacheGuidKey);
+ const std::string* v_cache_guid = dict.GetDict().FindString(kCacheGuidKey);
return v_cache_guid && *v_cache_guid == cache_guid;
}
@@ -61,9 +61,8 @@ DeviceInfoPrefs::~DeviceInfoPrefs() = default;
bool DeviceInfoPrefs::IsRecentLocalCacheGuid(
const std::string& cache_guid) const {
- base::Value::ConstListView recent_local_cache_guids =
- pref_service_->GetList(kDeviceInfoRecentGUIDsWithTimestamps)
- ->GetListDeprecated();
+ const base::Value::List& recent_local_cache_guids =
+ pref_service_->GetValueList(kDeviceInfoRecentGUIDsWithTimestamps);
for (const auto& v : recent_local_cache_guids) {
if (MatchesGuidInDictionary(v, cache_guid)) {
@@ -77,44 +76,42 @@ bool DeviceInfoPrefs::IsRecentLocalCacheGuid(
void DeviceInfoPrefs::AddLocalCacheGuid(const std::string& cache_guid) {
ListPrefUpdate update_cache_guids(pref_service_,
kDeviceInfoRecentGUIDsWithTimestamps);
+ base::Value::List& update_list = update_cache_guids->GetList();
- for (auto it = update_cache_guids->GetListDeprecated().begin();
- it != update_cache_guids->GetListDeprecated().end(); it++) {
+ for (auto it = update_list.begin(); it != update_list.end(); it++) {
if (MatchesGuidInDictionary(*it, cache_guid)) {
// Remove it from the list, to be reinserted below, in the first
// position.
- update_cache_guids->EraseListIter(it);
+ update_list.erase(it);
break;
}
}
- base::Value new_entry(base::Value::Type::DICTIONARY);
- new_entry.SetKey(kCacheGuidKey, base::Value(cache_guid));
- new_entry.SetKey(
- kTimestampKey,
- base::Value(clock_->Now().ToDeltaSinceWindowsEpoch().InDays()));
+ base::Value::Dict new_entry;
+ new_entry.Set(kCacheGuidKey, cache_guid);
+ new_entry.Set(kTimestampKey,
+ clock_->Now().ToDeltaSinceWindowsEpoch().InDays());
- update_cache_guids->Insert(update_cache_guids->GetListDeprecated().begin(),
- std::move(new_entry));
+ update_list.Insert(update_list.begin(), base::Value(std::move(new_entry)));
- while (update_cache_guids->GetListDeprecated().size() >
- kMaxLocalCacheGuidsStored) {
- update_cache_guids->EraseListIter(
- update_cache_guids->GetListDeprecated().end() - 1);
+ if (update_list.size() > kMaxLocalCacheGuidsStored) {
+ update_list.erase(update_list.begin() + kMaxLocalCacheGuidsStored,
+ update_list.end());
}
}
void DeviceInfoPrefs::GarbageCollectExpiredCacheGuids() {
ListPrefUpdate update_cache_guids(pref_service_,
kDeviceInfoRecentGUIDsWithTimestamps);
- update_cache_guids->EraseListValueIf([this](const auto& dict) {
+ update_cache_guids->GetList().EraseIf([this](const auto& dict) {
// Avoid crashes if the preference contains corrupt entries that are not
// dictionaries, and meanwhile clean up these corrupt entries.
if (!dict.is_dict()) {
return true;
}
- absl::optional<int> days_since_epoch = dict.FindIntKey(kTimestampKey);
+ absl::optional<int> days_since_epoch =
+ dict.GetDict().FindInt(kTimestampKey);
// Avoid crashes if the dictionary contains no timestamp and meanwhile clean
// up these corrupt entries.
diff --git a/chromium/components/sync_device_info/device_info_prefs_unittest.cc b/chromium/components/sync_device_info/device_info_prefs_unittest.cc
index 94495b2acbf..af7f8821366 100644
--- a/chromium/components/sync_device_info/device_info_prefs_unittest.cc
+++ b/chromium/components/sync_device_info/device_info_prefs_unittest.cc
@@ -58,18 +58,18 @@ TEST_F(DeviceInfoPrefsTest, ShouldCleanUpCorruptEntriesUponGarbageCollection) {
// which is a string instead of a dictionary.
ListPrefUpdate cache_guids_update(&pref_service_,
kDeviceInfoRecentGUIDsWithTimestamps);
- cache_guids_update->Insert(cache_guids_update->GetListDeprecated().begin(),
- base::Value("corrupt_string_entry"));
+ base::Value::List& update_list = cache_guids_update->GetList();
+ update_list.Insert(update_list.begin(), base::Value("corrupt_string_entry"));
// Add another corrupt entry: in this case the entry is a dictionary, but it
// contains no timestamp.
- cache_guids_update->Insert(cache_guids_update->GetListDeprecated().begin(),
- base::Value(base::Value::Type::DICTIONARY));
+ update_list.Insert(update_list.begin(),
+ base::Value(base::Value::Type::DICTIONARY));
// The end result is the list contains three entries among which one is valid.
- ASSERT_EQ(3u, pref_service_.GetList(kDeviceInfoRecentGUIDsWithTimestamps)
- ->GetListDeprecated()
- .size());
+ ASSERT_EQ(
+ 3u,
+ pref_service_.GetValueList(kDeviceInfoRecentGUIDsWithTimestamps).size());
ASSERT_TRUE(device_info_prefs_.IsRecentLocalCacheGuid("guid1"));
// Garbage collection should clean up the corrupt entries.
@@ -77,9 +77,9 @@ TEST_F(DeviceInfoPrefsTest, ShouldCleanUpCorruptEntriesUponGarbageCollection) {
ASSERT_TRUE(device_info_prefs_.IsRecentLocalCacheGuid("guid1"));
// |guid1| should be the only entry in the list.
- EXPECT_EQ(1u, pref_service_.GetList(kDeviceInfoRecentGUIDsWithTimestamps)
- ->GetListDeprecated()
- .size());
+ EXPECT_EQ(
+ 1u,
+ pref_service_.GetValueList(kDeviceInfoRecentGUIDsWithTimestamps).size());
}
TEST_F(DeviceInfoPrefsTest, ShouldTruncateAfterMaximumNumberOfGuids) {
diff --git a/chromium/components/sync_device_info/device_info_sync_bridge.cc b/chromium/components/sync_device_info/device_info_sync_bridge.cc
index 3922345285e..93b28026897 100644
--- a/chromium/components/sync_device_info/device_info_sync_bridge.cc
+++ b/chromium/components/sync_device_info/device_info_sync_bridge.cc
@@ -18,10 +18,10 @@
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/observer_list.h"
-#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "components/sync/base/model_type.h"
#include "components/sync/base/time.h"
+#include "components/sync/engine/commit_and_get_updates_types.h"
#include "components/sync/model/data_type_activation_request.h"
#include "components/sync/model/entity_change.h"
#include "components/sync/model/metadata_batch.h"
@@ -530,6 +530,26 @@ void DeviceInfoSyncBridge::ApplyStopSyncChanges(
}
}
+ModelTypeSyncBridge::CommitAttemptFailedBehavior
+DeviceInfoSyncBridge::OnCommitAttemptFailed(
+ syncer::SyncCommitError commit_error) {
+ // DeviceInfo is normally committed once a day and hence it's important to
+ // retry on the next sync cycle in case of auth or network errors. For other
+ // errors, do not retry to prevent blocking sync for other data types if
+ // DeviceInfo entity causes the error. OnCommitAttemptErrors would show that
+ // something is wrong with the DeviceInfo entity from the last commit request
+ // but those errors are not retried at the moment since it's a very tiny
+ // fraction.
+ switch (commit_error) {
+ case syncer::SyncCommitError::kAuthError:
+ case syncer::SyncCommitError::kNetworkError:
+ return CommitAttemptFailedBehavior::kShouldRetryOnNextCycle;
+ case syncer::SyncCommitError::kBadServerResponse:
+ case syncer::SyncCommitError::kServerError:
+ return CommitAttemptFailedBehavior::kDontRetryOnNextCycle;
+ }
+}
+
bool DeviceInfoSyncBridge::IsSyncing() const {
// Both conditions are neecessary due to the following possible cases:
// 1. This method is called from MergeSyncData() when IsTrackingMetadata()
diff --git a/chromium/components/sync_device_info/device_info_sync_bridge.h b/chromium/components/sync_device_info/device_info_sync_bridge.h
index 97754618646..d3422bcc6c7 100644
--- a/chromium/components/sync_device_info/device_info_sync_bridge.h
+++ b/chromium/components/sync_device_info/device_info_sync_bridge.h
@@ -83,6 +83,8 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge,
std::string GetStorageKey(const EntityData& entity_data) override;
void ApplyStopSyncChanges(
std::unique_ptr<MetadataChangeList> delete_metadata_change_list) override;
+ ModelTypeSyncBridge::CommitAttemptFailedBehavior OnCommitAttemptFailed(
+ syncer::SyncCommitError commit_error) override;
// DeviceInfoTracker implementation.
bool IsSyncing() const override;
diff --git a/chromium/components/sync_device_info/device_info_sync_bridge_unittest.cc b/chromium/components/sync_device_info/device_info_sync_bridge_unittest.cc
index 63425fb90ac..5468d6c5d3a 100644
--- a/chromium/components/sync_device_info/device_info_sync_bridge_unittest.cc
+++ b/chromium/components/sync_device_info/device_info_sync_bridge_unittest.cc
@@ -33,9 +33,9 @@
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/model_type_state.pb.h"
#include "components/sync/protocol/sync_enums.pb.h"
-#include "components/sync/test/model/mock_model_type_change_processor.h"
-#include "components/sync/test/model/model_type_store_test_util.h"
-#include "components/sync/test/model/test_matchers.h"
+#include "components/sync/test/mock_model_type_change_processor.h"
+#include "components/sync/test/model_type_store_test_util.h"
+#include "components/sync/test/test_matchers.h"
#include "components/sync_device_info/device_info_prefs.h"
#include "components/sync_device_info/device_info_util.h"
#include "components/sync_device_info/local_device_info_util.h"
diff --git a/chromium/components/sync_device_info/device_info_sync_client.h b/chromium/components/sync_device_info/device_info_sync_client.h
index bd64fc0da99..67766d828aa 100644
--- a/chromium/components/sync_device_info/device_info_sync_client.h
+++ b/chromium/components/sync_device_info/device_info_sync_client.h
@@ -23,9 +23,6 @@ class DeviceInfoSyncClient {
virtual ~DeviceInfoSyncClient();
virtual std::string GetSigninScopedDeviceId() const = 0;
- // TODO(crbug.com/1324936): This only returns false for one embedder, it can
- // be replaced with a check for whether send-tab-to-self is "enabled"
- // (preconditions met?).
virtual bool GetSendTabToSelfReceivingEnabled() const = 0;
virtual absl::optional<DeviceInfo::SharingInfo> GetLocalSharingInfo()
const = 0;
diff --git a/chromium/components/sync_device_info/fake_device_info_sync_service.h b/chromium/components/sync_device_info/fake_device_info_sync_service.h
index 12c40b046a6..fa1a7690c4c 100644
--- a/chromium/components/sync_device_info/fake_device_info_sync_service.h
+++ b/chromium/components/sync_device_info/fake_device_info_sync_service.h
@@ -5,7 +5,7 @@
#ifndef COMPONENTS_SYNC_DEVICE_INFO_FAKE_DEVICE_INFO_SYNC_SERVICE_H_
#define COMPONENTS_SYNC_DEVICE_INFO_FAKE_DEVICE_INFO_SYNC_SERVICE_H_
-#include "components/sync/test/model/fake_model_type_controller_delegate.h"
+#include "components/sync/test/fake_model_type_controller_delegate.h"
#include "components/sync_device_info/device_info_sync_service.h"
#include "components/sync_device_info/fake_device_info_tracker.h"
#include "components/sync_device_info/fake_local_device_info_provider.h"
diff --git a/chromium/components/sync_device_info/local_device_info_util.cc b/chromium/components/sync_device_info/local_device_info_util.cc
index 8da7db4a55c..6f32d770433 100644
--- a/chromium/components/sync_device_info/local_device_info_util.cc
+++ b/chromium/components/sync_device_info/local_device_info_util.cc
@@ -22,6 +22,13 @@
namespace syncer {
+// Declared here but defined in platform-specific files.
+std::string GetPersonalizableDeviceNameInternal();
+
+#if BUILDFLAG(IS_CHROMEOS)
+std::string GetChromeOSDeviceNameFromType();
+#endif
+
LocalDeviceNameInfo::LocalDeviceNameInfo() = default;
LocalDeviceNameInfo::LocalDeviceNameInfo(const LocalDeviceNameInfo& other) =
default;
@@ -39,7 +46,7 @@ void OnHardwareInfoReady(LocalDeviceNameInfo* name_info_ptr,
base::ScopedClosureRunner done_closure,
base::SysInfo::HardwareInfo hardware_info) {
name_info_ptr->manufacturer_name = std::move(hardware_info.manufacturer);
-#if BUILDFLAG(IS_CHROMEOS_ASH)
+#if BUILDFLAG(IS_CHROMEOS)
// For ChromeOS the returned model values are product code names like Eve. We
// want to use generic names like Chromebook.
name_info_ptr->model_name = GetChromeOSDeviceNameFromType();
@@ -68,13 +75,10 @@ void OnMachineStatisticsLoaded(LocalDeviceNameInfo* name_info_ptr,
} // namespace
-// Declared here but defined in platform-specific files.
-std::string GetPersonalizableDeviceNameInternal();
-
sync_pb::SyncEnums::DeviceType GetLocalDeviceType() {
-#if BUILDFLAG(IS_CHROMEOS_ASH)
+#if BUILDFLAG(IS_CHROMEOS)
return sync_pb::SyncEnums_DeviceType_TYPE_CROS;
-#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)
+#elif BUILDFLAG(IS_LINUX)
return sync_pb::SyncEnums_DeviceType_TYPE_LINUX;
#elif BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET
diff --git a/chromium/components/sync_device_info/local_device_info_util.h b/chromium/components/sync_device_info/local_device_info_util.h
index 7afce40a415..e0feae18028 100644
--- a/chromium/components/sync_device_info/local_device_info_util.h
+++ b/chromium/components/sync_device_info/local_device_info_util.h
@@ -8,7 +8,6 @@
#include <string>
#include "base/callback_forward.h"
-#include "build/chromeos_buildflags.h"
#include "components/sync/protocol/sync_enums.pb.h"
namespace syncer {
@@ -37,10 +36,6 @@ struct LocalDeviceNameInfo {
sync_pb::SyncEnums::DeviceType GetLocalDeviceType();
-#if BUILDFLAG(IS_CHROMEOS_ASH)
-std::string GetChromeOSDeviceNameFromType();
-#endif
-
// Returns the personalizable device name. This may contain
// personally-identifiable information - e.g. Alex's MacbookPro.
std::string GetPersonalizableDeviceNameBlocking();
diff --git a/chromium/components/sync_device_info/local_device_info_util_chromeos.cc b/chromium/components/sync_device_info/local_device_info_util_chromeos.cc
new file mode 100644
index 00000000000..063e4f36961
--- /dev/null
+++ b/chromium/components/sync_device_info/local_device_info_util_chromeos.cc
@@ -0,0 +1,31 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "chromeos/constants/devicetype.h"
+
+namespace syncer {
+
+std::string GetChromeOSDeviceNameFromType() {
+ switch (chromeos::GetDeviceType()) {
+ case chromeos::DeviceType::kChromebase:
+ return "Chromebase";
+ case chromeos::DeviceType::kChromebit:
+ return "Chromebit";
+ case chromeos::DeviceType::kChromebook:
+ return "Chromebook";
+ case chromeos::DeviceType::kChromebox:
+ return "Chromebox";
+ case chromeos::DeviceType::kUnknown:
+ break;
+ }
+ return "Chromebook";
+}
+
+std::string GetPersonalizableDeviceNameInternal() {
+ return GetChromeOSDeviceNameFromType();
+}
+
+} // namespace syncer
diff --git a/chromium/components/sync_device_info/local_device_info_util_linux.cc b/chromium/components/sync_device_info/local_device_info_util_linux.cc
index 30f8bfb3efc..e076504ccef 100644
--- a/chromium/components/sync_device_info/local_device_info_util_linux.cc
+++ b/chromium/components/sync_device_info/local_device_info_util_linux.cc
@@ -8,42 +8,15 @@
#include <string>
#include "base/linux_util.h"
-#include "build/chromeos_buildflags.h"
-
-#if BUILDFLAG(IS_CHROMEOS_ASH)
-#include "chromeos/constants/devicetype.h" // nogncheck
-#endif
namespace syncer {
-#if BUILDFLAG(IS_CHROMEOS_ASH)
-std::string GetChromeOSDeviceNameFromType() {
- switch (chromeos::GetDeviceType()) {
- case chromeos::DeviceType::kChromebase:
- return "Chromebase";
- case chromeos::DeviceType::kChromebit:
- return "Chromebit";
- case chromeos::DeviceType::kChromebook:
- return "Chromebook";
- case chromeos::DeviceType::kChromebox:
- return "Chromebox";
- case chromeos::DeviceType::kUnknown:
- break;
- }
- return "Chromebook";
-}
-#endif
-
std::string GetPersonalizableDeviceNameInternal() {
-#if BUILDFLAG(IS_CHROMEOS_ASH)
- return GetChromeOSDeviceNameFromType();
-#else
char hostname[HOST_NAME_MAX];
if (gethostname(hostname, HOST_NAME_MAX) == 0) { // Success.
return hostname;
}
return base::GetLinuxDistro();
-#endif
}
} // namespace syncer