| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/pairing/shark_connection_listener.h" | 5 #include "components/pairing/shark_connection_listener.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| 11 #include "components/pairing/bluetooth_host_pairing_controller.h" | 11 #include "components/pairing/bluetooth_host_pairing_controller.h" |
| 12 | 12 |
| 13 namespace pairing_chromeos { | 13 namespace pairing_chromeos { |
| 14 | 14 |
| 15 SharkConnectionListener::SharkConnectionListener(OnConnectedCallback callback) | 15 SharkConnectionListener::SharkConnectionListener( |
| 16 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner, |
| 17 OnConnectedCallback callback) |
| 16 : callback_(callback) { | 18 : callback_(callback) { |
| 17 controller_.reset(new BluetoothHostPairingController()); | 19 controller_.reset(new BluetoothHostPairingController(file_task_runner)); |
| 18 controller_->AddObserver(this); | 20 controller_->AddObserver(this); |
| 19 controller_->StartPairing(); | 21 controller_->StartPairing(); |
| 20 } | 22 } |
| 21 | 23 |
| 22 SharkConnectionListener::~SharkConnectionListener() { | 24 SharkConnectionListener::~SharkConnectionListener() { |
| 23 if (controller_) | 25 if (controller_) |
| 24 controller_->RemoveObserver(this); | 26 controller_->RemoveObserver(this); |
| 25 } | 27 } |
| 26 | 28 |
| 27 void SharkConnectionListener::PairingStageChanged(Stage new_stage) { | 29 void SharkConnectionListener::PairingStageChanged(Stage new_stage) { |
| 28 if (new_stage == HostPairingController::STAGE_WAITING_FOR_CODE_CONFIRMATION | 30 if (new_stage == HostPairingController::STAGE_WAITING_FOR_CODE_CONFIRMATION |
| 29 // Code confirmation stage can be skipped if devices were paired before. | 31 // Code confirmation stage can be skipped if devices were paired before. |
| 30 || new_stage == HostPairingController::STAGE_SETUP_BASIC_CONFIGURATION) { | 32 || new_stage == HostPairingController::STAGE_SETUP_BASIC_CONFIGURATION) { |
| 31 controller_->RemoveObserver(this); | 33 controller_->RemoveObserver(this); |
| 32 callback_.Run(std::move(controller_)); | 34 callback_.Run(std::move(controller_)); |
| 33 callback_.Reset(); | 35 callback_.Reset(); |
| 34 } else if (new_stage != HostPairingController::STAGE_WAITING_FOR_CONTROLLER) { | 36 } else if (new_stage != HostPairingController::STAGE_WAITING_FOR_CONTROLLER) { |
| 35 LOG(ERROR) << "Unexpected stage " << new_stage; | 37 LOG(ERROR) << "Unexpected stage " << new_stage; |
| 36 } | 38 } |
| 37 } | 39 } |
| 38 | 40 |
| 39 } // namespace pairing_chromeos | 41 } // namespace pairing_chromeos |
| OLD | NEW |