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

Side by Side Diff: device/bluetooth/bluetooth_socket_win.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 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_WIN_H_ 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_ 6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_
7 7
8 #include <WinSock2.h> 8 #include <WinSock2.h>
9 9
10 #include <queue>
10 #include <string> 11 #include <string>
11 12
13 #include "base/memory/linked_ptr.h"
12 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/threading/thread_checker.h"
16 #include "device/bluetooth/bluetooth_service_record_win.h"
13 #include "device/bluetooth/bluetooth_socket.h" 17 #include "device/bluetooth/bluetooth_socket.h"
18 #include "net/base/net_log.h"
14 19
15 namespace net { 20 namespace net {
16 21
22 class IOBufferWithSize;
17 class DrainableIOBuffer; 23 class DrainableIOBuffer;
18 class GrowableIOBuffer; 24 class TCPSocketWin;
19 25
20 } // namespace net 26 } // namespace net
21 27
22 namespace device { 28 namespace device {
23 29
24 class BluetoothServiceRecord; 30 class BluetoothServiceRecord;
25 31
26 // This class is an implementation of BluetoothSocket class for Windows 32 // This class is an implementation of BluetoothSocket class for Windows
27 // platform. 33 // platform.
28 class BluetoothSocketWin : public BluetoothSocket { 34 class BluetoothSocketWin : public BluetoothSocket {
29 public: 35 public:
30 static scoped_refptr<BluetoothSocket> CreateBluetoothSocket( 36 static scoped_refptr<BluetoothSocket> CreateBluetoothSocket(
31 const BluetoothServiceRecord& service_record); 37 const BluetoothServiceRecord& service_record,
38 scoped_refptr<base::SequencedTaskRunner> task_runner,
39 net::NetLog* net_log,
40 const net::NetLog::Source& source);
32 41
33 // BluetoothSocket override 42 // Overriden from BluetoothSocket:
34 virtual bool Receive(net::GrowableIOBuffer* buffer) OVERRIDE; 43 virtual void Connect(const base::Closure& success_callback,
35 virtual bool Send(net::DrainableIOBuffer* buffer) OVERRIDE; 44 const ErrorCompletionCallback& error_callback) OVERRIDE;
36 virtual std::string GetLastErrorMessage() const OVERRIDE; 45
46 virtual void Disconnect(const base::Closure& callback) OVERRIDE;
47
48 virtual void Receive(int count,
49 const ReceiveCompletionCallback& success_callback,
50 const ReceiveErrorCompletionCallback& error_callback)
51 OVERRIDE;
52 virtual void Send(scoped_refptr<net::IOBuffer> buffer,
53 int buffer_size,
54 const SendCompletionCallback& success_callback,
55 const ErrorCompletionCallback& error_callback) OVERRIDE;
37 56
38 protected: 57 protected:
39 virtual ~BluetoothSocketWin(); 58 virtual ~BluetoothSocketWin();
40 59
41 private: 60 private:
42 explicit BluetoothSocketWin(SOCKET fd); 61 struct WriteRequest {
62 scoped_refptr<net::IOBuffer> buffer;
63 int buffer_size;
64 SendCompletionCallback success_callback;
65 ErrorCompletionCallback error_callback;
66 };
43 67
44 const SOCKET fd_; 68 BluetoothSocketWin(scoped_refptr<base::SequencedTaskRunner> task_runner,
45 std::string error_message_; 69 net::NetLog* net_log,
70 const net::NetLog::Source& source);
71
72 void SendFrontWriteRequest();
73 void OnSocketWriteComplete(const SendCompletionCallback& success_callback,
74 const ErrorCompletionCallback& error_callback,
75 int net_status);
76 void OnSocketReadComplete(
77 const ReceiveCompletionCallback& success_callback,
78 const ReceiveErrorCompletionCallback& error_callback,
79 int send_result);
80
81 base::ThreadChecker thread_checker_;
82 scoped_refptr<base::SequencedTaskRunner> task_runner_;
83 net::NetLog* net_log_;
84 const net::NetLog::Source source_;
85 std::string device_address_;
86 bool supports_rfcomm_;
87 uint8 rfcomm_channel_;
88 BTH_ADDR bth_addr_;
89 scoped_ptr<net::TCPSocketWin> socket_win_;
90 // Queue of pending writes. The buffer at the front of the queue is the one
91 // being written.
92 std::queue<linked_ptr<WriteRequest> > write_queue_;
93 scoped_refptr<net::IOBufferWithSize> read_buffer_;
46 94
47 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketWin); 95 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketWin);
48 }; 96 };
49 97
50 } // namespace device 98 } // namespace device
51 99
52 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_ 100 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698