Chromium Code Reviews| 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. It is used entirely |
| 18 // on UI. | 18 // on the network thread. |
|
Lambros
2016/06/07 01:21:12
Actually, it's created on the UI thread, but there
Yuwei
2016/06/07 18:01:03
Done. Fixed comments.
| |
| 19 class JniPairingSecretFetcher { | 19 class JniPairingSecretFetcher { |
| 20 public: | 20 public: |
| 21 JniPairingSecretFetcher(ChromotingJniRuntime* runtime, | 21 JniPairingSecretFetcher(ChromotingJniRuntime* runtime, |
| 22 base::WeakPtr<JniClient> client, | 22 base::WeakPtr<JniClient> client, |
| 23 const std::string& host_id); | 23 const std::string& host_id); |
| 24 virtual ~JniPairingSecretFetcher(); | 24 virtual ~JniPairingSecretFetcher(); |
| 25 | 25 |
| 26 // Called on UI thread. Notifies the user interface that the user needs to | 26 // 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 | 27 // 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, | 28 void FetchSecret(bool pairable, |
| 30 const protocol::SecretFetchedCallback& callback); | 29 const protocol::SecretFetchedCallback& callback); |
| 31 | 30 |
| 32 // Provides the user's PIN and resumes the host authentication attempt. Call | 31 // 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, | 32 // 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()). | 33 // the UI has been asked to provide a PIN (via FetchSecret()). |
| 35 void ProvideSecret(const std::string& pin); | 34 void ProvideSecret(const std::string& pin); |
| 36 | 35 |
| 37 // Get weak pointer to be used on the UI thread. | 36 // Get weak pointer to be used on the UI thread. |
| 38 base::WeakPtr<JniPairingSecretFetcher> GetWeakPtr(); | 37 base::WeakPtr<JniPairingSecretFetcher> GetWeakPtr(); |
|
Lambros
2016/06/07 01:21:12
Can this be removed?
Yuwei
2016/06/07 17:36:00
Currently JniClient passes in a WeakPtr of the sec
Yuwei
2016/06/07 17:44:26
Hmm... Just thought about this again... The ctor o
| |
| 39 | 38 |
| 40 private: | 39 private: |
| 40 static void FetchSecretOnUI(base::WeakPtr<JniClient> client, | |
|
Lambros
2016/06/07 01:21:12
rename: FetchSecretOnUiThread
Yuwei
2016/06/07 18:01:03
Done.
| |
| 41 const std::string& host_id, | |
| 42 bool pairable); | |
| 43 | |
| 41 ChromotingJniRuntime* jni_runtime_; | 44 ChromotingJniRuntime* jni_runtime_; |
| 42 base::WeakPtr<JniClient> jni_client_; | 45 base::WeakPtr<JniClient> jni_client_; |
| 43 | 46 |
| 44 std::string host_id_; | 47 std::string host_id_; |
| 45 | 48 |
| 46 // Pass this the user's PIN once we have it. To be assigned and accessed on | 49 // 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. | 50 // the UI thread, but must be posted to the network thread to call it. |
| 48 protocol::SecretFetchedCallback callback_; | 51 protocol::SecretFetchedCallback callback_; |
| 49 | 52 |
| 50 base::WeakPtrFactory<JniPairingSecretFetcher> weak_factory_; | 53 base::WeakPtrFactory<JniPairingSecretFetcher> weak_factory_; |
| 51 | 54 |
| 52 DISALLOW_COPY_AND_ASSIGN(JniPairingSecretFetcher); | 55 DISALLOW_COPY_AND_ASSIGN(JniPairingSecretFetcher); |
| 53 }; | 56 }; |
| 54 | 57 |
| 55 } // namespace remoting | 58 } // namespace remoting |
| 56 | 59 |
| 57 #endif // REMOTING_CLIENT_JNI_JNI_PAIRING_SECRET_FETCHER_H_ | 60 #endif // REMOTING_CLIENT_JNI_JNI_PAIRING_SECRET_FETCHER_H_ |
| OLD | NEW |