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:
@@ -35,7 +35,8 @@ class CdmSession {
|
||||
// and |metrics| parameters. Both parameters are owned by the caller and
|
||||
// must remain in scope througout the scope of the new instance. |metrics|
|
||||
// must not be null.
|
||||
CdmSession(FileSystem* file_system, metrics::SessionMetrics* metrics);
|
||||
CdmSession(FileSystem* file_system,
|
||||
std::shared_ptr<metrics::SessionMetrics> metrics);
|
||||
virtual ~CdmSession();
|
||||
|
||||
void Close() { closed_ = true; }
|
||||
@@ -198,7 +199,7 @@ class CdmSession {
|
||||
|
||||
virtual CdmResponseType GetDecryptHashError(std::string* hash_error_string);
|
||||
|
||||
virtual metrics::SessionMetrics* GetMetrics() { return metrics_; }
|
||||
virtual metrics::SessionMetrics* GetMetrics() { return metrics_.get(); }
|
||||
|
||||
private:
|
||||
friend class CdmSessionTest;
|
||||
@@ -223,7 +224,7 @@ class CdmSession {
|
||||
void set_file_handle(DeviceFiles* file_handle);
|
||||
|
||||
// instance variables
|
||||
metrics::SessionMetrics* metrics_;
|
||||
std::shared_ptr<metrics::SessionMetrics> metrics_;
|
||||
metrics::CryptoMetrics* crypto_metrics_;
|
||||
metrics::TimerMetric life_span_;
|
||||
metrics::TimerMetric license_request_latency_;
|
||||
|
||||
@@ -133,8 +133,8 @@ CdmResponseType CdmEngine::OpenSession(
|
||||
|
||||
CloseExpiredReleaseSessions();
|
||||
|
||||
std::unique_ptr<CdmSession> new_session(new CdmSession(file_system_,
|
||||
metrics_->AddSession()));
|
||||
std::unique_ptr<CdmSession> new_session(
|
||||
new CdmSession(file_system_, metrics_->AddSession()));
|
||||
CdmResponseType sts = new_session->Init(property_set, forced_session_id,
|
||||
event_listener);
|
||||
if (sts != NO_ERROR) {
|
||||
|
||||
@@ -27,7 +27,7 @@ const size_t kKeySetIdLength = 14;
|
||||
namespace wvcdm {
|
||||
|
||||
CdmSession::CdmSession(FileSystem* file_system,
|
||||
metrics::SessionMetrics* metrics)
|
||||
std::shared_ptr<metrics::SessionMetrics> metrics)
|
||||
: metrics_(metrics),
|
||||
initialized_(false),
|
||||
closed_(true),
|
||||
@@ -47,7 +47,7 @@ CdmSession::CdmSession(FileSystem* file_system,
|
||||
usage_entry_number_(0),
|
||||
mock_license_parser_in_use_(false),
|
||||
mock_policy_engine_in_use_(false) {
|
||||
assert(metrics_); // metrics_ must not be null.
|
||||
assert(metrics_.get()); // metrics_ must not be null.
|
||||
crypto_metrics_ = metrics_->GetCryptoMetrics();
|
||||
crypto_session_.reset(CryptoSession::MakeCryptoSession(crypto_metrics_));
|
||||
life_span_.Start();
|
||||
@@ -67,8 +67,8 @@ CdmSession::~CdmSession() {
|
||||
}
|
||||
Properties::RemoveSessionPropertySet(session_id_);
|
||||
|
||||
if (metrics_) {
|
||||
M_RECORD(metrics_, cdm_session_life_span_, life_span_.AsMs());
|
||||
if (metrics_.get()) {
|
||||
M_RECORD(metrics_.get(), cdm_session_life_span_, life_span_.AsMs());
|
||||
metrics_->SetCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,8 @@ class CdmSessionTest : public WvCdmTestBase {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
WvCdmTestBase::SetUp();
|
||||
cdm_session_.reset(new CdmSession(NULL, &metrics_));
|
||||
metrics_.reset(new metrics::SessionMetrics);
|
||||
cdm_session_.reset(new CdmSession(NULL, metrics_));
|
||||
// Inject testing mocks.
|
||||
license_parser_ = new MockCdmLicense(cdm_session_->session_id());
|
||||
cdm_session_->set_license_parser(license_parser_);
|
||||
@@ -192,7 +193,7 @@ class CdmSessionTest : public WvCdmTestBase {
|
||||
cdm_session_.reset();
|
||||
}
|
||||
|
||||
metrics::SessionMetrics metrics_;
|
||||
std::shared_ptr<metrics::SessionMetrics> metrics_;
|
||||
std::unique_ptr<CdmSession> cdm_session_;
|
||||
MockCdmLicense* license_parser_;
|
||||
metrics::CryptoMetrics crypto_metrics_;
|
||||
|
||||
Reference in New Issue
Block a user