#include "components/data_sharing/internal/preview_server_proxy.h"
#include <optional>
#include <utility>
#include "base/base64.h"
#include "base/json/json_reader.h"
#include "base/json/values_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "components/data_sharing/public/features.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
namespace data_sharing {
namespace {
constexpr base::TimeDelta kTimeout = …;
constexpr char kContentType[] = …;
constexpr char kOAuthName[] = …;
constexpr char kOAuthScope[] = …;
constexpr char kDefaultServiceBaseUrl[] = …;
constexpr base::FeatureParam<std::string> kServiceBaseUrl{ … };
constexpr int kDefaultPreviewDataSize = …;
constexpr base::FeatureParam<int> kPreviewDataSize{ … };
constexpr char kSharedEntitiesKey[] = …;
constexpr char kClientTagHashKey[] = …;
constexpr char kDeletedKey[] = …;
constexpr char kNameKey[] = …;
constexpr char kVersionKey[] = …;
constexpr char kCollaborationKey[] = …;
constexpr char kCollaborationIdKey[] = …;
constexpr char kCreateTimeKey[] = …;
constexpr char kUpdateTimeKey[] = …;
constexpr char kNanosKey[] = …;
constexpr char kSecondsKey[] = …;
constexpr char kSpecificsKey[] = …;
constexpr char kSharedGroupDataKey[] = …;
constexpr char kGuidKey[] = …;
constexpr char kUpdateTimeWindowsEpochMicrosKey[] = …;
constexpr char kTabKey[] = …;
constexpr char kTabGroupKey[] = …;
constexpr char kUrlKey[] = …;
constexpr char kTitleKey[] = …;
constexpr char kFaviconUrlKey[] = …;
constexpr char kSharedTabGroupGuidKey[] = …;
constexpr char kUniquePositionKey[] = …;
constexpr char kCustomCompressedV1Key[] = …;
constexpr char kColorKey[] = …;
constexpr net::NetworkTrafficAnnotationTag
kGetSharedDataPreviewTrafficAnnotation = …;
std::optional<std::string> GetFieldValueFromChildDict(
const base::Value::Dict& parent_dict,
const std::string& child_dict_name,
const std::string& field_name) { … }
std::optional<sync_pb::SharedTab> ParseSharedTab(
const base::Value::Dict& dict) { … }
std::optional<sync_pb::EntitySpecifics> ParseEntitySpecifics(
const base::Value::Dict& dict) { … }
std::optional<base::Time> GetTimeFromDict(const base::Value::Dict& dict,
const std::string& timestamp_name) { … }
std::optional<SharedEntity> Deserialize(const base::Value& value) { … }
}
PreviewServerProxy::PreviewServerProxy(
signin::IdentityManager* identity_manager,
const scoped_refptr<network::SharedURLLoaderFactory>& url_loader_factory)
: … { … }
PreviewServerProxy::~PreviewServerProxy() = default;
void PreviewServerProxy::GetSharedDataPreview(
const GroupToken& group_token,
base::OnceCallback<
void(const DataSharingService::SharedDataPreviewOrFailureOutcome&)>
callback) { … }
std::unique_ptr<EndpointFetcher> PreviewServerProxy::CreateEndpointFetcher(
const GURL& url) { … }
void PreviewServerProxy::HandleServerResponse(
base::OnceCallback<void(
const DataSharingService::SharedDataPreviewOrFailureOutcome&)> callback,
std::unique_ptr<EndpointFetcher> endpoint_fetcher,
std::unique_ptr<EndpointResponse> response) { … }
void PreviewServerProxy::OnResponseJsonParsed(
base::OnceCallback<void(
const DataSharingService::SharedDataPreviewOrFailureOutcome&)> callback,
data_decoder::DataDecoder::ValueOrError result) { … }
}