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

Side by Side Diff: components/copresence_sockets/transports/bluetooth/copresence_socket_bluetooth.cc

Issue 610633002: Prototype for copresenceSockets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format specifiers build fix Created 6 years, 2 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 2014 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 "components/copresence_sockets/transports/bluetooth/copresence_socket_b luetooth.h"
6
7 #include "base/bind.h"
8 #include "base/strings/string_piece.h"
9 #include "device/bluetooth/bluetooth_socket.h"
10 #include "net/base/io_buffer.h"
11
12 namespace {
13
14 // TODO(rkc): This number is totally arbitrary. Figure out what this should be.
15 const int kMaxReceiveBytes = 4096;
16
17 } // namespace
18
19 namespace copresence_sockets {
20
21 CopresenceSocketBluetooth::CopresenceSocketBluetooth(
22 const scoped_refptr<device::BluetoothSocket>& socket)
23 : socket_(socket), weak_ptr_factory_(this) {
24 }
25
26 CopresenceSocketBluetooth::~CopresenceSocketBluetooth() {
27 }
28
29 bool CopresenceSocketBluetooth::Send(const scoped_refptr<net::IOBuffer>& buffer,
30 int buffer_size) {
31 socket_->Send(buffer,
32 buffer_size,
33 base::Bind(&CopresenceSocketBluetooth::OnSendComplete,
34 weak_ptr_factory_.GetWeakPtr()),
35 base::Bind(&CopresenceSocketBluetooth::OnSendError,
36 weak_ptr_factory_.GetWeakPtr()));
37 return true;
38 }
39
40 void CopresenceSocketBluetooth::Receive(const ReceiveCallback& callback) {
41 receive_callback_ = callback;
42 socket_->Receive(kMaxReceiveBytes,
43 base::Bind(&CopresenceSocketBluetooth::OnReceive,
44 weak_ptr_factory_.GetWeakPtr()),
45 base::Bind(&CopresenceSocketBluetooth::OnReceiveError,
46 weak_ptr_factory_.GetWeakPtr()));
47 }
48
49 void CopresenceSocketBluetooth::OnSendComplete(int status) {
50 }
51
52 void CopresenceSocketBluetooth::OnSendError(const std::string& message) {
53 LOG(ERROR) << "Bluetooth send error: " << message;
54 }
55
56 void CopresenceSocketBluetooth::OnReceive(
57 int size,
58 scoped_refptr<net::IOBuffer> io_buffer) {
59 // Dispatch the data to the callback and go back to listening for more data.
60 receive_callback_.Run(io_buffer, size);
61 socket_->Receive(kMaxReceiveBytes,
62 base::Bind(&CopresenceSocketBluetooth::OnReceive,
63 weak_ptr_factory_.GetWeakPtr()),
64 base::Bind(&CopresenceSocketBluetooth::OnReceiveError,
65 weak_ptr_factory_.GetWeakPtr()));
66 }
67
68 void CopresenceSocketBluetooth::OnReceiveError(
69 device::BluetoothSocket::ErrorReason /* reason */,
70 const std::string& message) {
71 LOG(ERROR) << "Bluetooth receive error: " << message;
72 }
73
74 } // namespace copresence_sockets
OLDNEW
« no previous file with comments | « components/copresence_sockets/transports/bluetooth/copresence_socket_bluetooth.h ('k') | extensions/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698