Commit 79597a80 authored by gunsch's avatar gunsch Committed by Commit bot

Chromecast fix: MetricsStateManager segfaults if callbacks are empty.

R=lcwu@chromium.org,asvitkine@chromium.org
BUG=None

Review URL: https://codereview.chromium.org/522853002

Cr-Commit-Position: refs/heads/master@{#292691}
parent 695d3e36
......@@ -45,6 +45,7 @@
'target_name': 'cast_metrics',
'type': '<(component)',
'dependencies': [
'cast_common',
'../components/components.gyp:component_metrics_proto',
'../components/components.gyp:metrics',
'../components/components.gyp:metrics_net',
......@@ -68,6 +69,21 @@
}],
],
},
{
'target_name': 'cast_metrics_unittests',
'type': '<(gtest_target_type)',
'dependencies': [
'cast_metrics',
'../base/base.gyp:base_prefs_test_support',
'../base/base.gyp:run_all_unittests',
'../base/base.gyp:test_support_base',
'../components/components.gyp:component_metrics_proto',
'../testing/gtest.gyp:gtest',
],
'sources': [
'metrics/cast_metrics_service_client_unittest.cc',
],
}, # end of target 'cast_metrics_unittests'
{
'target_name': 'cast_service',
'type': '<(component)',
......
......@@ -7,6 +7,7 @@
#include "base/i18n/rtl.h"
#include "chromecast/common/chromecast_config.h"
#include "chromecast/metrics/platform_metrics_providers.h"
#include "components/metrics/client_info.h"
#include "components/metrics/metrics_provider.h"
#include "components/metrics/metrics_service.h"
#include "components/metrics/metrics_state_manager.h"
......@@ -15,6 +16,17 @@
namespace chromecast {
namespace metrics {
namespace {
void StoreClientInfo(const ::metrics::ClientInfo& client_info) {
}
scoped_ptr<::metrics::ClientInfo> LoadClientInfo() {
return scoped_ptr<::metrics::ClientInfo>();
}
} // namespace
// static
CastMetricsServiceClient* CastMetricsServiceClient::Create(
PrefService* pref_service,
......@@ -92,12 +104,12 @@ CastMetricsServiceClient::CastMetricsServiceClient(
pref_service,
base::Bind(&CastMetricsServiceClient::IsReportingEnabled,
base::Unretained(this)),
::metrics::MetricsStateManager::StoreClientInfoCallback(),
::metrics::MetricsStateManager::LoadClientInfoCallback())),
base::Bind(&StoreClientInfo),
base::Bind(&LoadClientInfo))),
metrics_service_(new ::metrics::MetricsService(
metrics_state_manager_.get(),
this,
ChromecastConfig::GetInstance()->pref_service())),
pref_service)),
request_context_(request_context) {
// Always create a client id as it may also be used by crash reporting,
// (indirectly) included in feedback, and can be queried during setup.
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromecast/metrics/cast_metrics_service_client.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/testing_pref_service.h"
#include "components/metrics/metrics_service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromecast {
class CastMetricsTest : public testing::Test {
public:
CastMetricsTest() {}
virtual ~CastMetricsTest() {}
protected:
virtual void SetUp() OVERRIDE {
message_loop_.reset(new base::MessageLoop());
prefs_.reset(new TestingPrefServiceSimple());
::metrics::MetricsService::RegisterPrefs(prefs_->registry());
}
TestingPrefServiceSimple* prefs() { return prefs_.get(); }
private:
scoped_ptr<base::MessageLoop> message_loop_;
scoped_ptr<TestingPrefServiceSimple> prefs_;
DISALLOW_COPY_AND_ASSIGN(CastMetricsTest);
};
TEST_F(CastMetricsTest, CreateMetricsServiceClient) {
// Create and expect this to not crash.
metrics::CastMetricsServiceClient::Create(prefs(), NULL);
}
} // namespace chromecast
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment