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

Side by Side Diff: chrome/browser/devtools/device/devtools_android_bridge.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
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/devtools_android_bridge.h" 5 #include "chrome/browser/devtools/device/devtools_android_bridge.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 357 }
358 358
359 DevToolsAndroidBridge::AgentHostDelegate::~AgentHostDelegate() { 359 DevToolsAndroidBridge::AgentHostDelegate::~AgentHostDelegate() {
360 if (bridge_) 360 if (bridge_)
361 bridge_->host_delegates_.erase(id_); 361 bridge_->host_delegates_.erase(id_);
362 } 362 }
363 363
364 void DevToolsAndroidBridge::AgentHostDelegate::Attach( 364 void DevToolsAndroidBridge::AgentHostDelegate::Attach(
365 content::DevToolsExternalAgentProxy* proxy) { 365 content::DevToolsExternalAgentProxy* proxy) {
366 proxy_ = proxy; 366 proxy_ = proxy;
367 content::RecordAction(browser_id_.second.find(kWebViewSocketPrefix) == 0 ? 367 content::RecordAction(
368 base::UserMetricsAction("DevTools_InspectAndroidWebView") : 368 base::StartsWith(browser_id_.second, kWebViewSocketPrefix,
369 base::UserMetricsAction("DevTools_InspectAndroidPage")); 369 base::CompareCase::SENSITIVE)
370 ? base::UserMetricsAction("DevTools_InspectAndroidWebView")
371 : base::UserMetricsAction("DevTools_InspectAndroidPage"));
370 372
371 // Retain the device so it's not released until AgentHost is detached. 373 // Retain the device so it's not released until AgentHost is detached.
372 if (bridge_) 374 if (bridge_)
373 device_ = bridge_->FindDevice(browser_id_.first); 375 device_ = bridge_->FindDevice(browser_id_.first);
374 if (!device_.get()) 376 if (!device_.get())
375 return; 377 return;
376 378
377 web_socket_.reset( 379 web_socket_.reset(
378 device_->CreateWebSocket(browser_id_.second, target_path_, this)); 380 device_->CreateWebSocket(browser_id_.second, target_path_, this));
379 } 381 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 const base::DictionaryValue& value) { 461 const base::DictionaryValue& value) {
460 return base::StringPrintf("%s:%s:%s", browser_id.first.c_str(), 462 return base::StringPrintf("%s:%s:%s", browser_id.first.c_str(),
461 browser_id.second.c_str(), GetStringProperty(value, "id").c_str()); 463 browser_id.second.c_str(), GetStringProperty(value, "id").c_str());
462 } 464 }
463 465
464 static std::string GetFrontendURL(const base::DictionaryValue& value) { 466 static std::string GetFrontendURL(const base::DictionaryValue& value) {
465 std::string frontend_url = GetStringProperty(value, "devtoolsFrontendUrl"); 467 std::string frontend_url = GetStringProperty(value, "devtoolsFrontendUrl");
466 size_t ws_param = frontend_url.find("?ws"); 468 size_t ws_param = frontend_url.find("?ws");
467 if (ws_param != std::string::npos) 469 if (ws_param != std::string::npos)
468 frontend_url = frontend_url.substr(0, ws_param); 470 frontend_url = frontend_url.substr(0, ws_param);
469 if (frontend_url.find("http:") == 0) 471 if (base::StartsWith(frontend_url, "http:", base::CompareCase::SENSITIVE))
470 frontend_url = "https:" + frontend_url.substr(5); 472 frontend_url = "https:" + frontend_url.substr(5);
471 return frontend_url; 473 return frontend_url;
472 } 474 }
473 475
474 static std::string GetTargetPath(const base::DictionaryValue& value) { 476 static std::string GetTargetPath(const base::DictionaryValue& value) {
475 std::string target_path = GetStringProperty(value, "webSocketDebuggerUrl"); 477 std::string target_path = GetStringProperty(value, "webSocketDebuggerUrl");
476 478
477 if (target_path.find("ws://") == 0) { 479 if (base::StartsWith(target_path, "ws://", base::CompareCase::SENSITIVE)) {
478 size_t pos = target_path.find("/", 5); 480 size_t pos = target_path.find("/", 5);
479 if (pos == std::string::npos) 481 if (pos == std::string::npos)
480 pos = 5; 482 pos = 5;
481 target_path = target_path.substr(pos); 483 target_path = target_path.substr(pos);
482 } else { 484 } else {
483 target_path = std::string(); 485 target_path = std::string();
484 } 486 }
485 return target_path; 487 return target_path;
486 } 488 }
487 489
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 if (pref_value->GetAsBoolean(&enabled) && enabled) { 945 if (pref_value->GetAsBoolean(&enabled) && enabled) {
944 device_providers.push_back(new UsbDeviceProvider(profile_)); 946 device_providers.push_back(new UsbDeviceProvider(profile_));
945 } 947 }
946 948
947 device_manager_->SetDeviceProviders(device_providers); 949 device_manager_->SetDeviceProviders(device_providers);
948 if (NeedsDeviceListPolling()) { 950 if (NeedsDeviceListPolling()) {
949 StopDeviceListPolling(); 951 StopDeviceListPolling();
950 StartDeviceListPolling(); 952 StartDeviceListPolling();
951 } 953 }
952 } 954 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/device/android_device_info_query.cc ('k') | chrome/browser/extensions/api/proxy/proxy_api_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698