| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_JNI_CHROMOTING_JNI_H_ | 5 #ifndef REMOTING_CLIENT_JNI_CHROMOTING_JNI_H_ |
| 6 #define REMOTING_CLIENT_JNI_CHROMOTING_JNI_H_ | 6 #define REMOTING_CLIENT_JNI_CHROMOTING_JNI_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
| 11 #include "net/url_request/url_request_context_getter.h" | 11 #include "net/url_request/url_request_context_getter.h" |
| 12 #include "remoting/base/auto_thread.h" | 12 #include "remoting/base/auto_thread.h" |
| 13 #include "remoting/client/jni/chromoting_jni_instance.h" |
| 13 #include "remoting/protocol/connection_to_host.h" | 14 #include "remoting/protocol/connection_to_host.h" |
| 14 | 15 |
| 15 template<typename T> struct DefaultSingletonTraits; | 16 template<typename T> struct DefaultSingletonTraits; |
| 16 | 17 |
| 17 namespace remoting { | 18 namespace remoting { |
| 18 class ChromotingJniInstance; | |
| 19 | 19 |
| 20 // Houses the global resources on which the Chromoting components run | 20 // Houses the global resources on which the Chromoting components run |
| 21 // (e.g. message loops and task runners). Proxies outgoing JNI calls from its | 21 // (e.g. message loops and task runners). Proxies outgoing JNI calls from its |
| 22 // ChromotingJniInstance member to Java. All its methods should be invoked | 22 // ChromotingJniInstance member to Java. All its methods should be invoked |
| 23 // exclusively from the UI thread. | 23 // exclusively from the UI thread unless otherwise noted. |
| 24 class ChromotingJni { | 24 class ChromotingJni { |
| 25 public: | 25 public: |
| 26 // This class is instantiated at process initialization and persists until | 26 // This class is instantiated at process initialization and persists until |
| 27 // we close. Its components are reused across |ChromotingJniInstance|s. | 27 // we close. Its components are reused across |ChromotingJniInstance|s. |
| 28 static ChromotingJni* GetInstance(); | 28 static ChromotingJni* GetInstance(); |
| 29 | 29 |
| 30 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { | 30 scoped_refptr<AutoThreadTaskRunner> ui_task_runner() { |
| 31 return ui_task_runner_; | 31 return ui_task_runner_; |
| 32 } | 32 } |
| 33 | 33 |
| 34 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { | 34 scoped_refptr<AutoThreadTaskRunner> network_task_runner() { |
| 35 return network_task_runner_; | 35 return network_task_runner_; |
| 36 } | 36 } |
| 37 | 37 |
| 38 scoped_refptr<AutoThreadTaskRunner> display_task_runner() { | 38 scoped_refptr<AutoThreadTaskRunner> display_task_runner() { |
| 39 return display_task_runner_; | 39 return display_task_runner_; |
| 40 } | 40 } |
| 41 | 41 |
| 42 scoped_refptr<net::URLRequestContextGetter> url_requester() { | 42 scoped_refptr<net::URLRequestContextGetter> url_requester() { |
| 43 return url_requester_; | 43 return url_requester_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Initiates a connection with the specified host. Must only be called when | 46 // Initiates a connection with the specified host. Only call when a host |
| 47 // |session_| is null (i.e. before any other call to Connect() or following | 47 // connection is active (i.e. between a call to Connect() and the |
| 48 // a call to Disconnect()). | 48 // corresponding call to Disconnect()). |
| 49 void ConnectToHost(const char* username, | 49 void ConnectToHost(const char* username, |
| 50 const char* auth_token, | 50 const char* auth_token, |
| 51 const char* host_jid, | 51 const char* host_jid, |
| 52 const char* host_id, | 52 const char* host_id, |
| 53 const char* host_pubkey); | 53 const char* host_pubkey); |
| 54 | 54 |
| 55 // Terminates any ongoing connection attempt and cleans up by nullifying | 55 // Terminates any ongoing connection attempt and cleans up by nullifying |
| 56 // |session_|. This is a no-op unless |session| is currently non-null. | 56 // |session_|. This is a no-op unless |session| is currently non-null. |
| 57 void DisconnectFromHost(); | 57 void DisconnectFromHost(); |
| 58 | 58 |
| 59 // Returns the client for the currently-active session. Do not call if | 59 // Returns the client for the currently-active session. Do not call if |
| 60 // |session| is null. | 60 // |session| is null. |
| 61 scoped_refptr<ChromotingJniInstance> session() { | 61 scoped_refptr<ChromotingJniInstance> session() { |
| 62 DCHECK(session_); | 62 DCHECK(session_); |
| 63 return session_; | 63 return session_; |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Notifies the user that the connection status has changed. | 66 // Notifies the user that the connection status has changed. |
| 67 void ReportConnectionStatus(protocol::ConnectionToHost::State state, | 67 void ReportConnectionStatus(protocol::ConnectionToHost::State state, |
| 68 protocol::ErrorCode error); | 68 protocol::ErrorCode error); |
| 69 | 69 |
| 70 // Pops up a dialog box asking the user to enter a PIN. | 70 // Pops up a dialog box asking the user to enter a PIN. |
| 71 void DisplayAuthenticationPrompt(); | 71 void DisplayAuthenticationPrompt(); |
| 72 | 72 |
| 73 // Updates image dimensions and canvas memory space. Call on display thread. |
| 74 void UpdateImageBuffer(int width, int height, jobject buffer); |
| 75 |
| 76 // Draws the latest image buffer onto the canvas. Call on the display thread. |
| 77 void RedrawCanvas(); |
| 78 |
| 73 private: | 79 private: |
| 74 ChromotingJni(); | 80 ChromotingJni(); |
| 75 | 81 |
| 76 // Forces a DisconnectFromHost() in case there is any active or failed | 82 // Forces a DisconnectFromHost() in case there is any active or failed |
| 77 // connection, then proceeds to tear down the Chromium dependencies on which | 83 // connection, then proceeds to tear down the Chromium dependencies on which |
| 78 // all sessions depended. Because destruction only occurs at application exit | 84 // all sessions depended. Because destruction only occurs at application exit |
| 79 // after all connections have terminated, it is safe to make unretained | 85 // after all connections have terminated, it is safe to make unretained |
| 80 // cross-thread calls on the class. | 86 // cross-thread calls on the class. |
| 81 virtual ~ChromotingJni(); | 87 virtual ~ChromotingJni(); |
| 82 | 88 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 101 scoped_refptr<ChromotingJniInstance> session_; | 107 scoped_refptr<ChromotingJniInstance> session_; |
| 102 | 108 |
| 103 friend struct DefaultSingletonTraits<ChromotingJni>; | 109 friend struct DefaultSingletonTraits<ChromotingJni>; |
| 104 | 110 |
| 105 DISALLOW_COPY_AND_ASSIGN(ChromotingJni); | 111 DISALLOW_COPY_AND_ASSIGN(ChromotingJni); |
| 106 }; | 112 }; |
| 107 | 113 |
| 108 } // namespace remoting | 114 } // namespace remoting |
| 109 | 115 |
| 110 #endif | 116 #endif |
| OLD | NEW |