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_TEST_CHROMOTING_CLIENT_H_ | |
| 6 #define REMOTING_TEST_TEST_CHROMOTING_CLIENT_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 // TestChromotingClient 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 TestChromotingClient : public ClientUserInterface, | |
| 35 public protocol::ClipboardStub, | |
| 36 public protocol::CursorShapeStub { | |
| 37 public: | |
| 38 TestChromotingClient(); | |
| 39 ~TestChromotingClient() override; | |
| 40 | |
| 41 // Starts a chromoting connection with the specified remote host. | |
| 42 void StartConnection(const std::string& user_name, | |
| 43 const std::string& access_token, | |
| 44 const RemoteHostInfo& remote_host_info); | |
| 45 | |
| 46 // Ends the current remote connection and updates the connection state. | |
| 47 void EndConnection(); | |
| 48 | |
| 49 // Registers an observer which will be notfied when remote connection events | |
| 50 // occur. Registered Observers must not tear-down this object on receipt of | |
| 51 // these callbacks. The callbacks should be used for informational purposes. | |
| 52 void AddRemoteConnectionObserver(RemoteConnectionObserver* observer); | |
| 53 | |
| 54 // Unregisters an observerer from notifications for remote connection events. | |
| 55 void RemoveRemoteConnectionObserver(RemoteConnectionObserver* observer); | |
| 56 | |
| 57 // Used to set a fake/mock connection object for TestChromotingClient tests. | |
| 58 void SetConnectionToHostForTests( | |
| 59 scoped_ptr<protocol::ConnectionToHost> connection_to_host); | |
| 60 | |
| 61 // Used as the TokenFetcherCallback for App Remoting sessions. | |
| 62 static void FetchThirdPartyToken( | |
|
Sergey Ulanov
2015/03/11 00:09:52
this doesn't need to be a public static method. It
joedow
2015/03/11 19:06:39
Done.
| |
| 63 const std::string& authorization_token, | |
| 64 const std::string& shared_secret, | |
| 65 const GURL& token_url, | |
| 66 const std::string& host_public_key, | |
| 67 const std::string& scope, | |
| 68 const base::WeakPtr<TokenFetcherProxy> token_fetcher_proxy); | |
| 69 | |
| 70 // Used as the FetchSecretCallback for IT2Me or Me2Me sessions. | |
| 71 static void FetchSecretFromString( | |
| 72 const std::string& shared_secret, | |
| 73 bool pairing_supported, | |
| 74 const protocol::SecretFetchedCallback& secret_fetched_callback); | |
| 75 | |
| 76 private: | |
| 77 // ClientUserInterface interface. | |
| 78 void OnConnectionState(protocol::ConnectionToHost::State state, | |
| 79 protocol::ErrorCode error_code) override; | |
| 80 void OnConnectionReady(bool ready) override; | |
| 81 void OnRouteChanged(const std::string& channel_name, | |
| 82 const protocol::TransportRoute& route) override; | |
| 83 void SetCapabilities(const std::string& capabilities) override; | |
| 84 void SetPairingResponse( | |
| 85 const protocol::PairingResponse& pairing_response) override; | |
| 86 void DeliverHostMessage(const protocol::ExtensionMessage& message) override; | |
| 87 protocol::ClipboardStub* GetClipboardStub() override; | |
| 88 protocol::CursorShapeStub* GetCursorShapeStub() override; | |
| 89 | |
| 90 // protocol::ClipboardStub interface. | |
| 91 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override; | |
| 92 | |
| 93 // protocol::CursorShapeStub interface. | |
| 94 void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override; | |
| 95 | |
| 96 // Converts a State enum value to its string representation. | |
| 97 const char* ConnectionStateToFriendlyString( | |
| 98 protocol::ConnectionToHost::State state); | |
| 99 | |
| 100 // Converts an ErrorCode enum value to its string representation. | |
| 101 const char* ProtocolErrorToFriendlyString(protocol::ErrorCode error_code); | |
| 102 | |
| 103 // Tracks the current connection state. | |
| 104 protocol::ConnectionToHost::State connection_to_host_state_; | |
| 105 | |
| 106 // Tracks the most recent connection error code seen. | |
| 107 protocol::ErrorCode connection_error_code_; | |
| 108 | |
| 109 // List of observers which are notified when remote connection events occur. | |
| 110 // We specify true below for the 'check_empty' flag so the list will check to | |
| 111 // see if all observers have been unregistered when it is destroyed. | |
| 112 ObserverList<RemoteConnectionObserver, true> connection_observers_; | |
| 113 | |
| 114 // ConnectionToHost used by TestChromotingClient tests. | |
| 115 scoped_ptr<protocol::ConnectionToHost> test_connection_to_host_; | |
| 116 | |
| 117 // Callback which points to the FetchSecretFromString method in this class. | |
| 118 protocol::FetchSecretCallback fetch_secret_callback_; | |
|
Sergey Ulanov
2015/03/11 00:09:52
This doesn't need to be class member. StartConnect
joedow
2015/03/11 19:06:39
Done.
| |
| 119 | |
| 120 // Creates and manages the connection to the remote host. | |
| 121 scoped_ptr<ChromotingClient> chromoting_client_; | |
| 122 | |
| 123 // Manages the threads and task runners for |chromoting_client_|. | |
| 124 scoped_ptr<ClientContext> client_context_; | |
| 125 | |
| 126 // Processes video packets from the host. | |
| 127 scoped_ptr<VideoRenderer> video_renderer_; | |
| 128 | |
| 129 // Used to establishe an XMPP connection with the google talk service. | |
| 130 scoped_ptr<XmppSignalStrategy> signal_strategy_; | |
| 131 | |
| 132 DISALLOW_COPY_AND_ASSIGN(TestChromotingClient); | |
| 133 }; | |
| 134 | |
| 135 } // namespace test | |
| 136 } // namespace remoting | |
| 137 | |
| 138 #endif // REMOTING_TEST_TEST_CHROMOTING_CLIENT_H_ | |
| OLD | NEW |