| OLD | NEW |
| 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/session/remoting_client.h" | 9 #import "remoting/ios/session/remoting_client.h" |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 NSString* const kHostSessionStatusChanged = @"kHostSessionStatusChanged"; | 29 NSString* const kHostSessionStatusChanged = @"kHostSessionStatusChanged"; |
| 30 NSString* const kHostSessionPinProvided = @"kHostSessionPinProvided"; | 30 NSString* const kHostSessionPinProvided = @"kHostSessionPinProvided"; |
| 31 | 31 |
| 32 NSString* const kSessionDetails = @"kSessionDetails"; | 32 NSString* const kSessionDetails = @"kSessionDetails"; |
| 33 NSString* const kSessonStateErrorCode = @"kSessonStateErrorCode"; | 33 NSString* const kSessonStateErrorCode = @"kSessonStateErrorCode"; |
| 34 NSString* const kHostSessionPin = @"kHostSessionPin"; | 34 NSString* const kHostSessionPin = @"kHostSessionPin"; |
| 35 | 35 |
| 36 @interface RemotingClient () { | 36 @interface RemotingClient () { |
| 37 remoting::ChromotingClientRuntime* _runtime; | 37 remoting::ChromotingClientRuntime* _runtime; |
| 38 std::unique_ptr<remoting::ChromotingSession> _session; | 38 std::unique_ptr<remoting::ChromotingSession> _session; |
| 39 remoting::RemotingClientSessonDelegate* _sessonDelegate; | 39 std::unique_ptr<remoting::RemotingClientSessonDelegate> _sessonDelegate; |
| 40 ClientSessionDetails* _sessionDetails; | 40 ClientSessionDetails* _sessionDetails; |
| 41 // Call _secretFetchedCallback on the network thread. | 41 // Call _secretFetchedCallback on the network thread. |
| 42 remoting::protocol::SecretFetchedCallback _secretFetchedCallback; | 42 remoting::protocol::SecretFetchedCallback _secretFetchedCallback; |
| 43 std::unique_ptr<remoting::RendererProxy> _renderer; | 43 std::unique_ptr<remoting::RendererProxy> _renderer; |
| 44 std::unique_ptr<remoting::GestureInterpreter> _gestureInterpreter; | 44 std::unique_ptr<remoting::GestureInterpreter> _gestureInterpreter; |
| 45 // std::unique_ptr<remoting::KeyboardInterpreter> _keyboardInterpreter; | 45 // std::unique_ptr<remoting::KeyboardInterpreter> _keyboardInterpreter; |
| 46 } | 46 } |
| 47 @end | 47 @end |
| 48 | 48 |
| 49 @implementation RemotingClient | 49 @implementation RemotingClient |
| 50 | 50 |
| 51 @synthesize displayHandler = _displayHandler; | 51 @synthesize displayHandler = _displayHandler; |
| 52 | 52 |
| 53 - (instancetype)init { | 53 - (instancetype)init { |
| 54 self = [super init]; | 54 self = [super init]; |
| 55 if (self) { | 55 if (self) { |
| 56 _runtime = remoting::ChromotingClientRuntime::GetInstance(); | 56 _runtime = remoting::ChromotingClientRuntime::GetInstance(); |
| 57 _sessonDelegate = new remoting::RemotingClientSessonDelegate(self); | 57 _sessonDelegate.reset(new remoting::RemotingClientSessonDelegate(self)); |
| 58 _sessionDetails = [[ClientSessionDetails alloc] init]; | 58 _sessionDetails = [[ClientSessionDetails alloc] init]; |
| 59 | 59 |
| 60 [[NSNotificationCenter defaultCenter] | 60 [[NSNotificationCenter defaultCenter] |
| 61 addObserver:self | 61 addObserver:self |
| 62 selector:@selector(hostSessionPinProvided:) | 62 selector:@selector(hostSessionPinProvided:) |
| 63 name:kHostSessionPinProvided | 63 name:kHostSessionPinProvided |
| 64 object:nil]; | 64 object:nil]; |
| 65 } | 65 } |
| 66 return self; | 66 return self; |
| 67 } | 67 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 92 // info.capabilities = | 92 // info.capabilities = |
| 93 // info.flags = | 93 // info.flags = |
| 94 // info.host_version = | 94 // info.host_version = |
| 95 // info.host_os = | 95 // info.host_os = |
| 96 // info.host_os_version = | 96 // info.host_os_version = |
| 97 | 97 |
| 98 remoting::protocol::ClientAuthenticationConfig client_auth_config; | 98 remoting::protocol::ClientAuthenticationConfig client_auth_config; |
| 99 client_auth_config.host_id = info.host_id; | 99 client_auth_config.host_id = info.host_id; |
| 100 client_auth_config.pairing_client_id = info.pairing_id; | 100 client_auth_config.pairing_client_id = info.pairing_id; |
| 101 client_auth_config.pairing_secret = info.pairing_secret; | 101 client_auth_config.pairing_secret = info.pairing_secret; |
| 102 |
| 103 // ChromotingClient keeps strong reference to |client_auth_config| through its |
| 104 // lifetime. |
| 105 __weak RemotingClient* weakSelf = self; |
| 102 client_auth_config.fetch_secret_callback = base::BindBlockArc( | 106 client_auth_config.fetch_secret_callback = base::BindBlockArc( |
| 103 ^(bool pairing_supported, const remoting::protocol::SecretFetchedCallback& | 107 ^(bool pairing_supported, const remoting::protocol::SecretFetchedCallback& |
| 104 secret_fetched_callback) { | 108 secret_fetched_callback) { |
| 105 _secretFetchedCallback = secret_fetched_callback; | 109 RemotingClient* strongSelf = weakSelf; |
| 106 _sessionDetails.state = SessionPinPrompt; | 110 if (!strongSelf) { |
| 111 return; |
| 112 } |
| 113 strongSelf->_secretFetchedCallback = secret_fetched_callback; |
| 114 strongSelf->_sessionDetails.state = SessionPinPrompt; |
| 107 [[NSNotificationCenter defaultCenter] | 115 [[NSNotificationCenter defaultCenter] |
| 108 postNotificationName:kHostSessionStatusChanged | 116 postNotificationName:kHostSessionStatusChanged |
| 109 object:self | 117 object:weakSelf |
| 110 userInfo:[NSDictionary | 118 userInfo:[NSDictionary |
| 111 dictionaryWithObject:_sessionDetails | 119 dictionaryWithObject:strongSelf |
| 120 ->_sessionDetails |
| 112 forKey:kSessionDetails]]; | 121 forKey:kSessionDetails]]; |
| 113 }); | 122 }); |
| 114 | 123 |
| 115 // TODO(nicholss): Add audio support to iOS. | 124 // TODO(nicholss): Add audio support to iOS. |
| 116 base::WeakPtr<remoting::protocol::AudioStub> audioPlayer = nullptr; | 125 base::WeakPtr<remoting::protocol::AudioStub> audioPlayer = nullptr; |
| 117 | 126 |
| 118 _displayHandler = [[GlDisplayHandler alloc] init]; | 127 _displayHandler = [[GlDisplayHandler alloc] init]; |
| 119 _displayHandler.delegate = self; | 128 _displayHandler.delegate = self; |
| 120 | 129 |
| 121 _session.reset(new remoting::ChromotingSession( | 130 _session.reset(new remoting::ChromotingSession( |
| 122 _sessonDelegate->GetWeakPtr(), [_displayHandler CreateCursorShapeStub], | 131 _sessonDelegate->GetWeakPtr(), [_displayHandler CreateCursorShapeStub], |
| 123 [_displayHandler CreateVideoRenderer], audioPlayer, info, | 132 [_displayHandler CreateVideoRenderer], audioPlayer, info, |
| 124 client_auth_config)); | 133 client_auth_config)); |
| 125 | 134 |
| 126 _renderer = [_displayHandler CreateRendererProxy]; | 135 _renderer = [_displayHandler CreateRendererProxy]; |
| 127 | 136 |
| 128 _gestureInterpreter.reset( | 137 _gestureInterpreter.reset( |
| 129 new remoting::GestureInterpreter(_renderer.get(), _session.get())); | 138 new remoting::GestureInterpreter(_renderer.get(), _session.get())); |
| 130 | 139 |
| 131 _session->Connect(); | 140 _session->Connect(); |
| 132 } | 141 } |
| 133 | 142 |
| 134 - (void)disconnectFromHost { | 143 - (void)disconnectFromHost { |
| 135 if (_session) { | 144 if (_session) { |
| 136 _session->Disconnect(); | 145 _session->Disconnect(); |
| 146 _runtime->network_task_runner()->DeleteSoon(FROM_HERE, _session.release()); |
| 137 } | 147 } |
| 138 _displayHandler = nil; | 148 _displayHandler = nil; |
| 139 // TODO(nicholss): Do we need to cleanup more? | 149 |
| 150 // This needs to be deleted on the display thread since GlDisplayHandler binds |
| 151 // its WeakPtrFactory to the display thread. |
| 152 // TODO(yuweih): Ideally this constraint can be removed once we allow |
| 153 // GlRenderer to be created on the UI thread before being used. |
| 154 if (_renderer) { |
| 155 _runtime->display_task_runner()->DeleteSoon(FROM_HERE, _renderer.release()); |
| 156 } |
| 140 } | 157 } |
| 141 | 158 |
| 142 #pragma mark - Eventing | 159 #pragma mark - Eventing |
| 143 | 160 |
| 144 - (void)hostSessionPinProvided:(NSNotification*)notification { | 161 - (void)hostSessionPinProvided:(NSNotification*)notification { |
| 145 NSString* pin = [[notification userInfo] objectForKey:kHostSessionPin]; | 162 NSString* pin = [[notification userInfo] objectForKey:kHostSessionPin]; |
| 146 if (_secretFetchedCallback) { | 163 if (_secretFetchedCallback) { |
| 147 _runtime->network_task_runner()->PostTask( | 164 _runtime->network_task_runner()->PostTask( |
| 148 FROM_HERE, base::BindBlockArc(^{ | 165 FROM_HERE, base::BindBlockArc(^{ |
| 149 _secretFetchedCallback.Run(base::SysNSStringToUTF8(pin)); | 166 _secretFetchedCallback.Run(base::SysNSStringToUTF8(pin)); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 253 |
| 237 - (void)canvasSizeChanged:(CGSize)size { | 254 - (void)canvasSizeChanged:(CGSize)size { |
| 238 _gestureInterpreter->OnDesktopSizeChanged(size.width, size.height); | 255 _gestureInterpreter->OnDesktopSizeChanged(size.width, size.height); |
| 239 } | 256 } |
| 240 | 257 |
| 241 - (void)rendererTicked { | 258 - (void)rendererTicked { |
| 242 _gestureInterpreter->ProcessAnimations(); | 259 _gestureInterpreter->ProcessAnimations(); |
| 243 } | 260 } |
| 244 | 261 |
| 245 @end | 262 @end |
| OLD | NEW |