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

Side by Side Diff: remoting/ios/bridge/client_instance.h

Issue 186733007: iOS Chromoting Client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 #ifndef REMOTING_CLIENT_CHROMOTING_JNI_INSTANCE_H_ 5 #ifndef REMOTING_IOS_BRIDGE_CLIENT_INSTANCE_H_
6 #define REMOTING_CLIENT_CHROMOTING_JNI_INSTANCE_H_ 6 #define REMOTING_IOS_BRIDGE_CLIENT_INSTANCE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop/message_loop.h"
14 #include "remoting/client/chromoting_client.h" 13 #include "remoting/client/chromoting_client.h"
15 #include "remoting/client/client_config.h" 14 #include "remoting/client/client_config.h"
16 #include "remoting/client/client_context.h" 15 #include "remoting/client/client_context.h"
17 #include "remoting/client/client_user_interface.h" 16 #include "remoting/client/client_user_interface.h"
18 #include "remoting/client/frame_consumer_proxy.h" 17 #include "remoting/client/frame_consumer_proxy.h"
19 #include "remoting/client/jni/jni_frame_consumer.h" 18 #include "remoting/jingle_glue/network_settings.h"
20 #include "remoting/jingle_glue/xmpp_signal_strategy.h" 19 #include "remoting/jingle_glue/xmpp_signal_strategy.h"
21 #include "remoting/protocol/clipboard_stub.h" 20 #include "remoting/protocol/clipboard_stub.h"
22 #include "remoting/protocol/connection_to_host.h" 21 #include "remoting/protocol/connection_to_host.h"
23 #include "remoting/protocol/cursor_shape_stub.h" 22 #include "remoting/protocol/cursor_shape_stub.h"
24 23
24 #include "remoting/ios/bridge/frame_consumer_bridge.h"
25
25 namespace remoting { 26 namespace remoting {
26 27
27 namespace protocol { 28 class ClientBridge;
28 class ClipboardEvent;
29 class CursorShapeInfo;
30 } // namespace protocol
31 29
32 class VideoRenderer; 30 // ClientUserInterface that indirectly makes and receives OBJ_C calls.
33 31 class ClientInstance : public ClientUserInterface,
34 // ClientUserInterface that indirectly makes and receives JNI calls. 32 public protocol::ClipboardStub,
35 class ChromotingJniInstance 33 public protocol::CursorShapeStub,
36 : public ClientUserInterface, 34 public base::RefCountedThreadSafe<ClientInstance> {
37 public protocol::ClipboardStub,
38 public protocol::CursorShapeStub,
39 public base::RefCountedThreadSafe<ChromotingJniInstance> {
40 public: 35 public:
41 // Initiates a connection with the specified host. Call from the UI thread. 36 // Initiates a connection with the specified host. Call from the UI thread.
42 // The instance does not take ownership of |jni_runtime|. To connect with an 37 // The instance does not take ownership of |objc_runtime|. To connect with an
dcaiafa 2014/03/19 01:14:15 s/objc_runtime/bridge/
dcaiafa 2014/03/19 01:14:15 ClientInstance does take ownership of bridge which
aboone 2014/03/21 16:42:07 Done.
aboone 2014/03/21 16:42:07 I've changed it to a WeakPtr to be explicit that b
43 // unpaired host, pass in |pairing_id| and |pairing_secret| as empty strings. 38 // unpaired host, pass in |pairing_id| and |pairing_secret| as empty strings.
44 ChromotingJniInstance(ChromotingJniRuntime* jni_runtime, 39 ClientInstance(ClientBridge* bridge,
45 const char* username, 40 const char* username,
46 const char* auth_token, 41 const char* auth_token,
47 const char* host_jid, 42 const char* host_jid,
48 const char* host_id, 43 const char* host_id,
49 const char* host_pubkey, 44 const char* host_pubkey,
50 const char* pairing_id, 45 const char* pairing_id,
51 const char* pairing_secret); 46 const char* pairing_secret);
52 47
53 // Terminates the current connection (if it hasn't already failed) and cleans 48 // Terminates the current connection (if it hasn't already failed) and cleans
54 // up. Must be called before destruction. 49 // up. Must be called before destruction.
55 void Cleanup(); 50 void Cleanup();
56 51
57 // Provides the user's PIN and resumes the host authentication attempt. Call 52 // Provides the user's PIN and resumes the host authentication attempt. Call
58 // on the UI thread once the user has finished entering this PIN into the UI, 53 // on the UI thread once the user has finished entering this PIN into the UI,
59 // but only after the UI has been asked to provide a PIN (via FetchSecret()). 54 // but only after the UI has been asked to provide a PIN (via FetchSecret()).
60 void ProvideSecret(const std::string& pin, bool create_pair, 55 void ProvideSecret(const std::string& pin, bool create_pair);
61 const std::string& device_name);
62
63 // Schedules a redraw on the display thread. May be called from any thread.
64 void RedrawDesktop();
65 56
66 // Moves the host's cursor to the specified coordinates, optionally with some 57 // Moves the host's cursor to the specified coordinates, optionally with some
67 // mouse button depressed. If |button| is BUTTON_UNDEFINED, no click is made. 58 // mouse button depressed. If |button| is BUTTON_UNDEFINED, no click is made.
68 void PerformMouseAction(int x, int y, 59 void PerformMouseAction(
69 protocol::MouseEvent_MouseButton button, 60 const webrtc::DesktopVector& position,
70 bool button_down); 61 const webrtc::DesktopVector& wheel_delta,
71 62 int /* protocol::MouseEvent_MouseButton */ whichButton,
72 void PerformMouseWheelDeltaAction(int delta_x, int delta_y); 63 bool button_down);
73 64
74 // Sends the provided keyboard scan code to the host. 65 // Sends the provided keyboard scan code to the host.
75 void PerformKeyboardAction(int key_code, bool key_down); 66 void PerformKeyboardAction(int key_code, bool key_down);
76 67
77 // Records paint time for statistics logging, if enabled. May be called from
78 // any thread.
79 void RecordPaintTime(int64 paint_time_ms);
80
81 // ClientUserInterface implementation. 68 // ClientUserInterface implementation.
82 virtual void OnConnectionState( 69 virtual void OnConnectionState(protocol::ConnectionToHost::State state,
83 protocol::ConnectionToHost::State state, 70 protocol::ErrorCode error) OVERRIDE;
84 protocol::ErrorCode error) OVERRIDE;
85 virtual void OnConnectionReady(bool ready) OVERRIDE; 71 virtual void OnConnectionReady(bool ready) OVERRIDE;
86 virtual void OnRouteChanged(const std::string& channel_name, 72 virtual void OnRouteChanged(const std::string& channel_name,
87 const protocol::TransportRoute& route) OVERRIDE; 73 const protocol::TransportRoute& route) OVERRIDE;
88 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE; 74 virtual void SetCapabilities(const std::string& capabilities) OVERRIDE;
89 virtual void SetPairingResponse( 75 virtual void SetPairingResponse(const protocol::PairingResponse& response)
90 const protocol::PairingResponse& response) OVERRIDE; 76 OVERRIDE;
91 virtual void DeliverHostMessage( 77 virtual void DeliverHostMessage(const protocol::ExtensionMessage& message)
92 const protocol::ExtensionMessage& message) OVERRIDE; 78 OVERRIDE;
93 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE; 79 virtual protocol::ClipboardStub* GetClipboardStub() OVERRIDE;
94 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE; 80 virtual protocol::CursorShapeStub* GetCursorShapeStub() OVERRIDE;
95 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher> 81 virtual scoped_ptr<protocol::ThirdPartyClientAuthenticator::TokenFetcher>
96 GetTokenFetcher(const std::string& host_public_key) OVERRIDE; 82 GetTokenFetcher(const std::string& host_public_key) OVERRIDE;
97 83
98 // CursorShapeStub implementation. 84 // CursorShapeStub implementation.
99 virtual void InjectClipboardEvent( 85 virtual void InjectClipboardEvent(const protocol::ClipboardEvent& event)
100 const protocol::ClipboardEvent& event) OVERRIDE; 86 OVERRIDE;
101 87
102 // ClipboardStub implementation. 88 // ClipboardStub implementation.
103 virtual void SetCursorShape(const protocol::CursorShapeInfo& shape) OVERRIDE; 89 virtual void SetCursorShape(const protocol::CursorShapeInfo& shape) OVERRIDE;
104 90
105 private: 91 private:
106 // This object is ref-counted, so it cleans itself up. 92 // This object is ref-counted, so it cleans itself up.
107 virtual ~ChromotingJniInstance(); 93 virtual ~ClientInstance();
108 94
109 void ConnectToHostOnDisplayThread();
110 void ConnectToHostOnNetworkThread(); 95 void ConnectToHostOnNetworkThread();
111 void DisconnectFromHostOnNetworkThread(); 96 void DisconnectFromHostOnNetworkThread();
112 97
113 // Notifies the user interface that the user needs to enter a PIN. The 98 // Notifies the user interface that the user needs to enter a PIN. The
114 // current authentication attempt is put on hold until |callback| is invoked. 99 // current authentication attempt is put on hold until |callback| is invoked.
115 // May be called on any thread. 100 // May be called on any thread.
116 void FetchSecret(bool pairable, 101 void FetchSecret(bool pairable,
117 const protocol::SecretFetchedCallback& callback); 102 const protocol::SecretFetchedCallback& callback);
118 103
119 // Sets the device name. Can be called on any thread. 104 // Used to obtain task runner references and exchange messages between the
120 void SetDeviceName(const std::string& device_name); 105 // common Chromoting protocol and ojbc interface.
121 106 scoped_refptr<ClientBridge> bridge_;
122 // Enables or disables periodic logging of performance statistics. Called on
123 // the network thread.
124 void EnableStatsLogging(bool enabled);
125
126 // If logging is enabled, logs the current connection statistics, and
127 // triggers another call to this function after the logging time interval.
128 // Called on the network thread.
129 void LogPerfStats();
130
131 // Used to obtain task runner references and make calls to Java methods.
132 ChromotingJniRuntime* jni_runtime_;
133 107
134 // ID of the host we are connecting to. 108 // ID of the host we are connecting to.
135 std::string host_id_; 109 std::string host_id_;
136 110
137 // This group of variables is to be used on the display thread. 111 // This group of variables is to be used on the display thread.
dcaiafa 2014/03/19 01:14:15 s/display/UI
aboone 2014/03/21 16:42:07 Done.
138 scoped_refptr<FrameConsumerProxy> frame_consumer_; 112 scoped_ptr<VideoRenderer> video_renderer_;
139 scoped_ptr<JniFrameConsumer> view_; 113 scoped_ptr<FrameConsumerBridge> view_;
140 scoped_ptr<base::WeakPtrFactory<JniFrameConsumer> > view_weak_factory_; 114 scoped_ptr<base::WeakPtrFactory<FrameConsumer> > view_weak_factory_;
141 115
142 // This group of variables is to be used on the network thread. 116 // This group of variables is to be used on the network thread.
143 ClientConfig client_config_; 117 ClientConfig client_config_;
144 scoped_ptr<ClientContext> client_context_; 118 ClientContext client_context_;
145 scoped_ptr<VideoRenderer> video_renderer_;
146 scoped_ptr<protocol::ConnectionToHost> connection_; 119 scoped_ptr<protocol::ConnectionToHost> connection_;
147 scoped_ptr<ChromotingClient> client_; 120 scoped_ptr<ChromotingClient> client_;
148 XmppSignalStrategy::XmppServerConfig xmpp_config_; 121 XmppSignalStrategy::XmppServerConfig xmpp_config_;
149 scoped_ptr<XmppSignalStrategy> signaling_; // Must outlive client_ 122 scoped_ptr<XmppSignalStrategy> signaling_; // Must outlive client_
150 123
151 // Pass this the user's PIN once we have it. To be assigned and accessed on 124 // Pass this the user's PIN once we have it. To be assigned and accessed on
152 // the UI thread, but must be posted to the network thread to call it. 125 // the UI thread, but must be posted to the network thread to call it.
153 protocol::SecretFetchedCallback pin_callback_; 126 protocol::SecretFetchedCallback pin_callback_;
154 127
155 // Indicates whether to establish a new pairing with this host. This is 128 // Indicates whether to establish a new pairing with this host. This is
156 // modified in ProvideSecret(), but thereafter to be used only from the 129 // modified in ProvideSecret(), but thereafter to be used only from the
157 // network thread. (This is safe because ProvideSecret() is invoked at most 130 // network thread. (This is safe because ProvideSecret() is invoked at most
158 // once per run, and always before any reference to this flag.) 131 // once per run, and always before any reference to this flag.)
159 bool create_pairing_; 132 bool create_pairing_;
160 133
161 // The device name to appear in the paired-clients list. Accessed on the 134 friend class base::RefCountedThreadSafe<ClientInstance>;
162 // network thread.
163 std::string device_name_;
164 135
165 // If this is true, performance statistics will be periodically written to 136 DISALLOW_COPY_AND_ASSIGN(ClientInstance);
166 // the Android log. Used on the network thread.
167 bool stats_logging_enabled_;
168
169 friend class base::RefCountedThreadSafe<ChromotingJniInstance>;
170
171 DISALLOW_COPY_AND_ASSIGN(ChromotingJniInstance);
172 }; 137 };
173 138
174 } // namespace remoting 139 } // namespace remoting
175 140
176 #endif 141 #endif // REMOTING_IOS_BRIDGE_CLIENT_INSTANCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698