chromium/chrome/browser/policy/messaging_layer/util/upload_response_parser.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 "chrome/browser/policy/messaging_layer/util/upload_response_parser.h"

#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include <utility>

#include "base/base64.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/token.h"
#include "base/types/expected.h"
#include "base/types/expected_macros.h"
#include "base/uuid.h"
#include "base/values.h"
#include "chrome/browser/policy/messaging_layer/upload/record_upload_request_builder.h"
#include "components/reporting/proto/synced/configuration_file.pb.h"
#include "components/reporting/util/encrypted_reporting_json_keys.h"
#include "components/reporting/util/reporting_errors.h"
#include "components/reporting/util/status.h"
#include "components/reporting/util/status_macros.h"
#include "components/reporting/util/statusor.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"

namespace reporting {
namespace {

// Priority could come back as an int or as a std::string, this function handles
// both situations.
std::optional<Priority> GetPriorityProtoFromSequenceInformationValue(
    const base::Value::Dict& sequence_information) {}

// Returns a tuple of <SequencingId, GenerationId> if `sequencing_id` and
// `generation_id` can be parsed as numbers. Returns error status otherwise.
StatusOr<std::tuple<int64_t, int64_t>> ParseSequencingIdAndGenerationId(
    const std::string* sequencing_id,
    const std::string* generation_id) {}

// Destination comes back as a string from the server, transform it into a
// proto.
StatusOr<Destination> GetDestinationProto(
    const std::string& destination_string) {}

StatusOr<ConfigFile> GetConfigurationProtoFromDict(
    const base::Value::Dict& file) {}
}  // namespace

UploadResponseParser::UploadResponseParser(bool is_generation_guid_required,
                                           base::Value::Dict response)
    :{}

UploadResponseParser::UploadResponseParser(UploadResponseParser&& other) =
    default;
UploadResponseParser& UploadResponseParser::operator=(
    UploadResponseParser&& other) = default;

UploadResponseParser::~UploadResponseParser() = default;

StatusOr<SequenceInformation>
UploadResponseParser::last_successfully_uploaded_record_sequence_info() const {}

StatusOr<SignedEncryptionInfo> UploadResponseParser::encryption_settings()
    const {}

StatusOr<ConfigFile> UploadResponseParser::config_file() const {}

StatusOr<EncryptedRecord>
UploadResponseParser::gap_record_for_permanent_failure() const {}

bool UploadResponseParser::force_confirm_flag() const {}

bool UploadResponseParser::enable_upload_size_adjustment() const {}

#if BUILDFLAG(IS_CHROMEOS)
// Returns true if `generation_guid` can be parsed as a GUID or if
// `generation_guid` does not need to be parsed based on the type of device.
// Returns false otherwise.
bool GenerationGuidIsValid(bool is_generation_guid_required,
                           const std::string& generation_guid) {
  if (generation_guid.empty() && !is_generation_guid_required) {
    // This is a legacy ChromeOS managed device and is not required to have
    // a `generation_guid`.
    return true;
  }
  // If the generation guid has some value, try to parse it.
  return base::Uuid::ParseCaseInsensitive(generation_guid).is_valid();
}

// Returns true if `generation_guid` is required and missing.
// Returns false otherwise.
bool IsMissingGenerationGuid(bool is_generation_guid_required,
                             const std::string* generation_guid) {
  if (!is_generation_guid_required) {
    return false;
  }
  return !generation_guid || generation_guid->empty();
}
#endif  // BUILDFLAG(IS_CHROMEOS)

// Returns true if any required sequence info is missing. Returns
// false otherwise.
bool IsMissingSequenceInformation(bool is_generation_guid_required,
                                  const std::string* sequencing_id,
                                  const std::string* generation_id,
                                  const std::optional<Priority> priority_result,
                                  const std::string* generation_guid) {}

// static
StatusOr<SequenceInformation>
UploadResponseParser::SequenceInformationValueToProto(
    bool is_generation_guid_required,
    const base::Value::Dict& sequence_information_dict) {}

// static
StatusOr<EncryptedRecord>
UploadResponseParser::HandleFailedUploadedSequenceInformation(
    bool is_generation_guid_required,
    const SequenceInformation& highest_sequence_information,
    const base::Value::Dict& sequence_information_dict) {}
}  // namespace reporting