#include <numeric>
#include "chrome/browser/ui/webui/access_code_cast/access_code_cast_handler.h"
#include "base/containers/contains.h"
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/media/router/discovery/access_code/access_code_cast_sink_service_factory.h"
#include "chrome/browser/media/router/discovery/access_code/access_code_media_sink_util.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "components/access_code_cast/common/access_code_cast_metrics.h"
#include "components/media_router/browser/media_router.h"
#include "components/media_router/browser/media_router_factory.h"
#include "components/media_router/common/discovery/media_sink_internal.h"
#include "components/media_router/common/discovery/media_sink_service_base.h"
#include "components/media_router/common/mojom/media_router_mojom_traits.h"
#include "components/sessions/content/session_tab_helper.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
RouteRequestResultCode;
namespace media_router {
namespace {
const char* AddSinkResultCodeToStringHelper(AddSinkResultCode value) { … }
AccessCodeCastCastMode CastModeMetricsHelper(MediaCastMode mode) { … }
AddSinkResultCode AddSinkMetricsCallback(AddSinkResultCode result) { … }
std::string AddSinkResultCodeToString(AddSinkResultCode value) { … }
constexpr char kLoggerComponent[] = …;
std::string CastModeSetToString(
const media_router::CastModeSet& cast_mode_set) { … }
}
AccessCodeCastHandler::AccessCodeCastHandler(
mojo::PendingReceiver<access_code_cast::mojom::PageHandler> page_handler,
mojo::PendingRemote<access_code_cast::mojom::Page> page,
const media_router::CastModeSet& cast_mode_set,
std::unique_ptr<MediaRouteStarter> media_route_starter)
: … { … }
AccessCodeCastHandler::AccessCodeCastHandler(
mojo::PendingReceiver<access_code_cast::mojom::PageHandler> page_handler,
mojo::PendingRemote<access_code_cast::mojom::Page> page,
const media_router::CastModeSet& cast_mode_set,
std::unique_ptr<MediaRouteStarter> media_route_starter,
AccessCodeCastSinkService* access_code_sink_service)
: … { … }
AccessCodeCastHandler::~AccessCodeCastHandler() { … }
void AccessCodeCastHandler::Init() { … }
void AccessCodeCastHandler::AddSink(
const std::string& access_code,
access_code_cast::mojom::CastDiscoveryMethod discovery_method,
AddSinkCallback callback) { … }
bool AccessCodeCastHandler::IsCastModeAvailable(MediaCastMode mode) const { … }
void AccessCodeCastHandler::CheckForDiscoveryCompletion() { … }
void AccessCodeCastHandler::OnSinkAddedResult(
access_code_cast::mojom::AddSinkResultCode add_sink_result,
std::optional<MediaSink::Id> sink_id) { … }
void AccessCodeCastHandler::SetSinkCallbackForTesting(
AddSinkCallback callback) { … }
void AccessCodeCastHandler::OnSinksUpdated(
const std::vector<MediaSinkWithCastModes>& sinks) { … }
void AccessCodeCastHandler::CastToSink(CastToSinkCallback callback) { … }
void AccessCodeCastHandler::OnSinkAddedResultForTesting(
access_code_cast::mojom::AddSinkResultCode add_sink_result,
std::optional<MediaSink::Id> sink_id) { … }
void AccessCodeCastHandler::OnSinksUpdatedForTesting(
const std::vector<MediaSinkWithCastModes>& sinks) { … }
void AccessCodeCastHandler::OnRouteResponse(MediaCastMode cast_mode,
int route_request_id,
const MediaSink::Id& sink_id,
CastToSinkCallback dialog_callback,
const RouteRequestResult& result) { … }
bool AccessCodeCastHandler::HasActiveRoute(const MediaSink::Id& sink_id) { … }
void AccessCodeCastHandler::SetIdentityManagerForTesting(
signin::IdentityManager* identity_manager) { … }
void AccessCodeCastHandler::SetSyncServiceForTesting(
syncer::SyncService* sync_service) { … }
bool AccessCodeCastHandler::IsAccountSyncEnabled() { … }
}