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/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" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 if (socket_.get()) { | 65 if (socket_.get()) { |
66 socket_->Disconnect(base::Bind(&base::DoNothing)); | 66 socket_->Disconnect(base::Bind(&base::DoNothing)); |
67 socket_ = NULL; | 67 socket_ = NULL; |
68 } | 68 } |
69 if (adapter_.get()) { | 69 if (adapter_.get()) { |
70 adapter_->RemoveObserver(this); | 70 adapter_->RemoveObserver(this); |
71 adapter_ = NULL; | 71 adapter_ = NULL; |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 void BluetoothConnection::SendMessageImpl(scoped_ptr<WireMessage> message) { | 75 void BluetoothConnection::SendMessageImpl( |
| 76 std::unique_ptr<WireMessage> message) { |
76 DCHECK_EQ(status(), CONNECTED); | 77 DCHECK_EQ(status(), CONNECTED); |
77 | 78 |
78 // Serialize the message. | 79 // Serialize the message. |
79 std::string serialized_message = message->Serialize(); | 80 std::string serialized_message = message->Serialize(); |
80 int message_length = base::checked_cast<int>(serialized_message.size()); | 81 int message_length = base::checked_cast<int>(serialized_message.size()); |
81 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(message_length); | 82 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(message_length); |
82 memcpy(buffer->data(), serialized_message.c_str(), message_length); | 83 memcpy(buffer->data(), serialized_message.c_str(), message_length); |
83 | 84 |
84 // Send it. | 85 // Send it. |
85 pending_message_ = std::move(message); | 86 pending_message_ = std::move(message); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 PA_LOG(WARNING) << "Error receiving bytes: " << error_message; | 198 PA_LOG(WARNING) << "Error receiving bytes: " << error_message; |
198 | 199 |
199 // Post a task to delay the read until the socket is available, as | 200 // Post a task to delay the read until the socket is available, as |
200 // calling StartReceive at this point would error with ERR_IO_PENDING. | 201 // calling StartReceive at this point would error with ERR_IO_PENDING. |
201 base::ThreadTaskRunnerHandle::Get()->PostTask( | 202 base::ThreadTaskRunnerHandle::Get()->PostTask( |
202 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive, | 203 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive, |
203 weak_ptr_factory_.GetWeakPtr())); | 204 weak_ptr_factory_.GetWeakPtr())); |
204 } | 205 } |
205 | 206 |
206 } // namespace proximity_auth | 207 } // namespace proximity_auth |
OLD | NEW |