Implement operations used in the DeviceToDevice protocol.
[chromium-blink-merge.git] / media / blink / cdm_result_promise_helper.cc
blobc96121a0fed7aac94bb58165df4f8112e9b12b74
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/blink/cdm_result_promise_helper.h"
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
10 namespace media {
12 CdmResultForUMA ConvertCdmExceptionToResultForUMA(
13 MediaKeys::Exception exception_code) {
14 switch (exception_code) {
15 case MediaKeys::NOT_SUPPORTED_ERROR:
16 return NOT_SUPPORTED_ERROR;
17 case MediaKeys::INVALID_STATE_ERROR:
18 return INVALID_STATE_ERROR;
19 case MediaKeys::INVALID_ACCESS_ERROR:
20 return INVALID_ACCESS_ERROR;
21 case MediaKeys::QUOTA_EXCEEDED_ERROR:
22 return QUOTA_EXCEEDED_ERROR;
23 case MediaKeys::UNKNOWN_ERROR:
24 return UNKNOWN_ERROR;
25 case MediaKeys::CLIENT_ERROR:
26 return CLIENT_ERROR;
27 case MediaKeys::OUTPUT_ERROR:
28 return OUTPUT_ERROR;
30 NOTREACHED();
31 return UNKNOWN_ERROR;
34 blink::WebContentDecryptionModuleException ConvertCdmException(
35 MediaKeys::Exception exception_code) {
36 switch (exception_code) {
37 case MediaKeys::NOT_SUPPORTED_ERROR:
38 return blink::WebContentDecryptionModuleExceptionNotSupportedError;
39 case MediaKeys::INVALID_STATE_ERROR:
40 return blink::WebContentDecryptionModuleExceptionInvalidStateError;
41 case MediaKeys::INVALID_ACCESS_ERROR:
42 return blink::WebContentDecryptionModuleExceptionInvalidAccessError;
43 case MediaKeys::QUOTA_EXCEEDED_ERROR:
44 return blink::WebContentDecryptionModuleExceptionQuotaExceededError;
45 case MediaKeys::UNKNOWN_ERROR:
46 return blink::WebContentDecryptionModuleExceptionUnknownError;
47 case MediaKeys::CLIENT_ERROR:
48 return blink::WebContentDecryptionModuleExceptionClientError;
49 case MediaKeys::OUTPUT_ERROR:
50 return blink::WebContentDecryptionModuleExceptionOutputError;
52 NOTREACHED();
53 return blink::WebContentDecryptionModuleExceptionUnknownError;
56 void ReportCdmResultUMA(const std::string& uma_name, CdmResultForUMA result) {
57 if (uma_name.empty())
58 return;
60 base::LinearHistogram::FactoryGet(
61 uma_name,
63 NUM_RESULT_CODES,
64 NUM_RESULT_CODES + 1,
65 base::HistogramBase::kUmaTargetedHistogramFlag)->Add(result);
68 } // namespace media