2015-06-03 04:42:50 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef __DetailedPromise_h__
|
|
|
|
#define __DetailedPromise_h__
|
|
|
|
|
|
|
|
#include "mozilla/dom/Promise.h"
|
2015-09-23 07:43:46 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2015-07-27 02:52:19 +03:00
|
|
|
#include "EMEUtils.h"
|
2015-06-03 04:42:50 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is pretty horrible; bug 1160445.
|
|
|
|
* Extend Promise to add custom DOMException messages on rejection.
|
|
|
|
* Get rid of this once we've ironed out EME errors in the wild.
|
|
|
|
*/
|
|
|
|
class DetailedPromise : public Promise
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static already_AddRefed<DetailedPromise>
|
2015-09-23 07:43:46 +03:00
|
|
|
Create(nsIGlobalObject* aGlobal,
|
|
|
|
ErrorResult& aRv,
|
|
|
|
const nsACString& aName);
|
|
|
|
|
|
|
|
static already_AddRefed<DetailedPromise>
|
|
|
|
Create(nsIGlobalObject* aGlobal, ErrorResult& aRv,
|
|
|
|
const nsACString& aName,
|
2017-02-15 22:15:15 +03:00
|
|
|
Telemetry::HistogramID aSuccessLatencyProbe,
|
|
|
|
Telemetry::HistogramID aFailureLatencyProbe);
|
2015-06-03 04:42:50 +03:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void MaybeResolve(const T& aArg)
|
|
|
|
{
|
2015-07-27 02:52:19 +03:00
|
|
|
EME_LOG("%s promise resolved", mName.get());
|
2015-09-23 07:43:46 +03:00
|
|
|
MaybeReportTelemetry(Succeeded);
|
2015-06-03 04:42:50 +03:00
|
|
|
Promise::MaybeResolve<T>(aArg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MaybeReject(nsresult aArg) = delete;
|
2015-06-05 12:55:52 +03:00
|
|
|
void MaybeReject(nsresult aArg, const nsACString& aReason);
|
2015-06-03 04:42:50 +03:00
|
|
|
|
|
|
|
void MaybeReject(ErrorResult& aArg) = delete;
|
2015-06-05 12:55:52 +03:00
|
|
|
void MaybeReject(ErrorResult&, const nsACString& aReason);
|
2015-06-03 04:42:50 +03:00
|
|
|
|
|
|
|
private:
|
2015-09-23 07:43:46 +03:00
|
|
|
explicit DetailedPromise(nsIGlobalObject* aGlobal,
|
|
|
|
const nsACString& aName);
|
|
|
|
|
|
|
|
explicit DetailedPromise(nsIGlobalObject* aGlobal,
|
|
|
|
const nsACString& aName,
|
2017-02-15 22:15:15 +03:00
|
|
|
Telemetry::HistogramID aSuccessLatencyProbe,
|
|
|
|
Telemetry::HistogramID aFailureLatencyProbe);
|
2015-06-03 04:42:50 +03:00
|
|
|
virtual ~DetailedPromise();
|
|
|
|
|
2015-09-23 07:43:46 +03:00
|
|
|
enum Status { Succeeded, Failed };
|
|
|
|
void MaybeReportTelemetry(Status aStatus);
|
|
|
|
|
2015-07-27 02:52:19 +03:00
|
|
|
nsCString mName;
|
2015-06-03 04:42:50 +03:00
|
|
|
bool mResponded;
|
2015-09-23 07:43:46 +03:00
|
|
|
TimeStamp mStartTime;
|
2017-02-15 22:15:15 +03:00
|
|
|
Optional<Telemetry::HistogramID> mSuccessLatencyProbe;
|
|
|
|
Optional<Telemetry::HistogramID> mFailureLatencyProbe;
|
2015-06-03 04:42:50 +03:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2015-06-03 04:42:50 +03:00
|
|
|
|
|
|
|
#endif // __DetailedPromise_h__
|