Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/MediaResult.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:set ts=2 sw=2 sts=2 et cindent: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef MediaResult_h_
8
#define MediaResult_h_
9
10
#include "nsString.h" // Required before 'mozilla/ErrorNames.h'!?
11
#include "mozilla/ErrorNames.h"
12
#include "mozilla/TimeStamp.h"
13
#include "nsError.h"
14
#include "nsPrintfCString.h"
15
16
// MediaResult can be used interchangeably with nsresult.
17
// It allows to store extra information such as where the error occurred.
18
// While nsresult is typically passed by value; due to its potential size, using
19
// MediaResult const references is recommended.
20
namespace mozilla {
21
22
class MediaResult
23
{
24
public:
25
  MOZ_IMPLICIT MediaResult(nsresult aResult)
26
    : mCode(aResult)
27
0
  {
28
0
  }
29
  MediaResult(nsresult aResult, const nsACString& aMessage)
30
    : mCode(aResult)
31
    , mMessage(aMessage)
32
  {
33
  }
34
  MediaResult(nsresult aResult, const char* aMessage)
35
    : mCode(aResult)
36
    , mMessage(aMessage)
37
0
  {
38
0
  }
39
  MediaResult(const MediaResult& aOther) = default;
40
  MediaResult(MediaResult&& aOther) = default;
41
0
  MediaResult& operator=(const MediaResult& aOther) = default;
42
0
  MediaResult& operator=(MediaResult&& aOther) = default;
43
44
0
  nsresult Code() const { return mCode; }
45
  nsCString ErrorName() const
46
0
  {
47
0
    nsCString name;
48
0
    GetErrorName(mCode, name);
49
0
    return name;
50
0
  }
51
52
0
  const nsCString& Message() const { return mMessage; }
53
54
  // Interoperations with nsresult.
55
  bool operator==(nsresult aResult) const { return aResult == mCode; }
56
  bool operator!=(nsresult aResult) const { return aResult != mCode; }
57
0
  operator nsresult () const { return mCode; }
58
59
  nsCString Description() const
60
0
  {
61
0
    if (NS_SUCCEEDED(mCode)) {
62
0
      return nsCString();
63
0
    }
64
0
    return nsPrintfCString("%s (0x%08" PRIx32 ")%s%s",
65
0
                           ErrorName().get(),
66
0
                           static_cast<uint32_t>(mCode),
67
0
                           mMessage.IsEmpty() ? "" : " - ",
68
0
                           mMessage.get());
69
0
  }
70
71
0
  void SetGPUCrashTimeStamp(const TimeStamp& aTime) { mGPUCrashTimeStamp = aTime; }
72
  const TimeStamp& GPUCrashTimeStamp() const { return mGPUCrashTimeStamp; }
73
74
private:
75
  nsresult mCode;
76
  nsCString mMessage;
77
  TimeStamp mGPUCrashTimeStamp; // Used in bug 1393399 for temporary telemetry usage.
78
};
79
80
#ifdef _MSC_VER
81
#define RESULT_DETAIL(arg, ...) nsPrintfCString("%s: " arg, __FUNCSIG__, ##__VA_ARGS__)
82
#else
83
0
#define RESULT_DETAIL(arg, ...) nsPrintfCString("%s: " arg, __PRETTY_FUNCTION__, ##__VA_ARGS__)
84
#endif
85
86
} // namespace mozilla
87
#endif // MediaResult_h_