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

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

Issue 903273002: Update from https://crrev.com/315085 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « third_party/re2/util/util.h ('k') | tools/android/forwarder2/host_forwarder_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <signal.h> 5 #include <signal.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 7
8 #include <iostream> 8 #include <iostream>
9 #include <string> 9 #include <string>
10 10
(...skipping 30 matching lines...) Expand all
41 // Lets the daemon fetch the exit notifier file descriptor. 41 // Lets the daemon fetch the exit notifier file descriptor.
42 int GetExitNotifierFD() { 42 int GetExitNotifierFD() {
43 DCHECK(g_notifier); 43 DCHECK(g_notifier);
44 return g_notifier->receiver_fd(); 44 return g_notifier->receiver_fd();
45 } 45 }
46 46
47 class ServerDelegate : public Daemon::ServerDelegate { 47 class ServerDelegate : public Daemon::ServerDelegate {
48 public: 48 public:
49 ServerDelegate() : initialized_(false) {} 49 ServerDelegate() : initialized_(false) {}
50 50
51 virtual ~ServerDelegate() { 51 ~ServerDelegate() override {
52 if (!controller_thread_.get()) 52 if (!controller_thread_.get())
53 return; 53 return;
54 // The DeviceController instance, if any, is constructed on the controller 54 // The DeviceController instance, if any, is constructed on the controller
55 // thread. Make sure that it gets deleted on that same thread. Note that 55 // thread. Make sure that it gets deleted on that same thread. Note that
56 // DeleteSoon() is not used here since it would imply reading |controller_| 56 // DeleteSoon() is not used here since it would imply reading |controller_|
57 // from the main thread while it's set on the internal thread. 57 // from the main thread while it's set on the internal thread.
58 controller_thread_->message_loop_proxy()->PostTask( 58 controller_thread_->message_loop_proxy()->PostTask(
59 FROM_HERE, 59 FROM_HERE,
60 base::Bind(&ServerDelegate::DeleteControllerOnInternalThread, 60 base::Bind(&ServerDelegate::DeleteControllerOnInternalThread,
61 base::Unretained(this))); 61 base::Unretained(this)));
62 } 62 }
63 63
64 void DeleteControllerOnInternalThread() { 64 void DeleteControllerOnInternalThread() {
65 DCHECK( 65 DCHECK(
66 controller_thread_->message_loop_proxy()->RunsTasksOnCurrentThread()); 66 controller_thread_->message_loop_proxy()->RunsTasksOnCurrentThread());
67 controller_.reset(); 67 controller_.reset();
68 } 68 }
69 69
70 // Daemon::ServerDelegate: 70 // Daemon::ServerDelegate:
71 virtual void Init() override { 71 void Init() override {
72 DCHECK(!g_notifier); 72 DCHECK(!g_notifier);
73 g_notifier = new forwarder2::PipeNotifier(); 73 g_notifier = new forwarder2::PipeNotifier();
74 signal(SIGTERM, KillHandler); 74 signal(SIGTERM, KillHandler);
75 signal(SIGINT, KillHandler); 75 signal(SIGINT, KillHandler);
76 controller_thread_.reset(new base::Thread("controller_thread")); 76 controller_thread_.reset(new base::Thread("controller_thread"));
77 controller_thread_->Start(); 77 controller_thread_->Start();
78 } 78 }
79 79
80 virtual void OnClientConnected(scoped_ptr<Socket> client_socket) override { 80 void OnClientConnected(scoped_ptr<Socket> client_socket) override {
81 if (initialized_) { 81 if (initialized_) {
82 client_socket->WriteString("OK"); 82 client_socket->WriteString("OK");
83 return; 83 return;
84 } 84 }
85 controller_thread_->message_loop()->PostTask( 85 controller_thread_->message_loop()->PostTask(
86 FROM_HERE, 86 FROM_HERE,
87 base::Bind(&ServerDelegate::StartController, base::Unretained(this), 87 base::Bind(&ServerDelegate::StartController, base::Unretained(this),
88 GetExitNotifierFD(), base::Passed(&client_socket))); 88 GetExitNotifierFD(), base::Passed(&client_socket)));
89 initialized_ = true; 89 initialized_ = true;
90 } 90 }
(...skipping 21 matching lines...) Expand all
112 bool initialized_; 112 bool initialized_;
113 }; 113 };
114 114
115 class ClientDelegate : public Daemon::ClientDelegate { 115 class ClientDelegate : public Daemon::ClientDelegate {
116 public: 116 public:
117 ClientDelegate() : has_failed_(false) {} 117 ClientDelegate() : has_failed_(false) {}
118 118
119 bool has_failed() const { return has_failed_; } 119 bool has_failed() const { return has_failed_; }
120 120
121 // Daemon::ClientDelegate: 121 // Daemon::ClientDelegate:
122 virtual void OnDaemonReady(Socket* daemon_socket) override { 122 void OnDaemonReady(Socket* daemon_socket) override {
123 char buf[kBufSize]; 123 char buf[kBufSize];
124 const int bytes_read = daemon_socket->Read( 124 const int bytes_read = daemon_socket->Read(
125 buf, sizeof(buf) - 1 /* leave space for null terminator */); 125 buf, sizeof(buf) - 1 /* leave space for null terminator */);
126 CHECK_GT(bytes_read, 0); 126 CHECK_GT(bytes_read, 0);
127 DCHECK(static_cast<unsigned int>(bytes_read) < sizeof(buf)); 127 DCHECK(static_cast<unsigned int>(bytes_read) < sizeof(buf));
128 buf[bytes_read] = 0; 128 buf[bytes_read] = 0;
129 base::StringPiece msg(buf, bytes_read); 129 base::StringPiece msg(buf, bytes_read);
130 if (msg.starts_with("ERROR")) { 130 if (msg.starts_with("ERROR")) {
131 LOG(ERROR) << msg; 131 LOG(ERROR) << msg;
132 has_failed_ = true; 132 has_failed_ = true;
(...skipping 27 matching lines...) Expand all
160 return 1; 160 return 1;
161 return client_delegate.has_failed(); 161 return client_delegate.has_failed();
162 } 162 }
163 163
164 } // namespace 164 } // namespace
165 } // namespace forwarder2 165 } // namespace forwarder2
166 166
167 int main(int argc, char** argv) { 167 int main(int argc, char** argv) {
168 return forwarder2::RunDeviceForwarder(argc, argv); 168 return forwarder2::RunDeviceForwarder(argc, argv);
169 } 169 }
OLDNEW
« no previous file with comments | « third_party/re2/util/util.h ('k') | tools/android/forwarder2/host_forwarder_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698