| 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 #include <remoting/client/jni/jni_pairing_secret_fetcher.h> | 5 #include "remoting/client/jni/jni_pairing_secret_fetcher.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "remoting/client/jni/chromoting_jni_runtime.h" | 8 #include "remoting/client/jni/chromoting_jni_runtime.h" |
| 9 #include "remoting/client/jni/jni_client.h" | 9 #include "remoting/client/jni/jni_client.h" |
| 10 | 10 |
| 11 namespace remoting { | 11 namespace remoting { |
| 12 | 12 |
| 13 JniPairingSecretFetcher::JniPairingSecretFetcher(ChromotingJniRuntime* runtime, | 13 JniPairingSecretFetcher::JniPairingSecretFetcher(ChromotingJniRuntime* runtime, |
| 14 base::WeakPtr<JniClient> client, | 14 base::WeakPtr<JniClient> client, |
| 15 const std::string& host_id) : | 15 const std::string& host_id) : |
| 16 jni_runtime_(runtime), | 16 jni_runtime_(runtime), |
| 17 jni_client_(client), | 17 jni_client_(client), |
| 18 host_id_(host_id), | 18 host_id_(host_id), |
| 19 weak_factory_(this) {} | 19 weak_factory_(this) {} |
| 20 | 20 |
| 21 JniPairingSecretFetcher::~JniPairingSecretFetcher() { | 21 JniPairingSecretFetcher::~JniPairingSecretFetcher() { |
| 22 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); | 22 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void JniPairingSecretFetcher::FetchSecret( | 25 void JniPairingSecretFetcher::FetchSecret( |
| 26 bool pairable, | 26 bool pairable, |
| 27 const protocol::SecretFetchedCallback& callback) { | 27 const protocol::SecretFetchedCallback& callback) { |
| 28 DCHECK (jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); | 28 DCHECK (jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 29 | |
| 30 if (!jni_client_) { | |
| 31 return; | |
| 32 } | |
| 33 | |
| 34 // Delete pairing credentials if they exist. | |
| 35 jni_client_->CommitPairingCredentials(host_id_, "", ""); | |
| 36 | 29 |
| 37 callback_ = callback; | 30 callback_ = callback; |
| 38 jni_client_->DisplayAuthenticationPrompt(pairable); | 31 jni_runtime_->ui_task_runner()->PostTask( |
| 32 FROM_HERE, |
| 33 base::Bind(&JniPairingSecretFetcher::FetchSecretOnUI, jni_client_, |
| 34 host_id_, pairable)); |
| 39 } | 35 } |
| 40 | 36 |
| 41 void JniPairingSecretFetcher::ProvideSecret(const std::string& pin) { | 37 void JniPairingSecretFetcher::ProvideSecret(const std::string& pin) { |
| 42 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); | 38 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 43 DCHECK(!callback_.is_null()); | 39 DCHECK(!callback_.is_null()); |
| 44 | 40 |
| 45 jni_runtime_->network_task_runner()->PostTask(FROM_HERE, | 41 callback_.Run(pin); |
| 46 base::Bind(callback_, pin)); | |
| 47 } | 42 } |
| 48 | 43 |
| 49 base::WeakPtr<JniPairingSecretFetcher> JniPairingSecretFetcher::GetWeakPtr() { | 44 base::WeakPtr<JniPairingSecretFetcher> JniPairingSecretFetcher::GetWeakPtr() { |
| 50 return weak_factory_.GetWeakPtr(); | 45 return weak_factory_.GetWeakPtr(); |
| 51 } | 46 } |
| 52 | 47 |
| 48 // static |
| 49 void JniPairingSecretFetcher::FetchSecretOnUI(base::WeakPtr<JniClient> client, |
| 50 const std::string& host_id, |
| 51 bool pairable) { |
| 52 if (!client) { |
| 53 return; |
| 54 } |
| 55 |
| 56 // Delete pairing credentials if they exist. |
| 57 client->CommitPairingCredentials(host_id, "", ""); |
| 58 |
| 59 client->DisplayAuthenticationPrompt(pairable); |
| 60 } |
| 61 |
| 53 } // namespace remoting | 62 } // namespace remoting |
| OLD | NEW |