Joe Antonetti | 6095883f | 2023-03-06 19:00:25 | [diff] [blame] | 1 | // Copyright 2023 The Chromium Authors |
| 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 "fake_quick_start_decoder.h" |
| 6 | |
Joe Antonetti | 4c0b6b63 | 2023-04-13 20:55:04 | [diff] [blame] | 7 | #include "chromeos/ash/services/nearby/public/mojom/quick_start_decoder_types.mojom-forward.h" |
Joe Antonetti | f8710c5 | 2023-05-12 16:50:43 | [diff] [blame] | 8 | #include "chromeos/ash/services/nearby/public/mojom/quick_start_decoder_types.mojom-shared.h" |
| 9 | #include "chromeos/ash/services/nearby/public/mojom/quick_start_decoder_types.mojom.h" |
Joe Antonetti | 4c0b6b63 | 2023-04-13 20:55:04 | [diff] [blame] | 10 | |
Joe Antonetti | 6095883f | 2023-03-06 19:00:25 | [diff] [blame] | 11 | namespace ash::quick_start { |
| 12 | |
| 13 | FakeQuickStartDecoder::~FakeQuickStartDecoder() = default; |
| 14 | |
| 15 | FakeQuickStartDecoder::FakeQuickStartDecoder() = default; |
| 16 | |
| 17 | mojo::PendingRemote<mojom::QuickStartDecoder> |
| 18 | FakeQuickStartDecoder::GetRemote() { |
| 19 | mojo::PendingRemote<mojom::QuickStartDecoder> pending_remote; |
| 20 | receiver_set_.Add(this, pending_remote.InitWithNewPipeAndPassReceiver()); |
| 21 | return pending_remote; |
| 22 | } |
Brittany Hartmire | 6e68a04 | 2023-05-03 21:57:40 | [diff] [blame] | 23 | |
Curt Clemens | c1ae7f3 | 2023-09-19 21:03:05 | [diff] [blame] | 24 | void FakeQuickStartDecoder::DecodeQuickStartMessage( |
Arthur Sonzogni | 74f09f8a | 2023-12-06 19:35:29 | [diff] [blame] | 25 | const std::optional<std::vector<uint8_t>>& data, |
Curt Clemens | c1ae7f3 | 2023-09-19 21:03:05 | [diff] [blame] | 26 | DecodeQuickStartMessageCallback callback) { |
Michael Hansen | 0381eb4b7 | 2024-05-10 21:41:25 | [diff] [blame] | 27 | has_decode_been_called_ = true; |
Curt Clemens | edc8036 | 2023-10-24 17:35:09 | [diff] [blame] | 28 | CHECK(!results_.empty()); |
| 29 | auto [quick_start_message, error] = std::move(results_.front()); |
| 30 | results_.pop(); |
Arthur Sonzogni | 74f09f8a | 2023-12-06 19:35:29 | [diff] [blame] | 31 | if (error != std::nullopt) { |
Curt Clemens | edc8036 | 2023-10-24 17:35:09 | [diff] [blame] | 32 | std::move(callback).Run(nullptr, error); |
Curt Clemens | c1ae7f3 | 2023-09-19 21:03:05 | [diff] [blame] | 33 | } else { |
Arthur Sonzogni | 74f09f8a | 2023-12-06 19:35:29 | [diff] [blame] | 34 | std::move(callback).Run(std::move(quick_start_message), std::nullopt); |
Curt Clemens | c1ae7f3 | 2023-09-19 21:03:05 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
Joe Antonetti | 0faef6d | 2023-05-12 18:31:59 | [diff] [blame] | 38 | void FakeQuickStartDecoder::SetUserVerificationRequested( |
| 39 | bool is_awaiting_user_verification) { |
Curt Clemens | edc8036 | 2023-10-24 17:35:09 | [diff] [blame] | 40 | SetQuickStartMessage(mojom::QuickStartMessage::NewUserVerificationRequested( |
| 41 | mojom::UserVerificationRequested::New(is_awaiting_user_verification))); |
Joe Antonetti | 0faef6d | 2023-05-12 18:31:59 | [diff] [blame] | 42 | } |
| 43 | |
Curt Clemens | edc8036 | 2023-10-24 17:35:09 | [diff] [blame] | 44 | void FakeQuickStartDecoder::SetUserVerificationMethod( |
| 45 | bool use_source_lock_screen_prompt) { |
| 46 | SetQuickStartMessage(mojom::QuickStartMessage::NewUserVerificationMethod( |
| 47 | mojom::UserVerificationMethod::New(use_source_lock_screen_prompt))); |
Joe Antonetti | f8710c5 | 2023-05-12 16:50:43 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void FakeQuickStartDecoder::SetUserVerificationResponse( |
| 51 | mojom::UserVerificationResult result, |
| 52 | bool is_first_user_verification) { |
Curt Clemens | edc8036 | 2023-10-24 17:35:09 | [diff] [blame] | 53 | SetQuickStartMessage(mojom::QuickStartMessage::NewUserVerificationResponse( |
| 54 | mojom::UserVerificationResponse::New(result, |
| 55 | is_first_user_verification))); |
Joe Antonetti | f8710c5 | 2023-05-12 16:50:43 | [diff] [blame] | 56 | } |
| 57 | |
Joe Antonetti | 6095883f | 2023-03-06 19:00:25 | [diff] [blame] | 58 | void FakeQuickStartDecoder::SetAssertionResponse( |
Joe Antonetti | 09e99945 | 2023-07-19 14:54:31 | [diff] [blame] | 59 | mojom::FidoAssertionResponsePtr fido_assertion) { |
Curt Clemens | edc8036 | 2023-10-24 17:35:09 | [diff] [blame] | 60 | SetQuickStartMessage(mojom::QuickStartMessage::NewFidoAssertionResponse( |
| 61 | std::move(fido_assertion))); |
Joe Antonetti | 6095883f | 2023-03-06 19:00:25 | [diff] [blame] | 62 | } |
| 63 | |
Joe Antonetti | 4c0b6b63 | 2023-04-13 20:55:04 | [diff] [blame] | 64 | void FakeQuickStartDecoder::SetWifiCredentialsResponse( |
Curt Clemens | edc8036 | 2023-10-24 17:35:09 | [diff] [blame] | 65 | mojom::WifiCredentialsPtr credentials) { |
| 66 | SetQuickStartMessage( |
| 67 | mojom::QuickStartMessage::NewWifiCredentials(std::move(credentials))); |
Joe Antonetti | 4c0b6b63 | 2023-04-13 20:55:04 | [diff] [blame] | 68 | } |
| 69 | |
Brittany Hartmire | 6e68a04 | 2023-05-03 21:57:40 | [diff] [blame] | 70 | void FakeQuickStartDecoder::SetNotifySourceOfUpdateResponse( |
Curt Clemens | 3873be1 | 2023-09-07 16:34:22 | [diff] [blame] | 71 | mojom::NotifySourceOfUpdateResponsePtr notify_source_of_update_response) { |
Curt Clemens | edc8036 | 2023-10-24 17:35:09 | [diff] [blame] | 72 | SetQuickStartMessage( |
| 73 | mojom::QuickStartMessage::NewNotifySourceOfUpdateResponse( |
| 74 | std::move(notify_source_of_update_response))); |
Brittany Hartmire | 6e68a04 | 2023-05-03 21:57:40 | [diff] [blame] | 75 | } |
| 76 | |
Jennifer Serrano | 484f34c | 2023-05-22 17:22:55 | [diff] [blame] | 77 | void FakeQuickStartDecoder::SetBootstrapConfigurationsResponse( |
Michael Hansen | d5f9069 | 2023-11-23 10:25:03 | [diff] [blame] | 78 | const std::string& instance_id, |
| 79 | const bool is_supervised_account, |
| 80 | const std::string& email) { |
Curt Clemens | edc8036 | 2023-10-24 17:35:09 | [diff] [blame] | 81 | SetQuickStartMessage(mojom::QuickStartMessage::NewBootstrapConfigurations( |
Michael Hansen | d5f9069 | 2023-11-23 10:25:03 | [diff] [blame] | 82 | mojom::BootstrapConfigurations::New(instance_id, is_supervised_account, |
| 83 | email))); |
Jennifer Serrano | 484f34c | 2023-05-22 17:22:55 | [diff] [blame] | 84 | } |
| 85 | |
Curt Clemens | c1ae7f3 | 2023-09-19 21:03:05 | [diff] [blame] | 86 | void FakeQuickStartDecoder::SetQuickStartMessage( |
| 87 | mojom::QuickStartMessagePtr quick_start_message) { |
Arthur Sonzogni | 74f09f8a | 2023-12-06 19:35:29 | [diff] [blame] | 88 | results_.emplace(std::move(quick_start_message), std::nullopt); |
Curt Clemens | edc8036 | 2023-10-24 17:35:09 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void FakeQuickStartDecoder::SetDecoderError( |
| 92 | mojom::QuickStartDecoderError error) { |
| 93 | results_.emplace(nullptr, error); |
Curt Clemens | c1ae7f3 | 2023-09-19 21:03:05 | [diff] [blame] | 94 | } |
| 95 | |
Joe Antonetti | 6095883f | 2023-03-06 19:00:25 | [diff] [blame] | 96 | } // namespace ash::quick_start |