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 #include "device/bluetooth/bluetooth_socket_net.h" | 5 #include "device/bluetooth/bluetooth_socket_net.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.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 "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
17 #include "device/bluetooth/bluetooth_socket.h" | 17 #include "device/bluetooth/bluetooth_socket.h" |
18 #include "device/bluetooth/bluetooth_socket_thread.h" | 18 #include "device/bluetooth/bluetooth_socket_thread.h" |
19 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 21 #include "net/base/net_log.h" |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 const char kSocketNotConnected[] = "Socket is not connected."; | 25 const char kSocketNotConnected[] = "Socket is not connected."; |
25 | 26 |
26 static void DeactivateSocket( | 27 static void DeactivateSocket( |
27 const scoped_refptr<device::BluetoothSocketThread>& socket_thread) { | 28 const scoped_refptr<device::BluetoothSocketThread>& socket_thread) { |
28 socket_thread->OnSocketDeactivate(); | 29 socket_thread->OnSocketDeactivate(); |
29 } | 30 } |
30 | 31 |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 namespace device { | 34 namespace device { |
34 | 35 |
35 BluetoothSocketNet::WriteRequest::WriteRequest() | 36 BluetoothSocketNet::WriteRequest::WriteRequest() |
36 : buffer_size(0) {} | 37 : buffer_size(0) {} |
37 | 38 |
38 BluetoothSocketNet::WriteRequest::~WriteRequest() {} | 39 BluetoothSocketNet::WriteRequest::~WriteRequest() {} |
39 | 40 |
40 BluetoothSocketNet::BluetoothSocketNet( | 41 BluetoothSocketNet::BluetoothSocketNet( |
41 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 42 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
42 scoped_refptr<BluetoothSocketThread> socket_thread, | 43 scoped_refptr<BluetoothSocketThread> socket_thread) |
43 net::NetLog* net_log, | |
44 const net::NetLog::Source& source) | |
45 : ui_task_runner_(ui_task_runner), | 44 : ui_task_runner_(ui_task_runner), |
46 socket_thread_(socket_thread), | 45 socket_thread_(socket_thread) { |
47 net_log_(net_log), | |
48 source_(source) { | |
49 DCHECK(ui_task_runner->RunsTasksOnCurrentThread()); | 46 DCHECK(ui_task_runner->RunsTasksOnCurrentThread()); |
50 socket_thread_->OnSocketActivate(); | 47 socket_thread_->OnSocketActivate(); |
51 } | 48 } |
52 | 49 |
53 BluetoothSocketNet::~BluetoothSocketNet() { | 50 BluetoothSocketNet::~BluetoothSocketNet() { |
54 DCHECK(tcp_socket_.get() == NULL); | 51 DCHECK(tcp_socket_.get() == NULL); |
55 ui_task_runner_->PostTask(FROM_HERE, | 52 ui_task_runner_->PostTask(FROM_HERE, |
56 base::Bind(&DeactivateSocket, socket_thread_)); | 53 base::Bind(&DeactivateSocket, socket_thread_)); |
57 } | 54 } |
58 | 55 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 success_callback), | 109 success_callback), |
113 base::Bind(&BluetoothSocketNet::PostErrorCompletion, | 110 base::Bind(&BluetoothSocketNet::PostErrorCompletion, |
114 this, | 111 this, |
115 error_callback))); | 112 error_callback))); |
116 } | 113 } |
117 | 114 |
118 void BluetoothSocketNet::ResetData() { | 115 void BluetoothSocketNet::ResetData() { |
119 } | 116 } |
120 | 117 |
121 void BluetoothSocketNet::ResetTCPSocket() { | 118 void BluetoothSocketNet::ResetTCPSocket() { |
122 tcp_socket_.reset(new net::TCPSocket(net_log_, source_)); | 119 tcp_socket_.reset(new net::TCPSocket(NULL, net::NetLog::Source())); |
123 } | 120 } |
124 | 121 |
125 void BluetoothSocketNet::SetTCPSocket(scoped_ptr<net::TCPSocket> tcp_socket) { | 122 void BluetoothSocketNet::SetTCPSocket(scoped_ptr<net::TCPSocket> tcp_socket) { |
126 tcp_socket_ = tcp_socket.Pass(); | 123 tcp_socket_ = tcp_socket.Pass(); |
127 } | 124 } |
128 | 125 |
129 void BluetoothSocketNet::PostSuccess(const base::Closure& callback) { | 126 void BluetoothSocketNet::PostSuccess(const base::Closure& callback) { |
130 ui_task_runner_->PostTask(FROM_HERE, callback); | 127 ui_task_runner_->PostTask(FROM_HERE, callback); |
131 } | 128 } |
132 | 129 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 base::Bind(callback, reason, error_message)); | 301 base::Bind(callback, reason, error_message)); |
305 } | 302 } |
306 | 303 |
307 void BluetoothSocketNet::PostSendCompletion( | 304 void BluetoothSocketNet::PostSendCompletion( |
308 const SendCompletionCallback& callback, | 305 const SendCompletionCallback& callback, |
309 int bytes_written) { | 306 int bytes_written) { |
310 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, bytes_written)); | 307 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, bytes_written)); |
311 } | 308 } |
312 | 309 |
313 } // namespace device | 310 } // namespace device |
OLD | NEW |