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

Unified Diff: remoting/client/jni/chromoting_jni_instance.h

Issue 2007123003: [Android Client] Break down multi-threaded classes by thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename JniSecretFetcher to JniPairingSecretFetcher Created 4 years, 7 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/client/jni/chromoting_jni_instance.h
diff --git a/remoting/client/jni/chromoting_jni_instance.h b/remoting/client/jni/chromoting_jni_instance.h
index bdbbb4585409de5752e458985307e7bf688ac82a..151376f54f0c5d42a1dd34beb9979474b020a5af 100644
--- a/remoting/client/jni/chromoting_jni_instance.h
+++ b/remoting/client/jni/chromoting_jni_instance.h
@@ -32,20 +32,26 @@ class VideoRenderer;
class ChromotingJniRuntime;
class JniClient;
+class JniDisplayHandler;
class JniFrameConsumer;
+class JniPairingSecretFetcher;
-// ClientUserInterface that indirectly makes and receives JNI calls.
+// ChromotingJniInstance is scoped to the session.
+// This class is Created on the UI thread but thereafter it is used and
+// destroyed on the network thread. Except where indicated, all methods are
+// called on the network thread.
class ChromotingJniInstance
: public ClientUserInterface,
public protocol::ClipboardStub,
- public protocol::CursorShapeStub,
- public base::RefCountedThreadSafe<ChromotingJniInstance> {
+ public protocol::CursorShapeStub {
public:
// Initiates a connection with the specified host. Call from the UI thread.
// The instance does not take ownership of |jni_runtime|. To connect with an
// unpaired host, pass in |pairing_id| and |pairing_secret| as empty strings.
ChromotingJniInstance(ChromotingJniRuntime* jni_runtime,
- JniClient* jni_client,
+ base::WeakPtr<JniClient> jni_client,
+ base::WeakPtr<JniDisplayHandler> display,
+ base::WeakPtr<JniPairingSecretFetcher> secret_fetcher,
const std::string& username,
const std::string& auth_token,
const std::string& host_jid,
@@ -56,6 +62,8 @@ class ChromotingJniInstance
const std::string& capabilities,
const std::string& flags);
+ ~ChromotingJniInstance() override;
+
// Starts the connection. Can be called on any thread.
void Connect();
@@ -81,9 +89,6 @@ class ChromotingJniInstance
void ProvideSecret(const std::string& pin, bool create_pair,
const std::string& device_name);
- // Schedules a redraw on the display thread. May be called from any thread.
- void RedrawDesktop();
-
// Moves the host's cursor to the specified coordinates, optionally with some
// mouse button depressed. If |button| is BUTTON_UNDEFINED, no click is made.
void SendMouseEvent(int x, int y,
@@ -124,10 +129,11 @@ class ChromotingJniInstance
// ClipboardStub implementation.
void SetCursorShape(const protocol::CursorShapeInfo& shape) override;
- private:
- // This object is ref-counted, so it cleans itself up.
- ~ChromotingJniInstance() override;
+ // Get the weak pointer of the instance. Please only use it on the network
+ // thread.
+ base::WeakPtr<ChromotingJniInstance> GetWeakPtr();
+ private:
void ConnectToHostOnNetworkThread();
// Notifies the user interface that the user needs to enter a PIN. The
@@ -150,10 +156,17 @@ class ChromotingJniInstance
// Called on the network thread.
void LogPerfStats();
+ // Releases the resource in the right order.
+ void ReleaseResources();
+
// Used to obtain task runner references and make calls to Java methods.
ChromotingJniRuntime* jni_runtime_;
- JniClient* jni_client_;
+ base::WeakPtr<JniClient> jni_client_;
+
+ base::WeakPtr<JniDisplayHandler> display_handler_;
+
+ base::WeakPtr<JniPairingSecretFetcher> secret_fetcher_;
// ID of the host we are connecting to.
std::string host_jid_;
@@ -172,10 +185,6 @@ class ChromotingJniInstance
std::unique_ptr<XmppSignalStrategy> signaling_; // Must outlive client_
protocol::ThirdPartyTokenFetchedCallback third_party_token_fetched_callback_;
- // Pass this the user's PIN once we have it. To be assigned and accessed on
- // the UI thread, but must be posted to the network thread to call it.
- protocol::SecretFetchedCallback pin_callback_;
-
// Indicates whether to establish a new pairing with this host. This is
// modified in ProvideSecret(), but thereafter to be used only from the
// network thread. (This is safe because ProvideSecret() is invoked at most
@@ -199,8 +208,6 @@ class ChromotingJniInstance
// thread.
bool connected_ = false;
- friend class base::RefCountedThreadSafe<ChromotingJniInstance>;
-
base::WeakPtrFactory<ChromotingJniInstance> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(ChromotingJniInstance);
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/jni/Display.java ('k') | remoting/client/jni/chromoting_jni_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698