chromium/extensions/browser/api/socket/socket_api.h

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_
#define EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_

#include <stddef.h>
#include <stdint.h>

#include <memory>
#include <string>
#include <unordered_set>

#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/public/common/socket_permission_request.h"
#include "extensions/browser/api/api_resource_manager.h"
#include "extensions/browser/extension_function.h"
#include "extensions/common/api/socket.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/permissions/api_permission.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/address_list.h"
#include "net/base/network_change_notifier.h"
#include "net/dns/public/host_resolver_results.h"
#include "net/socket/tcp_client_socket.h"
#include "services/network/public/cpp/resolve_host_client_base.h"
#include "services/network/public/mojom/host_resolver.mojom.h"
#include "services/network/public/mojom/udp_socket.mojom.h"

namespace content {
class BrowserContext;
}  // namespace content

namespace net {
class IOBuffer;
}  // namespace net

namespace network::mojom {
class TLSClientSocket;
class TCPConnectedSocket;
}  // namespace network::mojom

namespace extensions {

#if BUILDFLAG(IS_CHROMEOS_ASH)
extern const char kCrOSTerminal[];
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

class Socket;

// A simple interface to ApiResourceManager<Socket> or derived class. The goal
// of this interface is to allow Socket API functions to use distinct instances
// of ApiResourceManager<> depending on the type of socket (old version in
// "socket" namespace vs new version in "socket.xxx" namespaces).
class SocketResourceManagerInterface {};

// Implementation of SocketResourceManagerInterface using an
// ApiResourceManager<T> instance (where T derives from Socket).
template <typename T>
class SocketResourceManager : public SocketResourceManagerInterface {};

// Base class for socket API functions, with some helper functions.
class SocketApiFunction : public ExtensionFunction {};

class SocketExtensionWithDnsLookupFunction
    : public SocketApiFunction,
      public network::ResolveHostClientBase {};

class SocketCreateFunction : public SocketApiFunction {};

class SocketDestroyFunction : public SocketApiFunction {};

class SocketConnectFunction : public SocketExtensionWithDnsLookupFunction {};

class SocketDisconnectFunction : public SocketApiFunction {};

class SocketBindFunction : public SocketApiFunction {};

class SocketListenFunction : public SocketApiFunction {};

class SocketAcceptFunction : public SocketApiFunction {};

class SocketReadFunction : public SocketApiFunction {};

class SocketWriteFunction : public SocketApiFunction {};

class SocketRecvFromFunction : public SocketApiFunction {};

class SocketSendToFunction : public SocketExtensionWithDnsLookupFunction {};

class SocketSetKeepAliveFunction : public SocketApiFunction {};

class SocketSetNoDelayFunction : public SocketApiFunction {};

class SocketGetInfoFunction : public SocketApiFunction {};

class SocketGetNetworkListFunction : public ExtensionFunction {};

class SocketJoinGroupFunction : public SocketApiFunction {};

class SocketLeaveGroupFunction : public SocketApiFunction {};

class SocketSetMulticastTimeToLiveFunction : public SocketApiFunction {};

class SocketSetMulticastLoopbackModeFunction : public SocketApiFunction {};

class SocketGetJoinedGroupsFunction : public SocketApiFunction {};

class SocketSecureFunction : public SocketApiFunction {};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_