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/new_session_cdm_result_promise.h" | 5 #include "media/blink/new_session_cdm_result_promise.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram_functions.h" |
8 #include "media/blink/cdm_result_promise_helper.h" | 9 #include "media/blink/cdm_result_promise_helper.h" |
9 #include "third_party/WebKit/public/platform/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
10 | 11 |
11 namespace media { | 12 namespace media { |
12 | 13 |
| 14 const char kTimeUMAPrefix[] = "TimeTo."; |
| 15 |
13 static blink::WebContentDecryptionModuleResult::SessionStatus ConvertStatus( | 16 static blink::WebContentDecryptionModuleResult::SessionStatus ConvertStatus( |
14 SessionInitStatus status) { | 17 SessionInitStatus status) { |
15 switch (status) { | 18 switch (status) { |
16 case SessionInitStatus::UNKNOWN_STATUS: | 19 case SessionInitStatus::UNKNOWN_STATUS: |
17 break; | 20 break; |
18 case SessionInitStatus::NEW_SESSION: | 21 case SessionInitStatus::NEW_SESSION: |
19 return blink::WebContentDecryptionModuleResult::NewSession; | 22 return blink::WebContentDecryptionModuleResult::NewSession; |
20 case SessionInitStatus::SESSION_NOT_FOUND: | 23 case SessionInitStatus::SESSION_NOT_FOUND: |
21 return blink::WebContentDecryptionModuleResult::SessionNotFound; | 24 return blink::WebContentDecryptionModuleResult::SessionNotFound; |
22 case SessionInitStatus::SESSION_ALREADY_EXISTS: | 25 case SessionInitStatus::SESSION_ALREADY_EXISTS: |
23 return blink::WebContentDecryptionModuleResult::SessionAlreadyExists; | 26 return blink::WebContentDecryptionModuleResult::SessionAlreadyExists; |
24 } | 27 } |
25 NOTREACHED(); | 28 NOTREACHED(); |
26 return blink::WebContentDecryptionModuleResult::SessionNotFound; | 29 return blink::WebContentDecryptionModuleResult::SessionNotFound; |
27 } | 30 } |
28 | 31 |
29 NewSessionCdmResultPromise::NewSessionCdmResultPromise( | 32 NewSessionCdmResultPromise::NewSessionCdmResultPromise( |
30 const blink::WebContentDecryptionModuleResult& result, | 33 const blink::WebContentDecryptionModuleResult& result, |
| 34 const std::string& key_system_uma_prefix, |
31 const std::string& uma_name, | 35 const std::string& uma_name, |
32 const SessionInitializedCB& new_session_created_cb) | 36 const SessionInitializedCB& new_session_created_cb) |
33 : web_cdm_result_(result), | 37 : web_cdm_result_(result), |
| 38 key_system_uma_prefix_(key_system_uma_prefix), |
34 uma_name_(uma_name), | 39 uma_name_(uma_name), |
35 new_session_created_cb_(new_session_created_cb) { | 40 new_session_created_cb_(new_session_created_cb), |
36 } | 41 creation_time_(base::TimeTicks::Now()) {} |
37 | 42 |
38 NewSessionCdmResultPromise::~NewSessionCdmResultPromise() { | 43 NewSessionCdmResultPromise::~NewSessionCdmResultPromise() { |
39 if (!IsPromiseSettled()) | 44 if (!IsPromiseSettled()) |
40 RejectPromiseOnDestruction(); | 45 RejectPromiseOnDestruction(); |
41 } | 46 } |
42 | 47 |
43 void NewSessionCdmResultPromise::resolve(const std::string& session_id) { | 48 void NewSessionCdmResultPromise::resolve(const std::string& session_id) { |
44 // |new_session_created_cb_| uses a WeakPtr<> and may not do anything | 49 // |new_session_created_cb_| uses a WeakPtr<> and may not do anything |
45 // if the session object has been destroyed. | 50 // if the session object has been destroyed. |
46 SessionInitStatus status = SessionInitStatus::UNKNOWN_STATUS; | 51 SessionInitStatus status = SessionInitStatus::UNKNOWN_STATUS; |
47 new_session_created_cb_.Run(session_id, &status); | 52 new_session_created_cb_.Run(session_id, &status); |
48 | 53 |
49 if (status == SessionInitStatus::UNKNOWN_STATUS) { | 54 if (status == SessionInitStatus::UNKNOWN_STATUS) { |
50 reject(INVALID_STATE_ERROR, 0, "Cannot finish session initialization"); | 55 reject(INVALID_STATE_ERROR, 0, "Cannot finish session initialization"); |
51 return; | 56 return; |
52 } | 57 } |
53 | 58 |
54 MarkPromiseSettled(); | 59 MarkPromiseSettled(); |
55 ReportCdmResultUMA(uma_name_, SUCCESS); | 60 ReportCdmResultUMA(key_system_uma_prefix_ + uma_name_, SUCCESS); |
| 61 |
| 62 // Only report time for promise resolution (not rejection). |
| 63 base::UmaHistogramTimes(key_system_uma_prefix_ + kTimeUMAPrefix + uma_name_, |
| 64 base::TimeTicks::Now() - creation_time_); |
| 65 |
56 web_cdm_result_.completeWithSession(ConvertStatus(status)); | 66 web_cdm_result_.completeWithSession(ConvertStatus(status)); |
57 } | 67 } |
58 | 68 |
59 void NewSessionCdmResultPromise::reject(CdmPromise::Exception exception_code, | 69 void NewSessionCdmResultPromise::reject(CdmPromise::Exception exception_code, |
60 uint32_t system_code, | 70 uint32_t system_code, |
61 const std::string& error_message) { | 71 const std::string& error_message) { |
62 MarkPromiseSettled(); | 72 MarkPromiseSettled(); |
63 ReportCdmResultUMA(uma_name_, | 73 ReportCdmResultUMA(uma_name_, |
64 ConvertCdmExceptionToResultForUMA(exception_code)); | 74 ConvertCdmExceptionToResultForUMA(exception_code)); |
65 web_cdm_result_.completeWithError(ConvertCdmException(exception_code), | 75 web_cdm_result_.completeWithError(ConvertCdmException(exception_code), |
66 system_code, | 76 system_code, |
67 blink::WebString::fromUTF8(error_message)); | 77 blink::WebString::fromUTF8(error_message)); |
68 } | 78 } |
69 | 79 |
70 } // namespace media | 80 } // namespace media |
OLD | NEW |