Update to build against libchrome-242728.
This CL updates metrics to build against libchrome-242728 and also converts
libmetrics into slotted libraries (libmetrics-180609 and libmetrics-242728).
BUG=chromium:341521
BUG=chromium:342866
CQ-DEPEND=CL:186027
CQ-DEPEND=CL:186026
CQ-DEPEND=CL:186037
CQ-DEPEND=CL:186092
CQ-DEPEND=CL:186028
CQ-DEPEND=CL:186029
CQ-DEPEND=CL:186038
CQ-DEPEND=CL:186093
CQ-DEPEND=CL:186100
CQ-DEPEND=CL:186039
TEST=Trybot run on paladin, release, and chromiumos-sdk builders.
Change-Id: I09dc3d47cfe24a22864abf217658c63493b35cba
Reviewed-on: https://chromium-review.googlesource.com/185187
Reviewed-by: Ben Chan <benchan@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
Commit-Queue: Ben Chan <benchan@chromium.org>
diff --git a/metrics/counter_test.cc b/metrics/counter_test.cc
index 73a50db..c0761e2 100644
--- a/metrics/counter_test.cc
+++ b/metrics/counter_test.cc
@@ -7,7 +7,7 @@
#include <base/file_util.h>
#include <base/logging.h>
#include <base/posix/eintr_wrapper.h>
-#include <base/string_util.h>
+#include <base/strings/string_util.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -15,6 +15,7 @@
#include "counter_mock.h" // For TaggedCounterMock.
#include "metrics_library_mock.h"
+using base::FilePath;
using ::testing::_;
using ::testing::MockFunction;
using ::testing::StrictMock;
@@ -58,7 +59,7 @@
virtual void TearDown() {
logging::SetLogMessageHandler(NULL);
test_ = NULL;
- file_util::Delete(FilePath(kTestRecordFile), false);
+ base::DeleteFile(FilePath(kTestRecordFile), false);
}
// Asserts that the record file contains the specified contents.
@@ -74,8 +75,8 @@
}
TaggedCounter::Record record;
- if (!file_util::ReadFromFD(fd, reinterpret_cast<char*>(&record),
- sizeof(record))) {
+ if (!base::ReadFromFD(fd, reinterpret_cast<char*>(&record),
+ sizeof(record))) {
testing::Message msg;
msg << "Unable to read " << sizeof(record) << " bytes from "
<< kTestRecordFile;
@@ -100,9 +101,9 @@
bool AssertNoOrEmptyRecordFile() {
FilePath record_file(counter_.filename_);
int64 record_file_size;
- return !file_util::PathExists(record_file) ||
- (file_util::GetFileSize(record_file, &record_file_size) &&
- record_file_size == 0);
+ return !base::PathExists(record_file) ||
+ (base::GetFileSize(record_file, &record_file_size) &&
+ record_file_size == 0);
}
// Adds a reporter call expectation that the specified tag/count
@@ -196,7 +197,7 @@
EXPECT_TRUE(LogContains("Unable to open the persistent counter file: "
"No such file or directory"));
EXPECT_EQ(TaggedCounter::kRecordInvalid, counter_.record_state_);
- file_util::Delete(FilePath(kDoesNotExistFile), false);
+ base::DeleteFile(FilePath(kDoesNotExistFile), false);
}
TEST_F(TaggedCounterTest, Flush) {
diff --git a/metrics/libmetrics-180609.gyp b/metrics/libmetrics-180609.gyp
new file mode 100644
index 0000000..4226712
--- /dev/null
+++ b/metrics/libmetrics-180609.gyp
@@ -0,0 +1,8 @@
+{
+ 'variables': {
+ 'libbase_ver': 180609,
+ },
+ 'includes': [
+ '../metrics/libmetrics.gypi',
+ ],
+}
diff --git a/metrics/libmetrics-242728.gyp b/metrics/libmetrics-242728.gyp
new file mode 100644
index 0000000..a8b1948
--- /dev/null
+++ b/metrics/libmetrics-242728.gyp
@@ -0,0 +1,8 @@
+{
+ 'variables': {
+ 'libbase_ver': 242728,
+ },
+ 'includes': [
+ '../metrics/libmetrics.gypi',
+ ],
+}
diff --git a/metrics/libmetrics.gypi b/metrics/libmetrics.gypi
new file mode 100644
index 0000000..21af05d
--- /dev/null
+++ b/metrics/libmetrics.gypi
@@ -0,0 +1,29 @@
+{
+ 'target_defaults': {
+ 'dependencies': [
+ '../libchromeos/libchromeos-<(libbase_ver).gyp:libchromeos-<(libbase_ver)',
+ ],
+ 'variables': {
+ 'deps': [
+ 'libchrome-<(libbase_ver)',
+ ]
+ },
+ 'cflags_cc': [
+ '-fno-exceptions',
+ ],
+ },
+ 'targets': [
+ {
+ 'target_name': 'libmetrics-<(libbase_ver)',
+ 'type': 'shared_library',
+ 'cflags': [
+ '-fvisibility=default',
+ ],
+ 'sources': [
+ 'c_metrics_library.cc',
+ 'metrics_library.cc',
+ 'timer.cc',
+ ],
+ },
+ ],
+}
diff --git a/metrics/metrics.gyp b/metrics/metrics.gyp
index 9709c35..0a5ac48 100644
--- a/metrics/metrics.gyp
+++ b/metrics/metrics.gyp
@@ -1,48 +1,32 @@
{
+ 'variables': {
+ 'libbase_ver': 242728,
+ },
'target_defaults': {
- 'dependencies': [
- '../libchromeos/libchromeos-<(libbase_ver).gyp:libchromeos-<(libbase_ver)',
- ],
- 'variables': {
- 'deps': [
- 'dbus-1',
- 'dbus-glib-1',
- 'glib-2.0',
- 'gobject-2.0',
- 'gthread-2.0',
- 'libchrome-<(libbase_ver)',
- ]
- },
- 'cflags_cc': [
- '-fno-exceptions',
- ],
+ 'dependencies': [
+ '../libchromeos/libchromeos-<(libbase_ver).gyp:libchromeos-<(libbase_ver)',
+ ],
+ 'variables': {
+ 'deps': [
+ 'dbus-1',
+ 'dbus-glib-1',
+ 'glib-2.0',
+ 'gobject-2.0',
+ 'gthread-2.0',
+ 'libchrome-<(libbase_ver)',
+ ]
+ },
+ 'cflags_cc': [
+ '-fno-exceptions',
+ ],
},
'targets': [
{
- 'target_name': 'metrics',
- 'type': 'static_library',
- 'sources': [
- 'c_metrics_library.cc',
- 'metrics_library.cc',
- 'timer.cc',
- ],
- },
- {
- 'target_name': 'libmetrics',
- 'type': 'shared_library',
- 'cflags': [
- '-fvisibility=default',
- ],
- 'sources': [
- 'c_metrics_library.cc',
- 'metrics_library.cc',
- 'timer.cc',
- ],
- },
- {
'target_name': 'libmetrics_daemon',
'type': 'static_library',
- 'dependencies': ['libmetrics'],
+ 'dependencies': [
+ '../metrics/libmetrics-<(libbase_ver).gyp:libmetrics-<(libbase_ver)',
+ ],
'link_settings': {
'libraries': [
'-lrootdev',
@@ -58,7 +42,9 @@
{
'target_name': 'metrics_client',
'type': 'executable',
- 'dependencies': ['libmetrics'],
+ 'dependencies': [
+ '../metrics/libmetrics-<(libbase_ver).gyp:libmetrics-<(libbase_ver)',
+ ],
'sources': [
'metrics_client.cc',
]
@@ -79,7 +65,9 @@
{
'target_name': 'metrics_library_test',
'type': 'executable',
- 'dependencies': ['libmetrics'],
+ 'dependencies': [
+ '../metrics/libmetrics-<(libbase_ver).gyp:libmetrics-<(libbase_ver)',
+ ],
'includes': ['../common-mk/common_test.gypi'],
'sources': [
'metrics_library_test.cc',
diff --git a/metrics/metrics_daemon.cc b/metrics/metrics_daemon.cc
index f3849ee..01fec16 100644
--- a/metrics/metrics_daemon.cc
+++ b/metrics/metrics_daemon.cc
@@ -11,15 +11,17 @@
#include <base/file_util.h>
#include <base/logging.h>
-#include <base/string_number_conversions.h>
-#include <base/string_util.h>
-#include <base/string_split.h>
-#include <base/stringprintf.h>
+#include <base/strings/string_number_conversions.h>
+#include <base/strings/string_split.h>
+#include <base/strings/string_util.h>
+#include <base/strings/stringprintf.h>
#include <chromeos/dbus/service_constants.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "counter.h"
+using base::FilePath;
+using base::StringPrintf;
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
@@ -528,13 +530,13 @@
bool MetricsDaemon::CheckSystemCrash(const string& crash_file) {
FilePath crash_detected(crash_file);
- if (!file_util::PathExists(crash_detected))
+ if (!base::PathExists(crash_detected))
return false;
// Deletes the crash-detected file so that the daemon doesn't report
// another kernel crash in case it's restarted.
- file_util::Delete(crash_detected,
- false); // recursive
+ base::DeleteFile(crash_detected,
+ false); // recursive
return true;
}
@@ -706,7 +708,7 @@
bool MetricsDaemon::VmStatsReadStats(struct VmstatRecord* stats) {
string value_string;
FilePath* path = new FilePath(vmstats_path_);
- if (!file_util::ReadFileToString(*path, &value_string)) {
+ if (!base::ReadFileToString(*path, &value_string)) {
delete path;
LOG(WARNING) << "cannot read " << vmstats_path_;
return false;
@@ -718,11 +720,11 @@
bool MetricsDaemon::ReadFreqToInt(const string& sysfs_file_name, int* value) {
const FilePath sysfs_path(sysfs_file_name);
string value_string;
- if (!file_util::ReadFileToString(sysfs_path, &value_string)) {
+ if (!base::ReadFileToString(sysfs_path, &value_string)) {
LOG(WARNING) << "cannot read " << sysfs_path.value().c_str();
return false;
}
- if (!RemoveChars(value_string, "\n", &value_string)) {
+ if (!base::RemoveChars(value_string, "\n", &value_string)) {
LOG(WARNING) << "no newline in " << value_string;
// Continue even though the lack of newline is suspicious.
}
@@ -901,7 +903,7 @@
bool MetricsDaemon::MeminfoCallback() {
string meminfo_raw;
const FilePath meminfo_path("/proc/meminfo");
- if (!file_util::ReadFileToString(meminfo_path, &meminfo_raw)) {
+ if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) {
LOG(WARNING) << "cannot read " << meminfo_path.value().c_str();
return false;
}
@@ -1051,7 +1053,7 @@
bool MetricsDaemon::MemuseCallbackWork() {
string meminfo_raw;
const FilePath meminfo_path("/proc/meminfo");
- if (!file_util::ReadFileToString(meminfo_path, &meminfo_raw)) {
+ if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) {
LOG(WARNING) << "cannot read " << meminfo_path.value().c_str();
return false;
}
diff --git a/metrics/metrics_daemon.h b/metrics/metrics_daemon.h
index 82372f8..6ceb136 100644
--- a/metrics/metrics_daemon.h
+++ b/metrics/metrics_daemon.h
@@ -9,9 +9,9 @@
#include <glib.h>
#include <map>
-#include <base/file_path.h>
+#include <base/files/file_path.h>
#include <base/memory/scoped_ptr.h>
-#include <base/time.h>
+#include <base/time/time.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
#include "metrics_library.h"
@@ -195,7 +195,7 @@
void ConfigureCrashFrequencyReporter(const char* histogram_name);
// Returns file path to persistent file for generating given histogram.
- FilePath GetHistogramPath(const char* histogram_name);
+ base::FilePath GetHistogramPath(const char* histogram_name);
// Creates the event loop and enters it.
void Loop();
diff --git a/metrics/metrics_daemon_main.cc b/metrics/metrics_daemon_main.cc
index 643a2bf..5fb7507 100644
--- a/metrics/metrics_daemon_main.cc
+++ b/metrics/metrics_daemon_main.cc
@@ -4,7 +4,7 @@
#include <base/logging.h>
-#include <base/string_util.h>
+#include <base/strings/string_util.h>
#include <gflags/gflags.h>
#include <rootdev/rootdev.h>
diff --git a/metrics/metrics_daemon_test.cc b/metrics/metrics_daemon_test.cc
index 9f07548..7f98a19 100644
--- a/metrics/metrics_daemon_test.cc
+++ b/metrics/metrics_daemon_test.cc
@@ -8,7 +8,7 @@
#include <vector>
#include <base/file_util.h>
-#include <base/stringprintf.h>
+#include <base/strings/stringprintf.h>
#include <chromeos/dbus/service_constants.h>
#include <gtest/gtest.h>
@@ -16,6 +16,8 @@
#include "metrics_daemon.h"
#include "metrics_library_mock.h"
+using base::FilePath;
+using base::StringPrintf;
using base::Time;
using base::TimeTicks;
using chromeos_metrics::FrequencyCounter;
@@ -132,8 +134,8 @@
EXPECT_EQ(MetricsDaemon::kUnknownPowerState, daemon_.power_state_);
EXPECT_EQ(MetricsDaemon::kUnknownSessionState, daemon_.session_state_);
- file_util::Delete(FilePath(kTestDir), true);
- file_util::CreateDirectory(FilePath(kTestDir));
+ base::DeleteFile(FilePath(kTestDir), true);
+ base::CreateDirectory(FilePath(kTestDir));
}
virtual void TearDown() {
@@ -261,7 +263,7 @@
// Creates or overwrites an input file containing a fake CPU frequency.
void CreateFakeCpuFrequencyFile(const char* filename, int frequency) {
FilePath path(filename);
- file_util::Delete(path, false);
+ base::DeleteFile(path, false);
std::string frequency_string = StringPrintf("%d\n", frequency);
int frequency_string_length = frequency_string.length();
EXPECT_EQ(frequency_string.length(),
@@ -291,12 +293,12 @@
FilePath crash_detected(kKernelCrashDetected);
file_util::WriteFile(crash_detected, "", 0);
- EXPECT_TRUE(file_util::PathExists(crash_detected));
+ EXPECT_TRUE(base::PathExists(crash_detected));
EXPECT_TRUE(daemon_.CheckSystemCrash(kKernelCrashDetected));
- EXPECT_FALSE(file_util::PathExists(crash_detected));
+ EXPECT_FALSE(base::PathExists(crash_detected));
EXPECT_FALSE(daemon_.CheckSystemCrash(kKernelCrashDetected));
- EXPECT_FALSE(file_util::PathExists(crash_detected));
- file_util::Delete(crash_detected, false);
+ EXPECT_FALSE(base::PathExists(crash_detected));
+ base::DeleteFile(crash_detected, false);
}
TEST_F(MetricsDaemonTest, ReportDailyUse) {
diff --git a/metrics/metrics_library.cc b/metrics/metrics_library.cc
index 12b0c71..c53c16b 100644
--- a/metrics/metrics_library.cc
+++ b/metrics/metrics_library.cc
@@ -86,8 +86,7 @@
MetricsLibrary::MetricsLibrary()
: uma_events_file_(NULL),
- consent_file_(kConsentFile),
- policy_provider_(NULL) {}
+ consent_file_(kConsentFile) {}
// We take buffer and buffer_size as parameters in order to simplify testing
// of various alignments of the |device_name| with |buffer_size|.
diff --git a/metrics/metrics_library_test.cc b/metrics/metrics_library_test.cc
index 03ccd4b..a748ed5 100644
--- a/metrics/metrics_library_test.cc
+++ b/metrics/metrics_library_test.cc
@@ -13,13 +13,14 @@
#include "c_metrics_library.h"
#include "metrics_library.h"
-static const FilePath kTestUMAEventsFile("test-uma-events");
-static const char kTestMounts[] = "test-mounts";
-
+using base::FilePath;
using ::testing::_;
using ::testing::Return;
using ::testing::AnyNumber;
+static const FilePath kTestUMAEventsFile("test-uma-events");
+static const char kTestMounts[] = "test-mounts";
+
ACTION_P(SetMetricsPolicy, enabled) {
*arg0 = enabled;
return true;
@@ -46,8 +47,8 @@
}
virtual void TearDown() {
- file_util::Delete(FilePath(kTestMounts), false);
- file_util::Delete(kTestUMAEventsFile, false);
+ base::DeleteFile(FilePath(kTestMounts), false);
+ base::DeleteFile(kTestUMAEventsFile, false);
}
void VerifyEnabledCacheHit(bool to_value);
@@ -182,7 +183,7 @@
char buf[100];
const int kLen = 40;
EXPECT_TRUE(lib_.SendEnumToUMA("Test.EnumMetric", 1, 3));
- EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
+ EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%clinearhistogram%cTest.EnumMetric 1 3",
@@ -194,7 +195,7 @@
EXPECT_TRUE(lib_.SendMessageToChrome(4, "test"));
EXPECT_TRUE(lib_.SendMessageToChrome(7, "content"));
std::string uma_events;
- EXPECT_TRUE(file_util::ReadFileToString(kTestUMAEventsFile, &uma_events));
+ EXPECT_TRUE(base::ReadFileToString(kTestUMAEventsFile, &uma_events));
EXPECT_EQ("testcontent", uma_events);
}
@@ -205,14 +206,14 @@
lib_.uma_events_file_ = kDoesNotExistFile;
static const char kDummyMessage[] = "Dummy Message";
EXPECT_FALSE(lib_.SendMessageToChrome(strlen(kDummyMessage), kDummyMessage));
- file_util::Delete(FilePath(kDoesNotExistFile), false);
+ base::DeleteFile(FilePath(kDoesNotExistFile), false);
}
TEST_F(MetricsLibraryTest, SendToUMA) {
char buf[100];
const int kLen = 37;
EXPECT_TRUE(lib_.SendToUMA("Test.Metric", 2, 1, 100, 50));
- EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
+ EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0);
@@ -223,7 +224,7 @@
char buf[100];
const int kLen = 30;
EXPECT_TRUE(lib_.SendUserActionToUMA("SomeKeyPressed"));
- EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
+ EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%cuseraction%cSomeKeyPressed", kLen, 0, 0, 0, 0);
@@ -234,7 +235,7 @@
char buf[100];
const int kLen = 4 + sizeof("sparsehistogram") + sizeof("Test.Sparse 1234");
EXPECT_TRUE(lib_.SendSparseToUMA("Test.Sparse", 1234));
- EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
+ EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%csparsehistogram%cTest.Sparse 1234", kLen, 0, 0, 0, 0);
@@ -248,7 +249,7 @@
0, 0, 0, 0, 0) + 1;
exp[0] = len;
char buf[100];
- EXPECT_EQ(len, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
+ EXPECT_EQ(len, base::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(0, memcmp(exp, buf, len));
}
@@ -275,7 +276,7 @@
virtual void TearDown() {
CMetricsLibraryDelete(lib_);
- file_util::Delete(kTestUMAEventsFile, false);
+ base::DeleteFile(kTestUMAEventsFile, false);
}
CMetricsLibrary lib_;
@@ -297,7 +298,7 @@
char buf[100];
const int kLen = 40;
EXPECT_TRUE(CMetricsLibrarySendEnumToUMA(lib_, "Test.EnumMetric", 1, 3));
- EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
+ EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%clinearhistogram%cTest.EnumMetric 1 3",
@@ -309,7 +310,7 @@
char buf[100];
const int kLen = 37;
EXPECT_TRUE(CMetricsLibrarySendToUMA(lib_, "Test.Metric", 2, 1, 100, 50));
- EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
+ EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0);
@@ -320,7 +321,7 @@
char buf[100];
const int kLen = 30;
EXPECT_TRUE(CMetricsLibrarySendUserActionToUMA(lib_, "SomeKeyPressed"));
- EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
+ EXPECT_EQ(kLen, base::ReadFile(kTestUMAEventsFile, buf, 100));
char exp[kLen];
sprintf(exp, "%c%c%c%cuseraction%cSomeKeyPressed", kLen, 0, 0, 0, 0);
@@ -333,7 +334,7 @@
int len = sprintf(exp, "%c%c%c%ccrash%cuser", 0, 0, 0, 0, 0) + 1;
exp[0] = len;
EXPECT_TRUE(CMetricsLibrarySendCrashToUMA(lib_, "user"));
- EXPECT_EQ(len, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
+ EXPECT_EQ(len, base::ReadFile(kTestUMAEventsFile, buf, 100));
EXPECT_EQ(0, memcmp(exp, buf, len));
}
diff --git a/metrics/timer.cc b/metrics/timer.cc
index c8e6176..90948b5 100644
--- a/metrics/timer.cc
+++ b/metrics/timer.cc
@@ -7,7 +7,6 @@
#include <string>
#include <base/memory/scoped_ptr.h>
-#include <base/time.h>
#include "metrics_library.h"
diff --git a/metrics/timer.h b/metrics/timer.h
index b949773..ce88873 100644
--- a/metrics/timer.h
+++ b/metrics/timer.h
@@ -10,7 +10,11 @@
#include <string>
#include <base/memory/scoped_ptr.h>
+#if BASE_VER >= 242728
+#include <base/time/time.h>
+#else
#include <base/time.h>
+#endif
#include <gtest/gtest_prod.h> // for FRIEND_TEST
class MetricsLibraryInterface;
diff --git a/metrics/timer_mock.h b/metrics/timer_mock.h
index 1f0c9de..6034ee3 100644
--- a/metrics/timer_mock.h
+++ b/metrics/timer_mock.h
@@ -9,7 +9,6 @@
#include <string>
#include <base/basictypes.h>
-#include <base/time.h>
#include <gmock/gmock.h>
#include "timer.h"
diff --git a/metrics/timer_test.cc b/metrics/timer_test.cc
index 03475d3..d64beab 100644
--- a/metrics/timer_test.cc
+++ b/metrics/timer_test.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include <base/memory/scoped_ptr.h>
-#include <base/time.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>