Commit b32520d2 authored by Rushan Suleymanov's avatar Rushan Suleymanov Committed by Commit Bot

[Sync] Make SharingMessageBridge as KeyedService.

SharingService has dependency on ProfileSyncService. Make
SharingMessageBridge a separate service with its own factory to prevent
cyclic dependency.

This change does not wire the bridge to any existing service but provides
the interface for creating and using it.

Bug: 1034930
Change-Id: I9907eb2687e48c65b7203d1b10e6ad34ed981010
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2007269
Commit-Queue: Rushan Suleymanov <rushans@google.com>
Reviewed-by: default avatarAlex Chau <alexchau@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarvitaliii <vitaliii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734415}
parent 54865c6d
...@@ -1593,6 +1593,8 @@ jumbo_static_library("browser") { ...@@ -1593,6 +1593,8 @@ jumbo_static_library("browser") {
"sharing/sharing_handler_registry_impl.cc", "sharing/sharing_handler_registry_impl.cc",
"sharing/sharing_handler_registry_impl.h", "sharing/sharing_handler_registry_impl.h",
"sharing/sharing_message_bridge.h", "sharing/sharing_message_bridge.h",
"sharing/sharing_message_bridge_factory.cc",
"sharing/sharing_message_bridge_factory.h",
"sharing/sharing_message_bridge_impl.cc", "sharing/sharing_message_bridge_impl.cc",
"sharing/sharing_message_bridge_impl.h", "sharing/sharing_message_bridge_impl.h",
"sharing/sharing_message_handler.h", "sharing/sharing_message_handler.h",
......
...@@ -7,17 +7,25 @@ ...@@ -7,17 +7,25 @@
#include <memory> #include <memory>
#include "base/memory/weak_ptr.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/sync/protocol/sharing_message_specifics.pb.h" #include "components/sync/protocol/sharing_message_specifics.pb.h"
namespace syncer {
class ModelTypeControllerDelegate;
} // namespace syncer
// Class to provide an interface to send sharing messages using Sync. // Class to provide an interface to send sharing messages using Sync.
class SharingMessageBridge { class SharingMessageBridge : public KeyedService {
public: public:
// TODO(crbug.com/1034930): take callbacks once commit error propagation back // TODO(crbug.com/1034930): take callbacks once commit error propagation back
// to the bridge is implemented. // to the bridge is implemented.
virtual void SendSharingMessage( virtual void SendSharingMessage(
std::unique_ptr<sync_pb::SharingMessageSpecifics> specifics) = 0; std::unique_ptr<sync_pb::SharingMessageSpecifics> specifics) = 0;
virtual ~SharingMessageBridge() = default; // Returns the delegate for the controller, i.e. sync integration point.
virtual base::WeakPtr<syncer::ModelTypeControllerDelegate>
GetControllerDelegate() = 0;
}; };
#endif // CHROME_BROWSER_SHARING_SHARING_MESSAGE_BRIDGE_H_ #endif // CHROME_BROWSER_SHARING_SHARING_MESSAGE_BRIDGE_H_
// Copyright 2020 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 "chrome/browser/sharing/sharing_message_bridge_factory.h"
#include "chrome/browser/sharing/sharing_message_bridge_impl.h"
#include "base/memory/singleton.h"
#include "chrome/common/channel_info.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/sync/base/report_unrecoverable_error.h"
#include "components/sync/model_impl/client_tag_based_model_type_processor.h"
namespace {
constexpr char kServiceName[] = "SharingMessageBridge";
} // namespace
SharingMessageBridgeFactory::SharingMessageBridgeFactory()
: BrowserContextKeyedServiceFactory(
kServiceName,
BrowserContextDependencyManager::GetInstance()) {}
SharingMessageBridgeFactory::~SharingMessageBridgeFactory() = default;
// static
SharingMessageBridgeFactory* SharingMessageBridgeFactory::GetInstance() {
return base::Singleton<SharingMessageBridgeFactory>::get();
}
// static
SharingMessageBridge* SharingMessageBridgeFactory::GetForBrowserContext(
content::BrowserContext* context) {
return static_cast<SharingMessageBridge*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}
KeyedService* SharingMessageBridgeFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
auto change_processor =
std::make_unique<syncer::ClientTagBasedModelTypeProcessor>(
syncer::SHARING_MESSAGE,
base::BindRepeating(&syncer::ReportUnrecoverableError,
chrome::GetChannel()));
return new SharingMessageBridgeImpl(std::move(change_processor));
}
// Copyright 2020 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.
#ifndef CHROME_BROWSER_SHARING_SHARING_MESSAGE_BRIDGE_FACTORY_H_
#define CHROME_BROWSER_SHARING_SHARING_MESSAGE_BRIDGE_FACTORY_H_
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace base {
template <typename T>
struct DefaultSingletonTraits;
} // namespace base
class SharingMessageBridge;
// Factory for sharing message bridge. We need this factory to prevent cyclic
// dependency between SharingServiceFactory and ProfileSyncServiceFactory.
class SharingMessageBridgeFactory : public BrowserContextKeyedServiceFactory {
public:
// Returns singleton instance of SharingMessageBridgeFactory.
static SharingMessageBridgeFactory* GetInstance();
// Returns the SharingMessageBridge associated with |context|.
static SharingMessageBridge* GetForBrowserContext(
content::BrowserContext* context);
private:
friend struct base::DefaultSingletonTraits<SharingMessageBridgeFactory>;
SharingMessageBridgeFactory();
~SharingMessageBridgeFactory() override;
SharingMessageBridgeFactory(const SharingMessageBridgeFactory&) = delete;
SharingMessageBridgeFactory& operator=(const SharingMessageBridgeFactory&) =
delete;
// BrowserContextKeyedServiceFactory overrides:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
};
#endif // CHROME_BROWSER_SHARING_SHARING_MESSAGE_BRIDGE_FACTORY_H_
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/sharing/sharing_message_bridge_impl.h" #include "chrome/browser/sharing/sharing_message_bridge_impl.h"
#include "base/guid.h"
#include "components/sync/model/metadata_batch.h" #include "components/sync/model/metadata_batch.h"
#include "components/sync/model/mutable_data_batch.h" #include "components/sync/model/mutable_data_batch.h"
#include "components/sync/model_impl/in_memory_metadata_change_list.h" #include "components/sync/model_impl/in_memory_metadata_change_list.h"
...@@ -13,6 +14,10 @@ namespace { ...@@ -13,6 +14,10 @@ namespace {
std::unique_ptr<syncer::EntityData> MoveToEntityData( std::unique_ptr<syncer::EntityData> MoveToEntityData(
std::unique_ptr<sync_pb::SharingMessageSpecifics> specifics) { std::unique_ptr<sync_pb::SharingMessageSpecifics> specifics) {
auto entity_data = std::make_unique<syncer::EntityData>(); auto entity_data = std::make_unique<syncer::EntityData>();
const std::string guid = base::GenerateGUID();
entity_data->client_tag_hash =
syncer::ClientTagHash::FromUnhashed(syncer::SHARING_MESSAGE, guid);
entity_data->name = guid;
entity_data->specifics.set_allocated_sharing_message(specifics.release()); entity_data->specifics.set_allocated_sharing_message(specifics.release());
return entity_data; return entity_data;
} }
...@@ -41,6 +46,11 @@ void SharingMessageBridgeImpl::SendSharingMessage( ...@@ -41,6 +46,11 @@ void SharingMessageBridgeImpl::SendSharingMessage(
metadata_change_list.get()); metadata_change_list.get());
} }
base::WeakPtr<syncer::ModelTypeControllerDelegate>
SharingMessageBridgeImpl::GetControllerDelegate() {
return change_processor()->GetControllerDelegate();
}
std::unique_ptr<syncer::MetadataChangeList> std::unique_ptr<syncer::MetadataChangeList>
SharingMessageBridgeImpl::CreateMetadataChangeList() { SharingMessageBridgeImpl::CreateMetadataChangeList() {
// The data type intentionally doesn't persist the data on disk, so metadata // The data type intentionally doesn't persist the data on disk, so metadata
......
...@@ -26,6 +26,8 @@ class SharingMessageBridgeImpl : public SharingMessageBridge, ...@@ -26,6 +26,8 @@ class SharingMessageBridgeImpl : public SharingMessageBridge,
// SharingMessageBridge implementation. // SharingMessageBridge implementation.
void SendSharingMessage( void SendSharingMessage(
std::unique_ptr<sync_pb::SharingMessageSpecifics> specifics) override; std::unique_ptr<sync_pb::SharingMessageSpecifics> specifics) override;
base::WeakPtr<syncer::ModelTypeControllerDelegate> GetControllerDelegate()
override;
// ModelTypeSyncBridge implementation. // ModelTypeSyncBridge implementation.
std::unique_ptr<syncer::MetadataChangeList> CreateMetadataChangeList() std::unique_ptr<syncer::MetadataChangeList> CreateMetadataChangeList()
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/security_events/security_event_recorder.h" #include "chrome/browser/security_events/security_event_recorder.h"
#include "chrome/browser/security_events/security_event_recorder_factory.h" #include "chrome/browser/security_events/security_event_recorder_factory.h"
#include "chrome/browser/sharing/sharing_message_bridge.h"
#include "chrome/browser/sharing/sharing_message_bridge_factory.h"
#include "chrome/browser/sync/bookmark_sync_service_factory.h" #include "chrome/browser/sync/bookmark_sync_service_factory.h"
#include "chrome/browser/sync/device_info_sync_service_factory.h" #include "chrome/browser/sync/device_info_sync_service_factory.h"
#include "chrome/browser/sync/model_type_store_service_factory.h" #include "chrome/browser/sync/model_type_store_service_factory.h"
...@@ -611,6 +613,9 @@ ChromeSyncClient::GetControllerDelegateForModelType(syncer::ModelType type) { ...@@ -611,6 +613,9 @@ ChromeSyncClient::GetControllerDelegateForModelType(syncer::ModelType type) {
return WifiConfigurationSyncServiceFactory::GetForProfile(profile_) return WifiConfigurationSyncServiceFactory::GetForProfile(profile_)
->GetControllerDelegate(); ->GetControllerDelegate();
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
case syncer::SHARING_MESSAGE:
return SharingMessageBridgeFactory::GetForBrowserContext(profile_)
->GetControllerDelegate();
case syncer::USER_CONSENTS: case syncer::USER_CONSENTS:
return ConsentAuditorFactory::GetForProfile(profile_) return ConsentAuditorFactory::GetForProfile(profile_)
->GetControllerDelegate(); ->GetControllerDelegate();
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/security_events/security_event_recorder_factory.h" #include "chrome/browser/security_events/security_event_recorder_factory.h"
#include "chrome/browser/sharing/sharing_message_bridge_factory.h"
#include "chrome/browser/signin/about_signin_internals_factory.h" #include "chrome/browser/signin/about_signin_internals_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h" #include "chrome/browser/spellchecker/spellcheck_factory.h"
...@@ -156,6 +157,7 @@ ProfileSyncServiceFactory::ProfileSyncServiceFactory() ...@@ -156,6 +157,7 @@ ProfileSyncServiceFactory::ProfileSyncServiceFactory()
DependsOn(PasswordStoreFactory::GetInstance()); DependsOn(PasswordStoreFactory::GetInstance());
DependsOn(SecurityEventRecorderFactory::GetInstance()); DependsOn(SecurityEventRecorderFactory::GetInstance());
DependsOn(SendTabToSelfSyncServiceFactory::GetInstance()); DependsOn(SendTabToSelfSyncServiceFactory::GetInstance());
DependsOn(SharingMessageBridgeFactory::GetInstance());
DependsOn(SpellcheckServiceFactory::GetInstance()); DependsOn(SpellcheckServiceFactory::GetInstance());
#if BUILDFLAG(ENABLE_SUPERVISED_USERS) #if BUILDFLAG(ENABLE_SUPERVISED_USERS)
DependsOn(SupervisedUserServiceFactory::GetInstance()); DependsOn(SupervisedUserServiceFactory::GetInstance());
......
...@@ -130,6 +130,7 @@ class ProfileSyncServiceFactoryTest : public testing::Test { ...@@ -130,6 +130,7 @@ class ProfileSyncServiceFactoryTest : public testing::Test {
datatypes.push_back(syncer::USER_EVENTS); datatypes.push_back(syncer::USER_EVENTS);
datatypes.push_back(syncer::USER_CONSENTS); datatypes.push_back(syncer::USER_CONSENTS);
datatypes.push_back(syncer::SEND_TAB_TO_SELF); datatypes.push_back(syncer::SEND_TAB_TO_SELF);
datatypes.push_back(syncer::SHARING_MESSAGE);
return datatypes; return datatypes;
} }
......
...@@ -354,6 +354,18 @@ ProfileSyncComponentsFactoryImpl::CreateCommonDataTypeControllers( ...@@ -354,6 +354,18 @@ ProfileSyncComponentsFactoryImpl::CreateCommonDataTypeControllers(
.get()))); .get())));
} }
#if !defined(OS_IOS)
if (!disabled_types.Has(syncer::SHARING_MESSAGE)) {
// Forward both full-sync and transport-only modes to the same delegate,
// since behavior for SHARING_MESSAGE does not differ. They both do not
// store data on persistent storage.
controllers.push_back(std::make_unique<ModelTypeController>(
syncer::SHARING_MESSAGE,
CreateForwardingControllerDelegate(syncer::SHARING_MESSAGE),
CreateForwardingControllerDelegate(syncer::SHARING_MESSAGE)));
}
#endif // !defined(OS_IOS)
// Forward both full-sync and transport-only modes to the same delegate, // Forward both full-sync and transport-only modes to the same delegate,
// since behavior for USER_CONSENTS does not differ (they are always // since behavior for USER_CONSENTS does not differ (they are always
// persisted). // persisted).
......
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