| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "media/blink/cdm_result_promise_helper.h" | 5 #include "media/blink/cdm_result_promise_helper.h" | 
| 6 | 6 | 
| 7 #include "base/logging.h" | 7 #include "base/logging.h" | 
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" | 
| 9 | 9 | 
| 10 namespace media { | 10 namespace media { | 
| 11 | 11 | 
| 12 CdmResultForUMA ConvertCdmExceptionToResultForUMA( | 12 CdmResultForUMA ConvertCdmExceptionToResultForUMA( | 
| 13     MediaKeys::Exception exception_code) { | 13     CdmPromise::Exception exception_code) { | 
| 14   switch (exception_code) { | 14   switch (exception_code) { | 
| 15     case MediaKeys::NOT_SUPPORTED_ERROR: | 15     case CdmPromise::NOT_SUPPORTED_ERROR: | 
| 16       return NOT_SUPPORTED_ERROR; | 16       return NOT_SUPPORTED_ERROR; | 
| 17     case MediaKeys::INVALID_STATE_ERROR: | 17     case CdmPromise::INVALID_STATE_ERROR: | 
| 18       return INVALID_STATE_ERROR; | 18       return INVALID_STATE_ERROR; | 
| 19     case MediaKeys::INVALID_ACCESS_ERROR: | 19     case CdmPromise::INVALID_ACCESS_ERROR: | 
| 20       return INVALID_ACCESS_ERROR; | 20       return INVALID_ACCESS_ERROR; | 
| 21     case MediaKeys::QUOTA_EXCEEDED_ERROR: | 21     case CdmPromise::QUOTA_EXCEEDED_ERROR: | 
| 22       return QUOTA_EXCEEDED_ERROR; | 22       return QUOTA_EXCEEDED_ERROR; | 
| 23     case MediaKeys::UNKNOWN_ERROR: | 23     case CdmPromise::UNKNOWN_ERROR: | 
| 24       return UNKNOWN_ERROR; | 24       return UNKNOWN_ERROR; | 
| 25     case MediaKeys::CLIENT_ERROR: | 25     case CdmPromise::CLIENT_ERROR: | 
| 26       return CLIENT_ERROR; | 26       return CLIENT_ERROR; | 
| 27     case MediaKeys::OUTPUT_ERROR: | 27     case CdmPromise::OUTPUT_ERROR: | 
| 28       return OUTPUT_ERROR; | 28       return OUTPUT_ERROR; | 
| 29   } | 29   } | 
| 30   NOTREACHED(); | 30   NOTREACHED(); | 
| 31   return UNKNOWN_ERROR; | 31   return UNKNOWN_ERROR; | 
| 32 } | 32 } | 
| 33 | 33 | 
| 34 blink::WebContentDecryptionModuleException ConvertCdmException( | 34 blink::WebContentDecryptionModuleException ConvertCdmException( | 
| 35     MediaKeys::Exception exception_code) { | 35     CdmPromise::Exception exception_code) { | 
| 36   switch (exception_code) { | 36   switch (exception_code) { | 
| 37     case MediaKeys::NOT_SUPPORTED_ERROR: | 37     case CdmPromise::NOT_SUPPORTED_ERROR: | 
| 38       return blink::WebContentDecryptionModuleExceptionNotSupportedError; | 38       return blink::WebContentDecryptionModuleExceptionNotSupportedError; | 
| 39     case MediaKeys::INVALID_STATE_ERROR: | 39     case CdmPromise::INVALID_STATE_ERROR: | 
| 40       return blink::WebContentDecryptionModuleExceptionInvalidStateError; | 40       return blink::WebContentDecryptionModuleExceptionInvalidStateError; | 
| 41 | 41 | 
| 42     // TODO(jrummell): Since InvalidAccess is not returned, thus should be | 42     // TODO(jrummell): Since InvalidAccess is not returned, thus should be | 
| 43     // renamed to TYPE_ERROR. http://crbug.com/570216#c11. | 43     // renamed to TYPE_ERROR. http://crbug.com/570216#c11. | 
| 44     case MediaKeys::INVALID_ACCESS_ERROR: | 44     case CdmPromise::INVALID_ACCESS_ERROR: | 
| 45       return blink::WebContentDecryptionModuleExceptionTypeError; | 45       return blink::WebContentDecryptionModuleExceptionTypeError; | 
| 46     case MediaKeys::QUOTA_EXCEEDED_ERROR: | 46     case CdmPromise::QUOTA_EXCEEDED_ERROR: | 
| 47       return blink::WebContentDecryptionModuleExceptionQuotaExceededError; | 47       return blink::WebContentDecryptionModuleExceptionQuotaExceededError; | 
| 48     case MediaKeys::UNKNOWN_ERROR: | 48     case CdmPromise::UNKNOWN_ERROR: | 
| 49       return blink::WebContentDecryptionModuleExceptionUnknownError; | 49       return blink::WebContentDecryptionModuleExceptionUnknownError; | 
| 50 | 50 | 
| 51     // These are deprecated, and should be removed. | 51     // These are deprecated, and should be removed. | 
| 52     // http://crbug.com/570216#c11. | 52     // http://crbug.com/570216#c11. | 
| 53     case MediaKeys::CLIENT_ERROR: | 53     case CdmPromise::CLIENT_ERROR: | 
| 54     case MediaKeys::OUTPUT_ERROR: | 54     case CdmPromise::OUTPUT_ERROR: | 
| 55       break; | 55       break; | 
| 56   } | 56   } | 
| 57   NOTREACHED(); | 57   NOTREACHED(); | 
| 58   return blink::WebContentDecryptionModuleExceptionUnknownError; | 58   return blink::WebContentDecryptionModuleExceptionUnknownError; | 
| 59 } | 59 } | 
| 60 | 60 | 
| 61 void ReportCdmResultUMA(const std::string& uma_name, CdmResultForUMA result) { | 61 void ReportCdmResultUMA(const std::string& uma_name, CdmResultForUMA result) { | 
| 62   if (uma_name.empty()) | 62   if (uma_name.empty()) | 
| 63     return; | 63     return; | 
| 64 | 64 | 
| 65   base::LinearHistogram::FactoryGet( | 65   base::LinearHistogram::FactoryGet( | 
| 66       uma_name, | 66       uma_name, | 
| 67       1, | 67       1, | 
| 68       NUM_RESULT_CODES, | 68       NUM_RESULT_CODES, | 
| 69       NUM_RESULT_CODES + 1, | 69       NUM_RESULT_CODES + 1, | 
| 70       base::HistogramBase::kUmaTargetedHistogramFlag)->Add(result); | 70       base::HistogramBase::kUmaTargetedHistogramFlag)->Add(result); | 
| 71 } | 71 } | 
| 72 | 72 | 
| 73 }  // namespace media | 73 }  // namespace media | 
| OLD | NEW | 
|---|