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

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

Issue 1869503004: Convert //tools to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, change iwyu fixes for converted directories to include <memory> Created 4 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
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // Daemon::ServerDelegate: 60 // Daemon::ServerDelegate:
61 void Init() override { 61 void Init() override {
62 DCHECK(!g_notifier); 62 DCHECK(!g_notifier);
63 g_notifier = new forwarder2::PipeNotifier(); 63 g_notifier = new forwarder2::PipeNotifier();
64 signal(SIGTERM, KillHandler); 64 signal(SIGTERM, KillHandler);
65 signal(SIGINT, KillHandler); 65 signal(SIGINT, KillHandler);
66 controller_thread_.reset(new base::Thread("controller_thread")); 66 controller_thread_.reset(new base::Thread("controller_thread"));
67 controller_thread_->Start(); 67 controller_thread_->Start();
68 } 68 }
69 69
70 void OnClientConnected(scoped_ptr<Socket> client_socket) override { 70 void OnClientConnected(std::unique_ptr<Socket> client_socket) override {
71 if (initialized_) { 71 if (initialized_) {
72 client_socket->WriteString("OK"); 72 client_socket->WriteString("OK");
73 return; 73 return;
74 } 74 }
75 controller_thread_->message_loop()->PostTask( 75 controller_thread_->message_loop()->PostTask(
76 FROM_HERE, 76 FROM_HERE,
77 base::Bind(&ServerDelegate::StartController, base::Unretained(this), 77 base::Bind(&ServerDelegate::StartController, base::Unretained(this),
78 GetExitNotifierFD(), base::Passed(&client_socket))); 78 GetExitNotifierFD(), base::Passed(&client_socket)));
79 initialized_ = true; 79 initialized_ = true;
80 } 80 }
81 81
82 private: 82 private:
83 void StartController(int exit_notifier_fd, scoped_ptr<Socket> client_socket) { 83 void StartController(int exit_notifier_fd,
84 std::unique_ptr<Socket> client_socket) {
84 DCHECK(!controller_.get()); 85 DCHECK(!controller_.get());
85 scoped_ptr<DeviceController> controller( 86 std::unique_ptr<DeviceController> controller(
86 DeviceController::Create(kUnixDomainSocketPath, exit_notifier_fd)); 87 DeviceController::Create(kUnixDomainSocketPath, exit_notifier_fd));
87 if (!controller.get()) { 88 if (!controller.get()) {
88 client_socket->WriteString( 89 client_socket->WriteString(
89 base::StringPrintf("ERROR: Could not initialize device controller " 90 base::StringPrintf("ERROR: Could not initialize device controller "
90 "with ADB socket path: %s", 91 "with ADB socket path: %s",
91 kUnixDomainSocketPath)); 92 kUnixDomainSocketPath));
92 return; 93 return;
93 } 94 }
94 controller_.swap(controller); 95 controller_.swap(controller);
95 controller_->Start(); 96 controller_->Start();
96 client_socket->WriteString("OK"); 97 client_socket->WriteString("OK");
97 client_socket->Close(); 98 client_socket->Close();
98 } 99 }
99 100
100 scoped_ptr<DeviceController> controller_; 101 std::unique_ptr<DeviceController> controller_;
101 scoped_ptr<base::Thread> controller_thread_; 102 std::unique_ptr<base::Thread> controller_thread_;
102 bool initialized_; 103 bool initialized_;
103 }; 104 };
104 105
105 class ClientDelegate : public Daemon::ClientDelegate { 106 class ClientDelegate : public Daemon::ClientDelegate {
106 public: 107 public:
107 ClientDelegate() : has_failed_(false) {} 108 ClientDelegate() : has_failed_(false) {}
108 109
109 bool has_failed() const { return has_failed_; } 110 bool has_failed() const { return has_failed_; }
110 111
111 // Daemon::ClientDelegate: 112 // Daemon::ClientDelegate:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 return 1; 151 return 1;
151 return client_delegate.has_failed(); 152 return client_delegate.has_failed();
152 } 153 }
153 154
154 } // namespace 155 } // namespace
155 } // namespace forwarder2 156 } // namespace forwarder2
156 157
157 int main(int argc, char** argv) { 158 int main(int argc, char** argv) {
158 return forwarder2::RunDeviceForwarder(argc, argv); 159 return forwarder2::RunDeviceForwarder(argc, argv);
159 } 160 }
OLDNEW
« no previous file with comments | « tools/android/forwarder2/device_controller.cc ('k') | tools/android/forwarder2/device_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698