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

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: 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 "device/bluetooth/bluetooth_socket.h"
9 #include "net/base/io_buffer.h"
10
11 namespace {
12
13 // TODO(rkc): This number is totaly arbitrary. Figure out what this should be.
14 const int kMaxReceiveBytes = 4096;
15
16 } // namespace
17
18 namespace copresence_sockets {
19
20 CopresenceSocketBluetooth::CopresenceSocketBluetooth(
21 scoped_refptr<device::BluetoothSocket> socket)
22 : socket_(socket) {
23 }
24
25 CopresenceSocketBluetooth::~CopresenceSocketBluetooth() {
26 }
27
28 bool CopresenceSocketBluetooth::Send(const std::string& data) {
29 scoped_refptr<net::StringIOBuffer> buffer = new net::StringIOBuffer(data);
30 socket_->Send(
31 buffer,
32 buffer->size(),
33 base::Bind(&CopresenceSocketBluetooth::OnSendComplete, AsWeakPtr()),
34 base::Bind(&CopresenceSocketBluetooth::OnSendError, AsWeakPtr()));
35 return true;
36 }
37
38 void CopresenceSocketBluetooth::Receive(ReceiveCallback callback) {
39 receive_callback_ = callback;
40 socket_->Receive(
41 4096,
Ryan Sleevi 2014/10/01 19:47:25 DESIGN: Magic Constants are bad.
rkc 2014/10/01 22:38:48 Done.
42 base::Bind(&CopresenceSocketBluetooth::OnReceive, AsWeakPtr()),
43 base::Bind(&CopresenceSocketBluetooth::OnReceiveError, AsWeakPtr()));
44 }
45
46 void CopresenceSocketBluetooth::OnSendComplete(int status) {
47 }
48
49 void CopresenceSocketBluetooth::OnSendError(const std::string& message) {
50 LOG(ERROR) << "Bluetooth send error: " << message;
51 }
52
53 void CopresenceSocketBluetooth::OnReceive(
54 int size,
55 scoped_refptr<net::IOBuffer> io_buffer) {
56 // Dispatch the data to the callback and go back to listening for more data.
57 receive_callback_.Run(std::string(io_buffer->data(), size));
58 socket_->Receive(
59 kMaxReceiveBytes,
60 base::Bind(&CopresenceSocketBluetooth::OnReceive, AsWeakPtr()),
61 base::Bind(&CopresenceSocketBluetooth::OnReceiveError, AsWeakPtr()));
62 }
63
64 void CopresenceSocketBluetooth::OnReceiveError(
65 device::BluetoothSocket::ErrorReason /* reason */,
66 const std::string& message) {
67 LOG(ERROR) << "Bluetooth receive error: " << message;
68 }
69
70 } // namespace copresence_sockets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698