#include "chrome/browser/media/router/discovery/access_code/access_code_cast_discovery_interface.h"
#include <cstddef>
#include <optional>
#include <string>
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "chrome/browser/media/router/discovery/access_code/access_code_cast_constants.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "components/signin/public/base/consent_level.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace media_router {
namespace {
constexpr char kLoggerComponent[] = …;
AddSinkResultCode;
constexpr base::TimeDelta kTimeout = …;
const net::NetworkTrafficAnnotationTag kTrafficAnnotation = …;
std::string GetDiscoveryUrl() { … }
}
AccessCodeCastDiscoveryInterface::AccessCodeCastDiscoveryInterface(
Profile* profile,
const std::string& access_code,
LoggerImpl* logger,
signin::IdentityManager* identity_manager)
: … { … }
AccessCodeCastDiscoveryInterface::~AccessCodeCastDiscoveryInterface() = default;
void AccessCodeCastDiscoveryInterface::ReportErrorViaCallback(
AddSinkResultCode error) { … }
AddSinkResultCode AccessCodeCastDiscoveryInterface::GetErrorFromResponse(
const base::Value& response) { … }
AddSinkResultCode AccessCodeCastDiscoveryInterface::IsResponseValid(
const std::optional<base::Value>& response) { … }
void AccessCodeCastDiscoveryInterface::SetDeviceCapabilitiesField(
chrome_browser_media::proto::DeviceCapabilities* device_proto,
bool value,
const std::string& key) { … }
void AccessCodeCastDiscoveryInterface::SetNetworkInfoField(
chrome_browser_media::proto::NetworkInfo* network_proto,
const std::string& value,
const std::string& key) { … }
std::unique_ptr<EndpointFetcher>
AccessCodeCastDiscoveryInterface::CreateEndpointFetcher(
const std::string& access_code) { … }
void AccessCodeCastDiscoveryInterface::ValidateDiscoveryAccessCode(
DiscoveryDeviceCallback callback) { … }
std::unique_ptr<EndpointFetcher>
AccessCodeCastDiscoveryInterface::CreateEndpointFetcherForTesting(
const std::string& access_code) { … }
void AccessCodeCastDiscoveryInterface::HandleServerErrorForTesting(
std::unique_ptr<EndpointResponse> endpoint_response) { … }
void AccessCodeCastDiscoveryInterface::HandleServerResponse(
std::unique_ptr<EndpointResponse> response) { … }
void AccessCodeCastDiscoveryInterface::HandleServerError(
std::unique_ptr<EndpointResponse> response) { … }
std::pair<std::optional<AccessCodeCastDiscoveryInterface::DiscoveryDevice>,
AccessCodeCastDiscoveryInterface::AddSinkResultCode>
AccessCodeCastDiscoveryInterface::ConstructDiscoveryDeviceFromJson(
base::Value json_response) { … }
}