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 "chrome/browser/devtools/device/devtools_android_bridge.h" | 5 #include "chrome/browser/devtools/device/devtools_android_bridge.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/base64.h" | 11 #include "base/base64.h" |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
14 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
15 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
16 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
38 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
39 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
40 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 41 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
41 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 42 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
42 #include "components/signin/core/browser/signin_manager.h" | 43 #include "components/signin/core/browser/signin_manager.h" |
43 #include "content/public/browser/devtools_agent_host.h" | 44 #include "content/public/browser/devtools_agent_host.h" |
44 #include "content/public/browser/devtools_external_agent_proxy.h" | 45 #include "content/public/browser/devtools_external_agent_proxy.h" |
45 #include "content/public/browser/devtools_external_agent_proxy_delegate.h" | 46 #include "content/public/browser/devtools_external_agent_proxy_delegate.h" |
46 #include "content/public/browser/user_metrics.h" | 47 #include "content/public/browser/user_metrics.h" |
47 #include "net/base/escape.h" | 48 #include "net/base/escape.h" |
49 #include "net/base/host_port_pair.h" | |
48 #include "net/base/net_errors.h" | 50 #include "net/base/net_errors.h" |
49 | 51 |
50 using content::BrowserThread; | 52 using content::BrowserThread; |
51 | 53 |
52 namespace { | 54 namespace { |
53 | 55 |
54 const char kPageListRequest[] = "/json"; | 56 const char kPageListRequest[] = "/json"; |
55 const char kVersionRequest[] = "/json/version"; | 57 const char kVersionRequest[] = "/json/version"; |
56 const char kClosePageRequest[] = "/json/close/%s"; | 58 const char kClosePageRequest[] = "/json/close/%s"; |
57 const char kNewPageRequestWithURL[] = "/json/new?%s"; | 59 const char kNewPageRequestWithURL[] = "/json/new?%s"; |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 void DevToolsAndroidBridge::ScheduleTaskDefault(const base::Closure& task) { | 904 void DevToolsAndroidBridge::ScheduleTaskDefault(const base::Closure& task) { |
903 BrowserThread::PostDelayedTask( | 905 BrowserThread::PostDelayedTask( |
904 BrowserThread::UI, | 906 BrowserThread::UI, |
905 FROM_HERE, | 907 FROM_HERE, |
906 task, | 908 task, |
907 base::TimeDelta::FromMilliseconds(kAdbPollingIntervalMs)); | 909 base::TimeDelta::FromMilliseconds(kAdbPollingIntervalMs)); |
908 } | 910 } |
909 | 911 |
910 void DevToolsAndroidBridge::CreateDeviceProviders() { | 912 void DevToolsAndroidBridge::CreateDeviceProviders() { |
911 AndroidDeviceManager::DeviceProviders device_providers; | 913 AndroidDeviceManager::DeviceProviders device_providers; |
914 | |
915 std::set<net::HostPortPair> targets; | |
916 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
917 if (command_line->HasSwitch(switches::kRemoteDebuggingTargets)) { | |
dgozman
2015/07/06 10:08:33
Could you please extract a method?
yurys
2015/07/06 13:57:07
Done.
| |
918 std::string value = | |
919 command_line->GetSwitchValueASCII(switches::kRemoteDebuggingTargets); | |
920 std::vector<std::string> addresses = base::SplitString( | |
921 value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
922 for (const std::string& address : addresses) { | |
923 net::HostPortPair target = net::HostPortPair::FromString(address); | |
924 if (target.IsEmpty()) { | |
925 LOG(WARNING) << "Invalid target: " << address; | |
926 continue; | |
927 } | |
928 targets.insert(target); | |
929 } | |
912 #if defined(DEBUG_DEVTOOLS) | 930 #if defined(DEBUG_DEVTOOLS) |
913 RemoteDebuggingServer::EnableTetheringForDebug(); | 931 } else { |
914 // We cannot rely on command line switch here as we might want to connect | 932 RemoteDebuggingServer::EnableTetheringForDebug(); |
915 // to another instance of Chrome. Using hard-coded port number instead. | 933 // We cannot rely on command line switch here as we might want to connect |
916 const int kDefaultDebuggingPort = 9222; | 934 // to another instance of Chrome. Using hard-coded port number instead. |
917 device_providers.push_back(new SelfAsDeviceProvider(kDefaultDebuggingPort)); | 935 const int kDefaultDebuggingPort = 9222; |
936 targets.insert(net::HostPortPair("127.0.0.1", kDefaultDebuggingPort)); | |
918 #endif | 937 #endif |
938 } | |
939 if (!targets.empty()) { | |
pfeldman
2015/07/06 10:10:04
s/{}//
yurys
2015/07/06 12:49:00
Done.
| |
940 device_providers.push_back(new SelfAsDeviceProvider(targets)); | |
941 } | |
919 device_providers.push_back(new AdbDeviceProvider()); | 942 device_providers.push_back(new AdbDeviceProvider()); |
920 | 943 |
921 PrefService* service = profile_->GetPrefs(); | 944 PrefService* service = profile_->GetPrefs(); |
922 const PrefService::Preference* pref = | 945 const PrefService::Preference* pref = |
923 service->FindPreference(prefs::kDevToolsDiscoverUsbDevicesEnabled); | 946 service->FindPreference(prefs::kDevToolsDiscoverUsbDevicesEnabled); |
924 const base::Value* pref_value = pref->GetValue(); | 947 const base::Value* pref_value = pref->GetValue(); |
925 | 948 |
926 bool enabled; | 949 bool enabled; |
927 if (pref_value->GetAsBoolean(&enabled) && enabled) { | 950 if (pref_value->GetAsBoolean(&enabled) && enabled) { |
928 device_providers.push_back(new UsbDeviceProvider(profile_)); | 951 device_providers.push_back(new UsbDeviceProvider(profile_)); |
929 } | 952 } |
930 | 953 |
931 if (IsWebRTCDeviceProviderEnabled()) { | 954 if (IsWebRTCDeviceProviderEnabled()) { |
932 device_providers.push_back( | 955 device_providers.push_back( |
933 new WebRTCDeviceProvider(profile_, signin_manager_, token_service_)); | 956 new WebRTCDeviceProvider(profile_, signin_manager_, token_service_)); |
934 } | 957 } |
935 | 958 |
936 device_manager_->SetDeviceProviders(device_providers); | 959 device_manager_->SetDeviceProviders(device_providers); |
937 if (NeedsDeviceListPolling()) { | 960 if (NeedsDeviceListPolling()) { |
938 StopDeviceListPolling(); | 961 StopDeviceListPolling(); |
939 StartDeviceListPolling(); | 962 StartDeviceListPolling(); |
940 } | 963 } |
941 } | 964 } |
OLD | NEW |