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

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_api_socket.h

Issue 278663002: Implement chrome.bluetoothSocket.listenUsing*() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix BluetoothAdapterMac include typo Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_SOCKET_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_SOCKET_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_SOCKET_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_SOCKET_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "device/bluetooth/bluetooth_device.h"
10 #include "device/bluetooth/bluetooth_socket.h" 11 #include "device/bluetooth/bluetooth_socket.h"
11 #include "device/bluetooth/bluetooth_uuid.h" 12 #include "device/bluetooth/bluetooth_uuid.h"
12 #include "extensions/browser/api/api_resource.h" 13 #include "extensions/browser/api/api_resource.h"
13 #include "extensions/browser/api/api_resource_manager.h" 14 #include "extensions/browser/api/api_resource_manager.h"
14 15
15 namespace net { 16 namespace net {
16 class IOBuffer; 17 class IOBuffer;
17 } // namespace net 18 } // namespace net
18 19
19 namespace extensions { 20 namespace extensions {
20 21
21 // Representation of socket instances from the "bluetooth" namespace, 22 // Representation of socket instances from the "bluetooth" namespace,
22 // abstracting away platform differences from the underlying BluetoothSocketXxx 23 // abstracting away platform differences from the underlying BluetoothSocketXxx
23 // class. All methods must be called on the |kThreadId| thread. 24 // class. All methods must be called on the |kThreadId| thread.
24 class BluetoothApiSocket : public ApiResource { 25 class BluetoothApiSocket : public ApiResource {
25 public: 26 public:
26 enum ErrorReason { kSystemError, kNotConnected, kIOPending, kDisconnected }; 27 enum ErrorReason { kSystemError, kNotConnected, kNotListening, kIOPending,
28 kDisconnected };
27 29
28 typedef base::Callback<void(int)> SendCompletionCallback; 30 typedef base::Callback<void(int)> SendCompletionCallback;
29 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> 31 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)>
30 ReceiveCompletionCallback; 32 ReceiveCompletionCallback;
33 typedef base::Callback<void(const device::BluetoothDevice* device,
34 scoped_refptr<device::BluetoothSocket>)>
35 AcceptCompletionCallback;
31 typedef base::Callback<void(ErrorReason, const std::string& error_message)> 36 typedef base::Callback<void(ErrorReason, const std::string& error_message)>
32 ErrorCompletionCallback; 37 ErrorCompletionCallback;
33 38
34 explicit BluetoothApiSocket(const std::string& owner_extension_id); 39 explicit BluetoothApiSocket(const std::string& owner_extension_id);
35 BluetoothApiSocket(const std::string& owner_extension_id, 40 BluetoothApiSocket(const std::string& owner_extension_id,
36 scoped_refptr<device::BluetoothSocket> socket, 41 scoped_refptr<device::BluetoothSocket> socket,
37 const std::string& device_address, 42 const std::string& device_address,
38 const device::BluetoothUUID& uuid); 43 const device::BluetoothUUID& uuid);
39 virtual ~BluetoothApiSocket(); 44 virtual ~BluetoothApiSocket();
40 45
41 // Adopts a socket |socket| connected to a device with address 46 // Adopts a socket |socket| connected to a device with address
42 // |device_address| using the service with UUID |uuid|. 47 // |device_address| using the service with UUID |uuid|.
43 virtual void AdoptConnectedSocket( 48 virtual void AdoptConnectedSocket(
44 scoped_refptr<device::BluetoothSocket> socket, 49 scoped_refptr<device::BluetoothSocket> socket,
45 const std::string& device_address, 50 const std::string& device_address,
46 const device::BluetoothUUID& uuid); 51 const device::BluetoothUUID& uuid);
47 52
53 // Adopts a socket |socket| listening on a service advertised with UUID
54 // |uuid|.
55 virtual void AdoptListeningSocket(
56 scoped_refptr<device::BluetoothSocket> socket,
57 const device::BluetoothUUID& uuid);
58
48 // Closes the underlying connection. This is a best effort, and never fails. 59 // Closes the underlying connection. This is a best effort, and never fails.
49 virtual void Disconnect(const base::Closure& success_callback); 60 virtual void Disconnect(const base::Closure& callback);
50 61
51 // Receives data from the socket and calls |success_callback| when data is 62 // Receives data from the socket and calls |success_callback| when data is
52 // available. |count| is maximum amount of bytes received. If an error occurs, 63 // available. |count| is maximum amount of bytes received. If an error occurs,
53 // calls |error_callback| with a reason and a message. In particular, if a 64 // calls |error_callback| with a reason and a message. In particular, if a
54 // |Receive| operation is still pending, |error_callback| will be called with 65 // |Receive| operation is still pending, |error_callback| will be called with
55 // |kIOPending| error. 66 // |kIOPending| error.
56 virtual void Receive(int count, 67 virtual void Receive(int count,
57 const ReceiveCompletionCallback& success_callback, 68 const ReceiveCompletionCallback& success_callback,
58 const ErrorCompletionCallback& error_callback); 69 const ErrorCompletionCallback& error_callback);
59 70
60 // Sends |buffer| to the socket and calls |success_callback| when data has 71 // Sends |buffer| to the socket and calls |success_callback| when data has
61 // been successfully sent. |buffer_size| is the numberof bytes contained in 72 // been successfully sent. |buffer_size| is the numberof bytes contained in
62 // |buffer|. If an error occurs, calls |error_callback| with a reason and a 73 // |buffer|. If an error occurs, calls |error_callback| with a reason and a
63 // message. Calling |Send| multiple times without waiting for the callbacks to 74 // message. Calling |Send| multiple times without waiting for the callbacks to
64 // be called is a valid usage, as |buffer| instances are buffered until the 75 // be called is a valid usage, as |buffer| instances are buffered until the
65 // underlying communication channel is available for sending data. 76 // underlying communication channel is available for sending data.
66 virtual void Send(scoped_refptr<net::IOBuffer> buffer, 77 virtual void Send(scoped_refptr<net::IOBuffer> buffer,
67 int buffer_size, 78 int buffer_size,
68 const SendCompletionCallback& success_callback, 79 const SendCompletionCallback& success_callback,
69 const ErrorCompletionCallback& error_callback); 80 const ErrorCompletionCallback& error_callback);
70 81
82 // Accepts a client connection from the socket and calls |success_callback|
83 // when one has connected. If an error occurs, calls |error_callback| with a
84 // reason and a message.
85 virtual void Accept(const AcceptCompletionCallback& success_callback,
86 const ErrorCompletionCallback& error_callback);
87
71 const std::string& device_address() const { return device_address_; } 88 const std::string& device_address() const { return device_address_; }
72 const device::BluetoothUUID& uuid() const { return uuid_; } 89 const device::BluetoothUUID& uuid() const { return uuid_; }
73 90
74 // Overriden from extensions::ApiResource. 91 // Overriden from extensions::ApiResource.
75 virtual bool IsPersistent() const OVERRIDE; 92 virtual bool IsPersistent() const OVERRIDE;
76 93
77 const std::string& name() const { return name_; } 94 const std::string& name() const { return name_; }
78 void set_name(const std::string& name) { name_ = name; } 95 void set_name(const std::string& name) { name_ = name; }
79 96
80 bool persistent() const { return persistent_; } 97 bool persistent() const { return persistent_; }
(...skipping 18 matching lines...) Expand all
99 116
100 static void OnSocketReceiveError( 117 static void OnSocketReceiveError(
101 const ErrorCompletionCallback& error_callback, 118 const ErrorCompletionCallback& error_callback,
102 device::BluetoothSocket::ErrorReason reason, 119 device::BluetoothSocket::ErrorReason reason,
103 const std::string& message); 120 const std::string& message);
104 121
105 static void OnSocketSendError( 122 static void OnSocketSendError(
106 const ErrorCompletionCallback& error_callback, 123 const ErrorCompletionCallback& error_callback,
107 const std::string& message); 124 const std::string& message);
108 125
126 static void OnSocketAcceptError(
127 const ErrorCompletionCallback& error_callback,
128 const std::string& message);
129
109 // The underlying device socket instance. 130 // The underlying device socket instance.
110 scoped_refptr<device::BluetoothSocket> socket_; 131 scoped_refptr<device::BluetoothSocket> socket_;
111 132
112 // The address of the device this socket is connected to. 133 // The address of the device this socket is connected to.
113 std::string device_address_; 134 std::string device_address_;
114 135
115 // The uuid of the service this socket is connected to. 136 // The uuid of the service this socket is connected to.
116 device::BluetoothUUID uuid_; 137 device::BluetoothUUID uuid_;
117 138
118 // Application-defined string - see bluetooth.idl. 139 // Application-defined string - see bluetooth.idl.
(...skipping 12 matching lines...) Expand all
131 152
132 // Flag indicating whether a socket is connected. 153 // Flag indicating whether a socket is connected.
133 bool connected_; 154 bool connected_;
134 155
135 DISALLOW_COPY_AND_ASSIGN(BluetoothApiSocket); 156 DISALLOW_COPY_AND_ASSIGN(BluetoothApiSocket);
136 }; 157 };
137 158
138 } // namespace extensions 159 } // namespace extensions
139 160
140 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_SOCKET_H_ 161 #endif // CHROME_BROWSER_EXTENSIONS_API_BLUETOOTH_BLUETOOTH_API_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698