Merge "metricsd: Replace scoped_ptr with unique_ptr."

This commit is contained in:
Bertrand Simonnet 2015-12-22 19:11:19 +00:00 committed by Gerrit Code Review
commit c947a13772
11 changed files with 55 additions and 50 deletions

View file

@ -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_;

View file

@ -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);
};

View file

@ -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

View file

@ -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_;
unique_ptr<PersistentInteger> version_cumulative_cpu_use_;
scoped_ptr<PersistentInteger> user_crash_interval_;
scoped_ptr<PersistentInteger> kernel_crash_interval_;
scoped_ptr<PersistentInteger> unclean_shutdown_interval_;
unique_ptr<PersistentInteger> user_crash_interval_;
unique_ptr<PersistentInteger> kernel_crash_interval_;
unique_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_;
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_;
scoped_ptr<CpuUsageCollector> cpu_usage_collector_;
scoped_ptr<DiskUsageCollector> disk_usage_collector_;
scoped_ptr<AveragedStatisticsCollector> averaged_stats_collector_;
unique_ptr<CpuUsageCollector> cpu_usage_collector_;
unique_ptr<DiskUsageCollector> disk_usage_collector_;
unique_ptr<AveragedStatisticsCollector> averaged_stats_collector_;
std::unique_ptr<weaved::Device> device_;
};

View file

@ -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.

View file

@ -18,8 +18,6 @@
#include <string>
#include <base/memory/scoped_ptr.h>
#include "metrics/metrics_library.h"
namespace chromeos_metrics {

View file

@ -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;
};

View file

@ -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_;
};

View file

@ -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())) {

View file

@ -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_;

View file

@ -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_;
};