Switch to using shared_ptr for Session Metrics

[ Merge from http://go/wvgerrit/71443 ]

The assumption that the metrics will always outlive the CdmSession
instance appears not to always hold (at least in a non-android
multi-threaded solution). The shared_ptr ensures that the metrics
are available even in these rare race conditions.

BUG: http://b/123321465
Test: CDM unit tests. Also http://go/wvgerrit/71264 parallel tests.
Change-Id: Iaa6a8f6c0fdc46a911789759d6e1228d849aa237
This commit is contained in:
Adam Stone
2019-01-29 11:27:21 -08:00
parent 9f31068de6
commit 05599927b9
8 changed files with 32 additions and 24 deletions

View File

@@ -154,7 +154,7 @@ void CryptoMetrics::Serialize(WvCdmMetrics::CryptoMetrics *crypto_metrics)
crypto_metrics->mutable_oemcrypto_update_usage_entry());
}
SessionMetrics::SessionMetrics() {}
SessionMetrics::SessionMetrics() : session_id_(""), completed_(false) {}
void SessionMetrics::Serialize(WvCdmMetrics::SessionMetrics *session_metrics)
const {
@@ -268,10 +268,10 @@ EngineMetrics::~EngineMetrics() {
}
}
SessionMetrics *EngineMetrics::AddSession() {
std::shared_ptr<SessionMetrics> EngineMetrics::AddSession() {
std::unique_lock<std::mutex> lock(session_metrics_lock_);
active_session_metrics_list_.push_back(std::make_shared<SessionMetrics>());
return active_session_metrics_list_.back().get();
return active_session_metrics_list_.back();
}
void EngineMetrics::RemoveSession(wvcdm::CdmSessionId session_id) {