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

Unified Diff: remoting/test/chromoting_instance.h

Issue 976233003: Adding the base ChromotingInstance implementation and unittests. This class will be used by the ap… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing a unit test name Created 5 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 side-by-side diff with in-line comments
Download patch
Index: remoting/test/chromoting_instance.h
diff --git a/remoting/test/chromoting_instance.h b/remoting/test/chromoting_instance.h
new file mode 100644
index 0000000000000000000000000000000000000000..107382f914c354500c740c7d1d7aa129006e9444
--- /dev/null
+++ b/remoting/test/chromoting_instance.h
@@ -0,0 +1,140 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_TEST_CHROMOTING_INSTANCE_H_
+#define REMOTING_TEST_CHROMOTING_INSTANCE_H_
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/observer_list.h"
+#include "remoting/client/client_user_interface.h"
+#include "remoting/protocol/cursor_shape_stub.h"
+#include "remoting/test/remote_connection_observer.h"
+#include "remoting/test/remote_host_info.h"
+
+namespace remoting {
+class ChromotingClient;
+class ClientContext;
+class TokenFetcherProxy;
+class XmppSignalStrategy;
+class VideoRenderer;
+}
+
+namespace remoting {
+namespace test {
+
+// Manages a chromoting connection to a remote host. Destroying a
+// ChromotingInstance object with an active connection will close it.
+// Must be used from a thread running an IO message loop.
+// RemoteConnectionObserver objects must not destroy this class within a
+// callback.
+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
+ public remoting::ClientUserInterface,
Sergey Ulanov 2015/03/09 06:44:41 nit: don't need remoting::
joedow 2015/03/09 21:09:26 Done.
+ public protocol::ClipboardStub,
+ public protocol::CursorShapeStub {
+ public:
+ ChromotingInstance();
+ ~ChromotingInstance() override;
+
+ // Starts a chromoting connection with the specified remote host.
+ void StartConnection(
+ const std::string& user_name,
+ const std::string& access_token,
+ const RemoteHostInfo& remote_host_info);
+
+ // Ends the current remote connection and updates the connection state.
+ void EndConnection();
+
+ // Registers an observer which will be notfied when remote connection events
+ // occur. Registered Observers must not tear-down this object on receipt of
+ // these callbacks. The callbacks should be used for informational purposes.
+ void AddRemoteConnectionObserver(RemoteConnectionObserver* observer);
+
+ // Unregisters an observerer from notifications for remote connection events.
+ void RemoveRemoteConnectionObserver(RemoteConnectionObserver* observer);
+
+ // Used to set a fake/mock connection object for ChromotingInstance tests.
+ void SetConnectionToHostForTests(
+ scoped_ptr<protocol::ConnectionToHost> connection_to_host);
+
+ // Used as the TokenFetcherCallback for App Remoting sessions.
+ static void FetchThirdPartyToken(
+ const std::string& authorization_token,
+ const std::string& shared_secret,
+ const GURL& token_url,
+ const std::string& host_public_key,
+ const std::string& scope,
+ const base::WeakPtr<remoting::TokenFetcherProxy> token_fetcher_proxy);
+
+ // Used as the FetchSecretCallback for IT2Me or Me2Me sessions.
+ static void FetchSecretFromString(
+ const std::string& shared_secret,
+ bool pairing_supported,
+ const protocol::SecretFetchedCallback& secret_fetched_callback);
+
+ private:
+ // ClientUserInterface interface.
+ void OnConnectionState(
+ protocol::ConnectionToHost::State state,
+ protocol::ErrorCode error_code) override;
+ void OnConnectionReady(bool ready) override;
+ void OnRouteChanged(
+ const std::string& channel_name,
+ const protocol::TransportRoute& route) override;
+ void SetCapabilities(const std::string& capabilities) override;
+ void SetPairingResponse(
+ const protocol::PairingResponse& pairing_response) override;
+ void DeliverHostMessage(const protocol::ExtensionMessage& message) override;
+ protocol::ClipboardStub* GetClipboardStub() override;
+ protocol::CursorShapeStub* GetCursorShapeStub() override;
+
+ // ClipboardStub interface.
+ void InjectClipboardEvent(const protocol::ClipboardEvent& event) override;
+
+ // CursorShapeStub interface.
+ void SetCursorShape(const protocol::CursorShapeInfo& cursor_shape) override;
+
+ // Converts a State enum value to its string representation.
+ const char* ConnectionStateToFriendlyString(
+ protocol::ConnectionToHost::State state);
+
+ // Converts an ErrorCode enum value to its string representation.
+ const char* ProtocolErrorToFriendlyString(protocol::ErrorCode error_code);
+
+ // Tracks the current connection state.
+ protocol::ConnectionToHost::State connection_to_host_state_;
+
+ // Tracks the most recent connection error code seen.
+ protocol::ErrorCode connection_error_code_;
+
+ // List of observers which are notified when remote connection events occur.
+ ObserverList<RemoteConnectionObserver> connection_observers_;
+
+ // ConnectionToHost used by ChromotingInstance tests.
+ scoped_ptr<protocol::ConnectionToHost> test_connection_to_host_;
+
+ // Callback which points to the FetchSecretFromString method in this class.
+ protocol::FetchSecretCallback fetch_secret_callback_;
+
+ // Creates and manages the connection to the remote host.
+ 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.
+
+ // Manages the threads and task runners for |chromoting_client_|.
+ scoped_ptr<remoting::ClientContext> client_context_;
+
+ // Processes video packets from the host.
+ scoped_ptr<remoting::VideoRenderer> video_renderer_;
+
+ // Used to establishe an XMPP connection with the google talk service.
+ scoped_ptr<remoting::XmppSignalStrategy> signal_strategy_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromotingInstance);
+};
+
+} // namespace test
+} // namespace remoting
+
+#endif // REMOTING_TEST_CHROMOTING_INSTANCE_H_

Powered by Google App Engine
This is Rietveld 408576698