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

@@ -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_;