OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chromeos/components/tether/disconnect_tethering_operation.h" | 5 #include "chromeos/components/tether/disconnect_tethering_operation.h" |
6 | 6 |
7 #include "chromeos/components/tether/message_wrapper.h" | 7 #include "chromeos/components/tether/message_wrapper.h" |
8 #include "chromeos/components/tether/proto/tether.pb.h" | 8 #include "chromeos/components/tether/proto/tether.pb.h" |
9 #include "components/proximity_auth/logging/logging.h" | 9 #include "components/proximity_auth/logging/logging.h" |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 return base::MakeUnique<DisconnectTetheringOperation>(device_to_connect, | 41 return base::MakeUnique<DisconnectTetheringOperation>(device_to_connect, |
42 connection_manager); | 42 connection_manager); |
43 } | 43 } |
44 | 44 |
45 DisconnectTetheringOperation::DisconnectTetheringOperation( | 45 DisconnectTetheringOperation::DisconnectTetheringOperation( |
46 const cryptauth::RemoteDevice& device_to_connect, | 46 const cryptauth::RemoteDevice& device_to_connect, |
47 BleConnectionManager* connection_manager) | 47 BleConnectionManager* connection_manager) |
48 : MessageTransferOperation( | 48 : MessageTransferOperation( |
49 std::vector<cryptauth::RemoteDevice>{device_to_connect}, | 49 std::vector<cryptauth::RemoteDevice>{device_to_connect}, |
50 connection_manager), | 50 connection_manager), |
| 51 device_id_(device_to_connect.GetDeviceId()), |
51 has_authenticated_(false) {} | 52 has_authenticated_(false) {} |
52 | 53 |
53 DisconnectTetheringOperation::~DisconnectTetheringOperation() {} | 54 DisconnectTetheringOperation::~DisconnectTetheringOperation() {} |
54 | 55 |
55 void DisconnectTetheringOperation::AddObserver(Observer* observer) { | 56 void DisconnectTetheringOperation::AddObserver(Observer* observer) { |
56 observer_list_.AddObserver(observer); | 57 observer_list_.AddObserver(observer); |
57 } | 58 } |
58 | 59 |
59 void DisconnectTetheringOperation::RemoveObserver(Observer* observer) { | 60 void DisconnectTetheringOperation::RemoveObserver(Observer* observer) { |
60 observer_list_.RemoveObserver(observer); | 61 observer_list_.RemoveObserver(observer); |
61 } | 62 } |
62 | 63 |
| 64 void DisconnectTetheringOperation::NotifyObserversOperationFinished( |
| 65 bool success) { |
| 66 for (auto& observer : observer_list_) { |
| 67 observer.OnOperationFinished(device_id_, success); |
| 68 } |
| 69 } |
| 70 |
63 void DisconnectTetheringOperation::OnDeviceAuthenticated( | 71 void DisconnectTetheringOperation::OnDeviceAuthenticated( |
64 const cryptauth::RemoteDevice& remote_device) { | 72 const cryptauth::RemoteDevice& remote_device) { |
65 DCHECK(remote_devices().size() == 1u && remote_devices()[0] == remote_device); | 73 DCHECK(remote_devices().size() == 1u && remote_devices()[0] == remote_device); |
66 has_authenticated_ = true; | 74 has_authenticated_ = true; |
67 | 75 |
68 SendMessageToDevice(remote_device, base::MakeUnique<MessageWrapper>( | 76 SendMessageToDevice(remote_device, base::MakeUnique<MessageWrapper>( |
69 DisconnectTetheringRequest())); | 77 DisconnectTetheringRequest())); |
70 UnregisterDevice(remote_device); | 78 UnregisterDevice(remote_device); |
71 } | 79 } |
72 | 80 |
73 void DisconnectTetheringOperation::OnOperationFinished() { | 81 void DisconnectTetheringOperation::OnOperationFinished() { |
74 for (auto& observer : observer_list_) { | 82 NotifyObserversOperationFinished(has_authenticated_); |
75 observer.OnOperationFinished(has_authenticated_); | |
76 } | |
77 } | 83 } |
78 | 84 |
79 MessageType DisconnectTetheringOperation::GetMessageTypeForConnection() { | 85 MessageType DisconnectTetheringOperation::GetMessageTypeForConnection() { |
80 return MessageType::DISCONNECT_TETHERING_REQUEST; | 86 return MessageType::DISCONNECT_TETHERING_REQUEST; |
81 } | 87 } |
82 | 88 |
83 } // namespace tether | 89 } // namespace tether |
84 | 90 |
85 } // namespace chromeos | 91 } // namespace chromeos |
OLD | NEW |