aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrand SIMONNET <bsimonnet@google.com>2015-12-21 14:56:40 -0800
committerBertrand SIMONNET <bsimonnet@google.com>2015-12-22 09:18:04 -0800
commit0ba1eeffb4c326fa3c4e526fb53f1533c0385bab (patch)
treed9cd1089eda9a0e845d0b4d7198ab3b64939756e
parentfa1ef586da984df161d2af263cce9d7d0b72b341 (diff)
downloadmetricsd-0ba1eeffb4c326fa3c4e526fb53f1533c0385bab.tar.gz
metricsd: Replace scoped_ptr with unique_ptr.
scoped_ptr are a chromism. We should use unique_ptr instead. Bug: 25958769 Test: unit tests. Change-Id: Ie23ae2ef42f66dcc76f45a9dafa66c8ceb0a2d90
-rw-r--r--collectors/averaged_statistics_collector_test.cc5
-rw-r--r--include/metrics/timer.h4
-rw-r--r--metrics_collector.cc8
-rw-r--r--metrics_collector.h58
-rw-r--r--persistent_integer_test.cc5
-rw-r--r--timer.cc2
-rw-r--r--timer_test.cc6
-rw-r--r--uploader/system_profile_cache.h4
-rw-r--r--uploader/upload_service.cc3
-rw-r--r--uploader/upload_service.h7
-rw-r--r--uploader/upload_service_test.cc9
11 files changed, 58 insertions, 53 deletions
diff --git a/collectors/averaged_statistics_collector_test.cc b/collectors/averaged_statistics_collector_test.cc
index 9c97f00..68f9f2f 100644
--- a/collectors/averaged_statistics_collector_test.cc
+++ b/collectors/averaged_statistics_collector_test.cc
@@ -16,11 +16,12 @@
#include "averaged_statistics_collector.h"
+#include <memory>
+
#include <inttypes.h>
#include <base/files/file_util.h>
#include <base/files/scoped_temp_dir.h>
-#include <base/memory/scoped_ptr.h>
#include <base/strings/stringprintf.h>
#include <gtest/gtest.h>
@@ -62,7 +63,7 @@ class AveragedStatisticsTest : public testing::Test {
}
// Collector used for tests.
- scoped_ptr<AveragedStatisticsCollector> collector_;
+ std::unique_ptr<AveragedStatisticsCollector> collector_;
// Temporary directory used for tests.
base::ScopedTempDir temp_dir_;
diff --git a/include/metrics/timer.h b/include/metrics/timer.h
index b36ffff..c1b8ede 100644
--- a/include/metrics/timer.h
+++ b/include/metrics/timer.h
@@ -19,10 +19,10 @@
#ifndef METRICS_TIMER_H_
#define METRICS_TIMER_H_
+#include <memory>
#include <string>
#include <base/macros.h>
-#include <base/memory/scoped_ptr.h>
#include <base/time/time.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
@@ -121,7 +121,7 @@ class Timer : public TimerInterface {
TimerState timer_state_;
// Wrapper for the calls to the system clock.
- scoped_ptr<ClockWrapper> clock_wrapper_;
+ std::unique_ptr<ClockWrapper> clock_wrapper_;
DISALLOW_COPY_AND_ASSIGN(Timer);
};
diff --git a/metrics_collector.cc b/metrics_collector.cc
index e9edf2e..a5daab5 100644
--- a/metrics_collector.cc
+++ b/metrics_collector.cc
@@ -19,6 +19,8 @@
#include <sysexits.h>
#include <time.h>
+#include <memory>
+
#include <base/bind.h>
#include <base/files/file_path.h>
#include <base/files/file_util.h>
@@ -665,7 +667,7 @@ void MetricsCollector::SendKernelCrashesCumulativeCountStats() {
}
void MetricsCollector::SendAndResetDailyUseSample(
- const scoped_ptr<PersistentInteger>& use) {
+ const unique_ptr<PersistentInteger>& use) {
SendSample(use->Name(),
use->GetAndClear(),
1, // value of first bucket
@@ -674,7 +676,7 @@ void MetricsCollector::SendAndResetDailyUseSample(
}
void MetricsCollector::SendAndResetCrashIntervalSample(
- const scoped_ptr<PersistentInteger>& interval) {
+ const unique_ptr<PersistentInteger>& interval) {
SendSample(interval->Name(),
interval->GetAndClear(),
1, // value of first bucket
@@ -683,7 +685,7 @@ void MetricsCollector::SendAndResetCrashIntervalSample(
}
void MetricsCollector::SendAndResetCrashFrequencySample(
- const scoped_ptr<PersistentInteger>& frequency) {
+ const unique_ptr<PersistentInteger>& frequency) {
SendSample(frequency->Name(),
frequency->GetAndClear(),
1, // value of first bucket
diff --git a/metrics_collector.h b/metrics_collector.h
index 422ed7c..45ef63d 100644
--- a/metrics_collector.h
+++ b/metrics_collector.h
@@ -20,11 +20,11 @@
#include <stdint.h>
#include <map>
+#include <memory>
#include <string>
#include <vector>
#include <base/files/file_path.h>
-#include <base/memory/scoped_ptr.h>
#include <base/time/time.h>
#include <brillo/daemons/dbus_daemon.h>
#include <libweaved/command.h>
@@ -38,6 +38,7 @@
#include "persistent_integer.h"
using chromeos_metrics::PersistentInteger;
+using std::unique_ptr;
class MetricsCollector : public brillo::DBusDaemon {
public:
@@ -151,18 +152,17 @@ class MetricsCollector : public brillo::DBusDaemon {
// Sends a sample representing the number of seconds of active use
// for a 24-hour period and reset |use|.
- void SendAndResetDailyUseSample(
- const scoped_ptr<PersistentInteger>& use);
+ void SendAndResetDailyUseSample(const unique_ptr<PersistentInteger>& use);
// Sends a sample representing a time interval between two crashes of the
// same type and reset |interval|.
void SendAndResetCrashIntervalSample(
- const scoped_ptr<PersistentInteger>& interval);
+ const unique_ptr<PersistentInteger>& interval);
// Sends a sample representing a frequency of crashes of some type and reset
// |frequency|.
void SendAndResetCrashFrequencySample(
- const scoped_ptr<PersistentInteger>& frequency);
+ const unique_ptr<PersistentInteger>& frequency);
// Initializes vm and disk stats reporting.
void StatsReporterInit();
@@ -241,36 +241,36 @@ class MetricsCollector : public brillo::DBusDaemon {
base::TimeDelta latest_cpu_use_microseconds_;
// Persistent values and accumulators for crash statistics.
- scoped_ptr<PersistentInteger> daily_cycle_;
- scoped_ptr<PersistentInteger> weekly_cycle_;
- scoped_ptr<PersistentInteger> version_cycle_;
+ unique_ptr<PersistentInteger> daily_cycle_;
+ unique_ptr<PersistentInteger> weekly_cycle_;
+ unique_ptr<PersistentInteger> version_cycle_;
// Active use accumulated in a day.
- scoped_ptr<PersistentInteger> daily_active_use_;
+ unique_ptr<PersistentInteger> daily_active_use_;
// Active use accumulated since the latest version update.
- scoped_ptr<PersistentInteger> version_cumulative_active_use_;
+ unique_ptr<PersistentInteger> version_cumulative_active_use_;
// The CPU time accumulator. This contains the CPU time, in milliseconds,
// used by the system since the most recent OS version update.
- scoped_ptr<PersistentInteger> version_cumulative_cpu_use_;
-
- scoped_ptr<PersistentInteger> user_crash_interval_;
- scoped_ptr<PersistentInteger> kernel_crash_interval_;
- scoped_ptr<PersistentInteger> unclean_shutdown_interval_;
-
- scoped_ptr<PersistentInteger> any_crashes_daily_count_;
- scoped_ptr<PersistentInteger> any_crashes_weekly_count_;
- scoped_ptr<PersistentInteger> user_crashes_daily_count_;
- scoped_ptr<PersistentInteger> user_crashes_weekly_count_;
- scoped_ptr<PersistentInteger> kernel_crashes_daily_count_;
- scoped_ptr<PersistentInteger> kernel_crashes_weekly_count_;
- scoped_ptr<PersistentInteger> kernel_crashes_version_count_;
- scoped_ptr<PersistentInteger> unclean_shutdowns_daily_count_;
- scoped_ptr<PersistentInteger> unclean_shutdowns_weekly_count_;
-
- scoped_ptr<CpuUsageCollector> cpu_usage_collector_;
- scoped_ptr<DiskUsageCollector> disk_usage_collector_;
- scoped_ptr<AveragedStatisticsCollector> averaged_stats_collector_;
+ unique_ptr<PersistentInteger> version_cumulative_cpu_use_;
+
+ unique_ptr<PersistentInteger> user_crash_interval_;
+ unique_ptr<PersistentInteger> kernel_crash_interval_;
+ unique_ptr<PersistentInteger> unclean_shutdown_interval_;
+
+ unique_ptr<PersistentInteger> any_crashes_daily_count_;
+ unique_ptr<PersistentInteger> any_crashes_weekly_count_;
+ unique_ptr<PersistentInteger> user_crashes_daily_count_;
+ unique_ptr<PersistentInteger> user_crashes_weekly_count_;
+ unique_ptr<PersistentInteger> kernel_crashes_daily_count_;
+ unique_ptr<PersistentInteger> kernel_crashes_weekly_count_;
+ unique_ptr<PersistentInteger> kernel_crashes_version_count_;
+ unique_ptr<PersistentInteger> unclean_shutdowns_daily_count_;
+ unique_ptr<PersistentInteger> unclean_shutdowns_weekly_count_;
+
+ unique_ptr<CpuUsageCollector> cpu_usage_collector_;
+ unique_ptr<DiskUsageCollector> disk_usage_collector_;
+ unique_ptr<AveragedStatisticsCollector> averaged_stats_collector_;
std::unique_ptr<weaved::Device> device_;
};
diff --git a/persistent_integer_test.cc b/persistent_integer_test.cc
index 55d6cbc..bf76261 100644
--- a/persistent_integer_test.cc
+++ b/persistent_integer_test.cc
@@ -14,12 +14,13 @@
* limitations under the License.
*/
-#include <gtest/gtest.h>
+#include <memory>
#include <base/compiler_specific.h>
#include <base/files/file_enumerator.h>
#include <base/files/file_util.h>
#include <base/files/scoped_temp_dir.h>
+#include <gtest/gtest.h>
#include "persistent_integer.h"
@@ -38,7 +39,7 @@ class PersistentIntegerTest : public testing::Test {
};
TEST_F(PersistentIntegerTest, BasicChecks) {
- scoped_ptr<PersistentInteger> pi(
+ std::unique_ptr<PersistentInteger> pi(
new PersistentInteger(kBackingFileName, temp_dir_.path()));
// Test initialization.
diff --git a/timer.cc b/timer.cc
index 0c2c119..06fc336 100644
--- a/timer.cc
+++ b/timer.cc
@@ -18,8 +18,6 @@
#include <string>
-#include <base/memory/scoped_ptr.h>
-
#include "metrics/metrics_library.h"
namespace chromeos_metrics {
diff --git a/timer_test.cc b/timer_test.cc
index bc7a2a1..7a67e11 100644
--- a/timer_test.cc
+++ b/timer_test.cc
@@ -16,9 +16,9 @@
#include <stdint.h>
-#include <base/memory/scoped_ptr.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include <memory>
#include "metrics/metrics_library_mock.h"
#include "metrics/timer.h"
@@ -61,7 +61,7 @@ class TimerTest : public testing::Test {
virtual void TearDown() {}
Timer timer_;
- scoped_ptr<ClockWrapperMock> clock_wrapper_mock_;
+ std::unique_ptr<ClockWrapperMock> clock_wrapper_mock_;
base::TimeTicks stime, etime, stime2, etime2, stime3, etime3;
};
@@ -436,7 +436,7 @@ class TimerReporterTest : public testing::Test {
TimerReporter timer_reporter_;
MetricsLibraryMock lib_;
- scoped_ptr<ClockWrapperMock> clock_wrapper_mock_;
+ std::unique_ptr<ClockWrapperMock> clock_wrapper_mock_;
base::TimeTicks stime, etime;
};
diff --git a/uploader/system_profile_cache.h b/uploader/system_profile_cache.h
index 0a21ad4..f9c484c 100644
--- a/uploader/system_profile_cache.h
+++ b/uploader/system_profile_cache.h
@@ -19,12 +19,12 @@
#include <stdint.h>
+#include <memory>
#include <string>
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
-#include "base/memory/scoped_ptr.h"
#include "persistent_integer.h"
#include "uploader/proto/system_profile.pb.h"
#include "uploader/system_profile_setter.h"
@@ -80,7 +80,7 @@ class SystemProfileCache : public SystemProfileSetter {
bool initialized_;
bool testing_;
base::FilePath metrics_directory_;
- scoped_ptr<chromeos_metrics::PersistentInteger> session_id_;
+ std::unique_ptr<chromeos_metrics::PersistentInteger> session_id_;
SystemProfile profile_;
};
diff --git a/uploader/upload_service.cc b/uploader/upload_service.cc
index ea8427a..2fb30c3 100644
--- a/uploader/upload_service.cc
+++ b/uploader/upload_service.cc
@@ -18,6 +18,7 @@
#include <sysexits.h>
+#include <memory>
#include <string>
#include <base/bind.h>
@@ -169,7 +170,7 @@ void UploadService::StageCurrentLog() {
if (!current_log_)
return;
- scoped_ptr<MetricsLog> staged_log;
+ std::unique_ptr<MetricsLog> staged_log;
staged_log.swap(current_log_);
staged_log->CloseLog();
if (!staged_log->PopulateSystemProfile(system_profile_setter_.get())) {
diff --git a/uploader/upload_service.h b/uploader/upload_service.h
index fe064b8..1d36121 100644
--- a/uploader/upload_service.h
+++ b/uploader/upload_service.h
@@ -17,6 +17,7 @@
#ifndef METRICS_UPLOADER_UPLOAD_SERVICE_H_
#define METRICS_UPLOADER_UPLOAD_SERVICE_H_
+#include <memory>
#include <string>
#include <base/metrics/histogram_base.h>
@@ -141,11 +142,11 @@ class UploadService : public base::HistogramFlattener, public brillo::Daemon {
// Returns the current log. If there is no current log, creates it first.
MetricsLog* GetOrCreateCurrentLog();
- scoped_ptr<SystemProfileSetter> system_profile_setter_;
+ std::unique_ptr<SystemProfileSetter> system_profile_setter_;
base::HistogramSnapshotManager histogram_snapshot_manager_;
- scoped_ptr<Sender> sender_;
+ std::unique_ptr<Sender> sender_;
chromeos_metrics::PersistentInteger failed_upload_count_;
- scoped_ptr<MetricsLog> current_log_;
+ std::unique_ptr<MetricsLog> current_log_;
std::shared_ptr<CrashCounters> counters_;
base::TimeDelta upload_interval_;
diff --git a/uploader/upload_service_test.cc b/uploader/upload_service_test.cc
index 0e2ba8f..ec507e8 100644
--- a/uploader/upload_service_test.cc
+++ b/uploader/upload_service_test.cc
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include <gtest/gtest.h>
+#include <memory>
#include <base/at_exit.h>
#include <base/files/file_util.h>
@@ -23,6 +23,7 @@
#include <base/metrics/sparse_histogram.h>
#include <base/metrics/statistics_recorder.h>
#include <base/sys_info.h>
+#include <gtest/gtest.h>
#include "constants.h"
#include "persistent_integer.h"
@@ -86,15 +87,15 @@ class UploadServiceTest : public testing::Test {
}
const metrics::SystemProfileProto_Stability GetCurrentStability() {
- EXPECT_TRUE(upload_service_->current_log_);
+ EXPECT_TRUE(upload_service_->current_log_.get());
return upload_service_->current_log_->uma_proto()->system_profile().stability();
}
base::ScopedTempDir dir_;
- scoped_ptr<UploadService> upload_service_;
+ std::unique_ptr<UploadService> upload_service_;
- scoped_ptr<base::AtExitManager> exit_manager_;
+ std::unique_ptr<base::AtExitManager> exit_manager_;
std::shared_ptr<CrashCounters> counters_;
};