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

Unified 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: Address code review feedback. 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_socket.h
diff --git a/device/bluetooth/bluetooth_socket.h b/device/bluetooth/bluetooth_socket.h
index 6ae349e9ac92c2f1480f4360b6546287e73cef41..6bf0f034a35a162c8d8ac095751bfd3deb7f73b8 100644
--- a/device/bluetooth/bluetooth_socket.h
+++ b/device/bluetooth/bluetooth_socket.h
@@ -7,13 +7,11 @@
#include <string>
+#include "base/callback.h"
#include "base/memory/ref_counted.h"
namespace net {
-
-class DrainableIOBuffer;
-class GrowableIOBuffer;
-
+class IOBuffer;
} // namespace net
namespace device {
@@ -21,24 +19,51 @@ namespace device {
// BluetoothSocket represents a socket to a specific service on a
// BluetoothDevice. BluetoothSocket objects are ref counted and may outlive
// both the BluetoothDevice and BluetoothAdapter that were involved in their
-// creation.
-class BluetoothSocket : public base::RefCounted<BluetoothSocket> {
+// creation. In terms of threading, platform specific implementation may differ
+// slightly, but platform independent callers must guarantee calling various
+// methods on the same thread for a given instance, and in a context that allows
+// IO.
+class BluetoothSocket : public base::RefCountedThreadSafe<BluetoothSocket> {
public:
- // Receives data from the socket and stores it in |buffer|. It returns whether
- // the reception has been successful. If it fails, the caller can get the
- // error message through |GetLastErrorMessage()|.
- virtual bool Receive(net::GrowableIOBuffer* buffer) = 0;
+ enum ErrorReason { kSystemError, kIOPending, kDisconnected };
+
+ typedef base::Callback<void(int)> SendCompletionCallback;
+ typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)>
+ ReceiveCompletionCallback;
+ typedef base::Callback<void(const std::string& error_message)>
+ ErrorCompletionCallback;
+ typedef base::Callback<void(ErrorReason, const std::string& error_message)>
+ ReceiveErrorCompletionCallback;
+
+ // Connected to the peer device and calls |success_callback| when the
+ // connection has been established successfully. If an error occurs, calls
+ // |error_callback| with a system error message.
+ virtual void Connect(const base::Closure& success_callback,
+ const ErrorCompletionCallback& error_callback) = 0;
keybuk 2014/03/20 16:34:49 Does this need to be part of the public cross-plat
rpaquay 2014/03/20 18:21:11 Done.
+
+ // Disconnects a connected socket and calls |callback| upon completion. There
+ // is no failure case, as this is a best effort operation.
+ virtual void Disconnect(const base::Closure& callback) = 0;
- // Sends |buffer| to the socket. It returns whether the sending has been
- // successful. If it fails, the caller can get the error message through
- // |GetLastErrorMessage()|.
- virtual bool Send(net::DrainableIOBuffer* buffer) = 0;
+ // Receives data from the socket and calls |success_callback| when data is
+ // available. If an error occurs, calls |error_callback| with a reason and a
+ // message.
keybuk 2014/03/20 01:21:56 need to document parameters
rpaquay 2014/03/20 18:21:11 Done.
+ virtual void Receive(
+ int count,
+ const ReceiveCompletionCallback& success_callback,
+ const ReceiveErrorCompletionCallback& error_callback) = 0;
- virtual std::string GetLastErrorMessage() const = 0;
+ // Sends |buffer| to the socket and calls |success_callback| when data has
+ // been successfully sent. If an error occurs, calls |error_callback| with a
+ // reason and a message.
keybuk 2014/03/20 01:21:56 buffer_size not documented
rpaquay 2014/03/20 18:21:11 Done.
+ virtual void Send(scoped_refptr<net::IOBuffer> buffer,
+ int buffer_size,
+ const SendCompletionCallback& success_callback,
+ const ErrorCompletionCallback& error_callback) = 0;
protected:
- friend class base::RefCounted<BluetoothSocket>;
- virtual ~BluetoothSocket() {}
+ friend class base::RefCountedThreadSafe<BluetoothSocket>;
+ virtual ~BluetoothSocket();
};
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698