| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <remoting/client/jni/jni_pairing_secret_fetcher.h> |
| 6 #include "base/bind.h" |
| 7 #include "base/location.h" |
| 8 #include "remoting/client/jni/chromoting_jni_runtime.h" |
| 9 #include "remoting/client/jni/jni_client.h" |
| 10 |
| 11 namespace remoting { |
| 12 |
| 13 JniPairingSecretFetcher::JniPairingSecretFetcher(ChromotingJniRuntime* runtime, |
| 14 base::WeakPtr<JniClient> client, |
| 15 const std::string& host_id) : |
| 16 jni_runtime_(runtime), |
| 17 jni_client_(client), |
| 18 host_id_(host_id), |
| 19 weak_factory_(this) {} |
| 20 |
| 21 JniPairingSecretFetcher::~JniPairingSecretFetcher() { |
| 22 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
| 23 } |
| 24 |
| 25 void JniPairingSecretFetcher::FetchSecret( |
| 26 bool pairable, |
| 27 const protocol::SecretFetchedCallback& callback) { |
| 28 DCHECK (jni_runtime_->ui_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 |
| 37 callback_ = callback; |
| 38 jni_client_->DisplayAuthenticationPrompt(pairable); |
| 39 } |
| 40 |
| 41 void JniPairingSecretFetcher::ProvideSecret(const std::string& pin) { |
| 42 DCHECK(jni_runtime_->ui_task_runner()->BelongsToCurrentThread()); |
| 43 DCHECK(!callback_.is_null()); |
| 44 |
| 45 jni_runtime_->network_task_runner()->PostTask(FROM_HERE, |
| 46 base::Bind(callback_, pin)); |
| 47 } |
| 48 |
| 49 base::WeakPtr<JniPairingSecretFetcher> JniPairingSecretFetcher::GetWeakPtr() { |
| 50 return weak_factory_.GetWeakPtr(); |
| 51 } |
| 52 |
| 53 } // namespace remoting |
| OLD | NEW |