Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Unified Diff: remoting/ios/facade/remoting_oauth_authentication.mm

Issue 2949713002: [CRD iOS] Refactor an interface for RemotingAuthorization (Closed)
Patch Set: Resolve feedback Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/ios/facade/remoting_oauth_authentication.mm
diff --git a/remoting/ios/facade/remoting_authentication.mm b/remoting/ios/facade/remoting_oauth_authentication.mm
similarity index 76%
rename from remoting/ios/facade/remoting_authentication.mm
rename to remoting/ios/facade/remoting_oauth_authentication.mm
index 9327511208ebabe46a9b367314b797e8c8f8084a..5c0045de299dfce0c6e416d94e5f0cdf7c928aa0 100644
--- a/remoting/ios/facade/remoting_authentication.mm
+++ b/remoting/ios/facade/remoting_oauth_authentication.mm
@@ -6,7 +6,7 @@
#error "This file requires ARC support."
#endif
-#import "remoting/ios/facade/remoting_authentication.h"
+#import "remoting/ios/facade/remoting_oauth_authentication.h"
#import <Foundation/Foundation.h>
#import <Security/Security.h>
@@ -45,7 +45,7 @@ CreateOAuthTokenGetterWithAuthorizationCode(
std::unique_ptr<remoting::OAuthTokenGetter> oauth_tokenGetter(
new remoting::OAuthTokenGetterImpl(
std::move(oauth_credentials), on_credentials_update,
- [RemotingService SharedInstance].runtime->url_requester(),
+ RemotingService.instance.runtime->url_requester(),
/*auto_refresh=*/true));
return oauth_tokenGetter;
}
@@ -61,19 +61,31 @@ std::unique_ptr<remoting::OAuthTokenGetter> CreateOAuthTokenWithRefreshToken(
std::unique_ptr<remoting::OAuthTokenGetter> oauth_tokenGetter(
new remoting::OAuthTokenGetterImpl(
std::move(oauth_credentials),
- [RemotingService SharedInstance].runtime->url_requester(),
+ RemotingService.instance.runtime->url_requester(),
/*auto_refresh=*/true));
return oauth_tokenGetter;
}
-@interface RemotingAuthentication () {
+RemotingAuthenticationStatus oauthStatusToRemotingAuthenticationStatus(
+ remoting::OAuthTokenGetter::Status status) {
+ switch (status) {
+ case remoting::OAuthTokenGetter::Status::AUTH_ERROR:
+ return RemotingAuthenticationStatusAuthError;
+ case remoting::OAuthTokenGetter::Status::NETWORK_ERROR:
+ return RemotingAuthenticationStatusNetworkError;
+ case remoting::OAuthTokenGetter::Status::SUCCESS:
+ return RemotingAuthenticationStatusSuccess;
+ }
+}
+
+@interface RemotingOAuthAuthentication () {
std::unique_ptr<remoting::OAuthTokenGetter> _tokenGetter;
KeychainWrapper* _keychainWrapper;
BOOL _firstLoadUserAttempt;
}
@end
-@implementation RemotingAuthentication
+@implementation RemotingOAuthAuthentication
@synthesize user = _user;
@synthesize delegate = _delegate;
@@ -107,7 +119,7 @@ std::unique_ptr<remoting::OAuthTokenGetter> CreateOAuthTokenWithRefreshToken(
#pragma mark - Class Implementation
- (void)authenticateWithAuthorizationCode:(NSString*)authorizationCode {
- __weak RemotingAuthentication* weakSelf = self;
+ __weak RemotingOAuthAuthentication* weakSelf = self;
_tokenGetter = CreateOAuthTokenGetterWithAuthorizationCode(
std::string(base::SysNSStringToUTF8(authorizationCode)),
base::BindBlockArc(
@@ -122,19 +134,17 @@ std::unique_ptr<remoting::OAuthTokenGetter> CreateOAuthTokenWithRefreshToken(
// Stimulate the oAuth Token Getter to fetch and access token, this forces it
// to convert the authorization code into a refresh token, and saving the
// refresh token will happen automaticly in the above block.
- [self callbackWithAccessToken:base::BindBlockArc(^(
- remoting::OAuthTokenGetter::Status status,
- const std::string& user_email,
- const std::string& access_token) {
- if (status == remoting::OAuthTokenGetter::Status::SUCCESS) {
- VLOG(1) << "Success fetching access token from authorization code.";
- } else {
- LOG(ERROR)
- << "Failed to fetch access token from authorization code. ("
- << status << ")";
- // TODO(nicholss): Deal with the sad path for a bad auth token.
- }
- })];
+ [self callbackWithAccessToken:^(RemotingAuthenticationStatus status,
+ NSString* user_email,
+ NSString* access_token) {
+ if (status == RemotingAuthenticationStatusSuccess) {
+ VLOG(1) << "Success fetching access token from authorization code.";
+ } else {
+ LOG(ERROR) << "Failed to fetch access token from authorization code. ("
+ << status << ")";
+ // TODO(nicholss): Deal with the sad path for a bad auth token.
+ }
+ }];
}
#pragma mark - Private
@@ -148,12 +158,17 @@ std::unique_ptr<remoting::OAuthTokenGetter> CreateOAuthTokenWithRefreshToken(
base::SysNSStringToUTF8(email));
}
-- (void)callbackWithAccessToken:
- (const remoting::OAuthTokenGetter::TokenCallback&)onAccessToken {
+- (void)callbackWithAccessToken:(AccessTokenCallback)onAccessToken {
// TODO(nicholss): Be careful here since a failure to reset onAccessToken
// will end up with retain cycle and memory leakage.
if (_tokenGetter) {
- _tokenGetter->CallWithToken(onAccessToken);
+ _tokenGetter->CallWithToken(base::BindBlockArc(
+ ^(remoting::OAuthTokenGetter::Status status,
+ const std::string& user_email, const std::string& access_token) {
+ onAccessToken(oauthStatusToRemotingAuthenticationStatus(status),
+ base::SysUTF8ToNSString(user_email),
+ base::SysUTF8ToNSString(access_token));
+ }));
}
}

Powered by Google App Engine
This is Rietveld 408576698