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

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

Issue 1197243004: Replace some Tokenize calls with SplitString. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android Created 5 years, 6 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 "chrome/browser/devtools/device/adb/mock_adb_server.h" 5 #include "chrome/browser/devtools/device/adb/mock_adb_server.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "base/threading/non_thread_safe.h" 15 #include "base/threading/non_thread_safe.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "content/public/test/browser_test.h" 17 #include "content/public/test/browser_test.h"
17 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
18 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
19 #include "net/base/ip_endpoint.h" 20 #include "net/base/ip_endpoint.h"
20 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 MockAndroidConnection::~MockAndroidConnection() { 492 MockAndroidConnection::~MockAndroidConnection() {
492 } 493 }
493 494
494 void MockAndroidConnection::Receive(const std::string& data) { 495 void MockAndroidConnection::Receive(const std::string& data) {
495 request_ += data; 496 request_ += data;
496 size_t request_end_pos = data.find(kHttpRequestTerminator); 497 size_t request_end_pos = data.find(kHttpRequestTerminator);
497 if (request_end_pos == std::string::npos) 498 if (request_end_pos == std::string::npos)
498 return; 499 return;
499 500
500 std::string request(request_.substr(0, request_end_pos)); 501 std::string request(request_.substr(0, request_end_pos));
501 std::vector<std::string> tokens; 502 std::vector<std::string> tokens =
502 Tokenize(request, " ", &tokens); 503 base::SplitString(request, " ", base::KEEP_WHITESPACE,
504 base::SPLIT_WANT_NONEMPTY);
503 CHECK_EQ(3U, tokens.size()); 505 CHECK_EQ(3U, tokens.size());
504 CHECK_EQ("GET", tokens[0]); 506 CHECK_EQ("GET", tokens[0]);
505 CHECK_EQ("HTTP/1.1", tokens[2]); 507 CHECK_EQ("HTTP/1.1", tokens[2]);
506 508
507 std::string path(tokens[1]); 509 std::string path(tokens[1]);
508 if (path == kJsonPath) 510 if (path == kJsonPath)
509 path = kJsonListPath; 511 path = kJsonListPath;
510 512
511 if (socket_name_ == "chrome_devtools_remote") { 513 if (socket_name_ == "chrome_devtools_remote") {
512 if (path == kJsonVersionPath) 514 if (path == kJsonVersionPath)
(...skipping 27 matching lines...) Expand all
540 NOTREACHED() << "Unknown socket " << socket_name_; 542 NOTREACHED() << "Unknown socket " << socket_name_;
541 } 543 }
542 } 544 }
543 545
544 void MockAndroidConnection::ProcessCommand(const std::string& command) { 546 void MockAndroidConnection::ProcessCommand(const std::string& command) {
545 if (command.find(kLocalAbstractPrefix) == 0) { 547 if (command.find(kLocalAbstractPrefix) == 0) {
546 socket_name_ = command.substr(strlen(kLocalAbstractPrefix)); 548 socket_name_ = command.substr(strlen(kLocalAbstractPrefix));
547 delegate_->SendSuccess(std::string()); 549 delegate_->SendSuccess(std::string());
548 } else { 550 } else {
549 if (command.find(kShellPrefix) == 0) { 551 if (command.find(kShellPrefix) == 0) {
550 std::vector<std::string> lines;
551 Tokenize(command.substr(strlen(kShellPrefix)), "\n", &lines);
552 std::string result; 552 std::string result;
553 for (const auto& line : lines) { 553 for (const auto& line :
554 base::SplitString(command.substr(strlen(kShellPrefix)), "\n",
555 base::KEEP_WHITESPACE,
556 base::SPLIT_WANT_NONEMPTY)) {
554 if (line == kDeviceModelCommand) { 557 if (line == kDeviceModelCommand) {
555 result += kDeviceModel; 558 result += kDeviceModel;
556 result += "\r\n"; 559 result += "\r\n";
557 } else if (line == kOpenedUnixSocketsCommand) { 560 } else if (line == kOpenedUnixSocketsCommand) {
558 result += kSampleOpenedUnixSockets; 561 result += kSampleOpenedUnixSockets;
559 } else if (line == kDumpsysCommand) { 562 } else if (line == kDumpsysCommand) {
560 result += kSampleDumpsys; 563 result += kSampleDumpsys;
561 } else if (line == kListProcessesCommand) { 564 } else if (line == kListProcessesCommand) {
562 result += kSampleListProcesses; 565 result += kSampleListProcesses;
563 } else if (line == kListUsersCommand) { 566 } else if (line == kListUsersCommand) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 598
596 void StopMockAdbServer() { 599 void StopMockAdbServer() {
597 BrowserThread::PostTaskAndReply( 600 BrowserThread::PostTaskAndReply(
598 BrowserThread::IO, 601 BrowserThread::IO,
599 FROM_HERE, 602 FROM_HERE,
600 base::Bind(&StopMockAdbServerOnIOThread), 603 base::Bind(&StopMockAdbServerOnIOThread),
601 base::MessageLoop::QuitClosure()); 604 base::MessageLoop::QuitClosure());
602 content::RunMessageLoop(); 605 content::RunMessageLoop();
603 } 606 }
604 607
OLDNEW
« no previous file with comments | « chrome/browser/devtools/device/adb/adb_device_provider.cc ('k') | chrome/browser/devtools/device/android_device_info_query.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698