| Index: remoting/ios/facade/remoting_service.mm
|
| diff --git a/remoting/ios/facade/remoting_service.mm b/remoting/ios/facade/remoting_service.mm
|
| index 10096f18f6a3a2a0083ddfe0731485ed948b6343..5c5a8f6a48876dc41a6a9aafdd8b8e1e1a57b104 100644
|
| --- a/remoting/ios/facade/remoting_service.mm
|
| +++ b/remoting/ios/facade/remoting_service.mm
|
| @@ -18,7 +18,6 @@
|
| #import "remoting/ios/facade/host_list_fetcher.h"
|
| #import "remoting/ios/facade/ios_client_runtime_delegate.h"
|
| #import "remoting/ios/facade/remoting_authentication.h"
|
| -#import "remoting/ios/facade/remoting_service.h"
|
| #import "remoting/ios/keychain_wrapper.h"
|
|
|
| #include "base/i18n/time_formatting.h"
|
| @@ -37,19 +36,19 @@ NSString* const kUserDidUpdate = @"kUserDidUpdate";
|
| NSString* const kUserInfo = @"kUserInfo";
|
|
|
| @interface RemotingService ()<RemotingAuthenticationDelegate> {
|
| - std::unique_ptr<remoting::OAuthTokenGetter> _tokenGetter;
|
| + id<RemotingAuthentication> _authentication;
|
| remoting::HostListFetcher* _hostListFetcher;
|
| remoting::IosClientRuntimeDelegate* _clientRuntimeDelegate;
|
| + BOOL _isHostListFetching;
|
| }
|
| @end
|
|
|
| @implementation RemotingService
|
|
|
| -@synthesize authentication = _authentication;
|
| @synthesize hosts = _hosts;
|
|
|
| // RemotingService is a singleton.
|
| -+ (RemotingService*)SharedInstance {
|
| ++ (RemotingService*)instance {
|
| static RemotingService* sharedInstance = nil;
|
| static dispatch_once_t guard;
|
| dispatch_once(&guard, ^{
|
| @@ -61,10 +60,10 @@ NSString* const kUserInfo = @"kUserInfo";
|
| - (instancetype)init {
|
| self = [super init];
|
| if (self) {
|
| - _authentication = [[RemotingAuthentication alloc] init];
|
| - _authentication.delegate = self;
|
| _hosts = nil;
|
| _hostListFetcher = nil;
|
| + // TODO(yuweih): Maybe better to just cancel the previous request.
|
| + _isHostListFetching = NO;
|
| // TODO(nicholss): This might need a pointer back to the service.
|
| _clientRuntimeDelegate =
|
| new remoting::IosClientRuntimeDelegate();
|
| @@ -76,6 +75,10 @@ NSString* const kUserInfo = @"kUserInfo";
|
| #pragma mark - RemotingService Implementation
|
|
|
| - (void)startHostListFetchWith:(NSString*)accessToken {
|
| + if (_isHostListFetching) {
|
| + return;
|
| + }
|
| + _isHostListFetching = YES;
|
| if (!_hostListFetcher) {
|
| _hostListFetcher = new remoting::HostListFetcher(
|
| remoting::ChromotingClientRuntime::GetInstance()->url_requester());
|
| @@ -116,6 +119,7 @@ NSString* const kUserInfo = @"kUserInfo";
|
| }
|
| _hosts = hosts;
|
| [self hostListUpdated];
|
| + _isHostListFetching = NO;
|
| }));
|
| }
|
|
|
| @@ -133,6 +137,7 @@ NSString* const kUserInfo = @"kUserInfo";
|
| NSDictionary* userInfo = nil;
|
| if (user) {
|
| userInfo = [NSDictionary dictionaryWithObject:user forKey:kUserInfo];
|
| + [self requestHostListFetch];
|
| } else {
|
| _hosts = nil;
|
| [self hostListUpdated];
|
| @@ -159,13 +164,21 @@ NSString* const kUserInfo = @"kUserInfo";
|
|
|
| - (void)requestHostListFetch {
|
| [_authentication
|
| - callbackWithAccessToken:base::BindBlockArc(^(
|
| - remoting::OAuthTokenGetter::Status status,
|
| - const std::string& user_email,
|
| - const std::string& access_token) {
|
| - NSString* accessToken = base::SysUTF8ToNSString(access_token);
|
| + callbackWithAccessToken:^(RemotingAuthenticationStatus status,
|
| + NSString* userEmail, NSString* accessToken) {
|
| [self startHostListFetchWith:accessToken];
|
| - })];
|
| + }];
|
| +}
|
| +
|
| +- (void)setAuthentication:(id<RemotingAuthentication>)authentication {
|
| + DCHECK(_authentication == nil);
|
| + authentication.delegate = self;
|
| + _authentication = authentication;
|
| +}
|
| +
|
| +- (id<RemotingAuthentication>)authentication {
|
| + DCHECK(_authentication != nil);
|
| + return _authentication;
|
| }
|
|
|
| @end
|
|
|