Commit c1dec1c5 authored by Tanya Gupta's avatar Tanya Gupta Committed by Commit Bot

[SendTabToSelf] Plumb device support for SendTabToSelf feature in DeviceInfo

A callback is used to populate the DeviceInfo with the latest state
on support for SendTabToSelf feature on the device. The information is used
to determine which set of devices tabs can be shared to.

Change-Id: Ib0f9093ae20ff8fc05494222789107a215057d79
Bug: 937004
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1570478
Commit-Queue: Tanya Gupta <tgupta@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Reviewed-by: default avatarsebsg <sebsg@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652375}
parent 64854803
...@@ -16,10 +16,9 @@ ...@@ -16,10 +16,9 @@
using syncer::DeviceInfo; using syncer::DeviceInfo;
namespace extensions { namespace extensions {
bool VerifyDictionary( bool VerifyDictionary(const std::string& path,
const std::string& path, const std::string& expected_value,
const std::string& expected_value, const base::DictionaryValue& dictionary) {
const base::DictionaryValue& dictionary) {
std::string out; std::string out;
if (dictionary.GetString(path, &out)) { if (dictionary.GetString(path, &out)) {
return (out == expected_value); return (out == expected_value);
...@@ -33,11 +32,13 @@ TEST(IdMappingHelperTest, SetIdsForDevices) { ...@@ -33,11 +32,13 @@ TEST(IdMappingHelperTest, SetIdsForDevices) {
devices.push_back(std::make_unique<DeviceInfo>( devices.push_back(std::make_unique<DeviceInfo>(
base::GenerateGUID(), "abc Device", "XYZ v1", "XYZ SyncAgent v1", base::GenerateGUID(), "abc Device", "XYZ v1", "XYZ SyncAgent v1",
sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id1")); sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id1",
/*send_tab_to_self_receiving_enabled=*/true));
devices.push_back(std::make_unique<DeviceInfo>( devices.push_back(std::make_unique<DeviceInfo>(
base::GenerateGUID(), "def Device", "XYZ v1", "XYZ SyncAgent v1", base::GenerateGUID(), "def Device", "XYZ v1", "XYZ SyncAgent v1",
sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id2")); sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id2",
/*send_tab_to_self_receiving_enabled=*/true));
base::DictionaryValue dictionary; base::DictionaryValue dictionary;
...@@ -54,7 +55,8 @@ TEST(IdMappingHelperTest, SetIdsForDevices) { ...@@ -54,7 +55,8 @@ TEST(IdMappingHelperTest, SetIdsForDevices) {
// Now add a third device. // Now add a third device.
devices.push_back(std::make_unique<DeviceInfo>( devices.push_back(std::make_unique<DeviceInfo>(
base::GenerateGUID(), "ghi Device", "XYZ v1", "XYZ SyncAgent v1", base::GenerateGUID(), "ghi Device", "XYZ v1", "XYZ SyncAgent v1",
sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id3")); sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id3",
/*send_tab_to_self_receiving_enabled=*/true));
CreateMappingForUnmappedDevices(devices, &dictionary); CreateMappingForUnmappedDevices(devices, &dictionary);
......
...@@ -47,7 +47,8 @@ class MockDeviceInfoTracker : public DeviceInfoTracker { ...@@ -47,7 +47,8 @@ class MockDeviceInfoTracker : public DeviceInfoTracker {
return std::make_unique<DeviceInfo>( return std::make_unique<DeviceInfo>(
device_info.guid(), device_info.client_name(), device_info.guid(), device_info.client_name(),
device_info.chrome_version(), device_info.sync_user_agent(), device_info.chrome_version(), device_info.sync_user_agent(),
device_info.device_type(), device_info.signin_scoped_device_id()); device_info.device_type(), device_info.signin_scoped_device_id(),
device_info.send_tab_to_self_receiving_enabled());
} }
std::vector<std::unique_ptr<DeviceInfo>> GetAllDeviceInfo() const override { std::vector<std::unique_ptr<DeviceInfo>> GetAllDeviceInfo() const override {
...@@ -88,19 +89,13 @@ TEST(SignedInDevicesAPITest, GetSignedInDevices) { ...@@ -88,19 +89,13 @@ TEST(SignedInDevicesAPITest, GetSignedInDevices) {
scoped_refptr<Extension> extension_test = scoped_refptr<Extension> extension_test =
extension_prefs.AddExtension(extension_name); extension_prefs.AddExtension(extension_name);
DeviceInfo device_info1(base::GenerateGUID(), DeviceInfo device_info1(
"abc Device", base::GenerateGUID(), "abc Device", "XYZ v1", "XYZ SyncAgent v1",
"XYZ v1", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id", true);
"XYZ SyncAgent v1",
sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
"device_id");
DeviceInfo device_info2(base::GenerateGUID(), DeviceInfo device_info2(
"def Device", base::GenerateGUID(), "def Device", "XYZ v2", "XYZ SyncAgent v2",
"XYZ v2", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id", true);
"XYZ SyncAgent v2",
sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
"device_id");
device_tracker.Add(&device_info1); device_tracker.Add(&device_info1);
device_tracker.Add(&device_info2); device_tracker.Add(&device_info2);
...@@ -117,12 +112,9 @@ TEST(SignedInDevicesAPITest, GetSignedInDevices) { ...@@ -117,12 +112,9 @@ TEST(SignedInDevicesAPITest, GetSignedInDevices) {
// Add a third device and make sure the first 2 ids are retained and a new // Add a third device and make sure the first 2 ids are retained and a new
// id is generated for the third device. // id is generated for the third device.
DeviceInfo device_info3(base::GenerateGUID(), DeviceInfo device_info3(
"def Device", base::GenerateGUID(), "def Device", "jkl v2", "XYZ SyncAgent v2",
"jkl v2", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id", true);
"XYZ SyncAgent v2",
sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
"device_id");
device_tracker.Add(&device_info3); device_tracker.Add(&device_info3);
...@@ -208,19 +200,13 @@ TEST_F(ExtensionSignedInDevicesTest, GetAll) { ...@@ -208,19 +200,13 @@ TEST_F(ExtensionSignedInDevicesTest, GetAll) {
DeviceInfoSyncServiceFactory::GetForProfile(profile())) DeviceInfoSyncServiceFactory::GetForProfile(profile()))
->mock_tracker(); ->mock_tracker();
DeviceInfo device_info1(base::GenerateGUID(), DeviceInfo device_info1(
"abc Device", base::GenerateGUID(), "abc Device", "XYZ v1", "XYZ SyncAgent v1",
"XYZ v1", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id", true);
"XYZ SyncAgent v1",
sync_pb::SyncEnums_DeviceType_TYPE_LINUX, DeviceInfo device_info2(
"device_id"); base::GenerateGUID(), "def Device", "XYZ v2", "XYZ SyncAgent v2",
sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "device_id", true);
DeviceInfo device_info2(base::GenerateGUID(),
"def Device",
"XYZ v2",
"XYZ SyncAgent v2",
sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
"device_id");
device_tracker->Add(&device_info1); device_tracker->Add(&device_info1);
device_tracker->Add(&device_info2); device_tracker->Add(&device_info2);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/sync/model_type_store_service_factory.h" #include "chrome/browser/sync/model_type_store_service_factory.h"
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/send_tab_to_self/features.h"
#include "components/sync/base/sync_prefs.h" #include "components/sync/base/sync_prefs.h"
#include "components/sync/device_info/device_info_sync_service_impl.h" #include "components/sync/device_info/device_info_sync_service_impl.h"
#include "components/sync/device_info/local_device_info_provider_impl.h" #include "components/sync/device_info/local_device_info_provider_impl.h"
...@@ -72,6 +73,8 @@ KeyedService* DeviceInfoSyncServiceFactory::BuildServiceInstanceFor( ...@@ -72,6 +73,8 @@ KeyedService* DeviceInfoSyncServiceFactory::BuildServiceInstanceFor(
syncer::LocalDeviceInfoProviderImpl::SigninScopedDeviceIdCallback syncer::LocalDeviceInfoProviderImpl::SigninScopedDeviceIdCallback
signin_scoped_device_id_callback; signin_scoped_device_id_callback;
syncer::LocalDeviceInfoProviderImpl::SendTabToSelfReceivingEnabledCallback
send_tab_to_self_receiving_enabled_callback;
bool local_sync_backend_enabled = false; bool local_sync_backend_enabled = false;
// Since the local sync backend is currently only supported on Windows don't // Since the local sync backend is currently only supported on Windows don't
...@@ -89,10 +92,15 @@ KeyedService* DeviceInfoSyncServiceFactory::BuildServiceInstanceFor( ...@@ -89,10 +92,15 @@ KeyedService* DeviceInfoSyncServiceFactory::BuildServiceInstanceFor(
base::BindRepeating(&GetSigninScopedDeviceIdForProfile, profile); base::BindRepeating(&GetSigninScopedDeviceIdForProfile, profile);
} }
send_tab_to_self_receiving_enabled_callback = base::BindRepeating(
&send_tab_to_self::IsReceivingEnabledByUserOnThisDevice,
profile->GetPrefs());
auto local_device_info_provider = auto local_device_info_provider =
std::make_unique<syncer::LocalDeviceInfoProviderImpl>( std::make_unique<syncer::LocalDeviceInfoProviderImpl>(
chrome::GetChannel(), chrome::GetVersionString(), chrome::GetChannel(), chrome::GetVersionString(),
signin_scoped_device_id_callback); signin_scoped_device_id_callback,
send_tab_to_self_receiving_enabled_callback);
return new syncer::DeviceInfoSyncServiceImpl( return new syncer::DeviceInfoSyncServiceImpl(
ModelTypeStoreServiceFactory::GetForProfile(profile)->GetStoreFactory(), ModelTypeStoreServiceFactory::GetForProfile(profile)->GetStoreFactory(),
std::move(local_device_info_provider)); std::move(local_device_info_provider));
......
...@@ -4,9 +4,19 @@ ...@@ -4,9 +4,19 @@
#include "components/send_tab_to_self/features.h" #include "components/send_tab_to_self/features.h"
#include "components/sync/base/sync_prefs.h"
#include "components/sync/base/user_selectable_type.h"
#include "components/sync/driver/sync_driver_switches.h"
namespace send_tab_to_self { namespace send_tab_to_self {
const base::Feature kSendTabToSelfShowSendingUI{ const base::Feature kSendTabToSelfShowSendingUI{
"SendTabToSelfShowSendingUI", base::FEATURE_DISABLED_BY_DEFAULT}; "SendTabToSelfShowSendingUI", base::FEATURE_DISABLED_BY_DEFAULT};
bool IsReceivingEnabledByUserOnThisDevice(PrefService* prefs) {
syncer::SyncPrefs sync_prefs(prefs);
return base::FeatureList::IsEnabled(switches::kSyncSendTabToSelf) &&
sync_prefs.GetSelectedTypes().Has(syncer::UserSelectableType::kTabs);
}
} // namespace send_tab_to_self } // namespace send_tab_to_self
...@@ -7,11 +7,20 @@ ...@@ -7,11 +7,20 @@
#include "base/feature_list.h" #include "base/feature_list.h"
class PrefService;
namespace send_tab_to_self { namespace send_tab_to_self {
// If this feature is enabled, we will display the UI to send tabs if the Sync // If this feature is enabled, we will display the UI to send tabs if the Sync
// datatype is also enabled. // datatype is also enabled.
extern const base::Feature kSendTabToSelfShowSendingUI; extern const base::Feature kSendTabToSelfShowSendingUI;
// Returns whether the receiving components of the feature is enabled on this
// device. This is different from IsReceivingEnabled in SendTabToSelfUtil
// because it doesn't rely on the SendTabToSelfSyncService to be actively up and
// ready.
bool IsReceivingEnabledByUserOnThisDevice(PrefService* prefs);
} // namespace send_tab_to_self } // namespace send_tab_to_self
#endif // COMPONENTS_SEND_TAB_TO_SELF_FEATURES_H_ #endif // COMPONENTS_SEND_TAB_TO_SELF_FEATURES_H_
...@@ -13,13 +13,15 @@ DeviceInfo::DeviceInfo(const std::string& guid, ...@@ -13,13 +13,15 @@ DeviceInfo::DeviceInfo(const std::string& guid,
const std::string& chrome_version, const std::string& chrome_version,
const std::string& sync_user_agent, const std::string& sync_user_agent,
const sync_pb::SyncEnums::DeviceType device_type, const sync_pb::SyncEnums::DeviceType device_type,
const std::string& signin_scoped_device_id) const std::string& signin_scoped_device_id,
bool send_tab_to_self_receiving_enabled)
: guid_(guid), : guid_(guid),
client_name_(client_name), client_name_(client_name),
chrome_version_(chrome_version), chrome_version_(chrome_version),
sync_user_agent_(sync_user_agent), sync_user_agent_(sync_user_agent),
device_type_(device_type), device_type_(device_type),
signin_scoped_device_id_(signin_scoped_device_id) {} signin_scoped_device_id_(signin_scoped_device_id),
send_tab_to_self_receiving_enabled_(send_tab_to_self_receiving_enabled) {}
DeviceInfo::~DeviceInfo() {} DeviceInfo::~DeviceInfo() {}
...@@ -51,6 +53,10 @@ const std::string& DeviceInfo::signin_scoped_device_id() const { ...@@ -51,6 +53,10 @@ const std::string& DeviceInfo::signin_scoped_device_id() const {
return signin_scoped_device_id_; return signin_scoped_device_id_;
} }
bool DeviceInfo::send_tab_to_self_receiving_enabled() const {
return send_tab_to_self_receiving_enabled_;
}
std::string DeviceInfo::GetOSString() const { std::string DeviceInfo::GetOSString() const {
switch (device_type_) { switch (device_type_) {
case sync_pb::SyncEnums_DeviceType_TYPE_WIN: case sync_pb::SyncEnums_DeviceType_TYPE_WIN:
...@@ -93,7 +99,9 @@ bool DeviceInfo::Equals(const DeviceInfo& other) const { ...@@ -93,7 +99,9 @@ bool DeviceInfo::Equals(const DeviceInfo& other) const {
this->chrome_version() == other.chrome_version() && this->chrome_version() == other.chrome_version() &&
this->sync_user_agent() == other.sync_user_agent() && this->sync_user_agent() == other.sync_user_agent() &&
this->device_type() == other.device_type() && this->device_type() == other.device_type() &&
this->signin_scoped_device_id() == other.signin_scoped_device_id(); this->signin_scoped_device_id() == other.signin_scoped_device_id() &&
this->send_tab_to_self_receiving_enabled() ==
other.send_tab_to_self_receiving_enabled();
} }
std::unique_ptr<base::DictionaryValue> DeviceInfo::ToValue() { std::unique_ptr<base::DictionaryValue> DeviceInfo::ToValue() {
...@@ -103,6 +111,8 @@ std::unique_ptr<base::DictionaryValue> DeviceInfo::ToValue() { ...@@ -103,6 +111,8 @@ std::unique_ptr<base::DictionaryValue> DeviceInfo::ToValue() {
value->SetString("os", GetOSString()); value->SetString("os", GetOSString());
value->SetString("type", GetDeviceTypeString()); value->SetString("type", GetDeviceTypeString());
value->SetString("chromeVersion", chrome_version_); value->SetString("chromeVersion", chrome_version_);
value->SetBoolean("sendTabToSelfReceivingEnabled",
send_tab_to_self_receiving_enabled());
return value; return value;
} }
...@@ -110,4 +120,8 @@ void DeviceInfo::set_public_id(const std::string& id) { ...@@ -110,4 +120,8 @@ void DeviceInfo::set_public_id(const std::string& id) {
public_id_ = id; public_id_ = id;
} }
void DeviceInfo::set_send_tab_to_self_receiving_enabled(bool new_value) {
send_tab_to_self_receiving_enabled_ = new_value;
}
} // namespace syncer } // namespace syncer
...@@ -26,7 +26,8 @@ class DeviceInfo { ...@@ -26,7 +26,8 @@ class DeviceInfo {
const std::string& chrome_version, const std::string& chrome_version,
const std::string& sync_user_agent, const std::string& sync_user_agent,
const sync_pb::SyncEnums::DeviceType device_type, const sync_pb::SyncEnums::DeviceType device_type,
const std::string& signin_scoped_device_id); const std::string& signin_scoped_device_id,
bool send_tab_to_self_receiving_enabled);
~DeviceInfo(); ~DeviceInfo();
// Sync specific unique identifier for the device. Note if a device // Sync specific unique identifier for the device. Note if a device
...@@ -56,6 +57,9 @@ class DeviceInfo { ...@@ -56,6 +57,9 @@ class DeviceInfo {
// annotating login scoped refresh token. // annotating login scoped refresh token.
const std::string& signin_scoped_device_id() const; const std::string& signin_scoped_device_id() const;
// Whether the receiving side of the SendTabToSelf feature is enabled.
bool send_tab_to_self_receiving_enabled() const;
// Gets the OS in string form. // Gets the OS in string form.
std::string GetOSString() const; std::string GetOSString() const;
...@@ -71,6 +75,8 @@ class DeviceInfo { ...@@ -71,6 +75,8 @@ class DeviceInfo {
// be used for tracking. // be used for tracking.
void set_public_id(const std::string& id); void set_public_id(const std::string& id);
void set_send_tab_to_self_receiving_enabled(bool new_value);
// Converts the |DeviceInfo| values to a JS friendly DictionaryValue, // Converts the |DeviceInfo| values to a JS friendly DictionaryValue,
// which extension APIs can expose to third party apps. // which extension APIs can expose to third party apps.
std::unique_ptr<base::DictionaryValue> ToValue(); std::unique_ptr<base::DictionaryValue> ToValue();
...@@ -94,6 +100,8 @@ class DeviceInfo { ...@@ -94,6 +100,8 @@ class DeviceInfo {
// and they are also reset when app/extension is uninstalled. // and they are also reset when app/extension is uninstalled.
std::string public_id_; std::string public_id_;
bool send_tab_to_self_receiving_enabled_;
DISALLOW_COPY_AND_ASSIGN(DeviceInfo); DISALLOW_COPY_AND_ASSIGN(DeviceInfo);
}; };
......
...@@ -31,6 +31,7 @@ using base::Time; ...@@ -31,6 +31,7 @@ using base::Time;
using base::TimeDelta; using base::TimeDelta;
using sync_pb::DeviceInfoSpecifics; using sync_pb::DeviceInfoSpecifics;
using sync_pb::EntitySpecifics; using sync_pb::EntitySpecifics;
using sync_pb::FeatureSpecificFields;
using sync_pb::ModelTypeState; using sync_pb::ModelTypeState;
using Record = ModelTypeStore::Record; using Record = ModelTypeStore::Record;
...@@ -56,7 +57,8 @@ std::unique_ptr<DeviceInfo> SpecificsToModel( ...@@ -56,7 +57,8 @@ std::unique_ptr<DeviceInfo> SpecificsToModel(
return std::make_unique<DeviceInfo>( return std::make_unique<DeviceInfo>(
specifics.cache_guid(), specifics.client_name(), specifics.cache_guid(), specifics.client_name(),
specifics.chrome_version(), specifics.sync_user_agent(), specifics.chrome_version(), specifics.sync_user_agent(),
specifics.device_type(), specifics.signin_scoped_device_id()); specifics.device_type(), specifics.signin_scoped_device_id(),
specifics.feature_fields().send_tab_to_self_receiving_enabled());
} }
// Allocate a EntityData and copies |specifics| into it. // Allocate a EntityData and copies |specifics| into it.
...@@ -82,6 +84,11 @@ std::unique_ptr<DeviceInfoSpecifics> ModelToSpecifics( ...@@ -82,6 +84,11 @@ std::unique_ptr<DeviceInfoSpecifics> ModelToSpecifics(
specifics->set_device_type(info.device_type()); specifics->set_device_type(info.device_type());
specifics->set_signin_scoped_device_id(info.signin_scoped_device_id()); specifics->set_signin_scoped_device_id(info.signin_scoped_device_id());
specifics->set_last_updated_timestamp(last_updated_timestamp); specifics->set_last_updated_timestamp(last_updated_timestamp);
FeatureSpecificFields* feature_fields = specifics->mutable_feature_fields();
feature_fields->set_send_tab_to_self_receiving_enabled(
info.send_tab_to_self_receiving_enabled());
return specifics; return specifics;
} }
......
...@@ -64,7 +64,10 @@ MATCHER_P(ModelEqualsSpecifics, expected_specifics, "") { ...@@ -64,7 +64,10 @@ MATCHER_P(ModelEqualsSpecifics, expected_specifics, "") {
expected_specifics.sync_user_agent() == arg.sync_user_agent() && expected_specifics.sync_user_agent() == arg.sync_user_agent() &&
expected_specifics.chrome_version() == arg.chrome_version() && expected_specifics.chrome_version() == arg.chrome_version() &&
expected_specifics.signin_scoped_device_id() == expected_specifics.signin_scoped_device_id() ==
arg.signin_scoped_device_id(); arg.signin_scoped_device_id() &&
expected_specifics.feature_fields()
.send_tab_to_self_receiving_enabled() ==
arg.send_tab_to_self_receiving_enabled();
} }
Matcher<std::unique_ptr<EntityData>> HasSpecifics( Matcher<std::unique_ptr<EntityData>> HasSpecifics(
...@@ -127,6 +130,8 @@ DeviceInfoSpecifics CreateSpecifics( ...@@ -127,6 +130,8 @@ DeviceInfoSpecifics CreateSpecifics(
specifics.set_chrome_version(ChromeVersionForSuffix(suffix)); specifics.set_chrome_version(ChromeVersionForSuffix(suffix));
specifics.set_signin_scoped_device_id(SigninScopedDeviceIdForSuffix(suffix)); specifics.set_signin_scoped_device_id(SigninScopedDeviceIdForSuffix(suffix));
specifics.set_last_updated_timestamp(TimeToProtoTime(last_updated)); specifics.set_last_updated_timestamp(TimeToProtoTime(last_updated));
specifics.mutable_feature_fields()->set_send_tab_to_self_receiving_enabled(
true);
return specifics; return specifics;
} }
...@@ -185,7 +190,7 @@ class TestLocalDeviceInfoProvider : public MutableLocalDeviceInfoProvider { ...@@ -185,7 +190,7 @@ class TestLocalDeviceInfoProvider : public MutableLocalDeviceInfoProvider {
cache_guid, session_name, ChromeVersionForSuffix(kLocalSuffix), cache_guid, session_name, ChromeVersionForSuffix(kLocalSuffix),
SyncUserAgentForSuffix(kLocalSuffix), SyncUserAgentForSuffix(kLocalSuffix),
sync_pb::SyncEnums_DeviceType_TYPE_LINUX, sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
SigninScopedDeviceIdForSuffix(kLocalSuffix)); SigninScopedDeviceIdForSuffix(kLocalSuffix), true);
} }
void Clear() override { local_device_info_.reset(); } void Clear() override { local_device_info_.reset(); }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/sync/device_info/local_device_info_provider_impl.h" #include "components/sync/device_info/local_device_info_provider_impl.h"
#include "base/bind.h" #include "base/bind.h"
#include "components/sync/base/sync_prefs.h"
#include "components/sync/device_info/local_device_info_util.h" #include "components/sync/device_info/local_device_info_util.h"
#include "components/sync/driver/sync_util.h" #include "components/sync/driver/sync_util.h"
...@@ -13,12 +14,17 @@ namespace syncer { ...@@ -13,12 +14,17 @@ namespace syncer {
LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl( LocalDeviceInfoProviderImpl::LocalDeviceInfoProviderImpl(
version_info::Channel channel, version_info::Channel channel,
const std::string& version, const std::string& version,
const SigninScopedDeviceIdCallback& signin_scoped_device_id_callback) const SigninScopedDeviceIdCallback& signin_scoped_device_id_callback,
const SendTabToSelfReceivingEnabledCallback&
send_tab_to_self_receiving_enabled_callback)
: channel_(channel), : channel_(channel),
version_(version), version_(version),
signin_scoped_device_id_callback_(signin_scoped_device_id_callback), signin_scoped_device_id_callback_(signin_scoped_device_id_callback),
send_tab_to_self_receiving_enabled_callback_(
send_tab_to_self_receiving_enabled_callback),
weak_factory_(this) { weak_factory_(this) {
DCHECK(signin_scoped_device_id_callback_); DCHECK(signin_scoped_device_id_callback_);
DCHECK(send_tab_to_self_receiving_enabled_callback_);
} }
LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() { LocalDeviceInfoProviderImpl::~LocalDeviceInfoProviderImpl() {
...@@ -32,6 +38,13 @@ version_info::Channel LocalDeviceInfoProviderImpl::GetChannel() const { ...@@ -32,6 +38,13 @@ version_info::Channel LocalDeviceInfoProviderImpl::GetChannel() const {
const DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const { const DeviceInfo* LocalDeviceInfoProviderImpl::GetLocalDeviceInfo() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bool send_tab_to_self_receiving_enabled =
send_tab_to_self_receiving_enabled_callback_.Run();
if (local_device_info_) {
local_device_info_->set_send_tab_to_self_receiving_enabled(
send_tab_to_self_receiving_enabled);
}
return local_device_info_.get(); return local_device_info_.get();
} }
...@@ -50,7 +63,8 @@ void LocalDeviceInfoProviderImpl::Initialize(const std::string& cache_guid, ...@@ -50,7 +63,8 @@ void LocalDeviceInfoProviderImpl::Initialize(const std::string& cache_guid,
local_device_info_ = std::make_unique<DeviceInfo>( local_device_info_ = std::make_unique<DeviceInfo>(
cache_guid, session_name, version_, MakeUserAgentForSync(channel_), cache_guid, session_name, version_, MakeUserAgentForSync(channel_),
GetLocalDeviceType(), signin_scoped_device_id_callback_.Run()); GetLocalDeviceType(), signin_scoped_device_id_callback_.Run(),
send_tab_to_self_receiving_enabled_callback_.Run());
// Notify observers. // Notify observers.
callback_list_.Notify(); callback_list_.Notify();
......
...@@ -21,11 +21,14 @@ namespace syncer { ...@@ -21,11 +21,14 @@ namespace syncer {
class LocalDeviceInfoProviderImpl : public MutableLocalDeviceInfoProvider { class LocalDeviceInfoProviderImpl : public MutableLocalDeviceInfoProvider {
public: public:
using SigninScopedDeviceIdCallback = base::RepeatingCallback<std::string()>; using SigninScopedDeviceIdCallback = base::RepeatingCallback<std::string()>;
using SendTabToSelfReceivingEnabledCallback = base::RepeatingCallback<bool()>;
LocalDeviceInfoProviderImpl( LocalDeviceInfoProviderImpl(
version_info::Channel channel, version_info::Channel channel,
const std::string& version, const std::string& version,
const SigninScopedDeviceIdCallback& signin_scoped_device_id_callback); const SigninScopedDeviceIdCallback& signin_scoped_device_id_callback,
const SendTabToSelfReceivingEnabledCallback&
send_tab_to_self_receiving_enabled_callback);
~LocalDeviceInfoProviderImpl() override; ~LocalDeviceInfoProviderImpl() override;
// MutableLocalDeviceInfoProvider implementation. // MutableLocalDeviceInfoProvider implementation.
...@@ -45,6 +48,8 @@ class LocalDeviceInfoProviderImpl : public MutableLocalDeviceInfoProvider { ...@@ -45,6 +48,8 @@ class LocalDeviceInfoProviderImpl : public MutableLocalDeviceInfoProvider {
const std::string version_; const std::string version_;
const SigninScopedDeviceIdCallback signin_scoped_device_id_callback_; const SigninScopedDeviceIdCallback signin_scoped_device_id_callback_;
const SendTabToSelfReceivingEnabledCallback
send_tab_to_self_receiving_enabled_callback_;
std::unique_ptr<DeviceInfo> local_device_info_; std::unique_ptr<DeviceInfo> local_device_info_;
base::CallbackList<void(void)> callback_list_; base::CallbackList<void(void)> callback_list_;
......
...@@ -28,7 +28,8 @@ class LocalDeviceInfoProviderImplTest : public testing::Test { ...@@ -28,7 +28,8 @@ class LocalDeviceInfoProviderImplTest : public testing::Test {
provider_ = std::make_unique<LocalDeviceInfoProviderImpl>( provider_ = std::make_unique<LocalDeviceInfoProviderImpl>(
version_info::Channel::UNKNOWN, version_info::Channel::UNKNOWN,
version_info::GetVersionStringWithModifier("UNKNOWN"), version_info::GetVersionStringWithModifier("UNKNOWN"),
signin_scoped_device_id_callback_.Get()); signin_scoped_device_id_callback_.Get(),
send_tab_to_self_receiving_enabled_callback_.Get());
} }
void TearDown() override { void TearDown() override {
...@@ -45,6 +46,9 @@ class LocalDeviceInfoProviderImplTest : public testing::Test { ...@@ -45,6 +46,9 @@ class LocalDeviceInfoProviderImplTest : public testing::Test {
testing::NiceMock<base::MockCallback< testing::NiceMock<base::MockCallback<
LocalDeviceInfoProviderImpl::SigninScopedDeviceIdCallback>> LocalDeviceInfoProviderImpl::SigninScopedDeviceIdCallback>>
signin_scoped_device_id_callback_; signin_scoped_device_id_callback_;
testing::NiceMock<base::MockCallback<
LocalDeviceInfoProviderImpl::SendTabToSelfReceivingEnabledCallback>>
send_tab_to_self_receiving_enabled_callback_;
std::unique_ptr<LocalDeviceInfoProviderImpl> provider_; std::unique_ptr<LocalDeviceInfoProviderImpl> provider_;
}; };
...@@ -77,5 +81,23 @@ TEST_F(LocalDeviceInfoProviderImplTest, GetSigninScopedDeviceId) { ...@@ -77,5 +81,23 @@ TEST_F(LocalDeviceInfoProviderImplTest, GetSigninScopedDeviceId) {
provider_->GetLocalDeviceInfo()->signin_scoped_device_id()); provider_->GetLocalDeviceInfo()->signin_scoped_device_id());
} }
TEST_F(LocalDeviceInfoProviderImplTest, SendTabToSelfReceivingEnabled) {
ON_CALL(send_tab_to_self_receiving_enabled_callback_, Run())
.WillByDefault(Return(true));
InitializeProvider();
ASSERT_THAT(provider_->GetLocalDeviceInfo(), NotNull());
EXPECT_TRUE(
provider_->GetLocalDeviceInfo()->send_tab_to_self_receiving_enabled());
ON_CALL(send_tab_to_self_receiving_enabled_callback_, Run())
.WillByDefault(Return(false));
ASSERT_THAT(provider_->GetLocalDeviceInfo(), NotNull());
EXPECT_FALSE(
provider_->GetLocalDeviceInfo()->send_tab_to_self_receiving_enabled());
}
} // namespace } // namespace
} // namespace syncer } // namespace syncer
...@@ -48,4 +48,20 @@ message DeviceInfoSpecifics { ...@@ -48,4 +48,20 @@ message DeviceInfoSpecifics {
// difference between this field and the current time, it should be possible // difference between this field and the current time, it should be possible
// to reason about the inactivity of any device that was syncing at one time. // to reason about the inactivity of any device that was syncing at one time.
optional int64 last_updated_timestamp = 8; optional int64 last_updated_timestamp = 8;
// Device info fields that are specific to a feature. This is information that
// can not be derived from the other fields in the proto and are not general
// enough to be used by another feature.
optional FeatureSpecificFields feature_fields = 9;
}
// Feature specific information about the device that is running a sync-enabled
// Chrome browser. Adding to this proto is discouraged and should only be added
// when the information can not be derived more generally.
message FeatureSpecificFields {
// Tracks whether the SendTabToSelf feature is enabled on the device. For this
// to be true, two things must be true: (1) The receiving side of the feature
// must be enabled on the device (2) The user has enabled sync for this
// feature
optional bool send_tab_to_self_receiving_enabled = 1;
} }
...@@ -335,6 +335,11 @@ VISIT_PROTO_FIELDS(const sync_pb::DeviceInfoSpecifics& proto) { ...@@ -335,6 +335,11 @@ VISIT_PROTO_FIELDS(const sync_pb::DeviceInfoSpecifics& proto) {
VISIT(chrome_version); VISIT(chrome_version);
VISIT(signin_scoped_device_id); VISIT(signin_scoped_device_id);
VISIT(last_updated_timestamp); VISIT(last_updated_timestamp);
VISIT(feature_fields);
}
VISIT_PROTO_FIELDS(const sync_pb::FeatureSpecificFields& proto) {
VISIT(send_tab_to_self_receiving_enabled);
} }
VISIT_PROTO_FIELDS(const sync_pb::DictionarySpecifics& proto) { VISIT_PROTO_FIELDS(const sync_pb::DictionarySpecifics& proto) {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "components/keyed_service/core/service_access_type.h" #include "components/keyed_service/core/service_access_type.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h" #include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/send_tab_to_self/features.h"
#include "components/signin/core/browser/device_id_helper.h" #include "components/signin/core/browser/device_id_helper.h"
#include "components/sync/device_info/device_info_sync_service_impl.h" #include "components/sync/device_info/device_info_sync_service_impl.h"
#include "components/sync/device_info/local_device_info_provider_impl.h" #include "components/sync/device_info/local_device_info_provider_impl.h"
...@@ -77,7 +78,11 @@ DeviceInfoSyncServiceFactory::BuildServiceInstanceFor( ...@@ -77,7 +78,11 @@ DeviceInfoSyncServiceFactory::BuildServiceInstanceFor(
::GetChannel(), ::GetVersionString(), ::GetChannel(), ::GetVersionString(),
/*signin_scoped_device_id_callback=*/ /*signin_scoped_device_id_callback=*/
base::BindRepeating(&signin::GetSigninScopedDeviceId, base::BindRepeating(&signin::GetSigninScopedDeviceId,
browser_state->GetPrefs())); browser_state->GetPrefs()),
/*send_tab_to_self_receiving_enabled_callback=*/
base::BindRepeating(
&send_tab_to_self::IsReceivingEnabledByUserOnThisDevice,
browser_state->GetPrefs()));
return std::make_unique<syncer::DeviceInfoSyncServiceImpl>( return std::make_unique<syncer::DeviceInfoSyncServiceImpl>(
ModelTypeStoreServiceFactory::GetForBrowserState(browser_state) ModelTypeStoreServiceFactory::GetForBrowserState(browser_state)
......
...@@ -56,7 +56,9 @@ WebViewDeviceInfoSyncServiceFactory::BuildServiceInstanceFor( ...@@ -56,7 +56,9 @@ WebViewDeviceInfoSyncServiceFactory::BuildServiceInstanceFor(
version_info::Channel::STABLE, version_info::GetVersionNumber(), version_info::Channel::STABLE, version_info::GetVersionNumber(),
/*signin_scoped_device_id_callback=*/ /*signin_scoped_device_id_callback=*/
base::BindRepeating(&signin::GetSigninScopedDeviceId, base::BindRepeating(&signin::GetSigninScopedDeviceId,
browser_state->GetPrefs())); browser_state->GetPrefs()),
/*send_tab_to_self_receiving_enabled_callback=*/
base::BindRepeating([]() { return false; }));
return std::make_unique<syncer::DeviceInfoSyncServiceImpl>( return std::make_unique<syncer::DeviceInfoSyncServiceImpl>(
WebViewModelTypeStoreServiceFactory::GetForBrowserState(browser_state) WebViewModelTypeStoreServiceFactory::GetForBrowserState(browser_state)
......
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