| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/strings/string_number_conversions.h" | 5 #include "base/strings/string_number_conversions.h" |
| 6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/threading/non_thread_safe.h" | 8 #include "base/threading/non_thread_safe.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "content/public/test/browser_test.h" | 10 #include "content/public/test/browser_test.h" |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 void ProcessCommand(const std::string& command) { | 456 void ProcessCommand(const std::string& command) { |
| 457 CHECK(CalledOnValidThread()); | 457 CHECK(CalledOnValidThread()); |
| 458 if (command == "host:devices") { | 458 if (command == "host:devices") { |
| 459 SendResponse(base::StringPrintf("%s\tdevice\n%s\toffline", | 459 SendResponse(base::StringPrintf("%s\tdevice\n%s\toffline", |
| 460 kSerialOnline, | 460 kSerialOnline, |
| 461 kSerialOffline)); | 461 kSerialOffline)); |
| 462 } else if (command.find(kHostTransportPrefix) == 0) { | 462 } else if (command.find(kHostTransportPrefix) == 0) { |
| 463 selected_device_ = command.substr(strlen(kHostTransportPrefix)); | 463 selected_device_ = command.substr(strlen(kHostTransportPrefix)); |
| 464 SendResponse(""); | 464 SendResponse(""); |
| 465 } else if (selected_device_ != kSerialOnline) { | 465 } else if (selected_device_ != kSerialOnline) { |
| 466 NOTREACHED() << "Unknown device - " << selected_device_; | 466 Send("FAIL", "device offline (x)"); |
| 467 } else if (command == kDeviceModelCommand) { | 467 } else if (command == kDeviceModelCommand) { |
| 468 SendResponse(kDeviceModel); | 468 SendResponse(kDeviceModel); |
| 469 } else if (command == kOpenedUnixSocketsCommand) { | 469 } else if (command == kOpenedUnixSocketsCommand) { |
| 470 SendResponse(kSampleOpenedUnixSockets); | 470 SendResponse(kSampleOpenedUnixSockets); |
| 471 } else if (command == kDumpsysCommand) { | 471 } else if (command == kDumpsysCommand) { |
| 472 SendResponse(kSampleDumpsys); | 472 SendResponse(kSampleDumpsys); |
| 473 } else if (command == kListProcessesCommand) { | 473 } else if (command == kListProcessesCommand) { |
| 474 SendResponse(kSampleListProcesses); | 474 SendResponse(kSampleListProcesses); |
| 475 } else if (command.find(kLocalAbstractPrefix) == 0) { | 475 } else if (command.find(kLocalAbstractPrefix) == 0) { |
| 476 selected_socket_ = command.substr(strlen(kLocalAbstractPrefix)); | 476 selected_socket_ = command.substr(strlen(kLocalAbstractPrefix)); |
| 477 SendResponse(""); | 477 SendResponse(""); |
| 478 } else { | 478 } else { |
| 479 NOTREACHED() << "Unknown command - " << command; | 479 NOTREACHED() << "Unknown command - " << command; |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | 482 |
| 483 void SendResponse(const std::string& response) { | 483 void SendResponse(const std::string& response) { Send("OKAY", response); } |
| 484 |
| 485 void Send(const std::string& status, const std::string& response) { |
| 484 CHECK(CalledOnValidThread()); | 486 CHECK(CalledOnValidThread()); |
| 487 CHECK_EQ(4U, status.size()); |
| 488 |
| 485 std::stringstream response_stream; | 489 std::stringstream response_stream; |
| 486 response_stream << "OKAY"; | 490 response_stream << status; |
| 487 | 491 |
| 488 int size = response.size(); | 492 int size = response.size(); |
| 489 if (size > 0) { | 493 if (size > 0) { |
| 490 static const char kHexChars[] = "0123456789ABCDEF"; | 494 static const char kHexChars[] = "0123456789ABCDEF"; |
| 491 for (int i = 3; i >= 0; i--) | 495 for (int i = 3; i >= 0; i--) |
| 492 response_stream << kHexChars[ (size >> 4*i) & 0x0f ]; | 496 response_stream << kHexChars[ (size >> 4*i) & 0x0f ]; |
| 493 response_stream << response; | 497 response_stream << response; |
| 494 } | 498 } |
| 495 | 499 |
| 496 server_->Send(response_stream.str()); | 500 server_->Send(response_stream.str()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 542 |
| 539 void StopMockAdbServer() { | 543 void StopMockAdbServer() { |
| 540 BrowserThread::PostTaskAndReply( | 544 BrowserThread::PostTaskAndReply( |
| 541 BrowserThread::IO, | 545 BrowserThread::IO, |
| 542 FROM_HERE, | 546 FROM_HERE, |
| 543 base::Bind(&StopMockAdbServerOnIOThread), | 547 base::Bind(&StopMockAdbServerOnIOThread), |
| 544 base::MessageLoop::QuitClosure()); | 548 base::MessageLoop::QuitClosure()); |
| 545 content::RunMessageLoop(); | 549 content::RunMessageLoop(); |
| 546 } | 550 } |
| 547 | 551 |
| OLD | NEW |