Commit 9c86de87 authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Refactor CWVSyncController for butter sync

- Replace SigninErrorController with the errors wrapped by SyncService
- Call opt ins for transport only data
- Rely on SyncService state change for delegate callbacks
- Introduce some new userInfo keys in the NSError object
- Redo unit test to use more fakes

Change-Id: Ibb954e142c254627380658dc9af1e624b96edf98
Bug: 1056416
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2103555
Commit-Queue: John Wu <jzw@chromium.org>
Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759132}
parent 4ee74a1c
...@@ -188,8 +188,6 @@ source_set("web_view_sources") { ...@@ -188,8 +188,6 @@ source_set("web_view_sources") {
"internal/signin/web_view_identity_manager_factory.mm", "internal/signin/web_view_identity_manager_factory.mm",
"internal/signin/web_view_signin_client_factory.h", "internal/signin/web_view_signin_client_factory.h",
"internal/signin/web_view_signin_client_factory.mm", "internal/signin/web_view_signin_client_factory.mm",
"internal/signin/web_view_signin_error_controller_factory.h",
"internal/signin/web_view_signin_error_controller_factory.mm",
"internal/sync/cwv_sync_controller.mm", "internal/sync/cwv_sync_controller.mm",
"internal/sync/cwv_sync_controller_internal.h", "internal/sync/cwv_sync_controller_internal.h",
"internal/sync/web_view_device_info_sync_service_factory.h", "internal/sync/web_view_device_info_sync_service_factory.h",
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#import "ios/web_view/internal/cwv_web_view_internal.h" #import "ios/web_view/internal/cwv_web_view_internal.h"
#import "ios/web_view/internal/passwords/web_view_account_password_store_factory.h" #import "ios/web_view/internal/passwords/web_view_account_password_store_factory.h"
#include "ios/web_view/internal/signin/web_view_identity_manager_factory.h" #include "ios/web_view/internal/signin/web_view_identity_manager_factory.h"
#include "ios/web_view/internal/signin/web_view_signin_error_controller_factory.h"
#import "ios/web_view/internal/sync/cwv_sync_controller_internal.h" #import "ios/web_view/internal/sync/cwv_sync_controller_internal.h"
#import "ios/web_view/internal/sync/web_view_profile_sync_service_factory.h" #import "ios/web_view/internal/sync/web_view_profile_sync_service_factory.h"
#include "ios/web_view/internal/web_view_browser_state.h" #include "ios/web_view/internal/web_view_browser_state.h"
...@@ -147,14 +146,10 @@ CWVWebViewConfiguration* gIncognitoConfiguration = nil; ...@@ -147,14 +146,10 @@ CWVWebViewConfiguration* gIncognitoConfiguration = nil;
signin::IdentityManager* identityManager = signin::IdentityManager* identityManager =
ios_web_view::WebViewIdentityManagerFactory::GetForBrowserState( ios_web_view::WebViewIdentityManagerFactory::GetForBrowserState(
self.browserState); self.browserState);
SigninErrorController* signinErrorController = _syncController = [[CWVSyncController alloc]
ios_web_view::WebViewSigninErrorControllerFactory::GetForBrowserState( initWithSyncService:syncService
self.browserState); identityManager:identityManager
prefService:_browserState->GetPrefs()];
_syncController =
[[CWVSyncController alloc] initWithSyncService:syncService
identityManager:identityManager
signinErrorController:signinErrorController];
} }
return _syncController; return _syncController;
} }
...@@ -179,7 +174,6 @@ CWVWebViewConfiguration* gIncognitoConfiguration = nil; ...@@ -179,7 +174,6 @@ CWVWebViewConfiguration* gIncognitoConfiguration = nil;
for (CWVWebView* webView in _webViews) { for (CWVWebView* webView in _webViews) {
[webView shutDown]; [webView shutDown];
} }
[_syncController shutDown];
_browserState.reset(); _browserState.reset();
} }
......
// Copyright 2017 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_SIGNIN_WEB_VIEW_SIGNIN_ERROR_CONTROLLER_FACTORY_H_
#define IOS_WEB_VIEW_INTERNAL_SIGNIN_WEB_VIEW_SIGNIN_ERROR_CONTROLLER_FACTORY_H_
#include <memory>
#include "base/macros.h"
#include "base/no_destructor.h"
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
class SigninErrorController;
namespace ios_web_view {
class WebViewBrowserState;
// Singleton that owns all SigninErrorControllers and associates them with
// a browser state.
class WebViewSigninErrorControllerFactory
: public BrowserStateKeyedServiceFactory {
public:
static SigninErrorController* GetForBrowserState(
ios_web_view::WebViewBrowserState* browser_state);
static WebViewSigninErrorControllerFactory* GetInstance();
private:
friend class base::NoDestructor<WebViewSigninErrorControllerFactory>;
WebViewSigninErrorControllerFactory();
~WebViewSigninErrorControllerFactory() override = default;
// BrowserStateKeyedServiceFactory implementation.
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
web::BrowserState* context) const override;
DISALLOW_COPY_AND_ASSIGN(WebViewSigninErrorControllerFactory);
};
} // namespace ios_web_view
#endif // IOS_WEB_VIEW_INTERNAL_SIGNIN_WEB_VIEW_SIGNIN_ERROR_CONTROLLER_FACTORY_H_
// Copyright 2017 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 "ios/web_view/internal/signin/web_view_signin_error_controller_factory.h"
#include <utility>
#include "base/no_destructor.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "ios/web_view/internal/signin/web_view_identity_manager_factory.h"
#include "ios/web_view/internal/web_view_browser_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace ios_web_view {
// static
SigninErrorController* WebViewSigninErrorControllerFactory::GetForBrowserState(
ios_web_view::WebViewBrowserState* browser_state) {
return static_cast<SigninErrorController*>(
GetInstance()->GetServiceForBrowserState(browser_state, true));
}
// static
WebViewSigninErrorControllerFactory*
WebViewSigninErrorControllerFactory::GetInstance() {
static base::NoDestructor<WebViewSigninErrorControllerFactory> instance;
return instance.get();
}
WebViewSigninErrorControllerFactory::WebViewSigninErrorControllerFactory()
: BrowserStateKeyedServiceFactory(
"SigninErrorController",
BrowserStateDependencyManager::GetInstance()) {
DependsOn(WebViewIdentityManagerFactory::GetInstance());
}
std::unique_ptr<KeyedService>
WebViewSigninErrorControllerFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
WebViewBrowserState* browser_state =
WebViewBrowserState::FromBrowserState(context);
return std::make_unique<SigninErrorController>(
SigninErrorController::AccountMode::ANY_ACCOUNT,
WebViewIdentityManagerFactory::GetForBrowserState(browser_state));
}
} // namespace ios_web_view
...@@ -17,21 +17,16 @@ namespace signin { ...@@ -17,21 +17,16 @@ namespace signin {
class IdentityManager; class IdentityManager;
} // namespace signin } // namespace signin
class SigninErrorController; class PrefService;
@interface CWVSyncController () @interface CWVSyncController ()
// All dependencies must out live this class. // All dependencies must out live this class.
- (instancetype) - (instancetype)initWithSyncService:(syncer::SyncService*)syncService
initWithSyncService:(syncer::SyncService*)syncService identityManager:(signin::IdentityManager*)identityManager
identityManager:(signin::IdentityManager*)identityManager prefService:(PrefService*)prefService
signinErrorController:(SigninErrorController*)signinErrorController
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
// Called by the associated CWVWebViewConfiguration in order to shut
// down cleanly. See CWVWebViewConfiguration's |shutDown| method for more info.
- (void)shutDown;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include "ios/web_view/internal/passwords/web_view_password_store_factory.h" #include "ios/web_view/internal/passwords/web_view_password_store_factory.h"
#include "ios/web_view/internal/signin/web_view_identity_manager_factory.h" #include "ios/web_view/internal/signin/web_view_identity_manager_factory.h"
#include "ios/web_view/internal/signin/web_view_signin_client_factory.h" #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"
#import "ios/web_view/internal/sync/web_view_gcm_profile_service_factory.h" #import "ios/web_view/internal/sync/web_view_gcm_profile_service_factory.h"
#import "ios/web_view/internal/sync/web_view_model_type_store_service_factory.h" #import "ios/web_view/internal/sync/web_view_model_type_store_service_factory.h"
#import "ios/web_view/internal/sync/web_view_profile_invalidation_provider_factory.h" #import "ios/web_view/internal/sync/web_view_profile_invalidation_provider_factory.h"
...@@ -186,7 +185,6 @@ void WebViewBrowserState::RegisterPrefs( ...@@ -186,7 +185,6 @@ void WebViewBrowserState::RegisterPrefs(
WebViewAccountPasswordStoreFactory::GetInstance(); WebViewAccountPasswordStoreFactory::GetInstance();
WebViewPasswordStoreFactory::GetInstance(); WebViewPasswordStoreFactory::GetInstance();
WebViewSigninClientFactory::GetInstance(); WebViewSigninClientFactory::GetInstance();
WebViewSigninErrorControllerFactory::GetInstance();
WebViewIdentityManagerFactory::GetInstance(); WebViewIdentityManagerFactory::GetInstance();
WebViewGCMProfileServiceFactory::GetInstance(); WebViewGCMProfileServiceFactory::GetInstance();
WebViewProfileInvalidationProviderFactory::GetInstance(); WebViewProfileInvalidationProviderFactory::GetInstance();
......
...@@ -17,6 +17,14 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -17,6 +17,14 @@ NS_ASSUME_NONNULL_BEGIN
// The error domain for sync errors. // The error domain for sync errors.
FOUNDATION_EXPORT CWV_EXPORT NSErrorDomain const CWVSyncErrorDomain; FOUNDATION_EXPORT CWV_EXPORT NSErrorDomain const CWVSyncErrorDomain;
// NSString description for the type of error.
FOUNDATION_EXPORT CWV_EXPORT
NSErrorUserInfoKey const CWVSyncErrorDescriptionKey;
// NSString message describing the error in more detail.
FOUNDATION_EXPORT CWV_EXPORT NSErrorUserInfoKey const CWVSyncErrorMessageKey;
// NSValue wrapped BOOL indicating if the error is transient.
FOUNDATION_EXPORT CWV_EXPORT
NSErrorUserInfoKey const CWVSyncErrorIsTransientKey;
// Possible error codes during syncing. // Possible error codes during syncing.
typedef NS_ENUM(NSInteger, CWVSyncError) { typedef NS_ENUM(NSInteger, CWVSyncError) {
......
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