Commit da493e5f authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Error API for CWVSyncControllerDelegate.

Not all GoogleServiceAuthErrors are possible on iOS.
See //ios/chrome/browser/sync/sync_setup_service.cc for comparison.

Bug: 867548
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I3eab6314ddb10e9d3f68b018494846b1257226aa
Reviewed-on: https://chromium-review.googlesource.com/1252378Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Commit-Queue: John Wu <jzw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595538}
parent 3b8e1106
......@@ -104,7 +104,9 @@ std::unique_ptr<GaiaAuthFetcher> IOSWebViewSigninClient::CreateGaiaAuthFetcher(
url_loader_factory);
}
void IOSWebViewSigninClient::OnErrorChanged() {}
void IOSWebViewSigninClient::OnErrorChanged() {
[sync_controller_ didUpdateAuthError:signin_error_controller_->auth_error()];
}
void IOSWebViewSigninClient::SetSyncController(
CWVSyncController* sync_controller) {
......
......@@ -23,6 +23,42 @@
#error "This file requires ARC support."
#endif
NSErrorDomain const CWVSyncErrorDomain =
@"org.chromium.chromewebview.SyncErrorDomain";
namespace {
CWVSyncError CWVConvertGoogleServiceAuthErrorStateToCWVSyncError(
GoogleServiceAuthError::State state) {
switch (state) {
case GoogleServiceAuthError::NONE:
return CWVSyncErrorNone;
case GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS:
return CWVSyncErrorInvalidGAIACredentials;
case GoogleServiceAuthError::USER_NOT_SIGNED_UP:
return CWVSyncErrorUserNotSignedUp;
case GoogleServiceAuthError::CONNECTION_FAILED:
return CWVSyncErrorConnectionFailed;
case GoogleServiceAuthError::SERVICE_UNAVAILABLE:
return CWVSyncErrorServiceUnavailable;
case GoogleServiceAuthError::REQUEST_CANCELED:
return CWVSyncErrorRequestCanceled;
case GoogleServiceAuthError::UNEXPECTED_SERVICE_RESPONSE:
return CWVSyncErrorUnexpectedServiceResponse;
// The following errors are unexpected on iOS.
case GoogleServiceAuthError::CAPTCHA_REQUIRED:
case GoogleServiceAuthError::ACCOUNT_DELETED:
case GoogleServiceAuthError::ACCOUNT_DISABLED:
case GoogleServiceAuthError::TWO_FACTOR:
case GoogleServiceAuthError::HOSTED_NOT_ALLOWED_DEPRECATED:
case GoogleServiceAuthError::SERVICE_ERROR:
case GoogleServiceAuthError::WEB_LOGIN_REQUIRED:
case GoogleServiceAuthError::NUM_STATES:
NOTREACHED();
return CWVSyncErrorNone;
}
}
} // namespace
@interface CWVSyncController ()
// Called by WebViewSyncServiceObserverBridge's |OnSyncConfigurationCompleted|.
......@@ -225,4 +261,17 @@ initWithProfileSyncService:(browser_sync::ProfileSyncService*)profileSyncService
[_delegate syncController:self didStopSyncWithReason:reason];
}
- (void)didUpdateAuthError:(const GoogleServiceAuthError&)authError {
CWVSyncError code =
CWVConvertGoogleServiceAuthErrorStateToCWVSyncError(authError.state());
if (code != CWVSyncErrorNone) {
if ([_delegate
respondsToSelector:@selector(syncController:didFailWithError:)]) {
NSError* error =
[NSError errorWithDomain:CWVSyncErrorDomain code:code userInfo:nil];
[_delegate syncController:self didFailWithError:error];
}
}
}
@end
......@@ -8,6 +8,7 @@
#include <set>
#include "components/signin/core/browser/signin_metrics.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "ios/web_view/internal/signin/web_view_profile_oauth2_token_service_ios_provider_impl.h"
#import "ios/web_view/public/cwv_sync_controller.h"
......@@ -38,6 +39,9 @@ initWithProfileSyncService:(browser_sync::ProfileSyncService*)profileSyncService
// Called by IOSWebViewSigninClient when signing out.
- (void)didSignoutWithSourceMetric:(signin_metrics::ProfileSignout)metric;
// Called by IOSWebViewSigninClient when auth error changes.
- (void)didUpdateAuthError:(const GoogleServiceAuthError&)authError;
@end
#endif // IOS_WEB_VIEW_INTERNAL_SYNC_CWV_SYNC_CONTROLLER_INTERNAL_H_
......@@ -90,6 +90,8 @@ WebViewProfileSyncServiceFactory::BuildServiceInstanceFor(
init_params.network_time_update_callback = base::DoNothing();
init_params.signin_scoped_device_id_callback = base::BindRepeating(
&signin::GetSigninScopedDeviceId, browser_state->GetPrefs());
init_params.network_connection_tracker =
ApplicationContext::GetInstance()->GetNetworkConnectionTracker();
auto profile_sync_service =
std::make_unique<ProfileSyncService>(std::move(init_params));
......
......@@ -15,6 +15,32 @@ NS_ASSUME_NONNULL_BEGIN
@protocol CWVSyncControllerDataSource;
@protocol CWVSyncControllerDelegate;
// The error domain for sync errors.
FOUNDATION_EXPORT CWV_EXPORT NSErrorDomain const CWVSyncErrorDomain;
// Possible error codes during syncing.
typedef NS_ENUM(NSInteger, CWVSyncError) {
// No error.
CWVSyncErrorNone = 0,
// The credentials supplied to GAIA were either invalid, or the locally
// cached credentials have expired.
CWVSyncErrorInvalidGAIACredentials = -100,
// The GAIA user is not authorized to use the service.
CWVSyncErrorUserNotSignedUp = -200,
// Could not connect to server to verify credentials. This could be in
// response to either failure to connect to GAIA or failure to connect to
// the service needing GAIA tokens during authentication.
CWVSyncErrorConnectionFailed = -300,
// The service is not available; try again later.
CWVSyncErrorServiceUnavailable = -400,
// The requestor of the authentication step cancelled the request
// prior to completion.
CWVSyncErrorRequestCanceled = -500,
// Indicates the service responded to a request, but we cannot
// interpret the response.
CWVSyncErrorUnexpectedServiceResponse = -600,
};
CWV_EXPORT
// Used to manage syncing for autofill and password data. Usage:
// 1. Call |startSyncWithIdentity:dataSource:| to start syncing with identity.
......
......@@ -27,8 +27,12 @@ typedef NS_ENUM(NSInteger, CWVStopSyncReason) {
// property to see if |unlockWithPassphrase:| is necessary.
- (void)syncControllerDidStartSync:(CWVSyncController*)syncController;
// Called after the sync was stopped.
// |reason| Indicates why sync was stopped.
// Called when sync fails. |error|'s code is a CWVSyncError.
// May need to call |stopSyncAndClearIdentity| and try starting again later.
- (void)syncController:(CWVSyncController*)syncController
didFailWithError:(NSError*)error;
// Called after sync was stopped. |reason| Indicates why sync was stopped.
- (void)syncController:(CWVSyncController*)syncController
didStopSyncWithReason:(CWVStopSyncReason)reason;
......
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