Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit 827a380

Browse files
gfhuangCommit bot
gfhuang
authored and
Commit bot
committed
(1) ExternalMetrics has to destroy itself in file thread due to weakptr.
(2) MetricsService has to stop before destruction of CastBrowserProcess, which is referenced inside MetricsService's stopping code. Review URL: https://codereview.chromium.org/845003002 Cr-Commit-Position: refs/heads/master@{#310958}
1 parent adfd269 commit 827a380

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

chromecast/browser/metrics/cast_metrics_service_client.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,13 @@ CastMetricsServiceClient::CastMetricsServiceClient(
175175
: io_task_runner_(io_task_runner),
176176
pref_service_(pref_service),
177177
cast_service_(NULL),
178+
external_metrics_(NULL),
178179
metrics_service_loop_(base::MessageLoopProxy::current()),
179180
request_context_(request_context) {
180181
}
181182

182183
CastMetricsServiceClient::~CastMetricsServiceClient() {
184+
DCHECK(!external_metrics_);
183185
}
184186

185187
void CastMetricsServiceClient::Initialize(CastService* cast_service) {
@@ -240,7 +242,7 @@ void CastMetricsServiceClient::Initialize(CastService* cast_service) {
240242
// Start external metrics collection, which feeds data from external
241243
// processes into the main external metrics.
242244
#if defined(OS_LINUX)
243-
external_metrics_.reset(new ExternalMetrics(stability_provider));
245+
external_metrics_ = new ExternalMetrics(stability_provider);
244246
external_metrics_->Start();
245247
#endif // defined(OS_LINUX)
246248
}
@@ -250,6 +252,13 @@ void CastMetricsServiceClient::Finalize() {
250252
// Set clean_shutdown bit.
251253
metrics_service_->RecordCompletedSessionEnd();
252254
#endif // !defined(OS_ANDROID)
255+
256+
// Stop metrics service cleanly before destructing CastMetricsServiceClient.
257+
#if defined(OS_LINUX)
258+
external_metrics_->StopAndDestroy();
259+
external_metrics_ = NULL;
260+
#endif // defined(OS_LINUX)
261+
metrics_service_->Stop();
253262
}
254263

255264
bool CastMetricsServiceClient::IsReportingEnabled() {

chromecast/browser/metrics/cast_metrics_service_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class CastMetricsServiceClient : public ::metrics::MetricsServiceClient {
9090
std::string client_id_;
9191

9292
#if defined(OS_LINUX)
93-
scoped_ptr<ExternalMetrics> external_metrics_;
93+
ExternalMetrics* external_metrics_;
9494
#endif // defined(OS_LINUX)
9595
const scoped_refptr<base::MessageLoopProxy> metrics_service_loop_;
9696
scoped_ptr< ::metrics::MetricsStateManager> metrics_state_manager_;

chromecast/browser/metrics/external_metrics.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ ExternalMetrics::ExternalMetrics(
5858
DCHECK(stability_provider);
5959
}
6060

61-
ExternalMetrics::~ExternalMetrics() {}
61+
ExternalMetrics::~ExternalMetrics() {
62+
}
63+
64+
void ExternalMetrics::StopAndDestroy() {
65+
content::BrowserThread::DeleteSoon(
66+
content::BrowserThread::FILE, FROM_HERE, this);
67+
}
6268

6369
void ExternalMetrics::Start() {
6470
ScheduleCollector();

chromecast/browser/metrics/external_metrics.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@ class CastStabilityMetricsProvider;
2424
class ExternalMetrics {
2525
public:
2626
explicit ExternalMetrics(CastStabilityMetricsProvider* stability_provider);
27-
~ExternalMetrics();
2827

2928
// Begins external data collection. Calls to RecordAction originate in the
3029
// File thread but are executed in the UI thread.
3130
void Start();
3231

32+
// Destroys itself in appropriate thread.
33+
void StopAndDestroy();
34+
3335
private:
36+
friend class base::DeleteHelper<ExternalMetrics>;
37+
38+
~ExternalMetrics();
39+
3440
// The max length of a message (name-value pair, plus header)
3541
static const int kMetricsMessageMaxLength = 1024; // be generous
3642

0 commit comments

Comments
 (0)