Commit 7431adcf authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Add some factory boilerplate needed for sync in //ios/web_view.

//ios/web_view will use sync for autofill and password data in the
near future. This is one of the many CLs needed for implementation.

Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I32c84aa7d5fd1836a99170741f525100dc0ac09c
Reviewed-on: https://chromium-review.googlesource.com/1139182
Commit-Queue: John Wu <jzw@chromium.org>
Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576194}
parent 591e5064
......@@ -147,6 +147,10 @@ ios_web_view_sources = [
"internal/signin/web_view_signin_error_controller_factory.mm",
"internal/signin/web_view_signin_manager_factory.h",
"internal/signin/web_view_signin_manager_factory.mm",
"internal/sync/web_view_gcm_profile_service_factory.h",
"internal/sync/web_view_gcm_profile_service_factory.mm",
"internal/sync/web_view_profile_invalidation_provider_factory.h",
"internal/sync/web_view_profile_invalidation_provider_factory.mm",
"internal/translate/cwv_translation_controller.mm",
"internal/translate/cwv_translation_controller_internal.h",
"internal/translate/cwv_translation_language_internal.h",
......@@ -216,7 +220,9 @@ ios_web_view_deps = [
"//components/autofill/ios/form_util",
"//components/content_settings/core/browser",
"//components/flags_ui",
"//components/gcm_driver",
"//components/image_fetcher/ios",
"//components/invalidation/impl",
"//components/infobars/core",
"//components/keyed_service/core",
"//components/keyed_service/ios",
......
......@@ -3,8 +3,10 @@ include_rules = [
"+components/autofill",
"+components/content_settings/core",
"+components/flags_ui",
"+components/gcm_driver",
"+components/image_fetcher/ios",
"+components/infobars/core",
"+components/invalidation/impl",
"+components/keyed_service/core",
"+components/keyed_service/ios",
"+components/language/core/browser",
......
// Copyright 2018 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 IOS_WEB_VIEW_INTERNAL_SYNC_WEB_VIEW_GCM_PROFILE_SERVICE_FACTORY_H_
#define IOS_WEB_VIEW_INTERNAL_SYNC_WEB_VIEW_GCM_PROFILE_SERVICE_FACTORY_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
namespace base {
template <typename T>
struct DefaultSingletonTraits;
}
namespace gcm {
class GCMProfileService;
}
namespace ios_web_view {
class WebViewBrowserState;
// Singleton that owns all GCMProfileService and associates them with
// WebViewBrowserState.
class WebViewGCMProfileServiceFactory : public BrowserStateKeyedServiceFactory {
public:
static gcm::GCMProfileService* GetForBrowserState(
WebViewBrowserState* browser_state);
static WebViewGCMProfileServiceFactory* GetInstance();
// Returns a string like "org.chromium.chromewebview" that should be used as
// the GCM category when an app_id is sent as a subtype instead of as a
// category. This string must never change during the lifetime of an install,
// since e.g. to unregister an Instance ID token the same category must be
// passed to GCM as was originally passed when registering it.
static std::string GetProductCategoryForSubtypes();
private:
friend struct base::DefaultSingletonTraits<WebViewGCMProfileServiceFactory>;
WebViewGCMProfileServiceFactory();
~WebViewGCMProfileServiceFactory() override;
// BrowserStateKeyedServiceFactory:
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
web::BrowserState* context) const override;
DISALLOW_COPY_AND_ASSIGN(WebViewGCMProfileServiceFactory);
};
} // namespace ios_web_view
#endif // IOS_WEB_VIEW_INTERNAL_SYNC_WEB_VIEW_GCM_PROFILE_SERVICE_FACTORY_H_
// Copyright 2018 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.
#import "ios/web_view/internal/sync/web_view_gcm_profile_service_factory.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
#include "base/sequenced_task_runner.h"
#include "base/task_scheduler/post_task.h"
#include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/gcm_profile_service.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/signin/core/browser/signin_manager.h"
#include "ios/web/public/web_thread.h"
#include "ios/web_view/internal/signin/web_view_identity_manager_factory.h"
#include "ios/web_view/internal/signin/web_view_oauth2_token_service_factory.h"
#include "ios/web_view/internal/signin/web_view_signin_manager_factory.h"
#include "ios/web_view/internal/web_view_browser_state.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace ios_web_view {
// static
gcm::GCMProfileService* WebViewGCMProfileServiceFactory::GetForBrowserState(
WebViewBrowserState* browser_state) {
return static_cast<gcm::GCMProfileService*>(
GetInstance()->GetServiceForBrowserState(browser_state, true));
}
// static
WebViewGCMProfileServiceFactory*
WebViewGCMProfileServiceFactory::GetInstance() {
return base::Singleton<WebViewGCMProfileServiceFactory>::get();
}
// static
std::string WebViewGCMProfileServiceFactory::GetProductCategoryForSubtypes() {
return "org.chromium.chromewebview";
}
WebViewGCMProfileServiceFactory::WebViewGCMProfileServiceFactory()
: BrowserStateKeyedServiceFactory(
"GCMProfileService",
BrowserStateDependencyManager::GetInstance()) {
DependsOn(WebViewSigninManagerFactory::GetInstance());
DependsOn(WebViewOAuth2TokenServiceFactory::GetInstance());
DependsOn(WebViewIdentityManagerFactory::GetInstance());
}
WebViewGCMProfileServiceFactory::~WebViewGCMProfileServiceFactory() {}
std::unique_ptr<KeyedService>
WebViewGCMProfileServiceFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
DCHECK(!context->IsOffTheRecord());
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BACKGROUND,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}));
WebViewBrowserState* browser_state =
WebViewBrowserState::FromBrowserState(context);
return std::make_unique<gcm::GCMProfileService>(
browser_state->GetPrefs(), browser_state->GetStatePath(),
browser_state->GetRequestContext(),
browser_state->GetSharedURLLoaderFactory(),
version_info::Channel::UNKNOWN, GetProductCategoryForSubtypes(),
WebViewIdentityManagerFactory::GetForBrowserState(browser_state),
WebViewSigninManagerFactory::GetForBrowserState(browser_state),
WebViewOAuth2TokenServiceFactory::GetForBrowserState(browser_state),
base::WrapUnique(new gcm::GCMClientFactory),
web::WebThread::GetTaskRunnerForThread(web::WebThread::UI),
web::WebThread::GetTaskRunnerForThread(web::WebThread::IO),
blocking_task_runner);
}
} // namespace ios_web_view
// Copyright 2018 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 IOS_WEB_VIEW_INTERNAL_SYNC_WEB_VIEW_PROFILE_INVALIDATION_PROVIDER_FACTORY_H_
#define IOS_WEB_VIEW_INTERNAL_SYNC_WEB_VIEW_PROFILE_INVALIDATION_PROVIDER_FACTORY_H_
#include <memory>
#include "base/macros.h"
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
namespace base {
template <typename T>
struct DefaultSingletonTraits;
}
namespace invalidation {
class ProfileInvalidationProvider;
}
namespace user_prefs {
class PrefRegistrySyncable;
}
namespace ios_web_view {
class WebViewBrowserState;
// A BrowserContextKeyedServiceFactory to construct InvalidationServices wrapped
// in ProfileInvalidationProviders.
class WebViewProfileInvalidationProviderFactory
: public BrowserStateKeyedServiceFactory {
public:
// Returns the ProfileInvalidationProvider for the given |browser_state|,
// lazily creating one first if required.
static invalidation::ProfileInvalidationProvider* GetForBrowserState(
WebViewBrowserState* browser_state);
static WebViewProfileInvalidationProviderFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<
WebViewProfileInvalidationProviderFactory>;
WebViewProfileInvalidationProviderFactory();
~WebViewProfileInvalidationProviderFactory() override;
// BrowserStateKeyedServiceFactory:
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
web::BrowserState* context) const override;
void RegisterBrowserStatePrefs(
user_prefs::PrefRegistrySyncable* registry) override;
DISALLOW_COPY_AND_ASSIGN(WebViewProfileInvalidationProviderFactory);
};
} // namespace ios_web_view
#endif // IOS_WEB_VIEW_INTERNAL_SYNC_WEB_VIEW_PROFILE_INVALIDATION_PROVIDER_FACTORY_H_
// Copyright 2018 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.
#import "ios/web_view/internal/sync/web_view_profile_invalidation_provider_factory.h"
#include <memory>
#include <utility>
#include "base/callback.h"
#include "base/memory/singleton.h"
#include "components/gcm_driver/gcm_profile_service.h"
#include "components/invalidation/impl/invalidator_storage.h"
#include "components/invalidation/impl/profile_identity_provider.h"
#include "components/invalidation/impl/profile_invalidation_provider.h"
#include "components/invalidation/impl/ticl_invalidation_service.h"
#include "components/invalidation/impl/ticl_profile_settings_provider.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_registry.h"
#include "components/signin/core/browser/signin_manager.h"
#include "ios/web/public/web_client.h"
#include "ios/web_view/internal/signin/web_view_identity_manager_factory.h"
#include "ios/web_view/internal/signin/web_view_oauth2_token_service_factory.h"
#include "ios/web_view/internal/signin/web_view_signin_manager_factory.h"
#include "ios/web_view/internal/sync/web_view_gcm_profile_service_factory.h"
#include "ios/web_view/internal/web_view_browser_state.h"
#include "net/url_request/url_request_context_getter.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using invalidation::InvalidatorStorage;
using invalidation::ProfileInvalidationProvider;
using invalidation::TiclInvalidationService;
namespace ios_web_view {
// static
invalidation::ProfileInvalidationProvider*
WebViewProfileInvalidationProviderFactory::GetForBrowserState(
WebViewBrowserState* browser_state) {
return static_cast<ProfileInvalidationProvider*>(
GetInstance()->GetServiceForBrowserState(browser_state, true));
}
// static
WebViewProfileInvalidationProviderFactory*
WebViewProfileInvalidationProviderFactory::GetInstance() {
return base::Singleton<WebViewProfileInvalidationProviderFactory>::get();
}
WebViewProfileInvalidationProviderFactory::
WebViewProfileInvalidationProviderFactory()
: BrowserStateKeyedServiceFactory(
"InvalidationService",
BrowserStateDependencyManager::GetInstance()) {
DependsOn(WebViewIdentityManagerFactory::GetInstance());
DependsOn(WebViewSigninManagerFactory::GetInstance());
DependsOn(WebViewGCMProfileServiceFactory::GetInstance());
DependsOn(WebViewOAuth2TokenServiceFactory::GetInstance());
}
WebViewProfileInvalidationProviderFactory::
~WebViewProfileInvalidationProviderFactory() {}
std::unique_ptr<KeyedService>
WebViewProfileInvalidationProviderFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
WebViewBrowserState* browser_state =
WebViewBrowserState::FromBrowserState(context);
std::unique_ptr<invalidation::ProfileIdentityProvider> identity_provider(
new invalidation::ProfileIdentityProvider(
WebViewIdentityManagerFactory::GetForBrowserState(browser_state)));
std::unique_ptr<TiclInvalidationService> service(new TiclInvalidationService(
web::GetWebClient()->GetUserAgent(web::UserAgentType::MOBILE),
std::move(identity_provider),
std::make_unique<invalidation::TiclProfileSettingsProvider>(
browser_state->GetPrefs()),
WebViewGCMProfileServiceFactory::GetForBrowserState(browser_state)
->driver(),
browser_state->GetRequestContext(),
browser_state->GetSharedURLLoaderFactory()));
service->Init(
std::make_unique<InvalidatorStorage>(browser_state->GetPrefs()));
return std::make_unique<ProfileInvalidationProvider>(std::move(service));
}
void WebViewProfileInvalidationProviderFactory::RegisterBrowserStatePrefs(
user_prefs::PrefRegistrySyncable* registry) {
ProfileInvalidationProvider::RegisterProfilePrefs(registry);
InvalidatorStorage::RegisterProfilePrefs(registry);
}
} // namespace ios_web_view
......@@ -12,6 +12,7 @@
#include "base/path_service.h"
#include "base/threading/thread_restrictions.h"
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/gcm_driver/gcm_channel_status_syncer.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/in_memory_pref_store.h"
......@@ -37,6 +38,8 @@
#include "ios/web_view/internal/signin/web_view_signin_client_factory.h"
#include "ios/web_view/internal/signin/web_view_signin_error_controller_factory.h"
#include "ios/web_view/internal/signin/web_view_signin_manager_factory.h"
#import "ios/web_view/internal/sync/web_view_gcm_profile_service_factory.h"
#import "ios/web_view/internal/sync/web_view_profile_invalidation_provider_factory.h"
#include "ios/web_view/internal/translate/web_view_translate_accept_languages_factory.h"
#include "ios/web_view/internal/translate/web_view_translate_ranker_factory.h"
#include "ios/web_view/internal/web_view_url_request_context_getter.h"
......@@ -160,6 +163,10 @@ void WebViewBrowserState::RegisterPrefs(
autofill::AutofillManager::RegisterProfilePrefs(pref_registry);
#endif // BUILDFLAG(IOS_WEB_VIEW_ENABLE_AUTOFILL)
#if BUILDFLAG(IOS_WEB_VIEW_ENABLE_SYNC)
gcm::GCMChannelStatusSyncer::RegisterProfilePrefs(pref_registry);
#endif // BUILDFLAG(IOS_WEB_VIEW_ENABLE_SYNC)
// Instantiate all factories to setup dependency graph for pref registration.
WebViewLanguageModelManagerFactory::GetInstance();
WebViewTranslateRankerFactory::GetInstance();
......@@ -182,6 +189,8 @@ void WebViewBrowserState::RegisterPrefs(
WebViewSigninErrorControllerFactory::GetInstance();
WebViewSigninManagerFactory::GetInstance();
WebViewIdentityManagerFactory::GetInstance();
WebViewGCMProfileServiceFactory::GetInstance();
WebViewProfileInvalidationProviderFactory::GetInstance();
#endif // BUILDFLAG(IOS_WEB_VIEW_ENABLE_SYNC)
BrowserStateDependencyManager::GetInstance()
......
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