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

Side by Side Diff: device/bluetooth/bluetooth_socket_win.cc

Issue 236203018: win: Implement Bluetooth server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 (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 #include "device/bluetooth/bluetooth_socket_win.h" 5 #include "device/bluetooth/bluetooth_socket_win.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 result->device_address_ = service_record_win->address(); 64 result->device_address_ = service_record_win->address();
65 if (service_record.SupportsRfcomm()) { 65 if (service_record.SupportsRfcomm()) {
66 result->supports_rfcomm_ = true; 66 result->supports_rfcomm_ = true;
67 result->rfcomm_channel_ = service_record_win->rfcomm_channel(); 67 result->rfcomm_channel_ = service_record_win->rfcomm_channel();
68 result->bth_addr_ = service_record_win->bth_addr(); 68 result->bth_addr_ = service_record_win->bth_addr();
69 } 69 }
70 70
71 return result; 71 return result;
72 } 72 }
73 73
74 // static
75 scoped_refptr<BluetoothSocketWin> BluetoothSocketWin::CreateBluetoothSocket(
76 scoped_ptr<net::TCPSocket> existing,
77 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
78 scoped_refptr<BluetoothSocketThreadWin> socket_thread,
79 net::NetLog* net_log,
80 const net::NetLog::Source& source) {
81 DCHECK(ui_task_runner->RunsTasksOnCurrentThread());
82
83 scoped_refptr<BluetoothSocketWin> result(
84 new BluetoothSocketWin(ui_task_runner, socket_thread, net_log, source));
85 result->tcp_socket_ = existing.Pass();
86
87 return result;
88 }
89
74 BluetoothSocketWin::BluetoothSocketWin( 90 BluetoothSocketWin::BluetoothSocketWin(
75 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, 91 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
76 scoped_refptr<BluetoothSocketThreadWin> socket_thread, 92 scoped_refptr<BluetoothSocketThreadWin> socket_thread,
77 net::NetLog* net_log, 93 net::NetLog* net_log,
78 const net::NetLog::Source& source) 94 const net::NetLog::Source& source)
79 : ui_task_runner_(ui_task_runner), 95 : ui_task_runner_(ui_task_runner),
80 socket_thread_(socket_thread), 96 socket_thread_(socket_thread),
81 net_log_(net_log), 97 net_log_(net_log),
82 source_(source), 98 source_(source),
83 supports_rfcomm_(false), 99 supports_rfcomm_(false),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 &BluetoothSocketWin::DoSend, 168 &BluetoothSocketWin::DoSend,
153 this, 169 this,
154 buffer, 170 buffer,
155 buffer_size, 171 buffer_size,
156 base::Bind( 172 base::Bind(
157 &BluetoothSocketWin::PostSendCompletion, this, success_callback), 173 &BluetoothSocketWin::PostSendCompletion, this, success_callback),
158 base::Bind( 174 base::Bind(
159 &BluetoothSocketWin::PostErrorCompletion, this, error_callback))); 175 &BluetoothSocketWin::PostErrorCompletion, this, error_callback)));
160 } 176 }
161 177
178 void BluetoothSocketWin::Accept(
179 const BluetoothSocketWin::OnAcceptCallback& on_accept_callback) {
180 DCHECK(on_accept_callback_.is_null());
181 on_accept_callback_ = on_accept_callback;
182 socket_thread_->task_runner()->PostTask(
183 FROM_HERE,
184 base::Bind(&BluetoothSocketWin::DoAccept, this));
185 }
186
162 void BluetoothSocketWin::DoClose() { 187 void BluetoothSocketWin::DoClose() {
163 DCHECK(socket_thread_->task_runner()->RunsTasksOnCurrentThread()); 188 DCHECK(socket_thread_->task_runner()->RunsTasksOnCurrentThread());
164 base::ThreadRestrictions::AssertIOAllowed(); 189 base::ThreadRestrictions::AssertIOAllowed();
165 190
166 if (tcp_socket_) { 191 if (tcp_socket_) {
167 tcp_socket_->Close(); 192 tcp_socket_->Close();
168 tcp_socket_.reset(NULL); 193 tcp_socket_.reset(NULL);
169 } 194 }
170 195
171 // Note: Closing |tcp_socket_| above released all potential pending 196 // Note: Closing |tcp_socket_| above released all potential pending
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 ui_task_runner_->PostTask(FROM_HERE, 417 ui_task_runner_->PostTask(FROM_HERE,
393 base::Bind(callback, reason, error_message)); 418 base::Bind(callback, reason, error_message));
394 } 419 }
395 420
396 void BluetoothSocketWin::PostSendCompletion( 421 void BluetoothSocketWin::PostSendCompletion(
397 const SendCompletionCallback& callback, 422 const SendCompletionCallback& callback,
398 int bytes_written) { 423 int bytes_written) {
399 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, bytes_written)); 424 ui_task_runner_->PostTask(FROM_HERE, base::Bind(callback, bytes_written));
400 } 425 }
401 426
427 void BluetoothSocketWin::DoAccept() {
428 DCHECK(socket_thread_->task_runner()->RunsTasksOnCurrentThread());
429 int result = tcp_socket_->Accept(
430 &accept_socket_,
431 &accept_address_,
432 base::Bind(&BluetoothSocketWin::OnAcceptOnSocketThread, this));
433 if (result != net::OK && result != net::ERR_IO_PENDING)
434 LOG(WARNING) << "Failed to accept, net err=" << result;
435 }
436
437 void BluetoothSocketWin::OnAcceptOnSocketThread(int accept_result) {
438 DCHECK(socket_thread_->task_runner()->RunsTasksOnCurrentThread());
439 if (accept_result != net::OK) {
440 LOG(WARNING) << "OnAccept error, net err=" << accept_result;
441 return;
442 }
443
444 ui_task_runner_->PostTask(
445 FROM_HERE,
446 base::Bind(&BluetoothSocketWin::OnAcceptOnUI,
447 this,
448 base::Passed(&accept_socket_),
449 accept_address_));
450 DoAccept();
451 }
452
453 void BluetoothSocketWin::OnAcceptOnUI(
454 scoped_ptr<net::TCPSocket> accept_socket,
455 const net::IPEndPoint& peer_address) {
456 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
457
458 on_accept_callback_.Run(
459 CreateBluetoothSocket(
460 accept_socket.Pass(),
461 ui_task_runner_,
462 socket_thread_,
463 net_log_,
464 source_),
465 peer_address);
466 }
467
402 } // namespace device 468 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698