chromium/components/data_sharing/internal/preview_server_proxy.cc

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

#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 {
// RPC timeout duration.
constexpr base::TimeDelta kTimeout =;

// Content type for network request.
constexpr char kContentType[] =;
// OAuth name.
constexpr char kOAuthName[] =;
// OAuth scope of the server.
constexpr char kOAuthScope[] =;

// Server address to get preview data.
constexpr char kDefaultServiceBaseUrl[] =;
constexpr base::FeatureParam<std::string> kServiceBaseUrl{};

// How many share entities to retrieve for preview.
constexpr int kDefaultPreviewDataSize =;
constexpr base::FeatureParam<int> kPreviewDataSize{};

// lowerCamelCase JSON proto message keys.
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[] =;

// Network annotation for getting preview data from server.
constexpr net::NetworkTrafficAnnotationTag
    kGetSharedDataPreviewTrafficAnnotation =;

// Find a a value for a field from a child dictionary in json.
std::optional<std::string> GetFieldValueFromChildDict(
    const base::Value::Dict& parent_dict,
    const std::string& child_dict_name,
    const std::string& field_name) {}

// Parse the shared tab from the dict.
std::optional<sync_pb::SharedTab> ParseSharedTab(
    const base::Value::Dict& dict) {}

// Parse the entity specifics from the dict.
std::optional<sync_pb::EntitySpecifics> ParseEntitySpecifics(
    const base::Value::Dict& dict) {}

// Returns a time for a timestamp object in a child dict.
std::optional<base::Time> GetTimeFromDict(const base::Value::Dict& dict,
                                          const std::string& timestamp_name) {}

// Deserializes a shared entity ID from JSON.
std::optional<SharedEntity> Deserialize(const base::Value& value) {}

}  // namespace

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) {}

}  // namespace data_sharing