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/bluetooth_controller_pairing_controller.h" | 5 #include "components/pairing/bluetooth_controller_pairing_controller.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 return device; | 44 return device; |
45 } | 45 } |
46 | 46 |
47 void BluetoothControllerPairingController::ChangeStage(Stage new_stage) { | 47 void BluetoothControllerPairingController::ChangeStage(Stage new_stage) { |
48 if (current_stage_ == new_stage) | 48 if (current_stage_ == new_stage) |
49 return; | 49 return; |
50 VLOG(1) << "ChangeStage " << new_stage; | 50 VLOG(1) << "ChangeStage " << new_stage; |
51 current_stage_ = new_stage; | 51 current_stage_ = new_stage; |
52 FOR_EACH_OBSERVER(ControllerPairingController::Observer, observers_, | 52 for (ControllerPairingController::Observer& observer : observers_) |
53 PairingStageChanged(new_stage)); | 53 observer.PairingStageChanged(new_stage); |
54 } | 54 } |
55 | 55 |
56 void BluetoothControllerPairingController::Reset() { | 56 void BluetoothControllerPairingController::Reset() { |
57 controller_device_id_.clear(); | 57 controller_device_id_.clear(); |
58 discovery_session_.reset(); | 58 discovery_session_.reset(); |
59 | 59 |
60 if (socket_.get()) { | 60 if (socket_.get()) { |
61 socket_->Close(); | 61 socket_->Close(); |
62 socket_ = NULL; | 62 socket_ = NULL; |
63 } | 63 } |
64 | 64 |
65 if (adapter_.get()) { | 65 if (adapter_.get()) { |
66 adapter_->RemoveObserver(this); | 66 adapter_->RemoveObserver(this); |
67 adapter_ = NULL; | 67 adapter_ = NULL; |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 void BluetoothControllerPairingController::DeviceFound( | 71 void BluetoothControllerPairingController::DeviceFound( |
72 device::BluetoothDevice* device) { | 72 device::BluetoothDevice* device) { |
73 DCHECK_EQ(current_stage_, STAGE_DEVICES_DISCOVERY); | 73 DCHECK_EQ(current_stage_, STAGE_DEVICES_DISCOVERY); |
74 DCHECK(thread_checker_.CalledOnValidThread()); | 74 DCHECK(thread_checker_.CalledOnValidThread()); |
75 if (base::StartsWith(device->GetNameForDisplay(), | 75 if (base::StartsWith(device->GetNameForDisplay(), |
76 base::ASCIIToUTF16(kDeviceNamePrefix), | 76 base::ASCIIToUTF16(kDeviceNamePrefix), |
77 base::CompareCase::INSENSITIVE_ASCII)) { | 77 base::CompareCase::INSENSITIVE_ASCII)) { |
78 discovered_devices_.insert(device->GetAddress()); | 78 discovered_devices_.insert(device->GetAddress()); |
79 FOR_EACH_OBSERVER(ControllerPairingController::Observer, observers_, | 79 for (ControllerPairingController::Observer& observer : observers_) |
80 DiscoveredDevicesListChanged()); | 80 observer.DiscoveredDevicesListChanged(); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void BluetoothControllerPairingController::DeviceLost( | 84 void BluetoothControllerPairingController::DeviceLost( |
85 device::BluetoothDevice* device) { | 85 device::BluetoothDevice* device) { |
86 DCHECK_EQ(current_stage_, STAGE_DEVICES_DISCOVERY); | 86 DCHECK_EQ(current_stage_, STAGE_DEVICES_DISCOVERY); |
87 DCHECK(thread_checker_.CalledOnValidThread()); | 87 DCHECK(thread_checker_.CalledOnValidThread()); |
88 std::set<std::string>::iterator ix = | 88 std::set<std::string>::iterator ix = |
89 discovered_devices_.find(device->GetAddress()); | 89 discovered_devices_.find(device->GetAddress()); |
90 if (ix != discovered_devices_.end()) { | 90 if (ix != discovered_devices_.end()) { |
91 discovered_devices_.erase(ix); | 91 discovered_devices_.erase(ix); |
92 FOR_EACH_OBSERVER(ControllerPairingController::Observer, observers_, | 92 for (ControllerPairingController::Observer& observer : observers_) |
93 DiscoveredDevicesListChanged()); | 93 observer.DiscoveredDevicesListChanged(); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 void BluetoothControllerPairingController::SendBuffer( | 97 void BluetoothControllerPairingController::SendBuffer( |
98 scoped_refptr<net::IOBuffer> io_buffer, int size) { | 98 scoped_refptr<net::IOBuffer> io_buffer, int size) { |
99 socket_->Send( | 99 socket_->Send( |
100 io_buffer, size, | 100 io_buffer, size, |
101 base::Bind(&BluetoothControllerPairingController::OnSendComplete, | 101 base::Bind(&BluetoothControllerPairingController::OnSendComplete, |
102 ptr_factory_.GetWeakPtr()), | 102 ptr_factory_.GetWeakPtr()), |
103 base::Bind(&BluetoothControllerPairingController::OnErrorWithMessage, | 103 base::Bind(&BluetoothControllerPairingController::OnErrorWithMessage, |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); | 500 ChangeStage(STAGE_WAITING_FOR_CODE_CONFIRMATION); |
501 } | 501 } |
502 | 502 |
503 void BluetoothControllerPairingController::AuthorizePairing( | 503 void BluetoothControllerPairingController::AuthorizePairing( |
504 device::BluetoothDevice* device) { | 504 device::BluetoothDevice* device) { |
505 // Disallow unknown device. | 505 // Disallow unknown device. |
506 device->RejectPairing(); | 506 device->RejectPairing(); |
507 } | 507 } |
508 | 508 |
509 } // namespace pairing_chromeos | 509 } // namespace pairing_chromeos |
OLD | NEW |