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

Side by Side Diff: components/proximity_auth/bluetooth_connection.cc

Issue 2561203002: Migrate weave-related classes from proximity_auth/ble to cryptauth/ble. (Closed)
Patch Set: Rebase. 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 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/proximity_auth/bluetooth_connection.h" 5 #include "components/proximity_auth/bluetooth_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/numerics/safe_conversions.h" 11 #include "base/numerics/safe_conversions.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "components/cryptauth/remote_device.h" 14 #include "components/cryptauth/remote_device.h"
15 #include "components/cryptauth/wire_message.h"
15 #include "components/proximity_auth/logging/logging.h" 16 #include "components/proximity_auth/logging/logging.h"
16 #include "components/proximity_auth/wire_message.h"
17 #include "device/bluetooth/bluetooth_adapter_factory.h" 17 #include "device/bluetooth/bluetooth_adapter_factory.h"
18 #include "device/bluetooth/bluetooth_device.h" 18 #include "device/bluetooth/bluetooth_device.h"
19 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
20 20
21 namespace proximity_auth { 21 namespace proximity_auth {
22 namespace { 22 namespace {
23 const int kReceiveBufferSizeBytes = 1024; 23 const int kReceiveBufferSizeBytes = 1024;
24 } 24 }
25 25
26 BluetoothConnection::BluetoothConnection( 26 BluetoothConnection::BluetoothConnection(
27 const cryptauth::RemoteDevice& remote_device, 27 const cryptauth::RemoteDevice& remote_device,
28 const device::BluetoothUUID& uuid) 28 const device::BluetoothUUID& uuid)
29 : Connection(remote_device), uuid_(uuid), weak_ptr_factory_(this) {} 29 : cryptauth::Connection(remote_device),
30 uuid_(uuid),
31 weak_ptr_factory_(this) {}
30 32
31 BluetoothConnection::~BluetoothConnection() { 33 BluetoothConnection::~BluetoothConnection() {
32 if (status() != DISCONNECTED) 34 if (status() != DISCONNECTED)
33 Disconnect(); 35 Disconnect();
34 } 36 }
35 37
36 void BluetoothConnection::Connect() { 38 void BluetoothConnection::Connect() {
37 if (status() != DISCONNECTED) { 39 if (status() != DISCONNECTED) {
38 PA_LOG(WARNING) 40 PA_LOG(WARNING)
39 << "Ignoring attempt to connect a non-disconnected connection."; 41 << "Ignoring attempt to connect a non-disconnected connection.";
(...skipping 26 matching lines...) Expand all
66 socket_->Disconnect(base::Bind(&base::DoNothing)); 68 socket_->Disconnect(base::Bind(&base::DoNothing));
67 socket_ = NULL; 69 socket_ = NULL;
68 } 70 }
69 if (adapter_.get()) { 71 if (adapter_.get()) {
70 adapter_->RemoveObserver(this); 72 adapter_->RemoveObserver(this);
71 adapter_ = NULL; 73 adapter_ = NULL;
72 } 74 }
73 } 75 }
74 76
75 void BluetoothConnection::SendMessageImpl( 77 void BluetoothConnection::SendMessageImpl(
76 std::unique_ptr<WireMessage> message) { 78 std::unique_ptr<cryptauth::WireMessage> message) {
77 DCHECK_EQ(status(), CONNECTED); 79 DCHECK_EQ(status(), CONNECTED);
78 80
79 // Serialize the message. 81 // Serialize the message.
80 std::string serialized_message = message->Serialize(); 82 std::string serialized_message = message->Serialize();
81 int message_length = base::checked_cast<int>(serialized_message.size()); 83 int message_length = base::checked_cast<int>(serialized_message.size());
82 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(message_length); 84 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(message_length);
83 memcpy(buffer->data(), serialized_message.c_str(), message_length); 85 memcpy(buffer->data(), serialized_message.c_str(), message_length);
84 86
85 // Send it. 87 // Send it.
86 pending_message_ = std::move(message); 88 pending_message_ = std::move(message);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 PA_LOG(WARNING) << "Error receiving bytes: " << error_message; 200 PA_LOG(WARNING) << "Error receiving bytes: " << error_message;
199 201
200 // Post a task to delay the read until the socket is available, as 202 // Post a task to delay the read until the socket is available, as
201 // calling StartReceive at this point would error with ERR_IO_PENDING. 203 // calling StartReceive at this point would error with ERR_IO_PENDING.
202 base::ThreadTaskRunnerHandle::Get()->PostTask( 204 base::ThreadTaskRunnerHandle::Get()->PostTask(
203 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive, 205 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive,
204 weak_ptr_factory_.GetWeakPtr())); 206 weak_ptr_factory_.GetWeakPtr()));
205 } 207 }
206 208
207 } // namespace proximity_auth 209 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698