Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/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
  {
28
  }
29
  MediaResult(nsresult aResult, const nsACString& aMessage)
30
    : mCode(aResult)
31
    , mMessage(aMessage)
32
0
  {
33
0
  }
34
  MediaResult(nsresult aResult, const char* aMessage)
35
    : mCode(aResult)
36
    , mMessage(aMessage)
37
  {
38
  }
39
0
  MediaResult(const MediaResult& aOther) = default;
40
0
  MediaResult(MediaResult&& aOther) = default;
41
  MediaResult& operator=(const MediaResult& aOther) = default;
42
  MediaResult& operator=(MediaResult&& aOther) = default;
43
44
  nsresult Code() const { return mCode; }
45
  nsCString ErrorName() const
46
  {
47
    nsCString name;
48
    GetErrorName(mCode, name);
49
    return name;
50
  }
51
52
  const nsCString& Message() const { return mMessage; }
53
54
  // Interoperations with nsresult.
55
0
  bool operator==(nsresult aResult) const { return aResult == mCode; }
56
0
  bool operator!=(nsresult aResult) const { return aResult != mCode; }
57
  operator nsresult () const { return mCode; }
58
59
  nsCString Description() const
60
  {
61
    if (NS_SUCCEEDED(mCode)) {
62
      return nsCString();
63
    }
64
    return nsPrintfCString("%s (0x%08" PRIx32 ")%s%s",
65
                           ErrorName().get(),
66
                           static_cast<uint32_t>(mCode),
67
                           mMessage.IsEmpty() ? "" : " - ",
68
                           mMessage.get());
69
  }
70
71
  void SetGPUCrashTimeStamp(const TimeStamp& aTime) { mGPUCrashTimeStamp = aTime; }
72
0
  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
#define RESULT_DETAIL(arg, ...) nsPrintfCString("%s: " arg, __PRETTY_FUNCTION__, ##__VA_ARGS__)
84
#endif
85
86
} // namespace mozilla
87
#endif // MediaResult_h_