Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 #ifndef REMOTING_TEST_CHROMOTING_INSTANCE_H_ | |
| 6 #define REMOTING_TEST_CHROMOTING_INSTANCE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/observer_list.h" | |
| 13 #include "remoting/client/client_user_interface.h" | |
| 14 #include "remoting/protocol/cursor_shape_stub.h" | |
| 15 #include "remoting/test/remote_connection_observer.h" | |
| 16 #include "remoting/test/remote_host_info.h" | |
| 17 | |
| 18 namespace remoting { | |
| 19 class ChromotingClient; | |
| 20 class ClientContext; | |
| 21 class TokenFetcherProxy; | |
| 22 class XmppSignalStrategy; | |
| 23 class VideoRenderer; | |
| 24 } | |
| 25 | |
| 26 namespace remoting { | |
| 27 namespace test { | |
| 28 | |
| 29 // Manages a chromoting connection to a remote host. Destroying a | |
| 30 // ChromotingInstance object with an active connection will close it. | |
| 31 // Must be used from a thread running an IO message loop. | |
| 32 // RemoteConnectionObserver objects must not destroy this class within a | |
| 33 // callback. | |
| 34 class ChromotingInstance : | |
|
Sergey Ulanov
2015/03/09 06:44:41
Can this be called something else? We already have
joedow
2015/03/09 21:09:26
I received the same feedback from Wez so I will th
| |
| 35 public remoting::ClientUserInterface, | |
|
Sergey Ulanov
2015/03/09 06:44:41
nit: don't need remoting::
joedow
2015/03/09 21:09:26
Done.
| |
| 36 public protocol::ClipboardStub, | |
| 37 public protocol::CursorShapeStub { | |
| 38 public: | |
| 39 ChromotingInstance(); | |
| 40 ~ChromotingInstance() override; | |
| 41 | |
| 42 // Starts a chromoting connection with the specified remote host. | |
| 43 void StartConnection( | |
| 44 const std::string& user_name, | |
| 45 const std::string& access_token, | |
| 46 const RemoteHostInfo& remote_host_info); | |
| 47 | |
| 48 // Ends the current remote connection and updates the connection state. | |
| 49 void EndConnection(); | |
| 50 | |
| 51 // Registers an observer which will be notfied when remote connection events | |
| 52 // occur. Registered Observers must not tear-down this object on receipt of | |
| 53 // these callbacks. The callbacks should be used for informational purposes. | |
| 54 void AddRemoteConnectionObserver(RemoteConnectionObserver* observer); | |
| 55 | |
| 56 // Unregisters an observerer from notifications for remote connection events. | |
| 57 void RemoveRemoteConnectionObserver(RemoteConnectionObserver* observer); | |
| 58 | |
| 59 // Used to set a fake/mock connection object for ChromotingInstance tests. | |
| 60 void SetConnectionToHostForTests( | |
| 61 scoped_ptr<protocol::ConnectionToHost> connection_to_host); | |
| 62 | |
| 63 // Used as the TokenFetcherCallback for App Remoting sessions. | |
| 64 static void FetchThirdPartyToken( | |
| 65 const std::string& authorization_token, | |
| 66 const std::string& shared_secret, | |
| 67 const GURL& token_url, | |
| 68 const std::string& host_public_key, | |
| 69 const std::string& scope, | |
| 70 const base::WeakPtr<remoting::TokenFetcherProxy> token_fetcher_proxy); | |
| 71 | |
| 72 // Used as the FetchSecretCallback for IT2Me or Me2Me sessions. | |
| 73 static void FetchSecretFromString( | |
| 74 const std::string& shared_secret, | |
| 75 bool pairing_supported, | |
| 76 const protocol::SecretFetchedCallback& secret_fetched_callback); | |
| 77 | |
| 78 private: | |
| 79 // ClientUserInterface interface. | |
| 80 void OnConnectionState( | |
| 81 protocol::ConnectionToHost::State state, | |
| 82 protocol::ErrorCode error_code) override; | |
| 83 void OnConnectionReady(bool ready) override; | |
| 84 void OnRouteChanged( | |
| 85 const std::string& channel_name, | |
| 86 const protocol::TransportRoute& route) override; | |
| 87 void SetCapabilities(const std::string& capabilities) override; | |
| 88 void SetPairingResponse( | |
| 89 const protocol::PairingResponse& pairing_response) override; | |
| 90 void DeliverHostMessage(const protocol::ExtensionMessage& message) override; | |
| 91 protocol::ClipboardStub* GetClipboardStub() override; | |
| 92 protocol::CursorShapeStub* GetCursorShapeStub() override; | |
| 93 | |
| 94 // ClipboardStub interface. | |
| 95 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override; | |
| 96 | |
| 97 // CursorShapeStub interface. | |
| 98 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override; | |
| 99 | |
| 100 // Converts a State enum value to its string representation. | |
| 101 const char* ConnectionStateToFriendlyString( | |
| 102 protocol::ConnectionToHost::State state); | |
| 103 | |
| 104 // Converts an ErrorCode enum value to its string representation. | |
| 105 const char* ProtocolErrorToFriendlyString(protocol::ErrorCode error_code); | |
| 106 | |
| 107 // Tracks the current connection state. | |
| 108 protocol::ConnectionToHost::State connection_to_host_state_; | |
| 109 | |
| 110 // Tracks the most recent connection error code seen. | |
| 111 protocol::ErrorCode connection_error_code_; | |
| 112 | |
| 113 // List of observers which are notified when remote connection events occur. | |
| 114 ObserverList<RemoteConnectionObserver> connection_observers_; | |
| 115 | |
| 116 // ConnectionToHost used by ChromotingInstance tests. | |
| 117 scoped_ptr<protocol::ConnectionToHost> test_connection_to_host_; | |
| 118 | |
| 119 // Callback which points to the FetchSecretFromString method in this class. | |
| 120 protocol::FetchSecretCallback fetch_secret_callback_; | |
| 121 | |
| 122 // Creates and manages the connection to the remote host. | |
| 123 scoped_ptr<remoting::ChromotingClient> chromoting_client_; | |
|
Sergey Ulanov
2015/03/09 06:44:41
Don't need to specify namespace
joedow
2015/03/09 21:09:26
Done.
| |
| 124 | |
| 125 // Manages the threads and task runners for |chromoting_client_|. | |
| 126 scoped_ptr<remoting::ClientContext> client_context_; | |
| 127 | |
| 128 // Processes video packets from the host. | |
| 129 scoped_ptr<remoting::VideoRenderer> video_renderer_; | |
| 130 | |
| 131 // Used to establishe an XMPP connection with the google talk service. | |
| 132 scoped_ptr<remoting::XmppSignalStrategy> signal_strategy_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(ChromotingInstance); | |
| 135 }; | |
| 136 | |
| 137 } // namespace test | |
| 138 } // namespace remoting | |
| 139 | |
| 140 #endif // REMOTING_TEST_CHROMOTING_INSTANCE_H_ | |
| OLD | NEW |