| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_JNI_PAIRING_SECRET_FETCHER_H_ | 5 #ifndef REMOTING_CLIENT_JNI_JNI_PAIRING_SECRET_FETCHER_H_ |
| 6 #define REMOTING_CLIENT_JNI_JNI_PAIRING_SECRET_FETCHER_H_ | 6 #define REMOTING_CLIENT_JNI_JNI_PAIRING_SECRET_FETCHER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "remoting/protocol/client_authentication_config.h" | 10 #include "remoting/protocol/client_authentication_config.h" |
| 11 | 11 |
| 12 namespace remoting { | 12 namespace remoting { |
| 13 | 13 |
| 14 class ChromotingJniRuntime; | 14 class ChromotingJniRuntime; |
| 15 class JniClient; | 15 class JniClient; |
| 16 | 16 |
| 17 // This class fetches the pairing secret on the UI thread. It must be deleted | 17 // This class fetches the pairing secret on the UI thread. This should be |
| 18 // on UI. | 18 // created on the UI thread but there after used and deleted on the network |
| 19 // thread. |
| 19 class JniPairingSecretFetcher { | 20 class JniPairingSecretFetcher { |
| 20 public: | 21 public: |
| 21 JniPairingSecretFetcher(ChromotingJniRuntime* runtime, | 22 JniPairingSecretFetcher(ChromotingJniRuntime* runtime, |
| 22 base::WeakPtr<JniClient> client, | 23 base::WeakPtr<JniClient> client, |
| 23 const std::string& host_id); | 24 const std::string& host_id); |
| 24 virtual ~JniPairingSecretFetcher(); | 25 virtual ~JniPairingSecretFetcher(); |
| 25 | 26 |
| 26 // Called on UI thread. Notifies the user interface that the user needs to | 27 // Notifies the user interface that the user needs to enter a PIN. The current |
| 27 // enter a PIN. The current authentication attempt is put on hold until | 28 // authentication attempt is put on hold until |callback| is invoked. |
| 28 // |callback| is invoked. |callback| will be run on the network thread. | |
| 29 void FetchSecret(bool pairable, | 29 void FetchSecret(bool pairable, |
| 30 const protocol::SecretFetchedCallback& callback); | 30 const protocol::SecretFetchedCallback& callback); |
| 31 | 31 |
| 32 // Provides the user's PIN and resumes the host authentication attempt. Call | 32 // Provides the user's PIN and resumes the host authentication attempt. Call |
| 33 // on the UI thread once the user has finished entering this PIN into the UI, | 33 // once the user has finished entering this PIN into the UI, but only after |
| 34 // but only after the UI has been asked to provide a PIN (via FetchSecret()). | 34 // the UI has been asked to provide a PIN (via FetchSecret()). |
| 35 void ProvideSecret(const std::string& pin); | 35 void ProvideSecret(const std::string& pin); |
| 36 | 36 |
| 37 // Get weak pointer to be used on the UI thread. | 37 // Get weak pointer to be used on the network thread. |
| 38 base::WeakPtr<JniPairingSecretFetcher> GetWeakPtr(); | 38 base::WeakPtr<JniPairingSecretFetcher> GetWeakPtr(); |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 static void FetchSecretOnUiThread(base::WeakPtr<JniClient> client, |
| 42 const std::string& host_id, |
| 43 bool pairable); |
| 44 |
| 41 ChromotingJniRuntime* jni_runtime_; | 45 ChromotingJniRuntime* jni_runtime_; |
| 42 base::WeakPtr<JniClient> jni_client_; | 46 base::WeakPtr<JniClient> jni_client_; |
| 43 | 47 |
| 44 std::string host_id_; | 48 std::string host_id_; |
| 45 | 49 |
| 46 // Pass this the user's PIN once we have it. To be assigned and accessed on | 50 // Pass this the user's PIN once we have it. To be assigned and accessed on |
| 47 // the UI thread, but must be posted to the network thread to call it. | 51 // the UI thread, but must be posted to the network thread to call it. |
| 48 protocol::SecretFetchedCallback callback_; | 52 protocol::SecretFetchedCallback callback_; |
| 49 | 53 |
| 50 base::WeakPtrFactory<JniPairingSecretFetcher> weak_factory_; | 54 base::WeakPtrFactory<JniPairingSecretFetcher> weak_factory_; |
| 51 | 55 |
| 52 DISALLOW_COPY_AND_ASSIGN(JniPairingSecretFetcher); | 56 DISALLOW_COPY_AND_ASSIGN(JniPairingSecretFetcher); |
| 53 }; | 57 }; |
| 54 | 58 |
| 55 } // namespace remoting | 59 } // namespace remoting |
| 56 | 60 |
| 57 #endif // REMOTING_CLIENT_JNI_JNI_PAIRING_SECRET_FETCHER_H_ | 61 #endif // REMOTING_CLIENT_JNI_JNI_PAIRING_SECRET_FETCHER_H_ |
| OLD | NEW |