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

Side by Side Diff: tools/android/forwarder2/device_listener.cc

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 #include "tools/android/forwarder2/device_listener.h" 5 #include "tools/android/forwarder2/device_listener.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
14 #include "tools/android/forwarder2/command.h" 13 #include "tools/android/forwarder2/command.h"
15 #include "tools/android/forwarder2/forwarder.h" 14 #include "tools/android/forwarder2/forwarder.h"
16 #include "tools/android/forwarder2/socket.h" 15 #include "tools/android/forwarder2/socket.h"
17 16
18 namespace forwarder2 { 17 namespace forwarder2 {
19 18
20 // static 19 // static
21 scoped_ptr<DeviceListener> DeviceListener::Create( 20 scoped_ptr<DeviceListener> DeviceListener::Create(
22 scoped_ptr<Socket> host_socket, 21 scoped_ptr<Socket> host_socket,
(...skipping 21 matching lines...) Expand all
44 DCHECK(deletion_task_runner_->RunsTasksOnCurrentThread()); 43 DCHECK(deletion_task_runner_->RunsTasksOnCurrentThread());
45 deletion_notifier_.Notify(); 44 deletion_notifier_.Notify();
46 } 45 }
47 46
48 void DeviceListener::Start() { 47 void DeviceListener::Start() {
49 thread_.Start(); 48 thread_.Start();
50 AcceptNextClientSoon(); 49 AcceptNextClientSoon();
51 } 50 }
52 51
53 void DeviceListener::SetAdbDataSocket(scoped_ptr<Socket> adb_data_socket) { 52 void DeviceListener::SetAdbDataSocket(scoped_ptr<Socket> adb_data_socket) {
54 thread_.message_loop_proxy()->PostTask( 53 thread_.task_runner()->PostTask(
55 FROM_HERE, 54 FROM_HERE,
56 base::Bind(&DeviceListener::OnAdbDataSocketReceivedOnInternalThread, 55 base::Bind(&DeviceListener::OnAdbDataSocketReceivedOnInternalThread,
57 base::Unretained(this), base::Passed(&adb_data_socket))); 56 base::Unretained(this), base::Passed(&adb_data_socket)));
58 } 57 }
59 58
60 DeviceListener::DeviceListener(scoped_ptr<Socket> listener_socket, 59 DeviceListener::DeviceListener(scoped_ptr<Socket> listener_socket,
61 scoped_ptr<Socket> host_socket, 60 scoped_ptr<Socket> host_socket,
62 int port, 61 int port,
63 const ErrorCallback& error_callback) 62 const ErrorCallback& error_callback)
64 : self_deleter_helper_(this, error_callback), 63 : self_deleter_helper_(this, error_callback),
65 listener_socket_(listener_socket.Pass()), 64 listener_socket_(listener_socket.Pass()),
66 host_socket_(host_socket.Pass()), 65 host_socket_(host_socket.Pass()),
67 listener_port_(port), 66 listener_port_(port),
68 deletion_task_runner_(base::MessageLoopProxy::current()), 67 deletion_task_runner_(base::MessageLoop::current()->task_runner()),
69 thread_("DeviceListener") { 68 thread_("DeviceListener") {
70 CHECK(host_socket_.get()); 69 CHECK(host_socket_.get());
71 DCHECK(deletion_task_runner_.get()); 70 DCHECK(deletion_task_runner_.get());
72 host_socket_->AddEventFd(deletion_notifier_.receiver_fd()); 71 host_socket_->AddEventFd(deletion_notifier_.receiver_fd());
73 listener_socket_->AddEventFd(deletion_notifier_.receiver_fd()); 72 listener_socket_->AddEventFd(deletion_notifier_.receiver_fd());
74 } 73 }
75 74
76 void DeviceListener::AcceptNextClientSoon() { 75 void DeviceListener::AcceptNextClientSoon() {
77 thread_.message_loop_proxy()->PostTask( 76 thread_.task_runner()->PostTask(
78 FROM_HERE, 77 FROM_HERE, base::Bind(&DeviceListener::AcceptClientOnInternalThread,
79 base::Bind(&DeviceListener::AcceptClientOnInternalThread, 78 base::Unretained(this)));
80 base::Unretained(this)));
81 } 79 }
82 80
83 void DeviceListener::AcceptClientOnInternalThread() { 81 void DeviceListener::AcceptClientOnInternalThread() {
84 device_data_socket_.reset(new Socket()); 82 device_data_socket_.reset(new Socket());
85 if (!listener_socket_->Accept(device_data_socket_.get())) { 83 if (!listener_socket_->Accept(device_data_socket_.get())) {
86 if (listener_socket_->DidReceiveEvent()) { 84 if (listener_socket_->DidReceiveEvent()) {
87 LOG(INFO) << "Received exit notification, stopped accepting clients."; 85 LOG(INFO) << "Received exit notification, stopped accepting clients.";
88 OnInternalThreadError(); 86 OnInternalThreadError();
89 return; 87 return;
90 } 88 }
(...skipping 30 matching lines...) Expand all
121 forwarders_manager_.CreateAndStartNewForwarder( 119 forwarders_manager_.CreateAndStartNewForwarder(
122 device_data_socket_.Pass(), adb_data_socket.Pass()); 120 device_data_socket_.Pass(), adb_data_socket.Pass());
123 AcceptNextClientSoon(); 121 AcceptNextClientSoon();
124 } 122 }
125 123
126 void DeviceListener::OnInternalThreadError() { 124 void DeviceListener::OnInternalThreadError() {
127 self_deleter_helper_.MaybeSelfDeleteSoon(); 125 self_deleter_helper_.MaybeSelfDeleteSoon();
128 } 126 }
129 127
130 } // namespace forwarder 128 } // namespace forwarder
OLDNEW
« no previous file with comments | « tools/android/forwarder2/device_forwarder_main.cc ('k') | tools/android/forwarder2/forwarders_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698