| OLD | NEW |
| 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 DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_NET_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_NET_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_NET_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_NET_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
| 16 #include "device/bluetooth/bluetooth_socket.h" | 16 #include "device/bluetooth/bluetooth_socket.h" |
| 17 #include "device/bluetooth/bluetooth_socket_thread.h" | 17 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 18 #include "net/base/net_log.h" | |
| 19 #include "net/socket/tcp_socket.h" | 18 #include "net/socket/tcp_socket.h" |
| 20 | 19 |
| 21 namespace net { | 20 namespace net { |
| 22 class IOBuffer; | 21 class IOBuffer; |
| 23 class IOBufferWithSize; | 22 class IOBufferWithSize; |
| 24 } // namespace net | 23 } // namespace net |
| 25 | 24 |
| 26 namespace device { | 25 namespace device { |
| 27 | 26 |
| 28 // This class is a base-class for implementations of BluetoothSocket that can | 27 // This class is a base-class for implementations of BluetoothSocket that can |
| 29 // use net::TCPSocket. All public methods (including the factory method) must | 28 // use net::TCPSocket. All public methods (including the factory method) must |
| 30 // be called on the UI thread, while underlying socket operations are | 29 // be called on the UI thread, while underlying socket operations are |
| 31 // performed on a separate thread. | 30 // performed on a separate thread. |
| 32 class BluetoothSocketNet : public BluetoothSocket { | 31 class BluetoothSocketNet : public BluetoothSocket { |
| 33 public: | 32 public: |
| 34 // BluetoothSocket: | 33 // BluetoothSocket: |
| 35 virtual void Close() OVERRIDE; | 34 virtual void Close() OVERRIDE; |
| 36 virtual void Disconnect(const base::Closure& callback) OVERRIDE; | 35 virtual void Disconnect(const base::Closure& callback) OVERRIDE; |
| 37 virtual void Receive(int buffer_size, | 36 virtual void Receive(int buffer_size, |
| 38 const ReceiveCompletionCallback& success_callback, | 37 const ReceiveCompletionCallback& success_callback, |
| 39 const ReceiveErrorCompletionCallback& error_callback) | 38 const ReceiveErrorCompletionCallback& error_callback) |
| 40 OVERRIDE; | 39 OVERRIDE; |
| 41 virtual void Send(scoped_refptr<net::IOBuffer> buffer, | 40 virtual void Send(scoped_refptr<net::IOBuffer> buffer, |
| 42 int buffer_size, | 41 int buffer_size, |
| 43 const SendCompletionCallback& success_callback, | 42 const SendCompletionCallback& success_callback, |
| 44 const ErrorCompletionCallback& error_callback) OVERRIDE; | 43 const ErrorCompletionCallback& error_callback) OVERRIDE; |
| 45 | 44 |
| 46 protected: | 45 protected: |
| 47 BluetoothSocketNet(scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 46 BluetoothSocketNet(scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
| 48 scoped_refptr<BluetoothSocketThread> socket_thread, | 47 scoped_refptr<BluetoothSocketThread> socket_thread); |
| 49 net::NetLog* net_log, | |
| 50 const net::NetLog::Source& source); | |
| 51 virtual ~BluetoothSocketNet(); | 48 virtual ~BluetoothSocketNet(); |
| 52 | 49 |
| 53 // Resets locally held data after a socket is closed. Default implementation | 50 // Resets locally held data after a socket is closed. Default implementation |
| 54 // does nothing, subclasses may override. | 51 // does nothing, subclasses may override. |
| 55 virtual void ResetData(); | 52 virtual void ResetData(); |
| 56 | 53 |
| 57 // Methods for subclasses to obtain the members. | 54 // Methods for subclasses to obtain the members. |
| 58 scoped_refptr<base::SequencedTaskRunner> ui_task_runner() const { | 55 scoped_refptr<base::SequencedTaskRunner> ui_task_runner() const { |
| 59 return ui_task_runner_; | 56 return ui_task_runner_; |
| 60 } | 57 } |
| 61 | 58 |
| 62 scoped_refptr<BluetoothSocketThread> socket_thread() const { | 59 scoped_refptr<BluetoothSocketThread> socket_thread() const { |
| 63 return socket_thread_; | 60 return socket_thread_; |
| 64 } | 61 } |
| 65 | 62 |
| 66 net::NetLog* net_log() const { return net_log_; } | |
| 67 const net::NetLog::Source& source() const { return source_; } | |
| 68 | |
| 69 net::TCPSocket* tcp_socket() { return tcp_socket_.get(); } | 63 net::TCPSocket* tcp_socket() { return tcp_socket_.get(); } |
| 70 | 64 |
| 71 void ResetTCPSocket(); | 65 void ResetTCPSocket(); |
| 72 void SetTCPSocket(scoped_ptr<net::TCPSocket> tcp_socket); | 66 void SetTCPSocket(scoped_ptr<net::TCPSocket> tcp_socket); |
| 73 | 67 |
| 74 void PostSuccess(const base::Closure& callback); | 68 void PostSuccess(const base::Closure& callback); |
| 75 void PostErrorCompletion(const ErrorCompletionCallback& callback, | 69 void PostErrorCompletion(const ErrorCompletionCallback& callback, |
| 76 const std::string& error); | 70 const std::string& error); |
| 77 | 71 |
| 78 private: | 72 private: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 109 scoped_refptr<net::IOBuffer> io_buffer); | 103 scoped_refptr<net::IOBuffer> io_buffer); |
| 110 void PostReceiveErrorCompletion( | 104 void PostReceiveErrorCompletion( |
| 111 const ReceiveErrorCompletionCallback& callback, | 105 const ReceiveErrorCompletionCallback& callback, |
| 112 ErrorReason reason, | 106 ErrorReason reason, |
| 113 const std::string& error_message); | 107 const std::string& error_message); |
| 114 void PostSendCompletion(const SendCompletionCallback& callback, | 108 void PostSendCompletion(const SendCompletionCallback& callback, |
| 115 int bytes_written); | 109 int bytes_written); |
| 116 | 110 |
| 117 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; | 111 scoped_refptr<base::SequencedTaskRunner> ui_task_runner_; |
| 118 scoped_refptr<BluetoothSocketThread> socket_thread_; | 112 scoped_refptr<BluetoothSocketThread> socket_thread_; |
| 119 net::NetLog* net_log_; | |
| 120 const net::NetLog::Source source_; | |
| 121 | 113 |
| 122 scoped_ptr<net::TCPSocket> tcp_socket_; | 114 scoped_ptr<net::TCPSocket> tcp_socket_; |
| 123 scoped_refptr<net::IOBufferWithSize> read_buffer_; | 115 scoped_refptr<net::IOBufferWithSize> read_buffer_; |
| 124 std::queue<linked_ptr<WriteRequest> > write_queue_; | 116 std::queue<linked_ptr<WriteRequest> > write_queue_; |
| 125 | 117 |
| 126 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketNet); | 118 DISALLOW_COPY_AND_ASSIGN(BluetoothSocketNet); |
| 127 }; | 119 }; |
| 128 | 120 |
| 129 } // namespace device | 121 } // namespace device |
| 130 | 122 |
| 131 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_NET_H_ | 123 #endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_NET_H_ |
| OLD | NEW |