Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: chromeos/components/tether/disconnect_tethering_operation.cc

Issue 2861603002: [CrOS Tether] Create DisconnectTetheringOperation, which sends a DisconnectTetheringRequest to a re… (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chromeos/components/tether/disconnect_tethering_operation.h"
6
7 #include "chromeos/components/tether/message_wrapper.h"
8 #include "chromeos/components/tether/proto/tether.pb.h"
9 #include "components/proximity_auth/logging/logging.h"
10
11 namespace chromeos {
12
13 namespace tether {
14
15 // static
16 DisconnectTetheringOperation::Factory*
17 DisconnectTetheringOperation::Factory::factory_instance_ = nullptr;
18
19 // static
20 std::unique_ptr<DisconnectTetheringOperation>
21 DisconnectTetheringOperation::Factory::NewInstance(
22 const cryptauth::RemoteDevice& device_to_connect,
23 BleConnectionManager* connection_manager) {
24 if (!factory_instance_) {
25 factory_instance_ = new Factory();
26 }
27 return factory_instance_->BuildInstance(device_to_connect,
28 connection_manager);
29 }
30
31 // static
32 void DisconnectTetheringOperation::Factory::SetInstanceForTesting(
33 Factory* factory) {
34 factory_instance_ = factory;
35 }
36
37 std::unique_ptr<DisconnectTetheringOperation>
38 DisconnectTetheringOperation::Factory::BuildInstance(
39 const cryptauth::RemoteDevice& device_to_connect,
40 BleConnectionManager* connection_manager) {
41 return base::MakeUnique<DisconnectTetheringOperation>(device_to_connect,
42 connection_manager);
43 }
44
45 DisconnectTetheringOperation::DisconnectTetheringOperation(
46 const cryptauth::RemoteDevice& device_to_connect,
47 BleConnectionManager* connection_manager)
48 : MessageTransferOperation(
49 std::vector<cryptauth::RemoteDevice>{device_to_connect},
50 connection_manager),
51 has_authenticated_(false) {}
52
53 DisconnectTetheringOperation::~DisconnectTetheringOperation() {}
54
55 void DisconnectTetheringOperation::AddObserver(Observer* observer) {
56 observer_list_.AddObserver(observer);
57 }
58
59 void DisconnectTetheringOperation::RemoveObserver(Observer* observer) {
60 observer_list_.RemoveObserver(observer);
61 }
62
63 void DisconnectTetheringOperation::OnDeviceAuthenticated(
64 const cryptauth::RemoteDevice& remote_device) {
65 DCHECK(remote_devices().size() == 1u && remote_devices()[0] == remote_device);
66 has_authenticated_ = true;
67
68 SendMessageToDevice(remote_device, base::MakeUnique<MessageWrapper>(
69 DisconnectTetheringRequest()));
70 UnregisterDevice(remote_device);
71 }
72
73 void DisconnectTetheringOperation::OnOperationFinished() {
74 for (auto& observer : observer_list_) {
75 observer.OnOperationFinished(has_authenticated_);
76 }
77 }
78
79 MessageType DisconnectTetheringOperation::GetMessageTypeForConnection() {
80 return MessageType::DISCONNECT_TETHERING_REQUEST;
81 }
82
83 } // namespace tether
84
85 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698