Commit b34bc113 authored by Himanshu Jaju's avatar Himanshu Jaju Committed by Commit Bot

Use SyncMode to decide device name

For full sync we use the PII name, but for transport only mode we use
the device's model name as client name.

Bug: 1009454
Change-Id: I4a31e012ad81715af91b1dcaf782a4f0466b6f06
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1852092
Commit-Queue: Himanshu Jaju <himanshujaju@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarAlex Chau <alexchau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705955}
parent 4de4e88f
......@@ -202,6 +202,8 @@ void DeviceInfoSyncBridge::OnSyncStarting(
device_info_prefs_->GarbageCollectExpiredCacheGuids();
// Add the cache guid to the local prefs.
device_info_prefs_->AddLocalCacheGuid(local_cache_guid_);
// SyncMode determines the client name in GetLocalClientName().
sync_mode_ = request.sync_mode;
}
std::unique_ptr<MetadataChangeList>
......@@ -216,9 +218,8 @@ base::Optional<ModelError> DeviceInfoSyncBridge::MergeSyncData(
DCHECK(all_data_.empty());
DCHECK(!local_cache_guid_.empty());
local_device_info_provider_->Initialize(local_cache_guid_,
local_personalizable_device_name_,
local_hardware_info_);
local_device_info_provider_->Initialize(
local_cache_guid_, GetLocalClientName(), local_hardware_info_);
std::unique_ptr<WriteBatch> batch = store_->CreateWriteBatch();
for (const auto& change : entity_data) {
......@@ -397,6 +398,22 @@ bool DeviceInfoSyncBridge::DeleteSpecifics(const std::string& guid,
}
}
std::string DeviceInfoSyncBridge::GetLocalClientName() const {
// |sync_mode_| may not be ready when this function is called.
if (!sync_mode_) {
auto device_it = all_data_.find(local_cache_guid_);
if (device_it != all_data_.end()) {
return device_it->second->client_name();
}
}
if (sync_mode_ == SyncMode::kFull) {
return local_personalizable_device_name_;
}
return local_hardware_info_.model;
}
void DeviceInfoSyncBridge::OnStoreCreated(
const base::Optional<syncer::ModelError>& error,
std::unique_ptr<ModelTypeStore> store) {
......@@ -498,9 +515,8 @@ void DeviceInfoSyncBridge::OnReadAllMetadata(
// If sync already enabled (usual case without data corruption), we can
// initialize the provider immediately.
local_cache_guid_ = local_cache_guid_in_metadata;
local_device_info_provider_->Initialize(local_cache_guid_,
local_personalizable_device_name_,
local_hardware_info_);
local_device_info_provider_->Initialize(
local_cache_guid_, GetLocalClientName(), local_hardware_info_);
// This probably isn't strictly needed, but in case the cache_guid has changed
// we save the new one to prefs.
......
......@@ -17,6 +17,7 @@
#include "base/system/sys_info.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "components/sync/base/sync_mode.h"
#include "components/sync/model/model_error.h"
#include "components/sync/model/model_type_store.h"
#include "components/sync/model/model_type_sync_bridge.h"
......@@ -96,6 +97,11 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge,
bool DeleteSpecifics(const std::string& tag,
ModelTypeStore::WriteBatch* batch);
// Returns the device name based on |sync_mode_|. For transport only mode,
// the device model name is returned. For full sync mode,
// |local_personalizable_device_name_| is returned.
std::string GetLocalClientName() const;
// Notify all registered observers.
void NotifyObservers();
......@@ -145,6 +151,7 @@ class DeviceInfoSyncBridge : public ModelTypeSyncBridge,
std::string local_personalizable_device_name_;
ClientIdToSpecifics all_data_;
base::SysInfo::HardwareInfo local_hardware_info_;
base::Optional<SyncMode> sync_mode_;
// Registered observers, not owned.
base::ObserverList<Observer, true>::Unchecked observers_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment