#include "chrome/browser/devtools/device/android_device_manager.h"
#include <stddef.h>
#include <string.h>
#include <string_view>
#include <utility>
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_pump_type.h"
#include "base/no_destructor.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "chrome/browser/devtools/device/usb/usb_device_manager_helper.h"
#include "chrome/browser/devtools/device/usb/usb_device_provider.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/io_buffer.h"
#include "net/base/ip_endpoint.h"
#include "net/base/net_errors.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_util.h"
#include "net/socket/stream_socket.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
BrowserThread;
namespace {
const char kDevToolsAdbBridgeThreadName[] = …;
const int kBufferSize = …;
static const char kModelOffline[] = …;
static const char kRequestLineFormat[] = …;
net::NetworkTrafficAnnotationTag kAndroidDeviceManagerTrafficAnnotation = …;
static void PostDeviceInfoCallback(
scoped_refptr<base::SingleThreadTaskRunner> response_task_runner,
AndroidDeviceManager::DeviceInfoCallback callback,
const AndroidDeviceManager::DeviceInfo& device_info) { … }
static void PostCommandCallback(
scoped_refptr<base::SingleThreadTaskRunner> response_task_runner,
AndroidDeviceManager::CommandCallback callback,
int result,
const std::string& response) { … }
static void PostHttpUpgradeCallback(
scoped_refptr<base::SingleThreadTaskRunner> response_task_runner,
AndroidDeviceManager::HttpUpgradeCallback callback,
int result,
const std::string& extensions,
const std::string& body_head,
std::unique_ptr<net::StreamSocket> socket) { … }
class HttpRequest { … };
class DevicesRequest : public base::RefCountedThreadSafe<DevicesRequest> { … };
void OnCountDevices(base::OnceCallback<void(int)> callback, int device_count) { … }
}
AndroidDeviceManager::BrowserInfo::BrowserInfo()
: … { … }
AndroidDeviceManager::BrowserInfo::BrowserInfo(const BrowserInfo& other) =
default;
AndroidDeviceManager::BrowserInfo& AndroidDeviceManager::BrowserInfo::operator=(
const BrowserInfo& other) = default;
AndroidDeviceManager::DeviceInfo::DeviceInfo()
: … { … }
AndroidDeviceManager::DeviceInfo::DeviceInfo(const DeviceInfo& other) = default;
AndroidDeviceManager::DeviceInfo::~DeviceInfo() { … }
AndroidDeviceManager::DeviceDescriptor::DeviceDescriptor() { … }
AndroidDeviceManager::DeviceDescriptor::DeviceDescriptor(
const DeviceDescriptor& other) = default;
AndroidDeviceManager::DeviceDescriptor::~DeviceDescriptor() { … }
void AndroidDeviceManager::DeviceProvider::SendJsonRequest(
const std::string& serial,
const std::string& socket_name,
const std::string& request,
CommandCallback callback) { … }
void AndroidDeviceManager::DeviceProvider::HttpUpgrade(
const std::string& serial,
const std::string& socket_name,
const std::string& path,
const std::string& extensions,
HttpUpgradeCallback callback) { … }
void AndroidDeviceManager::DeviceProvider::ReleaseDevice(
const std::string& serial) { … }
AndroidDeviceManager::DeviceProvider::DeviceProvider() { … }
AndroidDeviceManager::DeviceProvider::~DeviceProvider() { … }
void AndroidDeviceManager::Device::QueryDeviceInfo(
DeviceInfoCallback callback) { … }
void AndroidDeviceManager::Device::OpenSocket(const std::string& socket_name,
SocketCallback callback) { … }
void AndroidDeviceManager::Device::SendJsonRequest(
const std::string& socket_name,
const std::string& request,
CommandCallback callback) { … }
void AndroidDeviceManager::Device::HttpUpgrade(const std::string& socket_name,
const std::string& path,
const std::string& extensions,
HttpUpgradeCallback callback) { … }
AndroidDeviceManager::Device::Device(
scoped_refptr<base::SingleThreadTaskRunner> device_task_runner,
scoped_refptr<DeviceProvider> provider,
const std::string& serial)
: … { … }
AndroidDeviceManager::Device::~Device() { … }
AndroidDeviceManager::HandlerThread*
AndroidDeviceManager::HandlerThread::GetInstance() { … }
AndroidDeviceManager::HandlerThread::HandlerThread() { … }
scoped_refptr<base::SingleThreadTaskRunner>
AndroidDeviceManager::HandlerThread::message_loop() { … }
void AndroidDeviceManager::HandlerThread::StopThread(
base::Thread* thread) { … }
AndroidDeviceManager::HandlerThread::~HandlerThread() { … }
std::unique_ptr<AndroidDeviceManager> AndroidDeviceManager::Create() { … }
void AndroidDeviceManager::SetDeviceProviders(
const DeviceProviders& providers) { … }
void AndroidDeviceManager::QueryDevices(DevicesCallback callback) { … }
void AndroidDeviceManager::CountDevices(
base::OnceCallback<void(int)> callback) { … }
void AndroidDeviceManager::set_usb_device_manager_for_test(
mojo::PendingRemote<device::mojom::UsbDeviceManager> fake_usb_manager) { … }
AndroidDeviceManager::AndroidDeviceManager()
: … { … }
AndroidDeviceManager::~AndroidDeviceManager() { … }
void AndroidDeviceManager::UpdateDevices(
DevicesCallback callback,
std::unique_ptr<DeviceDescriptors> descriptors) { … }