| 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 weak_ptr_ = weak_factory_.GetWeakPtr(); |
| 21 } |
| 20 | 22 |
| 21 JniPairingSecretFetcher::~JniPairingSecretFetcher() { | 23 JniPairingSecretFetcher::~JniPairingSecretFetcher() { |
| 22 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 24 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 23 } | 25 } |
| 24 | 26 |
| 25 void JniPairingSecretFetcher::FetchSecret( | 27 void JniPairingSecretFetcher::FetchSecret( |
| 26 bool pairable, | 28 bool pairable, |
| 27 const protocol::SecretFetchedCallback& callback) { | 29 const protocol::SecretFetchedCallback& callback) { |
| 28 DCHECK (jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 30 DCHECK (jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 29 | 31 |
| 30 callback_ = callback; | 32 callback_ = callback; |
| 31 jni_runtime_->ui_task_runner()->PostTask( | 33 jni_runtime_->ui_task_runner()->PostTask( |
| 32 FROM_HERE, | 34 FROM_HERE, |
| 33 base::Bind(&JniPairingSecretFetcher::FetchSecretOnUiThread, jni_client_, | 35 base::Bind(&JniPairingSecretFetcher::FetchSecretOnUiThread, jni_client_, |
| 34 host_id_, pairable)); | 36 host_id_, pairable)); |
| 35 } | 37 } |
| 36 | 38 |
| 37 void JniPairingSecretFetcher::ProvideSecret(const std::string& pin) { | 39 void JniPairingSecretFetcher::ProvideSecret(const std::string& pin) { |
| 38 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); | 40 DCHECK(jni_runtime_->network_task_runner()->BelongsToCurrentThread()); |
| 39 DCHECK(!callback_.is_null()); | 41 DCHECK(!callback_.is_null()); |
| 40 | 42 |
| 41 callback_.Run(pin); | 43 callback_.Run(pin); |
| 42 } | 44 } |
| 43 | 45 |
| 44 base::WeakPtr<JniPairingSecretFetcher> JniPairingSecretFetcher::GetWeakPtr() { | 46 base::WeakPtr<JniPairingSecretFetcher> JniPairingSecretFetcher::GetWeakPtr() { |
| 45 return weak_factory_.GetWeakPtr(); | 47 return weak_ptr_; |
| 46 } | 48 } |
| 47 | 49 |
| 48 // static | 50 // static |
| 49 void JniPairingSecretFetcher::FetchSecretOnUiThread( | 51 void JniPairingSecretFetcher::FetchSecretOnUiThread( |
| 50 base::WeakPtr<JniClient> client, | 52 base::WeakPtr<JniClient> client, |
| 51 const std::string& host_id, | 53 const std::string& host_id, |
| 52 bool pairable) { | 54 bool pairable) { |
| 53 if (!client) { | 55 if (!client) { |
| 54 return; | 56 return; |
| 55 } | 57 } |
| 56 | 58 |
| 57 // Delete pairing credentials if they exist. | 59 // Delete pairing credentials if they exist. |
| 58 client->CommitPairingCredentials(host_id, "", ""); | 60 client->CommitPairingCredentials(host_id, "", ""); |
| 59 | 61 |
| 60 client->DisplayAuthenticationPrompt(pairable); | 62 client->DisplayAuthenticationPrompt(pairable); |
| 61 } | 63 } |
| 62 | 64 |
| 63 } // namespace remoting | 65 } // namespace remoting |
| OLD | NEW |