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

Side by Side Diff: chrome/browser/devtools/device/adb/mock_adb_server.cc

Issue 287643002: DevTools: Partially redesigned DevToolsAndroidBridge and AndroidDeviceManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unused include Created 6 years, 7 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 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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 void ProcessCommand(const std::string& command) { 464 void ProcessCommand(const std::string& command) {
465 CHECK(CalledOnValidThread()); 465 CHECK(CalledOnValidThread());
466 if (command == "host:devices") { 466 if (command == "host:devices") {
467 SendResponse(base::StringPrintf("%s\tdevice\n%s\toffline", 467 SendResponse(base::StringPrintf("%s\tdevice\n%s\toffline",
468 kSerialOnline, 468 kSerialOnline,
469 kSerialOffline)); 469 kSerialOffline));
470 } else if (command.find(kHostTransportPrefix) == 0) { 470 } else if (command.find(kHostTransportPrefix) == 0) {
471 selected_device_ = command.substr(strlen(kHostTransportPrefix)); 471 selected_device_ = command.substr(strlen(kHostTransportPrefix));
472 SendResponse(""); 472 SendResponse("");
473 } else if (selected_device_ != kSerialOnline) { 473 } else if (selected_device_ != kSerialOnline) {
474 NOTREACHED() << "Unknown device - " << selected_device_; 474 Send("FAIL", "device offline (x)");
475 } else if (command == kDeviceModelCommand) { 475 } else if (command == kDeviceModelCommand) {
476 SendResponse(kDeviceModel); 476 SendResponse(kDeviceModel);
477 } else if (command == kOpenedUnixSocketsCommand) { 477 } else if (command == kOpenedUnixSocketsCommand) {
478 SendResponse(kSampleOpenedUnixSockets); 478 SendResponse(kSampleOpenedUnixSockets);
479 } else if (command == kDumpsysCommand) { 479 } else if (command == kDumpsysCommand) {
480 SendResponse(kSampleDumpsys); 480 SendResponse(kSampleDumpsys);
481 } else if (command == kListProcessesCommand) { 481 } else if (command == kListProcessesCommand) {
482 SendResponse(kSampleListProcesses); 482 SendResponse(kSampleListProcesses);
483 } else if (command == kInstalledChromePackagesCommand) { 483 } else if (command == kInstalledChromePackagesCommand) {
484 SendResponse(kSampleListPackages); 484 SendResponse(kSampleListPackages);
485 } else if (command.find(kLocalAbstractPrefix) == 0) { 485 } else if (command.find(kLocalAbstractPrefix) == 0) {
486 selected_socket_ = command.substr(strlen(kLocalAbstractPrefix)); 486 selected_socket_ = command.substr(strlen(kLocalAbstractPrefix));
487 SendResponse(""); 487 SendResponse("");
488 } else { 488 } else {
489 NOTREACHED() << "Unknown command - " << command; 489 NOTREACHED() << "Unknown command - " << command;
490 } 490 }
491 } 491 }
492 492
493 void SendResponse(const std::string& response) { 493 void SendResponse(const std::string& response) { Send("OKAY", response); }
494
495 void Send(const std::string& status, const std::string& response) {
494 CHECK(CalledOnValidThread()); 496 CHECK(CalledOnValidThread());
497 CHECK_EQ(4U, status.size());
498
495 std::stringstream response_stream; 499 std::stringstream response_stream;
496 response_stream << "OKAY"; 500 response_stream << status;
497 501
498 int size = response.size(); 502 int size = response.size();
499 if (size > 0) { 503 if (size > 0) {
500 static const char kHexChars[] = "0123456789ABCDEF"; 504 static const char kHexChars[] = "0123456789ABCDEF";
501 for (int i = 3; i >= 0; i--) 505 for (int i = 3; i >= 0; i--)
502 response_stream << kHexChars[ (size >> 4*i) & 0x0f ]; 506 response_stream << kHexChars[ (size >> 4*i) & 0x0f ];
503 response_stream << response; 507 response_stream << response;
504 } 508 }
505 509
506 server_->Send(response_stream.str()); 510 server_->Send(response_stream.str());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 552
549 void StopMockAdbServer() { 553 void StopMockAdbServer() {
550 BrowserThread::PostTaskAndReply( 554 BrowserThread::PostTaskAndReply(
551 BrowserThread::IO, 555 BrowserThread::IO,
552 FROM_HERE, 556 FROM_HERE,
553 base::Bind(&StopMockAdbServerOnIOThread), 557 base::Bind(&StopMockAdbServerOnIOThread),
554 base::MessageLoop::QuitClosure()); 558 base::MessageLoop::QuitClosure());
555 content::RunMessageLoop(); 559 content::RunMessageLoop();
556 } 560 }
557 561
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698