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

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

Issue 2127373006: Use base::StartWith() in more places when appropriate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, resolve conflict Created 4 years, 5 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 | « storage/common/fileapi/file_system_util.cc ('k') | ui/display/chromeos/x11/display_util_x11.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 <errno.h> 5 #include <errno.h>
6 #include <signal.h> 6 #include <signal.h>
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <sys/wait.h> 10 #include <sys/wait.h>
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 const std::string& device_serial) { 233 const std::string& device_serial) {
234 base::hash_map<std::string, int>::const_iterator it = 234 base::hash_map<std::string, int>::const_iterator it =
235 device_serial_to_adb_port_map_.find(device_serial); 235 device_serial_to_adb_port_map_.find(device_serial);
236 if (it == device_serial_to_adb_port_map_.end()) 236 if (it == device_serial_to_adb_port_map_.end())
237 return; 237 return;
238 238
239 int port = it->second; 239 int port = it->second;
240 const std::string prefix = base::StringPrintf("%d:", port); 240 const std::string prefix = base::StringPrintf("%d:", port);
241 for (HostControllerMap::const_iterator others = controllers_->begin(); 241 for (HostControllerMap::const_iterator others = controllers_->begin();
242 others != controllers_->end(); ++others) { 242 others != controllers_->end(); ++others) {
243 if (others->first.find(prefix) == 0U) 243 if (base::StartsWith(others->first, prefix, base::CompareCase::SENSITIVE))
244 return; 244 return;
245 } 245 }
246 // No other port is being forwarded to this device: 246 // No other port is being forwarded to this device:
247 // - Remove it from our internal serial -> adb port map. 247 // - Remove it from our internal serial -> adb port map.
248 // - Remove from "adb forward" command. 248 // - Remove from "adb forward" command.
249 LOG(INFO) << "Device " << device_serial << " has no more ports."; 249 LOG(INFO) << "Device " << device_serial << " has no more ports.";
250 device_serial_to_adb_port_map_.erase(device_serial); 250 device_serial_to_adb_port_map_.erase(device_serial);
251 const std::string serial_part = device_serial.empty() ? 251 const std::string serial_part = device_serial.empty() ?
252 std::string() : std::string("-s ") + device_serial; 252 std::string() : std::string("-s ") + device_serial;
253 const std::string command = base::StringPrintf( 253 const std::string command = base::StringPrintf(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 std::unique_ptr<HostControllerMap> controllers_; 311 std::unique_ptr<HostControllerMap> controllers_;
312 bool has_failed_; 312 bool has_failed_;
313 std::unique_ptr<base::AtExitManager> 313 std::unique_ptr<base::AtExitManager>
314 at_exit_manager_; // Needed by base::Thread. 314 at_exit_manager_; // Needed by base::Thread.
315 std::unique_ptr<base::Thread> thread_; 315 std::unique_ptr<base::Thread> thread_;
316 base::WeakPtrFactory<HostControllersManager> weak_ptr_factory_; 316 base::WeakPtrFactory<HostControllersManager> weak_ptr_factory_;
317 }; 317 };
318 318
319 class ServerDelegate : public Daemon::ServerDelegate { 319 class ServerDelegate : public Daemon::ServerDelegate {
320 public: 320 public:
321 ServerDelegate(const std::string& adb_path) 321 explicit ServerDelegate(const std::string& adb_path)
322 : adb_path_(adb_path), has_failed_(false) {} 322 : adb_path_(adb_path), has_failed_(false) {}
323 323
324 bool has_failed() const { 324 bool has_failed() const {
325 return has_failed_ || controllers_manager_.has_failed(); 325 return has_failed_ || controllers_manager_.has_failed();
326 } 326 }
327 327
328 // Daemon::ServerDelegate: 328 // Daemon::ServerDelegate:
329 void Init() override { 329 void Init() override {
330 LOG(INFO) << "Starting host process daemon (pid=" << getpid() << ")"; 330 LOG(INFO) << "Starting host process daemon (pid=" << getpid() << ")";
331 DCHECK(!g_notifier); 331 DCHECK(!g_notifier);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 private: 363 private:
364 std::string adb_path_; 364 std::string adb_path_;
365 bool has_failed_; 365 bool has_failed_;
366 HostControllersManager controllers_manager_; 366 HostControllersManager controllers_manager_;
367 367
368 DISALLOW_COPY_AND_ASSIGN(ServerDelegate); 368 DISALLOW_COPY_AND_ASSIGN(ServerDelegate);
369 }; 369 };
370 370
371 class ClientDelegate : public Daemon::ClientDelegate { 371 class ClientDelegate : public Daemon::ClientDelegate {
372 public: 372 public:
373 ClientDelegate(const base::Pickle& command_pickle) 373 explicit ClientDelegate(const base::Pickle& command_pickle)
374 : command_pickle_(command_pickle), has_failed_(false) {} 374 : command_pickle_(command_pickle), has_failed_(false) {}
375 375
376 bool has_failed() const { return has_failed_; } 376 bool has_failed() const { return has_failed_; }
377 377
378 // Daemon::ClientDelegate: 378 // Daemon::ClientDelegate:
379 void OnDaemonReady(Socket* daemon_socket) override { 379 void OnDaemonReady(Socket* daemon_socket) override {
380 // Send the forward command to the daemon. 380 // Send the forward command to the daemon.
381 CHECK_EQ(static_cast<long>(command_pickle_.size()), 381 CHECK_EQ(static_cast<long>(command_pickle_.size()),
382 daemon_socket->WriteNumBytes(command_pickle_.data(), 382 daemon_socket->WriteNumBytes(command_pickle_.data(),
383 command_pickle_.size())); 383 command_pickle_.size()));
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 471
472 return client_delegate.has_failed() || daemon_delegate.has_failed(); 472 return client_delegate.has_failed() || daemon_delegate.has_failed();
473 } 473 }
474 474
475 } // namespace 475 } // namespace
476 } // namespace forwarder2 476 } // namespace forwarder2
477 477
478 int main(int argc, char** argv) { 478 int main(int argc, char** argv) {
479 return forwarder2::RunHostForwarder(argc, argv); 479 return forwarder2::RunHostForwarder(argc, argv);
480 } 480 }
OLDNEW
« no previous file with comments | « storage/common/fileapi/file_system_util.cc ('k') | ui/display/chromeos/x11/display_util_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698