Commit 8a57ae11 authored by Jon Mann's avatar Jon Mann Committed by Commit Bot

Create a profile keyed service for syncing wifi configurations.

Bug: 966270
Change-Id: I2e9e0bf0df06e0a4907b7e005de5f87e1d6bb150
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1728475Reviewed-by: default avatarCait Phillips <caitkp@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Jon Mann <jonmann@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683776}
parent 78a482f4
...@@ -3612,6 +3612,8 @@ jumbo_split_static_library("browser") { ...@@ -3612,6 +3612,8 @@ jumbo_split_static_library("browser") {
"sync/sync_error_notifier_ash.h", "sync/sync_error_notifier_ash.h",
"sync/sync_error_notifier_factory_ash.cc", "sync/sync_error_notifier_factory_ash.cc",
"sync/sync_error_notifier_factory_ash.h", "sync/sync_error_notifier_factory_ash.h",
"sync/wifi_configuration_sync_service_factory.cc",
"sync/wifi_configuration_sync_service_factory.h",
"task_manager/providers/arc/arc_process_task.cc", "task_manager/providers/arc/arc_process_task.cc",
"task_manager/providers/arc/arc_process_task.h", "task_manager/providers/arc/arc_process_task.h",
"task_manager/providers/arc/arc_process_task_provider.cc", "task_manager/providers/arc/arc_process_task_provider.cc",
...@@ -3631,6 +3633,7 @@ jumbo_split_static_library("browser") { ...@@ -3631,6 +3633,7 @@ jumbo_split_static_library("browser") {
"//chrome/services/cups_proxy", "//chrome/services/cups_proxy",
"//chrome/services/cups_proxy/public/mojom", "//chrome/services/cups_proxy/public/mojom",
"//chromeos/components/account_manager", "//chromeos/components/account_manager",
"//chromeos/components/sync_wifi",
"//chromeos/services/assistant/public:feature_flags", "//chromeos/services/assistant/public:feature_flags",
"//chromeos/services/assistant/public/cpp:prefs", "//chromeos/services/assistant/public/cpp:prefs",
"//chromeos/services/cellular_setup", "//chromeos/services/cellular_setup",
......
...@@ -123,8 +123,10 @@ ...@@ -123,8 +123,10 @@
#include "chrome/browser/chromeos/printing/printers_sync_bridge.h" #include "chrome/browser/chromeos/printing/printers_sync_bridge.h"
#include "chrome/browser/chromeos/printing/synced_printers_manager.h" #include "chrome/browser/chromeos/printing/synced_printers_manager.h"
#include "chrome/browser/chromeos/printing/synced_printers_manager_factory.h" #include "chrome/browser/chromeos/printing/synced_printers_manager_factory.h"
#include "chrome/browser/sync/wifi_configuration_sync_service_factory.h"
#include "chrome/browser/ui/app_list/arc/arc_package_sync_model_type_controller.h" #include "chrome/browser/ui/app_list/arc/arc_package_sync_model_type_controller.h"
#include "chrome/browser/ui/app_list/arc/arc_package_syncable_service.h" #include "chrome/browser/ui/app_list/arc/arc_package_syncable_service.h"
#include "chromeos/components/sync_wifi/wifi_configuration_sync_service.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
...@@ -529,6 +531,9 @@ ChromeSyncClient::GetControllerDelegateForModelType(syncer::ModelType type) { ...@@ -529,6 +531,9 @@ ChromeSyncClient::GetControllerDelegateForModelType(syncer::ModelType type) {
->GetSyncBridge() ->GetSyncBridge()
->change_processor() ->change_processor()
->GetControllerDelegate(); ->GetControllerDelegate();
case syncer::WIFI_CONFIGURATIONS:
return WifiConfigurationSyncServiceFactory::GetForProfile(profile_)
->GetControllerDelegate();
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
case syncer::USER_CONSENTS: case syncer::USER_CONSENTS:
return ConsentAuditorFactory::GetForProfile(profile_) return ConsentAuditorFactory::GetForProfile(profile_)
......
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/printing/synced_printers_manager_factory.h" #include "chrome/browser/chromeos/printing/synced_printers_manager_factory.h"
#include "chrome/browser/sync/wifi_configuration_sync_service_factory.h"
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
namespace { namespace {
...@@ -166,6 +167,7 @@ ProfileSyncServiceFactory::ProfileSyncServiceFactory() ...@@ -166,6 +167,7 @@ ProfileSyncServiceFactory::ProfileSyncServiceFactory()
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_EXTENSIONS)
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
DependsOn(chromeos::SyncedPrintersManagerFactory::GetInstance()); DependsOn(chromeos::SyncedPrintersManagerFactory::GetInstance());
DependsOn(WifiConfigurationSyncServiceFactory::GetInstance());
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
} }
......
// Copyright 2019 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/sync/wifi_configuration_sync_service_factory.h"
#include "base/memory/singleton.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/model_type_store_service_factory.h"
#include "chrome/common/channel_info.h"
#include "chromeos/components/sync_wifi/wifi_configuration_sync_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/sync/model/model_type_store_service.h"
// static
sync_wifi::WifiConfigurationSyncService*
WifiConfigurationSyncServiceFactory::GetForProfile(Profile* profile) {
return static_cast<sync_wifi::WifiConfigurationSyncService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
WifiConfigurationSyncServiceFactory*
WifiConfigurationSyncServiceFactory::GetInstance() {
return base::Singleton<WifiConfigurationSyncServiceFactory>::get();
}
WifiConfigurationSyncServiceFactory::WifiConfigurationSyncServiceFactory()
: BrowserContextKeyedServiceFactory(
"WifiConfigurationSyncService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(ModelTypeStoreServiceFactory::GetInstance());
}
WifiConfigurationSyncServiceFactory::~WifiConfigurationSyncServiceFactory() =
default;
KeyedService* WifiConfigurationSyncServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new sync_wifi::WifiConfigurationSyncService(
chrome::GetChannel(), ModelTypeStoreServiceFactory::GetForProfile(
Profile::FromBrowserContext(context))
->GetStoreFactory());
}
// Copyright 2019 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_SYNC_WIFI_CONFIGURATION_SYNC_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SYNC_WIFI_CONFIGURATION_SYNC_SERVICE_FACTORY_H_
#include <memory>
#include "base/macros.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
namespace base {
template <typename T>
struct DefaultSingletonTraits;
} // namespace base
namespace sync_wifi {
class WifiConfigurationSyncService;
} // namespace sync_wifi
class WifiConfigurationSyncServiceFactory
: public BrowserContextKeyedServiceFactory {
public:
static sync_wifi::WifiConfigurationSyncService* GetForProfile(
Profile* profile);
static WifiConfigurationSyncServiceFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<
WifiConfigurationSyncServiceFactory>;
WifiConfigurationSyncServiceFactory();
~WifiConfigurationSyncServiceFactory() override;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
DISALLOW_COPY_AND_ASSIGN(WifiConfigurationSyncServiceFactory);
};
#endif // CHROME_BROWSER_SYNC_WIFI_CONFIGURATION_SYNC_SERVICE_FACTORY_H_
...@@ -7,10 +7,14 @@ static_library("sync_wifi") { ...@@ -7,10 +7,14 @@ static_library("sync_wifi") {
"synced_network_updater.h", "synced_network_updater.h",
"wifi_configuration_bridge.cc", "wifi_configuration_bridge.cc",
"wifi_configuration_bridge.h", "wifi_configuration_bridge.h",
"wifi_configuration_sync_service.cc",
"wifi_configuration_sync_service.h",
] ]
deps = [ deps = [
"//base", "//base",
"//components/keyed_service/core",
"//components/sync", "//components/sync",
"//components/version_info",
] ]
} }
......
include_rules = [ include_rules = [
"+components/sync", "+components/sync",
"+components/keyed_service/core",
"+components/version_info",
] ]
// Copyright 2019 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 "chromeos/components/sync_wifi/wifi_configuration_sync_service.h"
#include <utility>
#include "base/bind_helpers.h"
#include "base/time/default_clock.h"
#include "chromeos/components/sync_wifi/wifi_configuration_bridge.h"
#include "components/sync/base/report_unrecoverable_error.h"
#include "components/sync/model/model_type_store.h"
#include "components/sync/model_impl/client_tag_based_model_type_processor.h"
namespace sync_wifi {
WifiConfigurationSyncService::WifiConfigurationSyncService(
version_info::Channel channel,
syncer::OnceModelTypeStoreFactory create_store_callback) {
bridge_ = std::make_unique<sync_wifi::WifiConfigurationBridge>(
/* synced_network_updater= */ nullptr,
std::make_unique<syncer::ClientTagBasedModelTypeProcessor>(
syncer::WIFI_CONFIGURATIONS,
base::BindRepeating(&syncer::ReportUnrecoverableError, channel)),
std::move(create_store_callback));
}
WifiConfigurationSyncService::~WifiConfigurationSyncService() = default;
base::WeakPtr<syncer::ModelTypeControllerDelegate>
WifiConfigurationSyncService::GetControllerDelegate() {
return bridge_->change_processor()->GetControllerDelegate();
}
} // namespace sync_wifi
\ No newline at end of file
// Copyright 2019 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 CHROMEOS_COMPONENTS_SYNC_WIFI_WIFI_CONFIGURATION_SYNC_SERVICE_H_
#define CHROMEOS_COMPONENTS_SYNC_WIFI_WIFI_CONFIGURATION_SYNC_SERVICE_H_
#include <memory>
#include <string>
#include "base/memory/weak_ptr.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/sync/model/model_type_store.h"
#include "components/sync/model/model_type_store_service.h"
#include "components/version_info/channel.h"
namespace syncer {
class ModelTypeControllerDelegate;
} // namespace syncer
namespace sync_wifi {
class WifiConfigurationBridge;
// A profile keyed service which instantiates and provides access to an instance
// of WifiConfigurationBridge.
class WifiConfigurationSyncService : public KeyedService {
public:
WifiConfigurationSyncService(
version_info::Channel channel,
syncer::OnceModelTypeStoreFactory create_store_callback);
~WifiConfigurationSyncService() override;
base::WeakPtr<syncer::ModelTypeControllerDelegate> GetControllerDelegate();
private:
std::unique_ptr<WifiConfigurationBridge> bridge_;
DISALLOW_COPY_AND_ASSIGN(WifiConfigurationSyncService);
};
} // namespace sync_wifi
#endif // CHROMEOS_COMPONENTS_SYNC_WIFI_WIFI_CONFIGURATION_SYNC_SERVICE_H_
...@@ -339,6 +339,15 @@ ProfileSyncComponentsFactoryImpl::CreateCommonDataTypeControllers( ...@@ -339,6 +339,15 @@ ProfileSyncComponentsFactoryImpl::CreateCommonDataTypeControllers(
base::Unretained(sync_client_), base::Unretained(sync_client_),
syncer::PRINTERS)))); syncer::PRINTERS))));
} }
if (!disabled_types.Has(syncer::WIFI_CONFIGURATIONS) &&
base::FeatureList::IsEnabled(switches::kSyncWifiConfigurations)) {
controllers.push_back(std::make_unique<ModelTypeController>(
syncer::WIFI_CONFIGURATIONS,
std::make_unique<syncer::ForwardingModelTypeControllerDelegate>(
sync_client_
->GetControllerDelegateForModelType(syncer::WIFI_CONFIGURATIONS)
.get())));
}
#endif #endif
// Reading list sync is enabled by default only on iOS. Register unless // Reading list sync is enabled by default only on iOS. Register unless
......
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