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

Side by Side Diff: device/bluetooth/bluetooth_socket.h

Issue 180163009: chrome.bluetooth API improvements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix threading ownership related to ApiResourceManager<BluetoothApiSocket> and BluetoothSocketEventD… Created 6 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 12
12 namespace net { 13 namespace net {
13 14
14 class DrainableIOBuffer; 15 class DrainableIOBuffer;
15 class GrowableIOBuffer; 16 class GrowableIOBuffer;
17 class IOBuffer;
16 18
17 } // namespace net 19 } // namespace net
18 20
19 namespace device { 21 namespace device {
20 22
21 // BluetoothSocket represents a socket to a specific service on a 23 // BluetoothSocket represents a socket to a specific service on a
22 // BluetoothDevice. BluetoothSocket objects are ref counted and may outlive 24 // BluetoothDevice. BluetoothSocket objects are ref counted and may outlive
23 // both the BluetoothDevice and BluetoothAdapter that were involved in their 25 // both the BluetoothDevice and BluetoothAdapter that were involved in their
24 // creation. 26 // creation. In terms of threading, platform specific implementation may differ
25 class BluetoothSocket : public base::RefCounted<BluetoothSocket> { 27 // slightly, but platform independent callers must guarantee calling various
28 // methods on the same thread for a given instance, and in a context that allows
29 // IO.
30 class BluetoothSocket : public base::RefCountedThreadSafe<BluetoothSocket> {
26 public: 31 public:
27 // Receives data from the socket and stores it in |buffer|. It returns whether 32 enum ErrorReason { kSystemError, kIOPending, kDisconnected };
28 // the reception has been successful. If it fails, the caller can get the
29 // error message through |GetLastErrorMessage()|.
30 virtual bool Receive(net::GrowableIOBuffer* buffer) = 0;
31 33
32 // Sends |buffer| to the socket. It returns whether the sending has been 34 typedef base::Callback<void(int)> SendCompletionCallback;
33 // successful. If it fails, the caller can get the error message through 35 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)>
34 // |GetLastErrorMessage()|. 36 ReceiveCompletionCallback;
35 virtual bool Send(net::DrainableIOBuffer* buffer) = 0; 37 typedef base::Callback<void(const std::string& error_message)>
38 ErrorCompletionCallback;
39 typedef base::Callback<void(ErrorReason, const std::string& error_message)>
40 ReceiveErrorCompletionCallback;
36 41
37 virtual std::string GetLastErrorMessage() const = 0; 42 // Connected to the peer device and calls |success_callback| when the
43 // connection has been established successfully. If an error occurs, calls
44 // |error_callback| with a system error message.
45 virtual void Connect(const base::Closure& success_callback,
46 const ErrorCompletionCallback& error_callback) = 0;
47
48 // Disconnects a connected socket and calls |callback| upon completion. There
49 // is no failure case, as this is a best effort operation.
50 virtual void Disconnect(const base::Closure& callback) = 0;
51
52 // Receives data from the socket and calls |success_callback| when data is
53 // available. If an error occurs, calls |error_callback| with a reason and a
54 // message.
55 virtual void Receive(
56 int count,
57 const ReceiveCompletionCallback& success_callback,
58 const ReceiveErrorCompletionCallback& error_callback) = 0;
59
60 // Sends |buffer| to the socket and calls |success_callback| when data has
61 // been successfully sent. If an error occurs, calls |error_callback| with a
62 // reason and a message.
63 virtual void Send(scoped_refptr<net::DrainableIOBuffer> buffer,
64 const SendCompletionCallback& success_callback,
65 const ErrorCompletionCallback& error_callback) = 0;
38 66
39 protected: 67 protected:
40 friend class base::RefCounted<BluetoothSocket>; 68 friend class base::RefCountedThreadSafe<BluetoothSocket>;
41 virtual ~BluetoothSocket() {} 69 virtual ~BluetoothSocket();
42 }; 70 };
43 71
44 } // namespace device 72 } // namespace device
45 73
46 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_ 74 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698