Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/ios/bridge/client_bridge.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/synchronization/waitable_event.h" | |
| 9 #include "remoting/base/url_request_context.h" | |
| 10 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | |
| 11 | |
| 12 #import "remoting/ios/bridge/client_controller.h" | |
| 13 | |
| 14 namespace remoting { | |
| 15 | |
| 16 ClientBridge::ClientBridge() { | |
| 17 | |
| 18 VLOG(1) << "Starting main message loop"; | |
| 19 if (!base::MessageLoopForUI::IsCurrent()) { | |
| 20 ui_loop_.reset(new base::MessageLoopForUI()); | |
| 21 ui_loop_->Attach(); | |
| 22 } else { | |
| 23 ui_loop_.reset(base::MessageLoopForUI::current()); | |
| 24 } | |
| 25 | |
| 26 VLOG(1) << "Spawning additional threads"; | |
| 27 | |
| 28 ui_task_runner_ = new AutoThreadTaskRunner(ui_loop_->message_loop_proxy(), | |
| 29 base::MessageLoop::QuitClosure()); | |
| 30 network_task_runner_ = AutoThread::CreateWithType( | |
| 31 "native_net", ui_task_runner_, base::MessageLoop::TYPE_IO); | |
| 32 | |
| 33 url_requester_ = new URLRequestContextGetter(network_task_runner_); | |
| 34 } | |
| 35 | |
| 36 ClientBridge::~ClientBridge() { | |
| 37 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 38 | |
| 39 // The session must be shut down first, since it depends on our other | |
| 40 // components' still being alive. | |
| 41 DisconnectFromHost(); | |
| 42 | |
| 43 base::WaitableEvent done_event(false, false); | |
| 44 network_task_runner_->PostTask( | |
| 45 FROM_HERE, | |
| 46 base::Bind(&ClientBridge::DetachFromVmAndSignal, | |
|
dcaiafa
2014/03/19 01:14:15
DetachFromVmAndSignal just signals the event. Do w
aboone
2014/03/21 16:42:07
Removed.
| |
| 47 base::Unretained(this), | |
| 48 &done_event)); | |
| 49 done_event.Wait(); | |
| 50 done_event.Wait(); | |
|
dcaiafa
2014/03/19 01:14:15
Remove duplicate.
aboone
2014/03/21 16:42:07
Done.
| |
| 51 } | |
| 52 | |
| 53 // CLIENT is requesting a new connection to a HOST | |
|
dcaiafa
2014/03/19 01:14:15
nit: method description comments belong in the hea
aboone
2014/03/21 16:42:07
Done.
| |
| 54 void ClientBridge::ConnectToHost(const char* username, | |
| 55 const char* auth_token, | |
| 56 const char* host_jid, | |
| 57 const char* host_id, | |
| 58 const char* host_pubkey, | |
| 59 const char* pairing_id, | |
| 60 const char* pairing_secret, | |
| 61 ClientController* controller) { | |
| 62 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 63 controller_ = controller; | |
| 64 DCHECK(!session_); | |
| 65 session_ = new ClientInstance(this, | |
| 66 username, | |
| 67 auth_token, | |
| 68 host_jid, | |
| 69 host_id, | |
| 70 host_pubkey, | |
| 71 pairing_id, | |
| 72 pairing_secret); | |
| 73 } | |
| 74 | |
| 75 // CLIENT is asking to close the connection | |
| 76 void ClientBridge::DisconnectFromHost() { | |
| 77 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 78 if (session_) { | |
| 79 session_->Cleanup(); | |
| 80 session_ = NULL; | |
| 81 } | |
| 82 } | |
| 83 // HOST reporting connection status | |
|
dcaiafa
2014/03/19 01:14:15
nit: empty line between methods.
aboone
2014/03/21 16:42:07
Done.
| |
| 84 void ClientBridge::ReportConnectionStatus( | |
| 85 protocol::ConnectionToHost::State state, | |
| 86 protocol::ErrorCode error) { | |
| 87 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 88 if (controller_) { | |
|
dcaiafa
2014/03/19 01:14:15
Is it really valid for controller_ to be NULL here
aboone
2014/03/21 16:42:07
Done.
| |
| 89 [controller_ reportConnectionStatus:state error:error]; | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 // HOST asking for PIN | |
| 94 void ClientBridge::DisplayAuthenticationPrompt(bool pairing_supported) { | |
| 95 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 96 if (controller_) { | |
| 97 [controller_ displayAuthenticationPrompt:pairing_supported]; | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 // HOST submitting credentials for storage | |
| 102 void ClientBridge::CommitPairingCredentials(const std::string& host, | |
| 103 const std::string& id, | |
| 104 const std::string& secret) { | |
| 105 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 106 if (controller_) { | |
| 107 NSString* hostString = [[NSString alloc] initWithUTF8String:host.c_str()]; | |
| 108 NSString* idString = [[NSString alloc] initWithUTF8String:id.c_str()]; | |
| 109 NSString* secretString = | |
| 110 [[NSString alloc] initWithUTF8String:secret.c_str()]; | |
| 111 [controller_ commitPairinedentials:hostString | |
| 112 pairId:idString | |
| 113 secret:secretString]; | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 // HOST delivering a Cursor (mouse) update | |
| 118 void ClientBridge::UpdateCursorShape( | |
| 119 const protocol::CursorShapeInfo& cursor_shape) { | |
| 120 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | |
| 121 if (controller_) { | |
| 122 [controller_ | |
| 123 updateCursorShape:webrtc::DesktopSize(cursor_shape.width(), | |
| 124 cursor_shape.height()) | |
| 125 hotspot:webrtc::DesktopVector(cursor_shape.hotspot_x(), | |
| 126 cursor_shape.hotspot_y()) | |
| 127 cursorData:(uint8_t*)cursor_shape.data().c_str()]; | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 // HOST delivierying a Canvas (desktop) update | |
| 132 void ClientBridge::RedrawCanvas(const webrtc::DesktopSize& view_size, | |
| 133 webrtc::DesktopFrame* buffer, | |
| 134 const webrtc::DesktopRegion& region) { | |
| 135 if (!ui_task_runner_->BelongsToCurrentThread()) { | |
| 136 ui_task_runner_->PostTask( | |
| 137 FROM_HERE, | |
| 138 base::Bind( | |
| 139 &ClientBridge::RedrawCanvas, this, view_size, buffer, region)); | |
| 140 return; | |
| 141 } | |
| 142 if (controller_) { | |
| 143 std::vector<webrtc::DesktopRect> regions; | |
| 144 | |
| 145 for (webrtc::DesktopRegion::Iterator i(region); !i.IsAtEnd(); i.Advance()) { | |
| 146 const webrtc::DesktopRect& rect(i.rect()); | |
| 147 | |
| 148 regions.push_back(webrtc::DesktopRect::MakeXYWH( | |
| 149 rect.left(), rect.top(), rect.width(), rect.height())); | |
| 150 } | |
| 151 | |
| 152 [controller_ updateImageBuffer:view_size | |
| 153 stride:buffer->stride() | |
| 154 data:buffer->data() | |
| 155 regions:regions]; | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 FrameConsumerBridgeCallback ClientBridge::BindToFrameConsumerBridgeCallback() { | |
| 160 return base::Bind(&ClientBridge::RedrawCanvas, base::Unretained(this)); | |
|
dcaiafa
2014/03/19 01:14:15
Delete this method (see comments in client_instanc
aboone
2014/03/21 16:42:07
Done.
| |
| 161 } | |
| 162 | |
| 163 void ClientBridge::DetachFromVmAndSignal(base::WaitableEvent* waiter) { | |
| 164 waiter->Signal(); | |
| 165 } | |
| 166 | |
| 167 } // namespace remoting | |
| OLD | NEW |