metrics: fix memory leaks in unittest.
This fixes the memory leaks exposed in unittest. BUG=chromium:408309 TEST=USE="clang asan" FEATURES="test" emerge-amd64-generic metrics passes. Change-Id: I6f612499d7e67fa9171b95de4dbfac4e7f6698a0 Reviewed-on: https://chromium-review.googlesource.com/215887 Reviewed-by: Yunlian Jiang <yunlian@chromium.org> Tested-by: Yunlian Jiang <yunlian@chromium.org> Commit-Queue: Yunlian Jiang <yunlian@chromium.org>
This commit is contained in:
parent
ef3aebe6a7
commit
e2c2d8947b
|
@ -13,6 +13,7 @@ class ChromeUserMetricsExtension;
|
|||
// information to simplify testing.
|
||||
class SystemProfileSetter {
|
||||
public:
|
||||
virtual ~SystemProfileSetter() {}
|
||||
// Populates the protobuf with system informations.
|
||||
virtual void Populate(metrics::ChromeUserMetricsExtension* profile_proto) = 0;
|
||||
};
|
||||
|
|
|
@ -53,7 +53,7 @@ void UploadService::StartNewLog() {
|
|||
CHECK(!staged_log_) << "the staged log should be discarded before starting "
|
||||
"a new metrics log";
|
||||
MetricsLog* log = new MetricsLog();
|
||||
log->PopulateSystemProfile(system_profile_setter_);
|
||||
log->PopulateSystemProfile(system_profile_setter_.get());
|
||||
current_log_.reset(log);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "base/metrics/histogram_snapshot_manager.h"
|
||||
#include "uploader/metrics_log.h"
|
||||
#include "uploader/sender.h"
|
||||
#include "uploader/system_profile_cache.h"
|
||||
|
||||
namespace metrics {
|
||||
class ChromeUserMetricsExtension;
|
||||
|
@ -126,7 +127,7 @@ class UploadService : public base::HistogramFlattener {
|
|||
// Returns the current log. If there is no current log, creates it first.
|
||||
MetricsLog* GetOrCreateCurrentLog();
|
||||
|
||||
SystemProfileSetter* system_profile_setter_;
|
||||
scoped_ptr<SystemProfileSetter> system_profile_setter_;
|
||||
base::HistogramSnapshotManager histogram_snapshot_manager_;
|
||||
scoped_ptr<Sender> sender_;
|
||||
int failed_upload_count_;
|
||||
|
|
|
@ -25,7 +25,7 @@ class UploadServiceTest : public testing::Test {
|
|||
: upload_service_(), exit_manager_(new base::AtExitManager()) {
|
||||
sender_ = new SenderMock;
|
||||
upload_service_.sender_.reset(sender_);
|
||||
upload_service_.system_profile_setter_ = new MockSystemProfileSetter();
|
||||
upload_service_.system_profile_setter_.reset(new MockSystemProfileSetter());
|
||||
upload_service_.Init();
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class UploadServiceTest : public testing::Test {
|
|||
}
|
||||
|
||||
base::ScopedTempDir dir_;
|
||||
SenderMock *sender_;
|
||||
SenderMock* sender_;
|
||||
SystemProfileCache cache_;
|
||||
UploadService upload_service_;
|
||||
|
||||
|
@ -191,8 +191,12 @@ TEST_F(UploadServiceTest, ValuesInConfigFileAreSent) {
|
|||
base::SysInfo::SetChromeOSVersionInfoForTest(content, base::Time());
|
||||
scoped_ptr<metrics::MetricSample> histogram =
|
||||
metrics::MetricSample::SparseHistogramSample("myhistogram", 1);
|
||||
SystemProfileCache* local_cache_ = new SystemProfileCache;
|
||||
local_cache_->is_testing_ = true;
|
||||
local_cache_->session_id_.reset(new chromeos_metrics::PersistentInteger(
|
||||
dir_.path().Append("session_id").value()));
|
||||
|
||||
upload_service_.system_profile_setter_ = &cache_;
|
||||
upload_service_.system_profile_setter_.reset(local_cache_);
|
||||
// Reset to create the new log with the profile setter.
|
||||
upload_service_.Reset();
|
||||
upload_service_.AddSample(*histogram.get());
|
||||
|
|
Loading…
Reference in New Issue