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

Commit

Permalink
(1) ExternalMetrics has to destroy itself in file thread due to weakptr.
Browse files Browse the repository at this point in the history
(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}
  • Loading branch information
gfhuang authored and Commit bot committed Jan 10, 2015
1 parent adfd269 commit 827a380
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
11 changes: 10 additions & 1 deletion chromecast/browser/metrics/cast_metrics_service_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,13 @@ CastMetricsServiceClient::CastMetricsServiceClient(
: io_task_runner_(io_task_runner),
pref_service_(pref_service),
cast_service_(NULL),
external_metrics_(NULL),
metrics_service_loop_(base::MessageLoopProxy::current()),
request_context_(request_context) {
}

CastMetricsServiceClient::~CastMetricsServiceClient() {
DCHECK(!external_metrics_);
}

void CastMetricsServiceClient::Initialize(CastService* cast_service) {
Expand Down Expand Up @@ -240,7 +242,7 @@ void CastMetricsServiceClient::Initialize(CastService* cast_service) {
// Start external metrics collection, which feeds data from external
// processes into the main external metrics.
#if defined(OS_LINUX)
external_metrics_.reset(new ExternalMetrics(stability_provider));
external_metrics_ = new ExternalMetrics(stability_provider);
external_metrics_->Start();
#endif // defined(OS_LINUX)
}
Expand All @@ -250,6 +252,13 @@ void CastMetricsServiceClient::Finalize() {
// Set clean_shutdown bit.
metrics_service_->RecordCompletedSessionEnd();
#endif // !defined(OS_ANDROID)

// Stop metrics service cleanly before destructing CastMetricsServiceClient.
#if defined(OS_LINUX)
external_metrics_->StopAndDestroy();
external_metrics_ = NULL;
#endif // defined(OS_LINUX)
metrics_service_->Stop();
}

bool CastMetricsServiceClient::IsReportingEnabled() {
Expand Down
2 changes: 1 addition & 1 deletion chromecast/browser/metrics/cast_metrics_service_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class CastMetricsServiceClient : public ::metrics::MetricsServiceClient {
std::string client_id_;

#if defined(OS_LINUX)
scoped_ptr<ExternalMetrics> external_metrics_;
ExternalMetrics* external_metrics_;
#endif // defined(OS_LINUX)
const scoped_refptr<base::MessageLoopProxy> metrics_service_loop_;
scoped_ptr< ::metrics::MetricsStateManager> metrics_state_manager_;
Expand Down
8 changes: 7 additions & 1 deletion chromecast/browser/metrics/external_metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ ExternalMetrics::ExternalMetrics(
DCHECK(stability_provider);
}

ExternalMetrics::~ExternalMetrics() {}
ExternalMetrics::~ExternalMetrics() {
}

void ExternalMetrics::StopAndDestroy() {
content::BrowserThread::DeleteSoon(
content::BrowserThread::FILE, FROM_HERE, this);
}

void ExternalMetrics::Start() {
ScheduleCollector();
Expand Down
8 changes: 7 additions & 1 deletion chromecast/browser/metrics/external_metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ class CastStabilityMetricsProvider;
class ExternalMetrics {
public:
explicit ExternalMetrics(CastStabilityMetricsProvider* stability_provider);
~ExternalMetrics();

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

// Destroys itself in appropriate thread.
void StopAndDestroy();

private:
friend class base::DeleteHelper<ExternalMetrics>;

~ExternalMetrics();

// The max length of a message (name-value pair, plus header)
static const int kMetricsMessageMaxLength = 1024; // be generous

Expand Down

0 comments on commit 827a380

Please sign in to comment.