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

Side by Side Diff: components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.cc

Issue 2561203002: Migrate weave-related classes from proximity_auth/ble to cryptauth/ble. (Closed)
Patch Set: Created 4 years 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/proximity_auth/ble/bluetooth_low_energy_weave_client_connec tion.h" 5 #include "components/cryptauth/ble/bluetooth_low_energy_weave_client_connection. h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/task_runner.h" 11 #include "base/task_runner.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "components/proximity_auth/bluetooth_throttler.h" 13 #include "components/proximity_auth/bluetooth_throttler.h"
14 #include "components/proximity_auth/connection_finder.h" 14 #include "components/proximity_auth/connection_finder.h"
15 #include "components/proximity_auth/logging/logging.h" 15 #include "components/proximity_auth/logging/logging.h"
16 #include "components/proximity_auth/wire_message.h" 16 #include "components/proximity_auth/wire_message.h"
17 #include "device/bluetooth/bluetooth_gatt_connection.h" 17 #include "device/bluetooth/bluetooth_gatt_connection.h"
18 18
19 using device::BluetoothAdapter; 19 using device::BluetoothAdapter;
20 using device::BluetoothDevice; 20 using device::BluetoothDevice;
21 using device::BluetoothGattConnection; 21 using device::BluetoothGattConnection;
22 using device::BluetoothRemoteGattService; 22 using device::BluetoothRemoteGattService;
23 using device::BluetoothRemoteGattCharacteristic; 23 using device::BluetoothRemoteGattCharacteristic;
24 using device::BluetoothGattNotifySession; 24 using device::BluetoothGattNotifySession;
25 using device::BluetoothUUID; 25 using device::BluetoothUUID;
26 26
27 namespace proximity_auth { 27 namespace cryptauth {
28 namespace weave { 28 namespace weave {
29 namespace { 29 namespace {
30 30
31 typedef BluetoothLowEnergyWeavePacketReceiver::State ReceiverState; 31 typedef BluetoothLowEnergyWeavePacketReceiver::State ReceiverState;
32 32
33 // The UUID of the TX characteristic used to transmit data to the server. 33 // The UUID of the TX characteristic used to transmit data to the server.
34 const char kTXCharacteristicUUID[] = "00000100-0004-1000-8000-001A11000101"; 34 const char kTXCharacteristicUUID[] = "00000100-0004-1000-8000-001A11000101";
35 35
36 // The UUID of the RX characteristic used to receive data from the server. 36 // The UUID of the RX characteristic used to receive data from the server.
37 const char kRXCharacteristicUUID[] = "00000100-0004-1000-8000-001A11000102"; 37 const char kRXCharacteristicUUID[] = "00000100-0004-1000-8000-001A11000102";
38 38
39 } // namespace 39 } // namespace
40 40
41 BluetoothLowEnergyWeaveClientConnection:: 41 BluetoothLowEnergyWeaveClientConnection::
42 BluetoothLowEnergyWeaveClientConnection( 42 BluetoothLowEnergyWeaveClientConnection(
43 const cryptauth::RemoteDevice& device, 43 const cryptauth::RemoteDevice& device,
44 scoped_refptr<device::BluetoothAdapter> adapter, 44 scoped_refptr<device::BluetoothAdapter> adapter,
45 const BluetoothUUID remote_service_uuid, 45 const BluetoothUUID remote_service_uuid,
46 BluetoothThrottler* bluetooth_throttler, 46 proximity_auth::BluetoothThrottler* bluetooth_throttler,
47 int max_number_of_write_attempts) 47 int max_number_of_write_attempts)
48 : Connection(device), 48 : Connection(device),
49 adapter_(adapter), 49 adapter_(adapter),
50 remote_service_({remote_service_uuid, ""}), 50 remote_service_({remote_service_uuid, ""}),
51 packet_generator_( 51 packet_generator_(
52 BluetoothLowEnergyWeavePacketGenerator::Factory::NewInstance()), 52 BluetoothLowEnergyWeavePacketGenerator::Factory::NewInstance()),
53 packet_receiver_( 53 packet_receiver_(
54 BluetoothLowEnergyWeavePacketReceiver::Factory::NewInstance( 54 BluetoothLowEnergyWeavePacketReceiver::Factory::NewInstance(
55 BluetoothLowEnergyWeavePacketReceiver::ReceiverType::CLIENT)), 55 BluetoothLowEnergyWeavePacketReceiver::ReceiverType::CLIENT)),
56 tx_characteristic_({BluetoothUUID(kTXCharacteristicUUID), ""}), 56 tx_characteristic_({BluetoothUUID(kTXCharacteristicUUID), ""}),
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 SetStatus(Status::IN_PROGRESS); 171 SetStatus(Status::IN_PROGRESS);
172 } 172 }
173 } 173 }
174 174
175 void BluetoothLowEnergyWeaveClientConnection::SetTaskRunnerForTesting( 175 void BluetoothLowEnergyWeaveClientConnection::SetTaskRunnerForTesting(
176 scoped_refptr<base::TaskRunner> task_runner) { 176 scoped_refptr<base::TaskRunner> task_runner) {
177 task_runner_ = task_runner; 177 task_runner_ = task_runner;
178 } 178 }
179 179
180 void BluetoothLowEnergyWeaveClientConnection::SendMessageImpl( 180 void BluetoothLowEnergyWeaveClientConnection::SendMessageImpl(
181 std::unique_ptr<WireMessage> message) { 181 std::unique_ptr<proximity_auth::WireMessage> message) {
182 PA_LOG(INFO) << "Sending message " << message->Serialize(); 182 PA_LOG(INFO) << "Sending message " << message->Serialize();
183 std::string serialized_msg = message->Serialize(); 183 std::string serialized_msg = message->Serialize();
184 184
185 std::vector<Packet> packets = 185 std::vector<Packet> packets =
186 packet_generator_->EncodeDataMessage(serialized_msg); 186 packet_generator_->EncodeDataMessage(serialized_msg);
187 187
188 std::shared_ptr<WireMessage> request_message(message.release()); 188 std::shared_ptr<proximity_auth::WireMessage> request_message(
189 message.release());
189 190
190 for (uint32_t i = 0; i < packets.size(); ++i) { 191 for (uint32_t i = 0; i < packets.size(); ++i) {
191 WriteRequestType request_type = (i == packets.size() - 1) 192 WriteRequestType request_type = (i == packets.size() - 1)
192 ? WriteRequestType::MESSAGE_COMPLETE 193 ? WriteRequestType::MESSAGE_COMPLETE
193 : WriteRequestType::REGULAR; 194 : WriteRequestType::REGULAR;
194 WriteRequest request(packets[i], request_type, request_message); 195 WriteRequest request(packets[i], request_type, request_message);
195 WriteRemoteCharacteristic(request); 196 WriteRemoteCharacteristic(request);
196 } 197 }
197 } 198 }
198 199
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 return "APPLICATION_ERROR"; 609 return "APPLICATION_ERROR";
609 default: 610 default:
610 NOTREACHED(); 611 NOTREACHED();
611 return ""; 612 return "";
612 } 613 }
613 } 614 }
614 615
615 BluetoothLowEnergyWeaveClientConnection::WriteRequest::WriteRequest( 616 BluetoothLowEnergyWeaveClientConnection::WriteRequest::WriteRequest(
616 const Packet& val, 617 const Packet& val,
617 WriteRequestType request_type, 618 WriteRequestType request_type,
618 std::shared_ptr<WireMessage> message) 619 std::shared_ptr<proximity_auth::WireMessage> message)
619 : value(val), 620 : value(val),
620 request_type(request_type), 621 request_type(request_type),
621 message(message), 622 message(message),
622 number_of_failed_attempts(0) {} 623 number_of_failed_attempts(0) {}
623 624
624 BluetoothLowEnergyWeaveClientConnection::WriteRequest::WriteRequest( 625 BluetoothLowEnergyWeaveClientConnection::WriteRequest::WriteRequest(
625 const Packet& val, 626 const Packet& val,
626 WriteRequestType request_type) 627 WriteRequestType request_type)
627 : value(val), 628 : value(val),
628 request_type(request_type), 629 request_type(request_type),
629 message(nullptr), 630 message(nullptr),
630 number_of_failed_attempts(0) {} 631 number_of_failed_attempts(0) {}
631 632
632 BluetoothLowEnergyWeaveClientConnection::WriteRequest::WriteRequest( 633 BluetoothLowEnergyWeaveClientConnection::WriteRequest::WriteRequest(
633 const WriteRequest& other) = default; 634 const WriteRequest& other) = default;
634 635
635 BluetoothLowEnergyWeaveClientConnection::WriteRequest::~WriteRequest() {} 636 BluetoothLowEnergyWeaveClientConnection::WriteRequest::~WriteRequest() {}
636 637
637 } // namespace weave 638 } // namespace weave
638 639
639 } // namespace proximity_auth 640 } // namespace cryptauth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698