#include "chrome/browser/sharing/sharing_device_registration_impl.h"
#include <stdint.h>
#include <vector>
#include "base/base64url.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/gcm_driver/crypto/p256_key_util.h"
#include "components/gcm_driver/instance_id/instance_id_driver.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/prefs/pref_service.h"
#include "components/sharing_message/buildflags.h"
#include "components/sharing_message/pref_names.h"
#include "components/sharing_message/sharing_constants.h"
#include "components/sharing_message/sharing_device_registration_result.h"
#include "components/sharing_message/sharing_sync_preference.h"
#include "components/sharing_message/sharing_target_device_info.h"
#include "components/sharing_message/sharing_utils.h"
#include "components/sharing_message/vapid_key_manager.h"
#include "components/sync/service/sync_service.h"
#include "components/sync_device_info/device_info.h"
#include "crypto/ec_private_key.h"
#if BUILDFLAG(IS_ANDROID)
#include "chrome/android/chrome_jni_headers/SharingJNIBridge_jni.h"
#endif
InstanceID;
SharingSpecificFields;
SharingDeviceRegistrationImpl::SharingDeviceRegistrationImpl(
PrefService* pref_service,
SharingSyncPreference* sharing_sync_preference,
VapidKeyManager* vapid_key_manager,
instance_id::InstanceIDDriver* instance_id_driver,
syncer::SyncService* sync_service)
: … { … }
SharingDeviceRegistrationImpl::~SharingDeviceRegistrationImpl() = default;
void SharingDeviceRegistrationImpl::RegisterDevice(
RegistrationCallback callback) { … }
void SharingDeviceRegistrationImpl::RetrieveTargetInfo(
const std::string& authorized_entity,
TargetInfoCallback callback) { … }
void SharingDeviceRegistrationImpl::OnFCMTokenReceived(
TargetInfoCallback callback,
const std::string& authorized_entity,
const std::string& fcm_token,
instance_id::InstanceID::Result result) { … }
void SharingDeviceRegistrationImpl::OnEncryptionInfoReceived(
TargetInfoCallback callback,
const std::string& fcm_token,
std::string p256dh,
std::string auth_secret) { … }
void SharingDeviceRegistrationImpl::OnVapidTargetInfoRetrieved(
RegistrationCallback callback,
std::optional<std::string> authorized_entity,
SharingDeviceRegistrationResult result,
std::optional<syncer::DeviceInfo::SharingTargetInfo> vapid_target_info) { … }
void SharingDeviceRegistrationImpl::OnSharingTargetInfoRetrieved(
RegistrationCallback callback,
std::optional<std::string> authorized_entity,
std::optional<syncer::DeviceInfo::SharingTargetInfo> vapid_target_info,
SharingDeviceRegistrationResult result,
std::optional<syncer::DeviceInfo::SharingTargetInfo> sharing_target_info) { … }
void SharingDeviceRegistrationImpl::UnregisterDevice(
RegistrationCallback callback) { … }
void SharingDeviceRegistrationImpl::OnVapidFCMTokenDeleted(
RegistrationCallback callback,
SharingDeviceRegistrationResult result) { … }
void SharingDeviceRegistrationImpl::DeleteFCMToken(
const std::string& authorized_entity,
RegistrationCallback callback) { … }
void SharingDeviceRegistrationImpl::OnFCMTokenDeleted(
RegistrationCallback callback,
InstanceID::Result result) { … }
std::optional<std::string>
SharingDeviceRegistrationImpl::GetAuthorizationEntity() const { … }
std::set<SharingSpecificFields::EnabledFeatures>
SharingDeviceRegistrationImpl::GetEnabledFeatures(bool supports_vapid) const { … }
bool SharingDeviceRegistrationImpl::IsClickToCallSupported() const { … }
bool SharingDeviceRegistrationImpl::IsSharedClipboardSupported() const { … }
bool SharingDeviceRegistrationImpl::IsSmsFetcherSupported() const { … }
bool SharingDeviceRegistrationImpl::IsRemoteCopySupported() const { … }
bool SharingDeviceRegistrationImpl::
IsOptimizationGuidePushNotificationSupported() const { … }
void SharingDeviceRegistrationImpl::SetEnabledFeaturesForTesting(
std::set<SharingSpecificFields::EnabledFeatures> enabled_features) { … }