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

Side by Side Diff: remoting/ios/app/remoting_view_controller.mm

Issue 2917253002: [CRD iOS] Create RemotingClient in ClientConnectionViewController (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 unified diff | Download patch
« no previous file with comments | « remoting/ios/app/client_connection_view_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #if !defined(__has_feature) || !__has_feature(objc_arc) 5 #if !defined(__has_feature) || !__has_feature(objc_arc)
6 #error "This file requires ARC support." 6 #error "This file requires ARC support."
7 #endif 7 #endif
8 8
9 #import "remoting/ios/app/remoting_view_controller.h" 9 #import "remoting/ios/app/remoting_view_controller.h"
10 10
11 #import "base/mac/bind_objc_block.h" 11 #import "base/mac/bind_objc_block.h"
12 #import "ios/third_party/material_components_ios/src/components/AnimationTiming/ src/MaterialAnimationTiming.h" 12 #import "ios/third_party/material_components_ios/src/components/AnimationTiming/ src/MaterialAnimationTiming.h"
13 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater ialAppBar.h" 13 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater ialAppBar.h"
14 #import "ios/third_party/material_components_ios/src/components/Dialogs/src/Mate rialDialogs.h" 14 #import "ios/third_party/material_components_ios/src/components/Dialogs/src/Mate rialDialogs.h"
15 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h" 15 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h"
16 #import "remoting/ios/app/client_connection_view_controller.h" 16 #import "remoting/ios/app/client_connection_view_controller.h"
17 #import "remoting/ios/app/host_collection_view_controller.h" 17 #import "remoting/ios/app/host_collection_view_controller.h"
18 #import "remoting/ios/app/host_view_controller.h" 18 #import "remoting/ios/app/host_view_controller.h"
19 #import "remoting/ios/app/remoting_settings_view_controller.h" 19 #import "remoting/ios/app/remoting_settings_view_controller.h"
20 #import "remoting/ios/domain/client_session_details.h" 20 #import "remoting/ios/domain/client_session_details.h"
21 #import "remoting/ios/facade/remoting_authentication.h" 21 #import "remoting/ios/facade/remoting_authentication.h"
22 #import "remoting/ios/facade/remoting_service.h" 22 #import "remoting/ios/facade/remoting_service.h"
23 #import "remoting/ios/session/remoting_client.h"
24 23
25 #include "base/strings/sys_string_conversions.h" 24 #include "base/strings/sys_string_conversions.h"
26 #include "remoting/base/oauth_token_getter.h" 25 #include "remoting/base/oauth_token_getter.h"
27 #include "remoting/client/connect_to_host_info.h" 26 #include "remoting/client/connect_to_host_info.h"
28 27
29 static CGFloat kHostInset = 5.f; 28 static CGFloat kHostInset = 5.f;
30 29
31 @interface RemotingViewController ()<HostCollectionViewControllerDelegate, 30 @interface RemotingViewController ()<HostCollectionViewControllerDelegate,
32 ClientConnectionViewControllerDelegate,
33 UIViewControllerAnimatedTransitioning, 31 UIViewControllerAnimatedTransitioning,
34 UIViewControllerTransitioningDelegate> { 32 UIViewControllerTransitioningDelegate> {
35 bool _isAuthenticated; 33 bool _isAuthenticated;
36 MDCDialogTransitionController* _dialogTransitionController; 34 MDCDialogTransitionController* _dialogTransitionController;
37 MDCAppBar* _appBar; 35 MDCAppBar* _appBar;
38 HostCollectionViewController* _collectionViewController; 36 HostCollectionViewController* _collectionViewController;
39 RemotingService* _remotingService; 37 RemotingService* _remotingService;
40 RemotingClient* _client;
41 } 38 }
42 @end 39 @end
43 40
44 // TODO(nicholss): Localize this file. 41 // TODO(nicholss): Localize this file.
45 // TODO(nicholss): This file is not finished with integration, the app flow is 42 // TODO(nicholss): This file is not finished with integration, the app flow is
46 // still pending development. 43 // still pending development.
47 44
48 @implementation RemotingViewController 45 @implementation RemotingViewController
49 46
50 - (instancetype)init { 47 - (instancetype)init {
(...skipping 27 matching lines...) Expand all
78 target:self 75 target:self
79 action:@selector(didSelectSettings)]; 76 action:@selector(didSelectSettings)];
80 self.navigationItem.leftBarButtonItem = menuButton; 77 self.navigationItem.leftBarButtonItem = menuButton;
81 78
82 UIBarButtonItem* refreshButton = 79 UIBarButtonItem* refreshButton =
83 [[UIBarButtonItem alloc] initWithTitle:@"Refresh" 80 [[UIBarButtonItem alloc] initWithTitle:@"Refresh"
84 style:UIBarButtonItemStyleDone 81 style:UIBarButtonItemStyleDone
85 target:self 82 target:self
86 action:@selector(didSelectRefresh)]; 83 action:@selector(didSelectRefresh)];
87 self.navigationItem.rightBarButtonItem = refreshButton; 84 self.navigationItem.rightBarButtonItem = refreshButton;
88
89 [[NSNotificationCenter defaultCenter]
90 addObserver:self
91 selector:@selector(hostSessionStatusChanged:)
92 name:kHostSessionStatusChanged
93 object:nil];
94 } 85 }
95 return self; 86 return self;
96 } 87 }
97 88
98 #pragma mark - UIViewController 89 #pragma mark - UIViewController
99 90
100 - (void)viewDidLoad { 91 - (void)viewDidLoad {
101 [super viewDidLoad]; 92 [super viewDidLoad];
102 [_appBar addSubviewsToParent]; 93 [_appBar addSubviewsToParent];
103 94
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 167 }
177 168
178 #pragma mark - RemotingHostListDelegate 169 #pragma mark - RemotingHostListDelegate
179 170
180 // TODO(nicholss): these need to be a stats change like "none, loading, 171 // TODO(nicholss): these need to be a stats change like "none, loading,
181 // updated"... 172 // updated"...
182 - (void)hostListUpdated { 173 - (void)hostListUpdated {
183 [_collectionViewController.collectionView reloadData]; 174 [_collectionViewController.collectionView reloadData];
184 } 175 }
185 176
186 #pragma mark - ClientConnectionViewControllerDelegate
187
188 - (void)clientConnected {
189 HostViewController* hostViewController =
190 [[HostViewController alloc] initWithClient:_client];
191 _client = nil;
192 [self presentViewController:hostViewController animated:YES completion:nil];
193 }
194
195 - (NSString*)getConnectingHostName {
196 if (_client) {
197 return _client.hostInfo.hostName;
198 }
199 return nil;
200 }
201
202 #pragma mark - HostCollectionViewControllerDelegate 177 #pragma mark - HostCollectionViewControllerDelegate
203 178
204 - (void)didSelectCell:(HostCollectionViewCell*)cell 179 - (void)didSelectCell:(HostCollectionViewCell*)cell
205 completion:(void (^)())completionBlock { 180 completion:(void (^)())completionBlock {
206 if (![cell.hostInfo isOnline]) { 181 if (![cell.hostInfo isOnline]) {
207 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; 182 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init];
208 message.text = @"Host is offline."; 183 message.text = @"Host is offline.";
209 [MDCSnackbarManager showMessage:message]; 184 [MDCSnackbarManager showMessage:message];
210 return; 185 return;
211 } 186 }
212 187
213 _client = [[RemotingClient alloc] init];
214
215 [_remotingService.authentication
216 callbackWithAccessToken:base::BindBlockArc(^(
217 remoting::OAuthTokenGetter::Status status,
218 const std::string& user_email,
219 const std::string& access_token) {
220 // TODO(nicholss): Check status.
221 HostInfo* hostInfo = cell.hostInfo;
222 [_client connectToHost:hostInfo
223 username:base::SysUTF8ToNSString(user_email)
224 accessToken:base::SysUTF8ToNSString(access_token)];
225 })];
226
227 ClientConnectionViewController* clientConnectionViewController = 188 ClientConnectionViewController* clientConnectionViewController =
228 [[ClientConnectionViewController alloc] init]; 189 [[ClientConnectionViewController alloc] initWithHostInfo:cell.hostInfo];
229 clientConnectionViewController.delegate = self;
230 [self presentViewController:clientConnectionViewController 190 [self presentViewController:clientConnectionViewController
231 animated:YES 191 animated:YES
232 completion:nil]; 192 completion:nil];
233 completionBlock(); 193 completionBlock();
234 } 194 }
235 195
236 - (NSInteger)getHostCount { 196 - (NSInteger)getHostCount {
237 return _remotingService.hosts.count; 197 return _remotingService.hosts.count;
238 } 198 }
239 199
(...skipping 22 matching lines...) Expand all
262 (id<UIViewControllerContextTransitioning>)transitionContext { 222 (id<UIViewControllerContextTransitioning>)transitionContext {
263 } 223 }
264 224
265 - (NSTimeInterval)transitionDuration: 225 - (NSTimeInterval)transitionDuration:
266 (id<UIViewControllerContextTransitioning>)transitionContext { 226 (id<UIViewControllerContextTransitioning>)transitionContext {
267 return 0.2; 227 return 0.2;
268 } 228 }
269 229
270 #pragma mark - Private 230 #pragma mark - Private
271 231
272 - (void)hostSessionStatusChanged:(NSNotification*)notification {
273 NSLog(@"hostSessionStatusChanged: %@", [notification userInfo]);
274 }
275
276 - (void)closeViewController { 232 - (void)closeViewController {
277 [self dismissViewControllerAnimated:true completion:nil]; 233 [self dismissViewControllerAnimated:true completion:nil];
278 } 234 }
279 235
280 - (void)didSelectRefresh { 236 - (void)didSelectRefresh {
281 // TODO(nicholss): Might want to rate limit this. Maybe remoting service 237 // TODO(nicholss): Might want to rate limit this. Maybe remoting service
282 // controls that. 238 // controls that.
283 [_remotingService requestHostListFetch]; 239 [_remotingService requestHostListFetch];
284 } 240 }
285 241
286 - (void)didSelectSettings { 242 - (void)didSelectSettings {
287 RemotingSettingsViewController* settingsViewController = 243 RemotingSettingsViewController* settingsViewController =
288 [[RemotingSettingsViewController alloc] init]; 244 [[RemotingSettingsViewController alloc] init];
289 [self presentViewController:settingsViewController 245 [self presentViewController:settingsViewController
290 animated:YES 246 animated:YES
291 completion:nil]; 247 completion:nil];
292 } 248 }
293 249
294 - (void)presentStatus { 250 - (void)presentStatus {
295 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init]; 251 MDCSnackbarMessage* message = [[MDCSnackbarMessage alloc] init];
296 if (_isAuthenticated) { 252 if (_isAuthenticated) {
297 message.text = [NSString 253 message.text = [NSString
298 stringWithFormat:@"Currently signed in as %@.", 254 stringWithFormat:@"Currently signed in as %@.",
299 _remotingService.authentication.user.userEmail]; 255 _remotingService.authentication.user.userEmail];
300 [MDCSnackbarManager showMessage:message]; 256 [MDCSnackbarManager showMessage:message];
301 } 257 }
302 } 258 }
303 259
304 @end 260 @end
OLDNEW
« no previous file with comments | « remoting/ios/app/client_connection_view_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698