1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80

media / base / status.cc [blame]

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

#include "media/base/status.h"

#include <memory>

#include "media/base/media_serializers.h"

namespace media {

namespace internal {

StatusData::StatusData() = default;

StatusData::StatusData(const StatusData& copy) {
  *this = copy;
}

StatusData::StatusData(StatusGroupType group,
                       StatusCodeType code,
                       std::string message,
                       UKMPackedType root_cause)
    : group(group),
      code(code),
      message(std::move(message)),
      data(base::Value(base::Value::Type::DICT)),
      packed_root_cause(root_cause) {}

std::unique_ptr<StatusData> StatusData::copy() const {
  auto result =
      std::make_unique<StatusData>(group, code, message, packed_root_cause);
  result->frames = frames.Clone();
  if (cause)
    result->cause = cause->copy();
  result->data = data.Clone();
  return result;
}

StatusData::~StatusData() = default;

StatusData& StatusData::operator=(const StatusData& copy) {
  group = copy.group;
  code = copy.code;
  message = copy.message;
  packed_root_cause = copy.packed_root_cause;
  frames = copy.frames.Clone();
  if (copy.cause)
    cause = copy.cause->copy();
  data = copy.data.Clone();
  return *this;
}

void StatusData::AddLocation(const base::Location& location) {
  frames.Append(MediaSerialize(location));
}

std::ostream& operator<<(std::ostream& stream,
                         const OkStatusImplicitConstructionHelper&) {
  stream << "kOk";
  return stream;
}

}  // namespace internal

const char StatusConstants::kCodeKey[] = "code";
const char StatusConstants::kGroupKey[] = "group";
const char StatusConstants::kMsgKey[] = "message";
const char StatusConstants::kStackKey[] = "stack";
const char StatusConstants::kDataKey[] = "data";
const char StatusConstants::kCauseKey[] = "cause";
const char StatusConstants::kFileKey[] = "file";
const char StatusConstants::kLineKey[] = "line";

internal::OkStatusImplicitConstructionHelper OkStatus() {
  return {};
}

}  // namespace media