Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Unified Diff: content/renderer/media/cdm_result_promise.cc

Issue 604283003: Refactor CdmPromise and related classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + override Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/cdm_result_promise.h ('k') | content/renderer/media/crypto/ppapi_decryptor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/cdm_result_promise.cc
diff --git a/content/renderer/media/cdm_result_promise.cc b/content/renderer/media/cdm_result_promise.cc
index ad591677b1dde5e859fec400d162629741487e13..5d673f061c385e5d6bec4541ffef37944825c0d9 100644
--- a/content/renderer/media/cdm_result_promise.cc
+++ b/content/renderer/media/cdm_result_promise.cc
@@ -4,12 +4,29 @@
#include "content/renderer/media/cdm_result_promise.h"
-#include "base/bind.h"
#include "base/logging.h"
+#include "base/metrics/histogram.h"
#include "third_party/WebKit/public/platform/WebString.h"
namespace content {
+namespace {
+
+// A superset of media::MediaKeys::Exception for UMA reporting. These values
+// should never be changed as it will affect existing reporting, and must match
+// the values for CdmPromiseResult in tools/metrics/histograms/histograms.xml.
+enum ResultCodeForUMA {
+ SUCCESS = 0,
+ NOT_SUPPORTED_ERROR = 1,
+ INVALID_STATE_ERROR = 2,
+ INVALID_ACCESS_ERROR = 3,
+ QUOTA_EXCEEDED_ERROR = 4,
+ UNKNOWN_ERROR = 5,
+ CLIENT_ERROR = 6,
+ OUTPUT_ERROR = 7,
+ NUM_RESULT_CODES
+};
+
static blink::WebContentDecryptionModuleException ConvertException(
media::MediaKeys::Exception exception_code) {
switch (exception_code) {
@@ -27,95 +44,117 @@ static blink::WebContentDecryptionModuleException ConvertException(
return blink::WebContentDecryptionModuleExceptionClientError;
case media::MediaKeys::OUTPUT_ERROR:
return blink::WebContentDecryptionModuleExceptionOutputError;
- default:
- NOTREACHED();
- return blink::WebContentDecryptionModuleExceptionUnknownError;
}
+ NOTREACHED();
+ return blink::WebContentDecryptionModuleExceptionUnknownError;
+}
+
+static ResultCodeForUMA ConvertExceptionToUMAResult(
+ media::MediaKeys::Exception exception_code) {
+ switch (exception_code) {
+ case media::MediaKeys::NOT_SUPPORTED_ERROR:
+ return NOT_SUPPORTED_ERROR;
+ case media::MediaKeys::INVALID_STATE_ERROR:
+ return INVALID_STATE_ERROR;
+ case media::MediaKeys::INVALID_ACCESS_ERROR:
+ return INVALID_ACCESS_ERROR;
+ case media::MediaKeys::QUOTA_EXCEEDED_ERROR:
+ return QUOTA_EXCEEDED_ERROR;
+ case media::MediaKeys::UNKNOWN_ERROR:
+ return UNKNOWN_ERROR;
+ case media::MediaKeys::CLIENT_ERROR:
+ return CLIENT_ERROR;
+ case media::MediaKeys::OUTPUT_ERROR:
+ return OUTPUT_ERROR;
+ }
+ NOTREACHED();
+ return UNKNOWN_ERROR;
}
-template <typename T>
-CdmResultPromise<T>::CdmResultPromise(
- const blink::WebContentDecryptionModuleResult& result)
- : media::CdmPromiseTemplate<T>(
- base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
- base::Bind(&CdmResultPromise::OnReject, base::Unretained(this))),
- web_cdm_result_(result) {
+static void ReportUMA(std::string uma_name, ResultCodeForUMA result) {
+ if (uma_name.empty())
+ return;
+
+ base::LinearHistogram::FactoryGet(
+ uma_name,
+ 1,
+ NUM_RESULT_CODES,
+ NUM_RESULT_CODES + 1,
+ base::HistogramBase::kUmaTargetedHistogramFlag)->Add(result);
}
-template <typename T>
-CdmResultPromise<T>::CdmResultPromise(
+} // namespace
+
+template <typename... T>
+CdmResultPromise<T...>::CdmResultPromise(
const blink::WebContentDecryptionModuleResult& result,
const std::string& uma_name)
- : media::CdmPromiseTemplate<T>(
- base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
- base::Bind(&CdmResultPromise::OnReject, base::Unretained(this)),
- uma_name),
- web_cdm_result_(result) {
+ : web_cdm_result_(result), uma_name_(uma_name) {
}
-template <typename T>
-CdmResultPromise<T>::~CdmResultPromise() {
+template <typename... T>
+CdmResultPromise<T...>::~CdmResultPromise() {
}
template <>
-void CdmResultPromise<std::string>::OnResolve(const std::string& result) {
- // This must be overridden in a subclass.
- NOTREACHED();
+void CdmResultPromise<>::resolve() {
+ MarkPromiseSettled();
+ ReportUMA(uma_name_, SUCCESS);
+ web_cdm_result_.complete();
}
template <>
-void CdmResultPromise<media::KeyIdsVector>::OnResolve(
+void CdmResultPromise<media::KeyIdsVector>::resolve(
const media::KeyIdsVector& result) {
// TODO(jrummell): Update blink::WebContentDecryptionModuleResult to
// handle the set of keys.
- OnReject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented.");
+ reject(media::MediaKeys::NOT_SUPPORTED_ERROR, 0, "Not implemented.");
}
-template <typename T>
-void CdmResultPromise<T>::OnReject(media::MediaKeys::Exception exception_code,
- uint32 system_code,
- const std::string& error_message) {
+template <typename... T>
+void CdmResultPromise<T...>::reject(media::MediaKeys::Exception exception_code,
+ uint32 system_code,
+ const std::string& error_message) {
+ MarkPromiseSettled();
+ ReportUMA(uma_name_, ConvertExceptionToUMAResult(exception_code));
web_cdm_result_.completeWithError(ConvertException(exception_code),
system_code,
blink::WebString::fromUTF8(error_message));
}
-CdmResultPromise<void>::CdmResultPromise(
- const blink::WebContentDecryptionModuleResult& result)
- : media::CdmPromiseTemplate<void>(
- base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
- base::Bind(&CdmResultPromise::OnReject, base::Unretained(this))),
- web_cdm_result_(result) {
-}
-
-CdmResultPromise<void>::CdmResultPromise(
+NewSessionCdmResultPromise::NewSessionCdmResultPromise(
const blink::WebContentDecryptionModuleResult& result,
- const std::string& uma_name)
- : media::CdmPromiseTemplate<void>(
- base::Bind(&CdmResultPromise::OnResolve, base::Unretained(this)),
- base::Bind(&CdmResultPromise::OnReject, base::Unretained(this)),
- uma_name),
- web_cdm_result_(result) {
+ const std::string& uma_name,
+ const SessionInitializedCB& new_session_created_cb)
+ : web_cdm_result_(result),
+ uma_name_(uma_name),
+ new_session_created_cb_(new_session_created_cb) {
}
-CdmResultPromise<void>::~CdmResultPromise() {
+NewSessionCdmResultPromise::~NewSessionCdmResultPromise() {
}
-void CdmResultPromise<void>::OnResolve() {
- web_cdm_result_.complete();
+void NewSessionCdmResultPromise::resolve(const std::string& web_session_id) {
+ MarkPromiseSettled();
+ ReportUMA(uma_name_, SUCCESS);
+ blink::WebContentDecryptionModuleResult::SessionStatus status =
+ new_session_created_cb_.Run(web_session_id);
+ web_cdm_result_.completeWithSession(status);
}
-void CdmResultPromise<void>::OnReject(
+void NewSessionCdmResultPromise::reject(
media::MediaKeys::Exception exception_code,
uint32 system_code,
const std::string& error_message) {
+ MarkPromiseSettled();
+ ReportUMA(uma_name_, ConvertExceptionToUMAResult(exception_code));
web_cdm_result_.completeWithError(ConvertException(exception_code),
system_code,
blink::WebString::fromUTF8(error_message));
}
// Explicit template instantiation for the templates needed.
-template class CdmResultPromise<std::string>;
+template class CdmResultPromise<>;
template class CdmResultPromise<media::KeyIdsVector>;
} // namespace content
« no previous file with comments | « content/renderer/media/cdm_result_promise.h ('k') | content/renderer/media/crypto/ppapi_decryptor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698