Merge "adb: win32: write ACK to separate pipe instead of stdout"
diff --git a/crash_reporter/chrome_collector.cc b/crash_reporter/chrome_collector.cc
deleted file mode 100644
index ec291c0..0000000
--- a/crash_reporter/chrome_collector.cc
+++ /dev/null
@@ -1,335 +0,0 @@
-// Copyright (c) 2013 The Chromium OS 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 "crash-reporter/chrome_collector.h"
-
-#include <pcrecpp.h>
-#include <stdint.h>
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include <base/files/file_util.h>
-#include <base/logging.h>
-#include <base/strings/string_number_conversions.h>
-#include <base/strings/string_util.h>
-#include <chromeos/data_encoding.h>
-#include <chromeos/dbus/service_constants.h>
-#include <chromeos/process.h>
-#include <chromeos/syslog_logging.h>
-
-using base::FilePath;
-using base::StringPrintf;
-
-namespace {
-
-const char kDefaultMinidumpName[] = "upload_file_minidump";
-
-// Path to the gzip binary.
-const char kGzipPath[] = "/bin/gzip";
-
-// Filenames for logs attached to crash reports. Also used as metadata keys.
-const char kChromeLogFilename[] = "chrome.txt";
-const char kGpuStateFilename[] = "i915_error_state.log.xz";
-
-// From //net/crash/collector/collector.h
-const int kDefaultMaxUploadBytes = 1024 * 1024;
-
-// Extract a string delimited by the given character, from the given offset
-// into a source string. Returns false if the string is zero-sized or no
-// delimiter was found.
-bool GetDelimitedString(const std::string &str, char ch, size_t offset,
- std::string *substr) {
- size_t at = str.find_first_of(ch, offset);
- if (at == std::string::npos || at == offset)
- return false;
- *substr = str.substr(offset, at - offset);
- return true;
-}
-
-// Gets the GPU's error state from debugd and writes it to |error_state_path|.
-// Returns true on success.
-bool GetDriErrorState(const FilePath &error_state_path,
- org::chromium::debugdProxy *proxy) {
- chromeos::ErrorPtr error;
- std::string error_state_str;
-
- proxy->GetLog("i915_error_state", &error_state_str, &error);
-
- if (error) {
- LOG(ERROR) << "Error calling D-Bus proxy call to interface "
- << "'" << proxy->GetObjectPath().value() << "':"
- << error->GetMessage();
- return false;
- }
-
- if (error_state_str == "<empty>")
- return false;
-
- const char kBase64Header[] = "<base64>: ";
- const size_t kBase64HeaderLength = sizeof(kBase64Header) - 1;
- if (error_state_str.compare(0, kBase64HeaderLength, kBase64Header)) {
- LOG(ERROR) << "i915_error_state is missing base64 header";
- return false;
- }
-
- std::string decoded_error_state;
-
- if (!chromeos::data_encoding::Base64Decode(
- error_state_str.c_str() + kBase64HeaderLength,
- &decoded_error_state)) {
- LOG(ERROR) << "Could not decode i915_error_state";
- return false;
- }
-
- int written = base::WriteFile(error_state_path,
- decoded_error_state.c_str(),
- decoded_error_state.length());
- if (written < 0 ||
- static_cast<size_t>(written) != decoded_error_state.length()) {
- LOG(ERROR) << "Could not write file " << error_state_path.value()
- << " Written: " << written << " Len: "
- << decoded_error_state.length();
- base::DeleteFile(error_state_path, false);
- return false;
- }
-
- return true;
-}
-
-// Gzip-compresses |path|, removes the original file, and returns the path of
-// the new file. On failure, the original file is left alone and an empty path
-// is returned.
-FilePath GzipFile(const FilePath& path) {
- chromeos::ProcessImpl proc;
- proc.AddArg(kGzipPath);
- proc.AddArg(path.value());
- const int res = proc.Run();
- if (res != 0) {
- LOG(ERROR) << "Failed to gzip " << path.value();
- return FilePath();
- }
- return path.AddExtension(".gz");
-}
-
-} // namespace
-
-
-ChromeCollector::ChromeCollector() : output_file_ptr_(stdout) {}
-
-ChromeCollector::~ChromeCollector() {}
-
-bool ChromeCollector::HandleCrash(const FilePath &file_path,
- const std::string &pid_string,
- const std::string &uid_string,
- const std::string &exe_name) {
- if (!is_feedback_allowed_function_())
- return true;
-
- LOG(WARNING) << "Received crash notification for " << exe_name << "["
- << pid_string << "] user " << uid_string << " (called directly)";
-
- if (exe_name.find('/') != std::string::npos) {
- LOG(ERROR) << "exe_name contains illegal characters: " << exe_name;
- return false;
- }
-
- FilePath dir;
- uid_t uid = atoi(uid_string.c_str());
- pid_t pid = atoi(pid_string.c_str());
- if (!GetCreatedCrashDirectoryByEuid(uid, &dir, nullptr)) {
- LOG(ERROR) << "Can't create crash directory for uid " << uid;
- return false;
- }
-
- std::string dump_basename = FormatDumpBasename(exe_name, time(nullptr), pid);
- FilePath meta_path = GetCrashPath(dir, dump_basename, "meta");
- FilePath minidump_path = GetCrashPath(dir, dump_basename, "dmp");
-
- std::string data;
- if (!base::ReadFileToString(file_path, &data)) {
- LOG(ERROR) << "Can't read crash log: " << file_path.value();
- return false;
- }
-
- if (!ParseCrashLog(data, dir, minidump_path, dump_basename)) {
- LOG(ERROR) << "Failed to parse Chrome's crash log";
- return false;
- }
-
-
- int64_t report_size = 0;
- base::GetFileSize(minidump_path, &report_size);
-
- // Keyed by crash metadata key name.
- const std::map<std::string, base::FilePath> additional_logs =
- GetAdditionalLogs(dir, dump_basename, exe_name);
- for (auto it : additional_logs) {
- int64_t file_size = 0;
- if (!base::GetFileSize(it.second, &file_size)) {
- PLOG(WARNING) << "Unable to get size of " << it.second.value();
- continue;
- }
- if (report_size + file_size > kDefaultMaxUploadBytes) {
- LOG(INFO) << "Skipping upload of " << it.second.value() << "("
- << file_size << "B) because report size would exceed limit ("
- << kDefaultMaxUploadBytes << "B)";
- continue;
- }
- VLOG(1) << "Adding metadata: " << it.first << " -> " << it.second.value();
- // Call AddCrashMetaUploadFile() rather than AddCrashMetaData() here. The
- // former adds a prefix to the key name; without the prefix, only the key
- // "logs" appears to be displayed on the crash server.
- AddCrashMetaUploadFile(it.first, it.second.value());
- report_size += file_size;
- }
-
- // We're done.
- WriteCrashMetaData(meta_path, exe_name, minidump_path.value());
-
- fprintf(output_file_ptr_, "%s", kSuccessMagic);
- fflush(output_file_ptr_);
-
- return true;
-}
-
-void ChromeCollector::SetUpDBus() {
- CrashCollector::SetUpDBus();
-
- debugd_proxy_.reset(
- new org::chromium::debugdProxy(bus_, debugd::kDebugdServiceName));
-}
-
-bool ChromeCollector::ParseCrashLog(const std::string &data,
- const FilePath &dir,
- const FilePath &minidump,
- const std::string &basename) {
- size_t at = 0;
- while (at < data.size()) {
- // Look for a : followed by a decimal number, followed by another :
- // followed by N bytes of data.
- std::string name, size_string;
- if (!GetDelimitedString(data, ':', at, &name)) {
- LOG(ERROR) << "Can't find : after name @ offset " << at;
- break;
- }
- at += name.size() + 1; // Skip the name & : delimiter.
-
- if (!GetDelimitedString(data, ':', at, &size_string)) {
- LOG(ERROR) << "Can't find : after size @ offset " << at;
- break;
- }
- at += size_string.size() + 1; // Skip the size & : delimiter.
-
- size_t size;
- if (!base::StringToSizeT(size_string, &size)) {
- LOG(ERROR) << "String not convertible to integer: " << size_string;
- break;
- }
-
- // Data would run past the end, did we get a truncated file?
- if (at + size > data.size()) {
- LOG(ERROR) << "Overrun, expected " << size << " bytes of data, got "
- << (data.size() - at);
- break;
- }
-
- if (name.find("filename") != std::string::npos) {
- // File.
- // Name will be in a semi-MIME format of
- // <descriptive name>"; filename="<name>"
- // Descriptive name will be upload_file_minidump for the dump.
- std::string desc, filename;
- pcrecpp::RE re("(.*)\" *; *filename=\"(.*)\"");
- if (!re.FullMatch(name.c_str(), &desc, &filename)) {
- LOG(ERROR) << "Filename was not in expected format: " << name;
- break;
- }
-
- if (desc.compare(kDefaultMinidumpName) == 0) {
- // The minidump.
- WriteNewFile(minidump, data.c_str() + at, size);
- } else {
- // Some other file.
- FilePath path = GetCrashPath(dir, basename + "-" + filename, "other");
- if (WriteNewFile(path, data.c_str() + at, size) >= 0) {
- AddCrashMetaUploadFile(desc, path.value());
- }
- }
- } else {
- // Other attribute.
- std::string value_str;
- value_str.reserve(size);
-
- // Since metadata is one line/value the values must be escaped properly.
- for (size_t i = at; i < at + size; i++) {
- switch (data[i]) {
- case '"':
- case '\\':
- value_str.push_back('\\');
- value_str.push_back(data[i]);
- break;
-
- case '\r':
- value_str += "\\r";
- break;
-
- case '\n':
- value_str += "\\n";
- break;
-
- case '\t':
- value_str += "\\t";
- break;
-
- case '\0':
- value_str += "\\0";
- break;
-
- default:
- value_str.push_back(data[i]);
- break;
- }
- }
- AddCrashMetaUploadData(name, value_str);
- }
-
- at += size;
- }
-
- return at == data.size();
-}
-
-std::map<std::string, base::FilePath> ChromeCollector::GetAdditionalLogs(
- const FilePath &dir,
- const std::string &basename,
- const std::string &exe_name) {
- std::map<std::string, base::FilePath> logs;
-
- // Run the command specified by the config file to gather logs.
- const FilePath chrome_log_path =
- GetCrashPath(dir, basename, kChromeLogFilename);
- if (GetLogContents(log_config_path_, exe_name, chrome_log_path)) {
- const FilePath compressed_path = GzipFile(chrome_log_path);
- if (!compressed_path.empty())
- logs[kChromeLogFilename] = compressed_path;
- else
- base::DeleteFile(chrome_log_path, false /* recursive */);
- }
-
- // For unit testing, debugd_proxy_ isn't initialized, so skip attempting to
- // get the GPU error state from debugd.
- if (debugd_proxy_) {
- const FilePath dri_error_state_path =
- GetCrashPath(dir, basename, kGpuStateFilename);
- if (GetDriErrorState(dri_error_state_path, debugd_proxy_.get()))
- logs[kGpuStateFilename] = dri_error_state_path;
- }
-
- return logs;
-}
-
-// static
-const char ChromeCollector::kSuccessMagic[] = "_sys_cr_finished";
diff --git a/crash_reporter/chrome_collector.h b/crash_reporter/chrome_collector.h
deleted file mode 100644
index 0b58c19..0000000
--- a/crash_reporter/chrome_collector.h
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CRASH_REPORTER_CHROME_COLLECTOR_H_
-#define CRASH_REPORTER_CHROME_COLLECTOR_H_
-
-#include <map>
-#include <string>
-
-#include <base/files/file_path.h>
-#include <base/macros.h>
-#include <gtest/gtest_prod.h> // for FRIEND_TEST
-
-#include "crash-reporter/crash_collector.h"
-#include "debugd/dbus-proxies.h"
-
-class SystemLogging;
-
-// Chrome crash collector.
-class ChromeCollector : public CrashCollector {
- public:
- ChromeCollector();
- ~ChromeCollector() override;
-
- // Magic string to let Chrome know the crash report succeeded.
- static const char kSuccessMagic[];
-
- // Handle a specific chrome crash. Returns true on success.
- bool HandleCrash(const base::FilePath &file_path,
- const std::string &pid_string,
- const std::string &uid_string,
- const std::string &exe_name);
-
- protected:
- void SetUpDBus() override;
-
- private:
- friend class ChromeCollectorTest;
- FRIEND_TEST(ChromeCollectorTest, GoodValues);
- FRIEND_TEST(ChromeCollectorTest, BadValues);
- FRIEND_TEST(ChromeCollectorTest, Newlines);
- FRIEND_TEST(ChromeCollectorTest, File);
- FRIEND_TEST(ChromeCollectorTest, HandleCrash);
-
- // Crashes are expected to be in a TLV-style format of:
- // <name>:<length>:<value>
- // Length is encoded as a decimal number. It can be zero, but must consist of
- // at least one character
- // For file values, name actually contains both a description and a filename,
- // in a fixed format of: <description>"; filename="<filename>"
- bool ParseCrashLog(const std::string &data, const base::FilePath &dir,
- const base::FilePath &minidump,
- const std::string &basename);
-
- // Writes additional logs for |exe_name| to files based on |basename| within
- // |dir|. Crash report metadata key names and the corresponding file paths are
- // returned.
- std::map<std::string, base::FilePath> GetAdditionalLogs(
- const base::FilePath &dir,
- const std::string &basename,
- const std::string &exe_name);
-
- FILE *output_file_ptr_;
-
- // D-Bus proxy for debugd interface. Unset in unit tests.
- std::unique_ptr<org::chromium::debugdProxy> debugd_proxy_;
-
- DISALLOW_COPY_AND_ASSIGN(ChromeCollector);
-};
-
-#endif // CRASH_REPORTER_CHROME_COLLECTOR_H_
diff --git a/crash_reporter/chrome_collector_test.cc b/crash_reporter/chrome_collector_test.cc
deleted file mode 100644
index 0d6a7ce..0000000
--- a/crash_reporter/chrome_collector_test.cc
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copyright (c) 2013 The Chromium OS 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 "crash-reporter/chrome_collector.h"
-
-#include <stdio.h>
-
-#include <base/auto_reset.h>
-#include <base/files/file_util.h>
-#include <base/files/scoped_temp_dir.h>
-#include <chromeos/syslog_logging.h>
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-
-using base::FilePath;
-
-namespace {
-
-const char kCrashFormatGood[] = "value1:10:abcdefghijvalue2:5:12345";
-const char kCrashFormatEmbeddedNewline[] =
- "value1:10:abcd\r\nghijvalue2:5:12\n34";
-const char kCrashFormatBad1[] = "value1:10:abcdefghijvalue2:6=12345";
-const char kCrashFormatBad2[] = "value1:10:abcdefghijvalue2:512345";
-const char kCrashFormatBad3[] = "value1:10::abcdefghijvalue2:5=12345";
-const char kCrashFormatBad4[] = "value1:10:abcdefghijvalue2:4=12345";
-
-const char kCrashFormatWithFile[] =
- "value1:10:abcdefghijvalue2:5:12345"
- "some_file\"; filename=\"foo.txt\":15:12345\n789\n12345"
- "value3:2:ok";
-
-void CountCrash() {
-}
-
-bool s_allow_crash = false;
-
-bool IsMetrics() {
- return s_allow_crash;
-}
-
-} // namespace
-
-class ChromeCollectorMock : public ChromeCollector {
- public:
- MOCK_METHOD0(SetUpDBus, void());
-};
-
-class ChromeCollectorTest : public ::testing::Test {
- protected:
- void ExpectFileEquals(const char *golden,
- const FilePath &file_path) {
- std::string contents;
- EXPECT_TRUE(base::ReadFileToString(file_path, &contents));
- EXPECT_EQ(golden, contents);
- }
-
- ChromeCollectorMock collector_;
-
- private:
- void SetUp() override {
- EXPECT_CALL(collector_, SetUpDBus()).WillRepeatedly(testing::Return());
-
- collector_.Initialize(CountCrash, IsMetrics);
- chromeos::ClearLog();
- }
-};
-
-TEST_F(ChromeCollectorTest, GoodValues) {
- FilePath dir(".");
- EXPECT_TRUE(collector_.ParseCrashLog(kCrashFormatGood,
- dir, dir.Append("minidump.dmp"),
- "base"));
-
- // Check to see if the values made it in properly.
- std::string meta = collector_.extra_metadata_;
- EXPECT_TRUE(meta.find("value1=abcdefghij") != std::string::npos);
- EXPECT_TRUE(meta.find("value2=12345") != std::string::npos);
-}
-
-TEST_F(ChromeCollectorTest, Newlines) {
- FilePath dir(".");
- EXPECT_TRUE(collector_.ParseCrashLog(kCrashFormatEmbeddedNewline,
- dir, dir.Append("minidump.dmp"),
- "base"));
-
- // Check to see if the values were escaped.
- std::string meta = collector_.extra_metadata_;
- EXPECT_TRUE(meta.find("value1=abcd\\r\\nghij") != std::string::npos);
- EXPECT_TRUE(meta.find("value2=12\\n34") != std::string::npos);
-}
-
-TEST_F(ChromeCollectorTest, BadValues) {
- FilePath dir(".");
- const struct {
- const char *data;
- } list[] = {
- {kCrashFormatBad1, },
- {kCrashFormatBad2, },
- {kCrashFormatBad3, },
- {kCrashFormatBad4, },
- };
-
- for (size_t i = 0; i < sizeof(list) / sizeof(list[0]); i++) {
- chromeos::ClearLog();
- EXPECT_FALSE(collector_.ParseCrashLog(list[i].data,
- dir, dir.Append("minidump.dmp"),
- "base"));
- }
-}
-
-TEST_F(ChromeCollectorTest, File) {
- base::ScopedTempDir scoped_temp_dir;
- ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
- const FilePath& dir = scoped_temp_dir.path();
- EXPECT_TRUE(collector_.ParseCrashLog(kCrashFormatWithFile,
- dir, dir.Append("minidump.dmp"),
- "base"));
-
- // Check to see if the values are still correct and that the file was
- // written with the right data.
- std::string meta = collector_.extra_metadata_;
- EXPECT_TRUE(meta.find("value1=abcdefghij") != std::string::npos);
- EXPECT_TRUE(meta.find("value2=12345") != std::string::npos);
- EXPECT_TRUE(meta.find("value3=ok") != std::string::npos);
- ExpectFileEquals("12345\n789\n12345", dir.Append("base-foo.txt.other"));
-}
-
-TEST_F(ChromeCollectorTest, HandleCrash) {
- base::AutoReset<bool> auto_reset(&s_allow_crash, true);
- base::ScopedTempDir scoped_temp_dir;
- ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
- const FilePath& dir = scoped_temp_dir.path();
- FilePath dump_file = dir.Append("test.dmp");
- ASSERT_EQ(strlen(kCrashFormatWithFile),
- base::WriteFile(dump_file, kCrashFormatWithFile,
- strlen(kCrashFormatWithFile)));
- collector_.ForceCrashDirectory(dir);
-
- FilePath log_file;
- {
- base::ScopedFILE output(
- base::CreateAndOpenTemporaryFileInDir(dir, &log_file));
- ASSERT_TRUE(output.get());
- base::AutoReset<FILE*> auto_reset_file_ptr(&collector_.output_file_ptr_,
- output.get());
- EXPECT_TRUE(collector_.HandleCrash(dump_file, "123", "456", "chrome_test"));
- }
- ExpectFileEquals(ChromeCollector::kSuccessMagic, log_file);
-}
diff --git a/crash_reporter/crash-reporter.gyp b/crash_reporter/crash-reporter.gyp
deleted file mode 100644
index a7f0e7e..0000000
--- a/crash_reporter/crash-reporter.gyp
+++ /dev/null
@@ -1,147 +0,0 @@
-{
- # Shouldn't need this, but doesn't work otherwise.
- # http://crbug.com/340086 and http://crbug.com/385186
- # Note: the unused dependencies are optimized out by the compiler.
- 'target_defaults': {
- 'variables': {
- 'deps': [
- 'libchromeos-<(libbase_ver)',
- ],
- },
- },
- 'targets': [
- {
- 'target_name': 'libcrash',
- 'type': 'static_library',
- 'variables': {
- 'exported_deps': [
- 'libchrome-<(libbase_ver)',
- 'libpcrecpp',
- ],
- 'deps': ['<@(exported_deps)'],
- },
- 'all_dependent_settings': {
- 'variables': {
- 'deps': [
- '<@(exported_deps)',
- ],
- },
- },
- 'sources': [
- 'chrome_collector.cc',
- 'crash_collector.cc',
- 'kernel_collector.cc',
- 'kernel_warning_collector.cc',
- 'udev_collector.cc',
- 'unclean_shutdown_collector.cc',
- 'user_collector.cc',
- ],
- 'actions': [
- {
- 'action_name': 'generate-session-manager-proxies',
- 'variables': {
- 'proxy_output_file': 'include/session_manager/dbus-proxies.h'
- },
- 'sources': [
- '../login_manager/org.chromium.SessionManagerInterface.xml',
- ],
- 'includes': ['../common-mk/generate-dbus-proxies.gypi'],
- },
- {
- 'action_name': 'generate-debugd-proxies',
- 'variables': {
- 'proxy_output_file': 'include/debugd/dbus-proxies.h'
- },
- 'sources': [
- '../debugd/share/org.chromium.debugd.xml',
- ],
- 'includes': ['../common-mk/generate-dbus-proxies.gypi'],
- },
- ],
- },
- {
- 'target_name': 'crash_reporter',
- 'type': 'executable',
- 'variables': {
- 'deps': [
- 'dbus-1',
- 'libmetrics-<(libbase_ver)',
- ],
- },
- 'dependencies': [
- 'libcrash',
- ],
- 'sources': [
- 'crash_reporter.cc',
- ],
- },
- {
- 'target_name': 'list_proxies',
- 'type': 'executable',
- 'variables': {
- 'deps': [
- 'dbus-1',
- 'libchrome-<(libbase_ver)',
- ],
- },
- 'sources': [
- 'list_proxies.cc',
- ],
- 'actions': [
- {
- 'action_name': 'generate-lib-cros-service-proxies',
- 'variables': {
- 'proxy_output_file': 'include/libcrosservice/dbus-proxies.h'
- },
- 'sources': [
- './dbus_bindings/org.chromium.LibCrosService.xml',
- ],
- 'includes': ['../common-mk/generate-dbus-proxies.gypi'],
- },
- ],
- },
- {
- 'target_name': 'warn_collector',
- 'type': 'executable',
- 'variables': {
- 'lexer_out_dir': 'crash-reporter',
- 'deps': [
- 'libmetrics-<(libbase_ver)',
- ],
- },
- 'link_settings': {
- 'libraries': [
- '-lfl',
- ],
- },
- 'sources': [
- 'warn_collector.l',
- ],
- 'includes': ['../common-mk/lex.gypi'],
- },
- ],
- 'conditions': [
- ['USE_test == 1', {
- 'targets': [
- {
- 'target_name': 'crash_reporter_test',
- 'type': 'executable',
- 'includes': ['../common-mk/common_test.gypi'],
- 'dependencies': ['libcrash'],
- 'sources': [
- 'chrome_collector_test.cc',
- 'crash_collector_test.cc',
- 'crash_collector_test.h',
- 'crash_reporter_logs_test.cc',
- 'kernel_collector_test.cc',
- 'kernel_collector_test.h',
- 'testrunner.cc',
- 'udev_collector_test.cc',
- 'unclean_shutdown_collector_test.cc',
- 'user_collector_test.cc',
- ],
- },
- ],
- }],
- ],
-}
diff --git a/crash_reporter/crash_collector.cc b/crash_reporter/crash_collector.cc
index 04f3ba8..69fe939 100644
--- a/crash_reporter/crash_collector.cc
+++ b/crash_reporter/crash_collector.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "crash-reporter/crash_collector.h"
+#include "crash_collector.h"
#include <dirent.h>
#include <fcntl.h> // For file creation modes.
@@ -23,8 +23,6 @@
#include <base/strings/string_split.h>
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
-#include <chromeos/cryptohome.h>
-#include <chromeos/dbus/service_constants.h>
#include <chromeos/key_value_store.h>
#include <chromeos/process.h>
@@ -87,8 +85,6 @@
}
CrashCollector::~CrashCollector() {
- if (bus_)
- bus_->ShutdownAndBlock();
}
void CrashCollector::Initialize(
@@ -99,21 +95,6 @@
count_crash_function_ = count_crash_function;
is_feedback_allowed_function_ = is_feedback_allowed_function;
-
- SetUpDBus();
-}
-
-void CrashCollector::SetUpDBus() {
- dbus::Bus::Options options;
- options.bus_type = dbus::Bus::SYSTEM;
-
- bus_ = new dbus::Bus(options);
- CHECK(bus_->Connect());
-
- session_manager_proxy_.reset(
- new org::chromium::SessionManagerInterfaceProxy(
- bus_,
- login_manager::kSessionManagerServiceName));
}
int CrashCollector::WriteNewFile(const FilePath &filename,
@@ -166,38 +147,6 @@
extension.c_str()));
}
-bool CrashCollector::GetActiveUserSessions(
- std::map<std::string, std::string> *sessions) {
- chromeos::ErrorPtr error;
- session_manager_proxy_->RetrieveActiveSessions(sessions, &error);
-
- if (error) {
- LOG(ERROR) << "Error calling D-Bus proxy call to interface "
- << "'" << session_manager_proxy_->GetObjectPath().value() << "':"
- << error->GetMessage();
- return false;
- }
-
- return true;
-}
-
-FilePath CrashCollector::GetUserCrashPath() {
- // In this multiprofile world, there is no one-specific user dir anymore.
- // Ask the session manager for the active ones, then just run with the
- // first result we get back.
- FilePath user_path = FilePath(kFallbackUserCrashPath);
- std::map<std::string, std::string> active_sessions;
- if (!GetActiveUserSessions(&active_sessions) || active_sessions.empty()) {
- LOG(ERROR) << "Could not get active user sessions, using default.";
- return user_path;
- }
-
- user_path = chromeos::cryptohome::home::GetHashedUserPath(
- active_sessions.begin()->second).Append("crash");
-
- return user_path;
-}
-
FilePath CrashCollector::GetCrashDirectoryInfo(
uid_t process_euid,
uid_t default_user_id,
@@ -205,17 +154,11 @@
mode_t *mode,
uid_t *directory_owner,
gid_t *directory_group) {
- // TODO(mkrebs): This can go away once Chrome crashes are handled
- // normally (see crosbug.com/5872).
- // Check if the user crash directory should be used. If we are
- // collecting chrome crashes during autotesting, we want to put them in
- // the system crash directory so they are outside the cryptohome -- in
- // case we are being run during logout (see crosbug.com/18637).
- if (process_euid == default_user_id && IsUserSpecificDirectoryEnabled()) {
+ if (process_euid == default_user_id) {
*mode = kUserCrashPathMode;
*directory_owner = default_user_id;
*directory_group = default_user_group;
- return GetUserCrashPath();
+ return FilePath(kFallbackUserCrashPath);
} else {
*mode = kSystemCrashPathMode;
*directory_owner = kRootOwner;
@@ -491,22 +434,3 @@
return false;
return base::PathExists(FilePath(kLeaveCoreFile));
}
-
-bool CrashCollector::ShouldHandleChromeCrashes() {
- // If we're testing crash reporter itself, we don't want to allow an
- // override for chrome crashes. And, let's be conservative and only
- // allow an override for developer images.
- if (!IsCrashTestInProgress() && IsDeveloperImage()) {
- // Check if there's an override to indicate we should indeed collect
- // chrome crashes. This allows the crashes to still be tracked when
- // they occur in autotests. See "crosbug.com/17987".
- if (base::PathExists(FilePath(kCollectChromeFile)))
- return true;
- }
- // We default to ignoring chrome crashes.
- return false;
-}
-
-bool CrashCollector::IsUserSpecificDirectoryEnabled() {
- return !ShouldHandleChromeCrashes();
-}
diff --git a/crash_reporter/crash_collector.h b/crash_reporter/crash_collector.h
index ef443d3..0d335cd 100644
--- a/crash_reporter/crash_collector.h
+++ b/crash_reporter/crash_collector.h
@@ -12,11 +12,8 @@
#include <base/files/file_path.h>
#include <base/macros.h>
-#include <base/memory/scoped_ptr.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
-#include "session_manager/dbus-proxies.h"
-
// User crash collector.
class CrashCollector {
public:
@@ -44,7 +41,6 @@
FRIEND_TEST(CrashCollectorTest, ForkExecAndPipe);
FRIEND_TEST(CrashCollectorTest, FormatDumpBasename);
FRIEND_TEST(CrashCollectorTest, Initialize);
- FRIEND_TEST(CrashCollectorTest, IsUserSpecificDirectoryEnabled);
FRIEND_TEST(CrashCollectorTest, MetaData);
FRIEND_TEST(CrashCollectorTest, Sanitize);
FRIEND_TEST(CrashCollectorTest, WriteNewFile);
@@ -61,9 +57,6 @@
// Set maximum enqueued crashes in a crash directory.
static const int kMaxCrashDirectorySize;
- // Set up D-Bus.
- virtual void SetUpDBus();
-
// Writes |data| of |size| to |filename|, which must be a new file.
// If the file already exists or writing fails, return a negative value.
// Otherwise returns the number of bytes written.
@@ -79,9 +72,6 @@
forced_crash_directory_ = forced_directory;
}
- virtual bool GetActiveUserSessions(
- std::map<std::string, std::string> *sessions);
- base::FilePath GetUserCrashPath();
base::FilePath GetCrashDirectoryInfo(uid_t process_euid,
uid_t default_user_id,
gid_t default_user_group,
@@ -154,10 +144,6 @@
// Returns true if we should consider ourselves to be running on a
// developer image.
bool IsDeveloperImage();
- // Returns true if chrome crashes should be handled.
- bool ShouldHandleChromeCrashes();
- // Returns true if user crash directory may be used.
- bool IsUserSpecificDirectoryEnabled();
CountCrashFunction count_crash_function_;
IsFeedbackAllowedFunction is_feedback_allowed_function_;
@@ -166,13 +152,7 @@
std::string lsb_release_;
base::FilePath log_config_path_;
- scoped_refptr<dbus::Bus> bus_;
-
private:
- // D-Bus proxy for session manager interface.
- std::unique_ptr<org::chromium::SessionManagerInterfaceProxy>
- session_manager_proxy_;
-
DISALLOW_COPY_AND_ASSIGN(CrashCollector);
};
diff --git a/crash_reporter/crash_collector_test.cc b/crash_reporter/crash_collector_test.cc
index ce9af2b..13fb76a 100644
--- a/crash_reporter/crash_collector_test.cc
+++ b/crash_reporter/crash_collector_test.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "crash-reporter/crash_collector_test.h"
+#include "crash_collector_test.h"
#include <unistd.h>
#include <utility>
@@ -13,7 +13,7 @@
#include <chromeos/syslog_logging.h>
#include <gtest/gtest.h>
-#include "crash-reporter/crash_collector.h"
+#include "crash_collector.h"
using base::FilePath;
using base::StringPrintf;
@@ -32,13 +32,6 @@
return false;
}
-bool GetActiveUserSessionsImpl(std::map<std::string, std::string> *sessions) {
- char kUser[] = "chicken@butt.com";
- char kHash[] = "hashcakes";
- sessions->insert(std::pair<std::string, std::string>(kUser, kHash));
- return true;
-}
-
} // namespace
class CrashCollectorTest : public ::testing::Test {
@@ -126,18 +119,13 @@
EXPECT_EQ(kRootUid, directory_owner);
EXPECT_EQ(kRootGid, directory_group);
- EXPECT_CALL(collector_, GetActiveUserSessions(testing::_))
- .WillOnce(Invoke(&GetActiveUserSessionsImpl));
-
- EXPECT_EQ(collector_.IsUserSpecificDirectoryEnabled(), true);
-
path = collector_.GetCrashDirectoryInfo(kChronosUid,
kChronosUid,
kChronosGid,
&directory_mode,
&directory_owner,
&directory_group);
- EXPECT_EQ("/home/user/hashcakes/crash", path.value());
+ EXPECT_EQ("/var/spool/crash", path.value());
EXPECT_EQ(kExpectedUserMode, directory_mode);
EXPECT_EQ(kChronosUid, directory_owner);
EXPECT_EQ(kChronosGid, directory_group);
diff --git a/crash_reporter/crash_collector_test.h b/crash_reporter/crash_collector_test.h
index 8339fa0..c875d44 100644
--- a/crash_reporter/crash_collector_test.h
+++ b/crash_reporter/crash_collector_test.h
@@ -5,7 +5,7 @@
#ifndef CRASH_REPORTER_CRASH_COLLECTOR_TEST_H_
#define CRASH_REPORTER_CRASH_COLLECTOR_TEST_H_
-#include "crash-reporter/crash_collector.h"
+#include "crash_collector.h"
#include <map>
#include <string>
diff --git a/crash_reporter/crash_reporter.cc b/crash_reporter/crash_reporter.cc
index 1528b3f..0e45992 100644
--- a/crash_reporter/crash_reporter.cc
+++ b/crash_reporter/crash_reporter.cc
@@ -16,12 +16,11 @@
#include <chromeos/syslog_logging.h>
#include <metrics/metrics_library.h>
-#include "crash-reporter/chrome_collector.h"
-#include "crash-reporter/kernel_collector.h"
-#include "crash-reporter/kernel_warning_collector.h"
-#include "crash-reporter/udev_collector.h"
-#include "crash-reporter/unclean_shutdown_collector.h"
-#include "crash-reporter/user_collector.h"
+#include "kernel_collector.h"
+#include "kernel_warning_collector.h"
+#include "udev_collector.h"
+#include "unclean_shutdown_collector.h"
+#include "user_collector.h"
static const char kCrashCounterHistogram[] = "Logging.CrashCounter";
static const char kUserCrashSignal[] =
@@ -97,12 +96,6 @@
LOG_IF(WARNING, status != 0) << "dbus-send running failed";
}
-static void CountChromeCrash() {
- // For now, consider chrome crashes the same as user crashes for reporting
- // purposes.
- CountUserCrash();
-}
-
static int Initialize(KernelCollector *kernel_collector,
UserCollector *user_collector,
@@ -164,25 +157,6 @@
return 0;
}
-static int HandleChromeCrash(ChromeCollector *chrome_collector,
- const std::string& chrome_dump_file,
- const std::string& pid,
- const std::string& uid,
- const std::string& exe) {
- CHECK(!chrome_dump_file.empty()) << "--chrome= must be set";
- CHECK(!pid.empty()) << "--pid= must be set";
- CHECK(!uid.empty()) << "--uid= must be set";
- CHECK(!exe.empty()) << "--exe= must be set";
-
- chromeos::LogToString(true);
- bool handled = chrome_collector->HandleCrash(FilePath(chrome_dump_file),
- pid, uid, exe);
- chromeos::LogToString(false);
- if (!handled)
- return 1;
- return 0;
-}
-
static int HandleUdevCrash(UdevCollector *udev_collector,
const std::string& udev_event) {
// Handle a crash indicated by a udev event.
@@ -258,7 +232,6 @@
DEFINE_bool(unclean_check, true, "Check for unclean shutdown");
DEFINE_string(udev, "", "Udev event description (type:device:subsystem)");
DEFINE_bool(kernel_warning, false, "Report collected kernel warning");
- DEFINE_string(chrome, "", "Chrome crash dump file");
DEFINE_string(pid, "", "PID of crashing process");
DEFINE_string(uid, "", "UID of crashing process");
DEFINE_string(exe, "", "Executable name of crashing process");
@@ -289,8 +262,6 @@
IsFeedbackAllowed);
UdevCollector udev_collector;
udev_collector.Initialize(CountUdevCrash, IsFeedbackAllowed);
- ChromeCollector chrome_collector;
- chrome_collector.Initialize(CountChromeCrash, IsFeedbackAllowed);
KernelWarningCollector kernel_warning_collector;
kernel_warning_collector.Initialize(CountUdevCrash, IsFeedbackAllowed);
@@ -322,13 +293,5 @@
return HandleKernelWarning(&kernel_warning_collector);
}
- if (!FLAGS_chrome.empty()) {
- return HandleChromeCrash(&chrome_collector,
- FLAGS_chrome,
- FLAGS_pid,
- FLAGS_uid,
- FLAGS_exe);
- }
-
return HandleUserCrash(&user_collector, FLAGS_user, FLAGS_crash_test);
}
diff --git a/crash_reporter/kernel_collector.cc b/crash_reporter/kernel_collector.cc
index d86efbd..b3cbede 100644
--- a/crash_reporter/kernel_collector.cc
+++ b/crash_reporter/kernel_collector.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "crash-reporter/kernel_collector.h"
+#include "kernel_collector.h"
#include <map>
#include <sys/stat.h>
diff --git a/crash_reporter/kernel_collector.h b/crash_reporter/kernel_collector.h
index c8aedfe..5fc4ac2 100644
--- a/crash_reporter/kernel_collector.h
+++ b/crash_reporter/kernel_collector.h
@@ -13,7 +13,7 @@
#include <base/macros.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
-#include "crash-reporter/crash_collector.h"
+#include "crash_collector.h"
// Kernel crash collector.
class KernelCollector : public CrashCollector {
diff --git a/crash_reporter/kernel_collector_test.cc b/crash_reporter/kernel_collector_test.cc
index 48d94ea..a534803 100644
--- a/crash_reporter/kernel_collector_test.cc
+++ b/crash_reporter/kernel_collector_test.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "crash-reporter/kernel_collector_test.h"
+#include "kernel_collector_test.h"
#include <unistd.h>
diff --git a/crash_reporter/kernel_collector_test.h b/crash_reporter/kernel_collector_test.h
index 75ac01e..d450134 100644
--- a/crash_reporter/kernel_collector_test.h
+++ b/crash_reporter/kernel_collector_test.h
@@ -5,7 +5,7 @@
#ifndef CRASH_REPORTER_KERNEL_COLLECTOR_TEST_H_
#define CRASH_REPORTER_KERNEL_COLLECTOR_TEST_H_
-#include "crash-reporter/kernel_collector.h"
+#include "kernel_collector.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
diff --git a/crash_reporter/kernel_warning_collector.cc b/crash_reporter/kernel_warning_collector.cc
index 5dcd1f6..4cf7640 100644
--- a/crash_reporter/kernel_warning_collector.cc
+++ b/crash_reporter/kernel_warning_collector.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "crash-reporter/kernel_warning_collector.h"
+#include "kernel_warning_collector.h"
#include <base/files/file_util.h>
#include <base/logging.h>
diff --git a/crash_reporter/kernel_warning_collector.h b/crash_reporter/kernel_warning_collector.h
index f326b23..82c509c 100644
--- a/crash_reporter/kernel_warning_collector.h
+++ b/crash_reporter/kernel_warning_collector.h
@@ -10,7 +10,7 @@
#include <base/macros.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
-#include "crash-reporter/crash_collector.h"
+#include "crash_collector.h"
// Kernel warning collector.
class KernelWarningCollector : public CrashCollector {
diff --git a/crash_reporter/udev_collector.cc b/crash_reporter/udev_collector.cc
index 908bbc9..85f40db 100644
--- a/crash_reporter/udev_collector.cc
+++ b/crash_reporter/udev_collector.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "crash-reporter/udev_collector.h"
+#include "udev_collector.h"
#include <map>
#include <utility>
diff --git a/crash_reporter/udev_collector.h b/crash_reporter/udev_collector.h
index 1689dd3..d9b37eb 100644
--- a/crash_reporter/udev_collector.h
+++ b/crash_reporter/udev_collector.h
@@ -11,7 +11,7 @@
#include <base/macros.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
-#include "crash-reporter/crash_collector.h"
+#include "crash_collector.h"
// Udev crash collector.
class UdevCollector : public CrashCollector {
diff --git a/crash_reporter/udev_collector_test.cc b/crash_reporter/udev_collector_test.cc
index 08d9b2c..4897b91 100644
--- a/crash_reporter/udev_collector_test.cc
+++ b/crash_reporter/udev_collector_test.cc
@@ -10,7 +10,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-#include "crash-reporter/udev_collector.h"
+#include "udev_collector.h"
using base::FilePath;
diff --git a/crash_reporter/unclean_shutdown_collector.cc b/crash_reporter/unclean_shutdown_collector.cc
index e8273b5..a6da1bb 100644
--- a/crash_reporter/unclean_shutdown_collector.cc
+++ b/crash_reporter/unclean_shutdown_collector.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "crash-reporter/unclean_shutdown_collector.h"
+#include "unclean_shutdown_collector.h"
#include <base/files/file_util.h>
#include <base/logging.h>
diff --git a/crash_reporter/unclean_shutdown_collector.h b/crash_reporter/unclean_shutdown_collector.h
index d30a0b2..2ce0842 100644
--- a/crash_reporter/unclean_shutdown_collector.h
+++ b/crash_reporter/unclean_shutdown_collector.h
@@ -11,7 +11,7 @@
#include <base/macros.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
-#include "crash-reporter/crash_collector.h"
+#include "crash_collector.h"
// Unclean shutdown collector.
class UncleanShutdownCollector : public CrashCollector {
diff --git a/crash_reporter/unclean_shutdown_collector_test.cc b/crash_reporter/unclean_shutdown_collector_test.cc
index f5e1b32..dc420fb 100644
--- a/crash_reporter/unclean_shutdown_collector_test.cc
+++ b/crash_reporter/unclean_shutdown_collector_test.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "crash-reporter/unclean_shutdown_collector.h"
+#include "unclean_shutdown_collector.h"
#include <unistd.h>
diff --git a/crash_reporter/user_collector.cc b/crash_reporter/user_collector.cc
index 302b130..069b581 100644
--- a/crash_reporter/user_collector.cc
+++ b/crash_reporter/user_collector.cc
@@ -2,25 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "crash-reporter/user_collector.h"
+#include "user_collector.h"
-#include <bits/wordsize.h>
#include <elf.h>
#include <fcntl.h>
#include <grp.h> // For struct group.
#include <pcrecpp.h>
#include <pwd.h> // For struct passwd.
#include <stdint.h>
+#include <sys/cdefs.h> // For __WORDSIZE
#include <sys/types.h> // For getpwuid_r, getgrnam_r, WEXITSTATUS.
-#include <set>
#include <string>
#include <vector>
#include <base/files/file_util.h>
#include <base/logging.h>
#include <base/posix/eintr_wrapper.h>
-#include <base/stl_util.h>
#include <base/strings/string_split.h>
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
@@ -495,101 +493,11 @@
kernel_supplied_name);
}
-// Returns true if the given executable name matches that of Chrome. This
-// includes checks for threads that Chrome has renamed.
-static bool IsChromeExecName(const std::string &exec) {
- static const char *kChromeNames[] = {
- "chrome",
- // These are additional thread names seen in http://crash/
- "MediaPipeline",
- // These come from the use of base::PlatformThread::SetName() directly
- "CrBrowserMain", "CrRendererMain", "CrUtilityMain", "CrPPAPIMain",
- "CrPPAPIBrokerMain", "CrPluginMain", "CrWorkerMain", "CrGpuMain",
- "BrokerEvent", "CrVideoRenderer", "CrShutdownDetector",
- "UsbEventHandler", "CrNaClMain", "CrServiceMain",
- // These thread names come from the use of base::Thread
- "Gamepad polling thread", "Chrome_InProcGpuThread",
- "Chrome_DragDropThread", "Renderer::FILE", "VC manager",
- "VideoCaptureModuleImpl", "JavaBridge", "VideoCaptureManagerThread",
- "Geolocation", "Geolocation_wifi_provider",
- "Device orientation polling thread", "Chrome_InProcRendererThread",
- "NetworkChangeNotifier", "Watchdog", "inotify_reader",
- "cf_iexplore_background_thread", "BrowserWatchdog",
- "Chrome_HistoryThread", "Chrome_SyncThread", "Chrome_ShellDialogThread",
- "Printing_Worker", "Chrome_SafeBrowsingThread", "SimpleDBThread",
- "D-Bus thread", "AudioThread", "NullAudioThread", "V4L2Thread",
- "ChromotingClientDecodeThread", "Profiling_Flush",
- "worker_thread_ticker", "AudioMixerAlsa", "AudioMixerCras",
- "FakeAudioRecordingThread", "CaptureThread",
- "Chrome_WebSocketproxyThread", "ProcessWatcherThread",
- "Chrome_CameraThread", "import_thread", "NaCl_IOThread",
- "Chrome_CloudPrintJobPrintThread", "Chrome_CloudPrintProxyCoreThread",
- "DaemonControllerFileIO", "ChromotingMainThread",
- "ChromotingEncodeThread", "ChromotingDesktopThread",
- "ChromotingIOThread", "ChromotingFileIOThread",
- "Chrome_libJingle_WorkerThread", "Chrome_ChildIOThread",
- "GLHelperThread", "RemotingHostPlugin",
- // "PAC thread #%d", // not easy to check because of "%d"
- "Chrome_DBThread", "Chrome_WebKitThread", "Chrome_FileThread",
- "Chrome_FileUserBlockingThread", "Chrome_ProcessLauncherThread",
- "Chrome_CacheThread", "Chrome_IOThread", "Cache Thread", "File Thread",
- "ServiceProcess_IO", "ServiceProcess_File",
- "extension_crash_uploader", "gpu-process_crash_uploader",
- "plugin_crash_uploader", "renderer_crash_uploader",
- // These come from the use of webkit_glue::WebThreadImpl
- "Compositor", "Browser Compositor",
- // "WorkerPool/%d", // not easy to check because of "%d"
- // These come from the use of base::Watchdog
- "Startup watchdog thread Watchdog", "Shutdown watchdog thread Watchdog",
- // These come from the use of AudioDeviceThread::Start
- "AudioDevice", "AudioInputDevice", "AudioOutputDevice",
- // These come from the use of MessageLoopFactory::GetMessageLoop
- "GpuVideoDecoder", "RtcVideoDecoderThread", "PipelineThread",
- "AudioDecoderThread", "VideoDecoderThread",
- // These come from the use of MessageLoopFactory::GetMessageLoopProxy
- "CaptureVideoDecoderThread", "CaptureVideoDecoder",
- // These come from the use of base::SimpleThread
- "LocalInputMonitor/%d", // "%d" gets lopped off for kernel-supplied
- // These come from the use of base::DelegateSimpleThread
- "ipc_channel_nacl reader thread/%d", "plugin_audio_input_thread/%d",
- "plugin_audio_thread/%d",
- // These come from the use of base::SequencedWorkerPool
- "BrowserBlockingWorker%d/%d", // "%d" gets lopped off for kernel-supplied
- };
- static std::set<std::string> chrome_names;
-
- // Initialize a set of chrome names, for efficient lookup
- if (chrome_names.empty()) {
- for (size_t i = 0; i < arraysize(kChromeNames); i++) {
- std::string check_name(kChromeNames[i]);
- chrome_names.insert(check_name);
- // When checking a kernel-supplied name, it should be truncated to 15
- // chars. See PR_SET_NAME in
- // http://www.kernel.org/doc/man-pages/online/pages/man2/prctl.2.html,
- // although that page misleads by saying "16 bytes".
- chrome_names.insert("supplied_" + std::string(check_name, 0, 15));
- }
- }
-
- return ContainsKey(chrome_names, exec);
-}
-
bool UserCollector::ShouldDump(bool has_owner_consent,
bool is_developer,
- bool handle_chrome_crashes,
- const std::string &exec,
std::string *reason) {
reason->clear();
- // Treat Chrome crashes as if the user opted-out. We stop counting Chrome
- // crashes towards user crashes, so user crashes really mean non-Chrome
- // user-space crashes.
- if (!handle_chrome_crashes && IsChromeExecName(exec)) {
- *reason = "ignoring call by kernel - chrome crash; "
- "waiting for chrome to call us directly";
- return false;
- }
-
// For developer builds, we always want to keep the crash reports unless
// we're testing the crash facilities themselves. This overrides
// feedback. Crash sending still obeys consent.
@@ -646,8 +554,6 @@
std::string reason;
bool dump = ShouldDump(is_feedback_allowed_function_(),
IsDeveloperImage(),
- ShouldHandleChromeCrashes(),
- exec,
&reason);
LOG(WARNING) << "Received crash notification for " << exec << "[" << pid
diff --git a/crash_reporter/user_collector.h b/crash_reporter/user_collector.h
index aac94cb..7b356ee 100644
--- a/crash_reporter/user_collector.h
+++ b/crash_reporter/user_collector.h
@@ -12,7 +12,7 @@
#include <base/macros.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
-#include "crash-reporter/crash_collector.h"
+#include "crash_collector.h"
class SystemLogging;
@@ -169,8 +169,6 @@
bool ShouldDump(bool has_owner_consent,
bool is_developer,
- bool handle_chrome_crashes,
- const std::string &exec,
std::string *reason);
bool generate_diagnostics_;
diff --git a/crash_reporter/user_collector_test.cc b/crash_reporter/user_collector_test.cc
index 823d8b4..ee3ca12 100644
--- a/crash_reporter/user_collector_test.cc
+++ b/crash_reporter/user_collector_test.cc
@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "crash-reporter/user_collector.h"
+#include "user_collector.h"
-#include <bits/wordsize.h>
#include <elf.h>
+#include <sys/cdefs.h> // For __WORDSIZE
#include <unistd.h>
#include <base/files/file_util.h>
@@ -164,81 +164,20 @@
TEST_F(UserCollectorTest, ShouldDumpDeveloperImageOverridesConsent) {
std::string reason;
- EXPECT_TRUE(collector_.ShouldDump(false, true, false,
- "chrome-wm", &reason));
+ EXPECT_TRUE(collector_.ShouldDump(false, true, &reason));
EXPECT_EQ("developer build - not testing - always dumping", reason);
// When running a crash test, behave as normal.
- EXPECT_FALSE(collector_.ShouldDump(false, false, false,
- "chrome-wm", &reason));
+ EXPECT_FALSE(collector_.ShouldDump(false, false, &reason));
EXPECT_EQ("ignoring - no consent", reason);
}
-TEST_F(UserCollectorTest, ShouldDumpChromeOverridesDeveloperImage) {
- std::string reason;
- // When running a crash test, behave as normal.
- EXPECT_FALSE(collector_.ShouldDump(false, false, false,
- "chrome", &reason));
- EXPECT_EQ(kChromeIgnoreMsg, reason);
- EXPECT_FALSE(collector_.ShouldDump(false, false, false,
- "supplied_Compositor", &reason));
- EXPECT_EQ(kChromeIgnoreMsg, reason);
- EXPECT_FALSE(collector_.ShouldDump(false, false, false,
- "supplied_PipelineThread", &reason));
- EXPECT_EQ(kChromeIgnoreMsg, reason);
- EXPECT_FALSE(collector_.ShouldDump(false, false, false,
- "Chrome_ChildIOThread", &reason));
- EXPECT_EQ(kChromeIgnoreMsg, reason);
- EXPECT_FALSE(collector_.ShouldDump(false, false, false,
- "supplied_Chrome_ChildIOT", &reason));
- EXPECT_EQ(kChromeIgnoreMsg, reason);
- EXPECT_FALSE(collector_.ShouldDump(false, false, false,
- "supplied_ChromotingClien", &reason));
- EXPECT_EQ(kChromeIgnoreMsg, reason);
- EXPECT_FALSE(collector_.ShouldDump(false, false, false,
- "supplied_LocalInputMonit", &reason));
- EXPECT_EQ(kChromeIgnoreMsg, reason);
-
- // When running a developer image, test that chrome crashes are handled
- // when the "handle_chrome_crashes" flag is set.
- EXPECT_TRUE(collector_.ShouldDump(false, true, true,
- "chrome", &reason));
- EXPECT_EQ("developer build - not testing - always dumping",
- reason);
- EXPECT_TRUE(collector_.ShouldDump(false, true, true,
- "supplied_Compositor", &reason));
- EXPECT_EQ("developer build - not testing - always dumping",
- reason);
- EXPECT_TRUE(collector_.ShouldDump(false, true, true,
- "supplied_PipelineThread", &reason));
- EXPECT_EQ("developer build - not testing - always dumping",
- reason);
- EXPECT_TRUE(collector_.ShouldDump(false, true, true,
- "Chrome_ChildIOThread", &reason));
- EXPECT_EQ("developer build - not testing - always dumping",
- reason);
- EXPECT_TRUE(collector_.ShouldDump(false, true, true,
- "supplied_Chrome_ChildIOT", &reason));
- EXPECT_EQ("developer build - not testing - always dumping",
- reason);
- EXPECT_TRUE(collector_.ShouldDump(false, true, true,
- "supplied_ChromotingClien", &reason));
- EXPECT_EQ("developer build - not testing - always dumping",
- reason);
- EXPECT_TRUE(collector_.ShouldDump(false, true, true,
- "supplied_LocalInputMonit", &reason));
- EXPECT_EQ("developer build - not testing - always dumping",
- reason);
-}
-
TEST_F(UserCollectorTest, ShouldDumpUseConsentProductionImage) {
std::string result;
- EXPECT_FALSE(collector_.ShouldDump(false, false, false,
- "chrome-wm", &result));
+ EXPECT_FALSE(collector_.ShouldDump(false, false, &result));
EXPECT_EQ("ignoring - no consent", result);
- EXPECT_TRUE(collector_.ShouldDump(true, false, false,
- "chrome-wm", &result));
+ EXPECT_TRUE(collector_.ShouldDump(true, false, &result));
EXPECT_EQ("handling", result);
}
diff --git a/crash_reporter/warn_collector.l b/crash_reporter/warn_collector.l
index 691ef99..de746fe 100644
--- a/crash_reporter/warn_collector.l
+++ b/crash_reporter/warn_collector.l
@@ -11,6 +11,8 @@
* shipment to the crash server.
*/
+%option noyywrap
+
%{
#include <fcntl.h>
#include <inttypes.h>
@@ -122,6 +124,7 @@
hash_bitmap[word_index] |= 1 << bit_index;
}
+#pragma GCC diagnostic ignored "-Wwrite-strings"
int WarnStart(void) {
uint32_t hash;
char *spacep;
@@ -140,7 +143,7 @@
yyout = fopen(warn_dump_path, "w");
if (yyout == NULL)
Die("fopen %s failed: %s\n", warn_dump_path, strerror(errno));
- spacep = index(yytext, ' ');
+ spacep = strchr(yytext, ' ');
if (spacep == NULL || spacep[1] == '\0')
spacep = "unknown-function";
fprintf(yyout, "%08x-%s\n", hash, spacep + 1);
@@ -318,5 +321,4 @@
*/
void UnusedFunctionWarningSuppressor(void) {
yyunput(0, 0);
- (void) input();
}
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index b964a36..5d7b151 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -189,25 +189,16 @@
return load_fd(fd, _sz);
}
-int match_fastboot_with_serial(usb_ifc_info *info, const char *local_serial)
-{
- if(!(vendor_id && (info->dev_vendor == vendor_id)) &&
- (info->dev_vendor != 0x18d1) && // Google
- (info->dev_vendor != 0x8087) && // Intel
- (info->dev_vendor != 0x0451) &&
- (info->dev_vendor != 0x0502) &&
- (info->dev_vendor != 0x0fce) && // Sony Ericsson
- (info->dev_vendor != 0x05c6) && // Qualcomm
- (info->dev_vendor != 0x22b8) && // Motorola
- (info->dev_vendor != 0x0955) && // Nvidia
- (info->dev_vendor != 0x413c) && // DELL
- (info->dev_vendor != 0x2314) && // INQ Mobile
- (info->dev_vendor != 0x0b05) && // Asus
- (info->dev_vendor != 0x0bb4)) // HTC
- return -1;
- if(info->ifc_class != 0xff) return -1;
- if(info->ifc_subclass != 0x42) return -1;
- if(info->ifc_protocol != 0x03) return -1;
+int match_fastboot_with_serial(usb_ifc_info* info, const char* local_serial) {
+ // Require a matching vendor id if the user specified one with -i.
+ if (vendor_id != 0 && info->dev_vendor != vendor_id) {
+ return -1;
+ }
+
+ if (info->ifc_class != 0xff || info->ifc_subclass != 0x42 || info->ifc_protocol != 0x03) {
+ return -1;
+ }
+
// require matching serial number or device path if requested
// at the command line with the -s option.
if (local_serial && (strcmp(local_serial, info->serial_number) != 0 &&
diff --git a/metrics/uploader/system_profile_cache.cc b/metrics/uploader/system_profile_cache.cc
deleted file mode 100644
index ea4a38c..0000000
--- a/metrics/uploader/system_profile_cache.cc
+++ /dev/null
@@ -1,238 +0,0 @@
-// Copyright 2014 The Chromium OS 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 "metrics/uploader/system_profile_cache.h"
-
-#include <string>
-#include <vector>
-
-#include "base/files/file_util.h"
-#include "base/guid.h"
-#include "base/logging.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_util.h"
-#include "base/sys_info.h"
-#include "metrics/persistent_integer.h"
-#include "metrics/uploader/metrics_log_base.h"
-#include "metrics/uploader/proto/chrome_user_metrics_extension.pb.h"
-#include "vboot/crossystem.h"
-
-namespace {
-
-const char kPersistentGUIDFile[] = "/var/lib/metrics/Sysinfo.GUID";
-const char kPersistentSessionIdFilename[] = "Sysinfo.SessionId";
-const char kProductIdFieldName[] = "GOOGLE_METRICS_PRODUCT_ID";
-
-} // namespace
-
-std::string ChannelToString(
- const metrics::SystemProfileProto_Channel& channel) {
- switch (channel) {
- case metrics::SystemProfileProto::CHANNEL_STABLE:
- return "STABLE";
- case metrics::SystemProfileProto::CHANNEL_DEV:
- return "DEV";
- case metrics::SystemProfileProto::CHANNEL_BETA:
- return "BETA";
- case metrics::SystemProfileProto::CHANNEL_CANARY:
- return "CANARY";
- default:
- return "UNKNOWN";
- }
-}
-
-SystemProfileCache::SystemProfileCache()
- : initialized_(false),
- testing_(false),
- config_root_("/"),
- session_id_(new chromeos_metrics::PersistentInteger(
- kPersistentSessionIdFilename)) {
-}
-
-SystemProfileCache::SystemProfileCache(bool testing,
- const std::string& config_root)
- : initialized_(false),
- testing_(testing),
- config_root_(config_root),
- session_id_(new chromeos_metrics::PersistentInteger(
- kPersistentSessionIdFilename)) {
-}
-
-bool SystemProfileCache::Initialize() {
- CHECK(!initialized_)
- << "this should be called only once in the metrics_daemon lifetime.";
-
- std::string chromeos_version;
- std::string board;
- std::string build_type;
- if (!base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_NAME",
- &profile_.os_name) ||
- !base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_VERSION",
- &profile_.os_version) ||
- !base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BOARD", &board) ||
- !base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BUILD_TYPE",
- &build_type) ||
- !GetChromeOSVersion(&chromeos_version) ||
- !GetHardwareId(&profile_.hardware_class)) {
- DLOG(ERROR) << "failing to initialize profile cache";
- return false;
- }
-
- std::string channel_string;
- base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_TRACK", &channel_string);
- profile_.channel = ProtoChannelFromString(channel_string);
-
- profile_.app_version = chromeos_version + " (" + build_type + ")" +
- ChannelToString(profile_.channel) + " " + board;
-
- // If the product id is not defined, use the default one from the protobuf.
- profile_.product_id = metrics::ChromeUserMetricsExtension::CHROME;
- if (GetProductId(&profile_.product_id)) {
- DLOG(INFO) << "Set the product id to " << profile_.product_id;
- }
-
- profile_.client_id =
- testing_ ? "client_id_test" : GetPersistentGUID(kPersistentGUIDFile);
-
- // Increment the session_id everytime we initialize this. If metrics_daemon
- // does not crash, this should correspond to the number of reboots of the
- // system.
- // TODO(bsimonnet): Change this to map to the number of time system-services
- // is started.
- session_id_->Add(1);
- profile_.session_id = static_cast<int32_t>(session_id_->Get());
-
- initialized_ = true;
- return initialized_;
-}
-
-bool SystemProfileCache::InitializeOrCheck() {
- return initialized_ || Initialize();
-}
-
-void SystemProfileCache::Populate(
- metrics::ChromeUserMetricsExtension* metrics_proto) {
- CHECK(metrics_proto);
- CHECK(InitializeOrCheck())
- << "failed to initialize system information.";
-
- // The client id is hashed before being sent.
- metrics_proto->set_client_id(
- metrics::MetricsLogBase::Hash(profile_.client_id));
- metrics_proto->set_session_id(profile_.session_id);
-
- // Sets the product id.
- metrics_proto->set_product(profile_.product_id);
-
- metrics::SystemProfileProto* profile_proto =
- metrics_proto->mutable_system_profile();
- profile_proto->mutable_hardware()->set_hardware_class(
- profile_.hardware_class);
- profile_proto->set_app_version(profile_.app_version);
- profile_proto->set_channel(profile_.channel);
-
- metrics::SystemProfileProto_OS* os = profile_proto->mutable_os();
- os->set_name(profile_.os_name);
- os->set_version(profile_.os_version);
-}
-
-std::string SystemProfileCache::GetPersistentGUID(const std::string& filename) {
- std::string guid;
- base::FilePath filepath(filename);
- if (!base::ReadFileToString(filepath, &guid)) {
- guid = base::GenerateGUID();
- // If we can't read or write the file, the guid will not be preserved during
- // the next reboot. Crash.
- CHECK(base::WriteFile(filepath, guid.c_str(), guid.size()));
- }
- return guid;
-}
-
-bool SystemProfileCache::GetChromeOSVersion(std::string* version) {
- if (testing_) {
- *version = "0.0.0.0";
- return true;
- }
-
- std::string milestone, build, branch, patch;
- unsigned tmp;
- if (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_CHROME_MILESTONE",
- &milestone) &&
- base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BUILD_NUMBER",
- &build) &&
- base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BRANCH_NUMBER",
- &branch) &&
- base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_PATCH_NUMBER",
- &patch)) {
- // Convert to uint to ensure those fields are positive numbers.
- if (base::StringToUint(milestone, &tmp) &&
- base::StringToUint(build, &tmp) &&
- base::StringToUint(branch, &tmp) &&
- base::StringToUint(patch, &tmp)) {
- std::vector<std::string> parts = {milestone, build, branch, patch};
- *version = JoinString(parts, '.');
- return true;
- }
- DLOG(INFO) << "The milestone, build, branch or patch is not a positive "
- << "number.";
- return false;
- }
- DLOG(INFO) << "Field missing from /etc/lsb-release";
- return false;
-}
-
-bool SystemProfileCache::GetHardwareId(std::string* hwid) {
- CHECK(hwid);
-
- if (testing_) {
- // if we are in test mode, we do not call crossystem directly.
- DLOG(INFO) << "skipping hardware id";
- *hwid = "";
- return true;
- }
-
- char buffer[128];
- if (buffer != VbGetSystemPropertyString("hwid", buffer, sizeof(buffer))) {
- LOG(ERROR) << "error getting hwid";
- return false;
- }
-
- *hwid = std::string(buffer);
- return true;
-}
-
-bool SystemProfileCache::GetProductId(int* product_id) const {
- chromeos::OsReleaseReader reader;
- if (testing_) {
- base::FilePath root(config_root_);
- reader.LoadTestingOnly(root);
- } else {
- reader.Load();
- }
-
- std::string id;
- if (reader.GetString(kProductIdFieldName, &id)) {
- CHECK(base::StringToInt(id, product_id)) << "Failed to convert product_id "
- << id << " to int.";
- return true;
- }
- return false;
-}
-
-metrics::SystemProfileProto_Channel SystemProfileCache::ProtoChannelFromString(
- const std::string& channel) {
-
- if (channel == "stable-channel") {
- return metrics::SystemProfileProto::CHANNEL_STABLE;
- } else if (channel == "dev-channel") {
- return metrics::SystemProfileProto::CHANNEL_DEV;
- } else if (channel == "beta-channel") {
- return metrics::SystemProfileProto::CHANNEL_BETA;
- } else if (channel == "canary-channel") {
- return metrics::SystemProfileProto::CHANNEL_CANARY;
- }
-
- DLOG(INFO) << "unknown channel: " << channel;
- return metrics::SystemProfileProto::CHANNEL_UNKNOWN;
-}
diff --git a/metrics/MODULE_LICENSE_BSD b/metricsd/MODULE_LICENSE_BSD
similarity index 100%
rename from metrics/MODULE_LICENSE_BSD
rename to metricsd/MODULE_LICENSE_BSD
diff --git a/metrics/NOTICE b/metricsd/NOTICE
similarity index 100%
rename from metrics/NOTICE
rename to metricsd/NOTICE
diff --git a/metrics/OWNERS b/metricsd/OWNERS
similarity index 100%
rename from metrics/OWNERS
rename to metricsd/OWNERS
diff --git a/metrics/README b/metricsd/README
similarity index 100%
rename from metrics/README
rename to metricsd/README
diff --git a/metrics/WATCHLISTS b/metricsd/WATCHLISTS
similarity index 100%
rename from metrics/WATCHLISTS
rename to metricsd/WATCHLISTS
diff --git a/metrics/c_metrics_library.cc b/metricsd/c_metrics_library.cc
similarity index 100%
rename from metrics/c_metrics_library.cc
rename to metricsd/c_metrics_library.cc
diff --git a/metricsd/constants.h b/metricsd/constants.h
new file mode 100644
index 0000000..d65e0e0
--- /dev/null
+++ b/metricsd/constants.h
@@ -0,0 +1,29 @@
+//
+// Copyright (C) 2015 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef METRICS_CONSTANTS_H_
+#define METRICS_CONSTANTS_H_
+
+namespace metrics {
+static const char kMetricsDirectory[] = "/data/misc/metrics/";
+static const char kMetricsEventsFilePath[] = "/data/misc/metrics/uma-events";
+static const char kMetricsGUIDFilePath[] = "/data/misc/metrics/Sysinfo.GUID";
+static const char kMetricsServer[] = "http://clients4.google.com/uma/v2";
+static const char kConsentFilePath[] = "/data/misc/metrics/enabled";
+static const char kDefaultVersion[] = "0.0.0.0";
+} // namespace metrics
+
+#endif // METRICS_CONSTANTS_H_
diff --git a/metrics/c_metrics_library.h b/metricsd/include/metrics/c_metrics_library.h
similarity index 100%
rename from metrics/c_metrics_library.h
rename to metricsd/include/metrics/c_metrics_library.h
diff --git a/metrics/metrics_library.h b/metricsd/include/metrics/metrics_library.h
similarity index 93%
rename from metrics/metrics_library.h
rename to metricsd/include/metrics/metrics_library.h
index a90f3e6..1c124d2 100644
--- a/metrics/metrics_library.h
+++ b/metricsd/include/metrics/metrics_library.h
@@ -14,8 +14,6 @@
#include <base/memory/scoped_ptr.h>
#include <gtest/gtest_prod.h> // for FRIEND_TEST
-#include "policy/libpolicy.h"
-
class MetricsLibraryInterface {
public:
virtual void Init() = 0;
@@ -28,7 +26,7 @@
virtual ~MetricsLibraryInterface() {}
};
-// Library used to send metrics to both Autotest and Chrome/UMA.
+// Library used to send metrics to Chrome/UMA.
class MetricsLibrary : public MetricsLibraryInterface {
public:
MetricsLibrary();
@@ -109,9 +107,6 @@
// number in the histograms dashboard).
bool SendCrosEventToUMA(const std::string& event);
- // Sends to Autotest and returns true on success.
- static bool SendToAutotest(const std::string& name, int value);
-
private:
friend class CMetricsLibraryTest;
friend class MetricsLibraryTest;
@@ -130,9 +125,6 @@
char* buffer, int buffer_size,
bool* result);
- // This function is used by tests only to mock the device policies.
- void SetPolicyProvider(policy::PolicyProvider* provider);
-
// Time at which we last checked if metrics were enabled.
static time_t cached_enabled_time_;
@@ -142,8 +134,6 @@
std::string uma_events_file_;
std::string consent_file_;
- scoped_ptr<policy::PolicyProvider> policy_provider_;
-
DISALLOW_COPY_AND_ASSIGN(MetricsLibrary);
};
diff --git a/metrics/init/metrics_daemon.conf b/metricsd/init/metrics_daemon.conf
similarity index 100%
rename from metrics/init/metrics_daemon.conf
rename to metricsd/init/metrics_daemon.conf
diff --git a/metrics/init/metrics_library.conf b/metricsd/init/metrics_library.conf
similarity index 100%
rename from metrics/init/metrics_library.conf
rename to metricsd/init/metrics_library.conf
diff --git a/metrics/libmetrics-334380.gyp b/metricsd/libmetrics-334380.gyp
similarity index 100%
rename from metrics/libmetrics-334380.gyp
rename to metricsd/libmetrics-334380.gyp
diff --git a/metrics/libmetrics.gypi b/metricsd/libmetrics.gypi
similarity index 100%
rename from metrics/libmetrics.gypi
rename to metricsd/libmetrics.gypi
diff --git a/metrics/libmetrics.pc.in b/metricsd/libmetrics.pc.in
similarity index 100%
rename from metrics/libmetrics.pc.in
rename to metricsd/libmetrics.pc.in
diff --git a/metrics/make_tests.sh b/metricsd/make_tests.sh
similarity index 100%
rename from metrics/make_tests.sh
rename to metricsd/make_tests.sh
diff --git a/metrics/metrics.gyp b/metricsd/metrics.gyp
similarity index 100%
rename from metrics/metrics.gyp
rename to metricsd/metrics.gyp
diff --git a/metrics/metrics_client.cc b/metricsd/metrics_client.cc
similarity index 73%
rename from metrics/metrics_client.cc
rename to metricsd/metrics_client.cc
index bbe9dcd..b587e3a 100644
--- a/metrics/metrics_client.cc
+++ b/metricsd/metrics_client.cc
@@ -19,17 +19,15 @@
void ShowUsage() {
fprintf(stderr,
- "Usage: metrics_client [-ab] [-t] name sample min max nbuckets\n"
- " metrics_client [-ab] -e name sample max\n"
- " metrics_client [-ab] -s name sample\n"
- " metrics_client [-ab] -v event\n"
+ "Usage: metrics_client [-t] name sample min max nbuckets\n"
+ " metrics_client -e name sample max\n"
+ " metrics_client -s name sample\n"
+ " metrics_client -v event\n"
" metrics_client -u action\n"
" metrics_client [-cg]\n"
"\n"
- " default: send metric with integer values to Chrome only\n"
+ " default: send metric with integer values \n"
" |min| > 0, |min| <= sample < |max|\n"
- " -a: send metric (name/sample) to Autotest only\n"
- " -b: send metric to both Chrome and Autotest\n"
" -c: return exit status 0 if user consents to stats, 1 otherwise,\n"
" in guest mode always return 1\n"
" -e: send linear/enumeration histogram data\n"
@@ -64,9 +62,7 @@
static int SendStats(char* argv[],
int name_index,
enum Mode mode,
- bool secs_to_msecs,
- bool send_to_autotest,
- bool send_to_chrome) {
+ bool secs_to_msecs) {
const char* name = argv[name_index];
int sample;
if (secs_to_msecs) {
@@ -75,25 +71,18 @@
sample = ParseInt(argv[name_index + 1]);
}
- // Send metrics
- if (send_to_autotest) {
- MetricsLibrary::SendToAutotest(name, sample);
- }
-
- if (send_to_chrome) {
- MetricsLibrary metrics_lib;
- metrics_lib.Init();
- if (mode == kModeSendSparseSample) {
- metrics_lib.SendSparseToUMA(name, sample);
- } else if (mode == kModeSendEnumSample) {
- int max = ParseInt(argv[name_index + 2]);
- metrics_lib.SendEnumToUMA(name, sample, max);
- } else {
- int min = ParseInt(argv[name_index + 2]);
- int max = ParseInt(argv[name_index + 3]);
- int nbuckets = ParseInt(argv[name_index + 4]);
- metrics_lib.SendToUMA(name, sample, min, max, nbuckets);
- }
+ MetricsLibrary metrics_lib;
+ metrics_lib.Init();
+ if (mode == kModeSendSparseSample) {
+ metrics_lib.SendSparseToUMA(name, sample);
+ } else if (mode == kModeSendEnumSample) {
+ int max = ParseInt(argv[name_index + 2]);
+ metrics_lib.SendEnumToUMA(name, sample, max);
+ } else {
+ int min = ParseInt(argv[name_index + 2]);
+ int max = ParseInt(argv[name_index + 3]);
+ int nbuckets = ParseInt(argv[name_index + 4]);
+ metrics_lib.SendToUMA(name, sample, min, max, nbuckets);
}
return 0;
}
@@ -133,22 +122,12 @@
int main(int argc, char** argv) {
enum Mode mode = kModeSendSample;
- bool send_to_autotest = false;
- bool send_to_chrome = true;
bool secs_to_msecs = false;
// Parse arguments
int flag;
while ((flag = getopt(argc, argv, "abcegstuv")) != -1) {
switch (flag) {
- case 'a':
- send_to_autotest = true;
- send_to_chrome = false;
- break;
- case 'b':
- send_to_chrome = true;
- send_to_autotest = true;
- break;
case 'c':
mode = kModeHasConsent;
break;
@@ -203,9 +182,7 @@
return SendStats(argv,
arg_index,
mode,
- secs_to_msecs,
- send_to_autotest,
- send_to_chrome);
+ secs_to_msecs);
case kModeSendUserAction:
return SendUserAction(argv, arg_index);
case kModeSendCrosEvent:
diff --git a/metrics/metrics_daemon.cc b/metricsd/metrics_daemon.cc
similarity index 91%
rename from metrics/metrics_daemon.cc
rename to metricsd/metrics_daemon.cc
index 880e90c..f9061d5 100644
--- a/metrics/metrics_daemon.cc
+++ b/metricsd/metrics_daemon.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/metrics_daemon.h"
+#include "metrics_daemon.h"
#include <fcntl.h>
#include <inttypes.h>
@@ -11,6 +11,7 @@
#include <sysexits.h>
#include <time.h>
+#include <base/bind.h>
#include <base/files/file_path.h>
#include <base/files/file_util.h>
#include <base/hash.h>
@@ -20,9 +21,10 @@
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
#include <base/sys_info.h>
-#include <chromeos/dbus/service_constants.h>
#include <dbus/dbus.h>
#include <dbus/message.h>
+
+#include "constants.h"
#include "uploader/upload_service.h"
using base::FilePath;
@@ -44,10 +46,6 @@
const char kCrashReporterMatchRule[] =
"type='signal',interface='%s',path='/',member='%s'";
-// Build type of an official build.
-// See src/third_party/chromiumos-overlay/chromeos/scripts/cros_set_lsb_release.
-const char kOfficialBuild[] = "Official Build";
-
const int kSecondsPerMinute = 60;
const int kMinutesPerHour = 60;
const int kHoursPerDay = 24;
@@ -199,28 +197,21 @@
if (version_hash_is_cached)
return cached_version_hash;
version_hash_is_cached = true;
- std::string version;
- if (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_VERSION", &version)) {
- cached_version_hash = base::Hash(version);
- } else if (testing_) {
+ std::string version = metrics::kDefaultVersion;
+ // The version might not be set for development devices. In this case, use the
+ // zero version.
+ base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &version);
+ cached_version_hash = base::Hash(version);
+ if (testing_) {
cached_version_hash = 42; // return any plausible value for the hash
- } else {
- LOG(FATAL) << "could not find CHROMEOS_RELEASE_VERSION";
}
return cached_version_hash;
}
-bool MetricsDaemon::IsOnOfficialBuild() const {
- std::string build_type;
- return (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_BUILD_TYPE",
- &build_type) &&
- build_type == kOfficialBuild);
-}
-
void MetricsDaemon::Init(bool testing,
bool uploader_active,
+ bool dbus_enabled,
MetricsLibraryInterface* metrics_lib,
- const string& diskstats_path,
const string& vmstats_path,
const string& scaling_max_freq_path,
const string& cpuinfo_max_freq_path,
@@ -230,6 +221,7 @@
const string& config_root) {
testing_ = testing;
uploader_active_ = uploader_active;
+ dbus_enabled_ = dbus_enabled;
config_root_ = config_root;
DCHECK(metrics_lib != nullptr);
metrics_lib_ = metrics_lib;
@@ -279,77 +271,58 @@
weekly_cycle_.reset(new PersistentInteger("weekly.cycle"));
version_cycle_.reset(new PersistentInteger("version.cycle"));
- diskstats_path_ = diskstats_path;
vmstats_path_ = vmstats_path;
scaling_max_freq_path_ = scaling_max_freq_path;
cpuinfo_max_freq_path_ = cpuinfo_max_freq_path;
-
- // If testing, initialize Stats Reporter without connecting DBus
- if (testing_)
- StatsReporterInit();
}
int MetricsDaemon::OnInit() {
- int return_code = chromeos::DBusDaemon::OnInit();
+ int return_code = dbus_enabled_ ? chromeos::DBusDaemon::OnInit() :
+ chromeos::Daemon::OnInit();
if (return_code != EX_OK)
return return_code;
- StatsReporterInit();
-
- // Start collecting meminfo stats.
- ScheduleMeminfoCallback(kMetricMeminfoInterval);
- memuse_final_time_ = GetActiveTime() + kMemuseIntervals[0];
- ScheduleMemuseCallback(kMemuseIntervals[0]);
-
if (testing_)
return EX_OK;
- bus_->AssertOnDBusThread();
- CHECK(bus_->SetUpAsyncOperations());
+ if (dbus_enabled_) {
+ bus_->AssertOnDBusThread();
+ CHECK(bus_->SetUpAsyncOperations());
- if (bus_->is_connected()) {
- const std::string match_rule =
- base::StringPrintf(kCrashReporterMatchRule,
- kCrashReporterInterface,
- kCrashReporterUserCrashSignal);
+ if (bus_->is_connected()) {
+ const std::string match_rule =
+ base::StringPrintf(kCrashReporterMatchRule,
+ kCrashReporterInterface,
+ kCrashReporterUserCrashSignal);
- bus_->AddFilterFunction(&MetricsDaemon::MessageFilter, this);
+ bus_->AddFilterFunction(&MetricsDaemon::MessageFilter, this);
- DBusError error;
- dbus_error_init(&error);
- bus_->AddMatch(match_rule, &error);
+ DBusError error;
+ dbus_error_init(&error);
+ bus_->AddMatch(match_rule, &error);
- if (dbus_error_is_set(&error)) {
- LOG(ERROR) << "Failed to add match rule \"" << match_rule << "\". Got "
- << error.name << ": " << error.message;
- return EX_SOFTWARE;
+ if (dbus_error_is_set(&error)) {
+ LOG(ERROR) << "Failed to add match rule \"" << match_rule << "\". Got "
+ << error.name << ": " << error.message;
+ return EX_SOFTWARE;
+ }
+ } else {
+ LOG(ERROR) << "DBus isn't connected.";
+ return EX_UNAVAILABLE;
}
- } else {
- LOG(ERROR) << "DBus isn't connected.";
- return EX_UNAVAILABLE;
}
- base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
- base::Bind(&MetricsDaemon::HandleUpdateStatsTimeout,
- base::Unretained(this)),
- base::TimeDelta::FromMilliseconds(kUpdateStatsIntervalMs));
-
if (uploader_active_) {
- if (IsOnOfficialBuild()) {
- LOG(INFO) << "uploader enabled";
- upload_service_.reset(
- new UploadService(new SystemProfileCache(), metrics_lib_, server_));
- upload_service_->Init(upload_interval_, metrics_file_);
- } else {
- LOG(INFO) << "uploader disabled on non-official build";
- }
+ upload_service_.reset(
+ new UploadService(new SystemProfileCache(), metrics_lib_, server_));
+ upload_service_->Init(upload_interval_, metrics_file_);
}
return EX_OK;
}
void MetricsDaemon::OnShutdown(int* return_code) {
- if (!testing_ && bus_->is_connected()) {
+ if (!testing_ && dbus_enabled_ && bus_->is_connected()) {
const std::string match_rule =
base::StringPrintf(kCrashReporterMatchRule,
kCrashReporterInterface,
@@ -520,41 +493,6 @@
base::TimeDelta::FromSeconds(wait));
}
-bool MetricsDaemon::DiskStatsReadStats(uint64_t* read_sectors,
- uint64_t* write_sectors) {
- int nchars;
- int nitems;
- bool success = false;
- char line[200];
- if (diskstats_path_.empty()) {
- return false;
- }
- int file = HANDLE_EINTR(open(diskstats_path_.c_str(), O_RDONLY));
- if (file < 0) {
- PLOG(WARNING) << "cannot open " << diskstats_path_;
- return false;
- }
- nchars = HANDLE_EINTR(read(file, line, sizeof(line)));
- if (nchars < 0) {
- PLOG(WARNING) << "cannot read from " << diskstats_path_;
- return false;
- } else {
- LOG_IF(WARNING, nchars == sizeof(line))
- << "line too long in " << diskstats_path_;
- line[nchars] = '\0';
- nitems = sscanf(line, "%*d %*d %" PRIu64 " %*d %*d %*d %" PRIu64,
- read_sectors, write_sectors);
- if (nitems == 2) {
- success = true;
- } else {
- LOG(WARNING) << "found " << nitems << " items in "
- << diskstats_path_ << ", expected 2";
- }
- }
- IGNORE_EINTR(close(file));
- return success;
-}
-
bool MetricsDaemon::VmStatsParseStats(const char* stats,
struct VmstatRecord* record) {
// a mapping of string name to field in VmstatRecord and whether we found it
diff --git a/metrics/metrics_daemon.h b/metricsd/metrics_daemon.h
similarity index 98%
rename from metrics/metrics_daemon.h
rename to metricsd/metrics_daemon.h
index b1b2d11..ccac52a 100644
--- a/metrics/metrics_daemon.h
+++ b/metricsd/metrics_daemon.h
@@ -18,7 +18,7 @@
#include <gtest/gtest_prod.h> // for FRIEND_TEST
#include "metrics/metrics_library.h"
-#include "metrics/persistent_integer.h"
+#include "persistent_integer.h"
#include "uploader/upload_service.h"
using chromeos_metrics::PersistentInteger;
@@ -31,8 +31,8 @@
// Initializes metrics class variables.
void Init(bool testing,
bool uploader_active,
+ bool dbus_enabled,
MetricsLibraryInterface* metrics_lib,
- const std::string& diskstats_path,
const std::string& vmstats_path,
const std::string& cpuinfo_max_freq_path,
const std::string& scaling_max_freq_path,
@@ -269,9 +269,6 @@
// to a unsigned 32-bit int.
uint32_t GetOsVersionHash();
- // Returns true if the system is using an official build.
- bool IsOnOfficialBuild() const;
-
// Updates stats, additionally sending them to UMA if enough time has elapsed
// since the last report.
void UpdateStats(base::TimeTicks now_ticks, base::Time now_wall_time);
@@ -293,6 +290,10 @@
// Whether the uploader is enabled or disabled.
bool uploader_active_;
+ // Whether or not dbus should be used.
+ // If disabled, we will not collect the frequency of crashes.
+ bool dbus_enabled_;
+
// Root of the configuration files to use.
std::string config_root_;
@@ -356,7 +357,6 @@
scoped_ptr<PersistentInteger> unclean_shutdowns_daily_count_;
scoped_ptr<PersistentInteger> unclean_shutdowns_weekly_count_;
- std::string diskstats_path_;
std::string vmstats_path_;
std::string scaling_max_freq_path_;
std::string cpuinfo_max_freq_path_;
diff --git a/metrics/metrics_daemon_main.cc b/metricsd/metrics_daemon_main.cc
similarity index 69%
rename from metrics/metrics_daemon_main.cc
rename to metricsd/metrics_daemon_main.cc
index 1f64ef3..6c580ba 100644
--- a/metrics/metrics_daemon_main.cc
+++ b/metricsd/metrics_daemon_main.cc
@@ -8,40 +8,15 @@
#include <base/strings/string_util.h>
#include <chromeos/flag_helper.h>
#include <chromeos/syslog_logging.h>
-#include <rootdev/rootdev.h>
-#include "metrics/metrics_daemon.h"
+#include "constants.h"
+#include "metrics_daemon.h"
const char kScalingMaxFreqPath[] =
"/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq";
const char kCpuinfoMaxFreqPath[] =
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
-// Returns the path to the disk stats in the sysfs. Returns the null string if
-// it cannot find the disk stats file.
-static
-const std::string MetricsMainDiskStatsPath() {
- char dev_path_cstr[PATH_MAX];
- std::string dev_prefix = "/dev/";
- std::string dev_path;
- std::string dev_name;
-
- int ret = rootdev(dev_path_cstr, sizeof(dev_path_cstr), true, true);
- if (ret != 0) {
- LOG(WARNING) << "error " << ret << " determining root device";
- return "";
- }
- dev_path = dev_path_cstr;
- // Check that rootdev begins with "/dev/".
- if (!base::StartsWithASCII(dev_path, dev_prefix, false)) {
- LOG(WARNING) << "unexpected root device " << dev_path;
- return "";
- }
- // Get the device name, e.g. "sda" from "/dev/sda".
- dev_name = dev_path.substr(dev_prefix.length());
- return "/sys/class/block/" + dev_name + "/stat";
-}
-
int main(int argc, char** argv) {
DEFINE_bool(daemon, true, "run as daemon (use -nodaemon for debugging)");
@@ -54,16 +29,19 @@
false,
"run the uploader once and exit");
+ // Enable dbus.
+ DEFINE_bool(withdbus, true, "Enable dbus");
+
// Upload Service flags.
DEFINE_int32(upload_interval_secs,
1800,
"Interval at which metrics_daemon sends the metrics. (needs "
"-uploader)");
DEFINE_string(server,
- "https://clients4.google.com/uma/v2",
+ metrics::kMetricsServer,
"Server to upload the metrics to. (needs -uploader)");
DEFINE_string(metrics_file,
- "/var/lib/metrics/uma-events",
+ metrics::kMetricsEventsFilePath,
"File to use as a proxy for uploading the metrics");
DEFINE_string(config_root,
"/", "Root of the configuration files (testing only)");
@@ -83,8 +61,8 @@
MetricsDaemon daemon;
daemon.Init(FLAGS_uploader_test,
FLAGS_uploader | FLAGS_uploader_test,
+ FLAGS_withdbus,
&metrics_lib,
- MetricsMainDiskStatsPath(),
"/proc/vmstat",
kScalingMaxFreqPath,
kCpuinfoMaxFreqPath,
diff --git a/metrics/metrics_daemon_test.cc b/metricsd/metrics_daemon_test.cc
similarity index 98%
rename from metrics/metrics_daemon_test.cc
rename to metricsd/metrics_daemon_test.cc
index 7dafbd6..5aa7ab8 100644
--- a/metrics/metrics_daemon_test.cc
+++ b/metricsd/metrics_daemon_test.cc
@@ -15,9 +15,9 @@
#include <chromeos/dbus/service_constants.h>
#include <gtest/gtest.h>
-#include "metrics/metrics_daemon.h"
-#include "metrics/metrics_library_mock.h"
-#include "metrics/persistent_integer_mock.h"
+#include "metrics_daemon.h"
+#include "metrics_library_mock.h"
+#include "persistent_integer_mock.h"
using base::FilePath;
using base::StringPrintf;
@@ -44,8 +44,6 @@
static const char kFakeVmStatsName[] = "fake-vm-stats";
static const char kFakeScalingMaxFreqPath[] = "fake-scaling-max-freq";
static const char kFakeCpuinfoMaxFreqPath[] = "fake-cpuinfo-max-freq";
-static const char kMetricsServer[] = "https://clients4.google.com/uma/v2";
-static const char kMetricsFilePath[] = "/var/lib/metrics/uma-events";
class MetricsDaemonTest : public testing::Test {
protected:
diff --git a/metrics/metrics_library.cc b/metricsd/metrics_library.cc
similarity index 71%
rename from metrics/metrics_library.cc
rename to metricsd/metrics_library.cc
index 70c8eac..f777f28 100644
--- a/metrics/metrics_library.cc
+++ b/metricsd/metrics_library.cc
@@ -13,14 +13,10 @@
#include <cstdio>
#include <cstring>
-#include "metrics/serialization/metric_sample.h"
-#include "metrics/serialization/serialization_utils.h"
+#include "constants.h"
+#include "serialization/metric_sample.h"
+#include "serialization/serialization_utils.h"
-#include "policy/device_policy.h"
-
-static const char kAutotestPath[] = "/var/log/metrics/autotest-events";
-static const char kUMAEventsPath[] = "/var/lib/metrics/uma-events";
-static const char kConsentFile[] = "/home/chronos/Consent To Send Stats";
static const char kCrosEventHistogramName[] = "Platform.CrOSEvent";
static const int kCrosEventHistogramMax = 100;
@@ -48,7 +44,7 @@
time_t MetricsLibrary::cached_enabled_time_ = 0;
bool MetricsLibrary::cached_enabled_ = false;
-MetricsLibrary::MetricsLibrary() : consent_file_(kConsentFile) {}
+MetricsLibrary::MetricsLibrary() : consent_file_(metrics::kConsentFilePath) {}
MetricsLibrary::~MetricsLibrary() {}
// We take buffer and buffer_size as parameters in order to simplify testing
@@ -123,47 +119,13 @@
time_t this_check_time = time(nullptr);
if (this_check_time != cached_enabled_time_) {
cached_enabled_time_ = this_check_time;
-
- if (!policy_provider_.get())
- policy_provider_.reset(new policy::PolicyProvider());
- policy_provider_->Reload();
- // We initialize with the default value which is false and will be preserved
- // if the policy is not set.
- bool enabled = false;
- bool has_policy = false;
- if (policy_provider_->device_policy_is_loaded()) {
- has_policy =
- policy_provider_->GetDevicePolicy().GetMetricsEnabled(&enabled);
- }
- // If policy couldn't be loaded or the metrics policy is not set we should
- // still respect the consent file if it is present for migration purposes.
- // TODO(pastarmovj)
- if (!has_policy) {
- enabled = stat(consent_file_.c_str(), &stat_buffer) >= 0;
- }
-
- if (enabled && !IsGuestMode())
- cached_enabled_ = true;
- else
- cached_enabled_ = false;
+ cached_enabled_ = stat(consent_file_.c_str(), &stat_buffer) >= 0;
}
return cached_enabled_;
}
void MetricsLibrary::Init() {
- uma_events_file_ = kUMAEventsPath;
-}
-
-bool MetricsLibrary::SendToAutotest(const std::string& name, int value) {
- FILE* autotest_file = fopen(kAutotestPath, "a+");
- if (autotest_file == nullptr) {
- PLOG(ERROR) << kAutotestPath << ": fopen";
- return false;
- }
-
- fprintf(autotest_file, "%s=%d\n", name.c_str(), value);
- fclose(autotest_file);
- return true;
+ uma_events_file_ = metrics::kMetricsEventsFilePath;
}
bool MetricsLibrary::SendToUMA(const std::string& name,
@@ -174,34 +136,30 @@
return metrics::SerializationUtils::WriteMetricToFile(
*metrics::MetricSample::HistogramSample(name, sample, min, max, nbuckets)
.get(),
- kUMAEventsPath);
+ metrics::kMetricsEventsFilePath);
}
bool MetricsLibrary::SendEnumToUMA(const std::string& name, int sample,
int max) {
return metrics::SerializationUtils::WriteMetricToFile(
*metrics::MetricSample::LinearHistogramSample(name, sample, max).get(),
- kUMAEventsPath);
+ metrics::kMetricsEventsFilePath);
}
bool MetricsLibrary::SendSparseToUMA(const std::string& name, int sample) {
return metrics::SerializationUtils::WriteMetricToFile(
*metrics::MetricSample::SparseHistogramSample(name, sample).get(),
- kUMAEventsPath);
+ metrics::kMetricsEventsFilePath);
}
bool MetricsLibrary::SendUserActionToUMA(const std::string& action) {
return metrics::SerializationUtils::WriteMetricToFile(
- *metrics::MetricSample::UserActionSample(action).get(), kUMAEventsPath);
+ *metrics::MetricSample::UserActionSample(action).get(), metrics::kMetricsEventsFilePath);
}
bool MetricsLibrary::SendCrashToUMA(const char *crash_kind) {
return metrics::SerializationUtils::WriteMetricToFile(
- *metrics::MetricSample::CrashSample(crash_kind).get(), kUMAEventsPath);
-}
-
-void MetricsLibrary::SetPolicyProvider(policy::PolicyProvider* provider) {
- policy_provider_.reset(provider);
+ *metrics::MetricSample::CrashSample(crash_kind).get(), metrics::kMetricsEventsFilePath);
}
bool MetricsLibrary::SendCrosEventToUMA(const std::string& event) {
diff --git a/metrics/metrics_library_mock.h b/metricsd/metrics_library_mock.h
similarity index 100%
rename from metrics/metrics_library_mock.h
rename to metricsd/metrics_library_mock.h
diff --git a/metrics/metrics_library_test.cc b/metricsd/metrics_library_test.cc
similarity index 100%
rename from metrics/metrics_library_test.cc
rename to metricsd/metrics_library_test.cc
diff --git a/metrics/persistent_integer.cc b/metricsd/persistent_integer.cc
similarity index 91%
rename from metrics/persistent_integer.cc
rename to metricsd/persistent_integer.cc
index dd38f1e..0dcd52a 100644
--- a/metrics/persistent_integer.cc
+++ b/metricsd/persistent_integer.cc
@@ -2,21 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/persistent_integer.h"
+#include "persistent_integer.h"
#include <fcntl.h>
#include <base/logging.h>
#include <base/posix/eintr_wrapper.h>
+#include "constants.h"
#include "metrics/metrics_library.h"
-namespace {
-
-// The directory for the persistent storage.
-const char kBackingFilesDirectory[] = "/var/lib/metrics/";
-
-}
namespace chromeos_metrics {
@@ -31,7 +26,7 @@
if (testing_) {
backing_file_name_ = name_;
} else {
- backing_file_name_ = kBackingFilesDirectory + name_;
+ backing_file_name_ = metrics::kMetricsDirectory + name_;
}
}
diff --git a/metrics/persistent_integer.h b/metricsd/persistent_integer.h
similarity index 100%
rename from metrics/persistent_integer.h
rename to metricsd/persistent_integer.h
diff --git a/metrics/persistent_integer_mock.h b/metricsd/persistent_integer_mock.h
similarity index 93%
rename from metrics/persistent_integer_mock.h
rename to metricsd/persistent_integer_mock.h
index 2061e55..31bfc35 100644
--- a/metrics/persistent_integer_mock.h
+++ b/metricsd/persistent_integer_mock.h
@@ -9,7 +9,7 @@
#include <gmock/gmock.h>
-#include "metrics/persistent_integer.h"
+#include "persistent_integer.h"
namespace chromeos_metrics {
diff --git a/metrics/persistent_integer_test.cc b/metricsd/persistent_integer_test.cc
similarity index 97%
rename from metrics/persistent_integer_test.cc
rename to metricsd/persistent_integer_test.cc
index a56aede..4fccb72 100644
--- a/metrics/persistent_integer_test.cc
+++ b/metricsd/persistent_integer_test.cc
@@ -8,7 +8,7 @@
#include <base/files/file_enumerator.h>
#include <base/files/file_util.h>
-#include "metrics/persistent_integer.h"
+#include "persistent_integer.h"
const char kBackingFileName[] = "1.pibakf";
const char kBackingFilePattern[] = "*.pibakf";
diff --git a/metrics/platform2_preinstall.sh b/metricsd/platform2_preinstall.sh
similarity index 100%
rename from metrics/platform2_preinstall.sh
rename to metricsd/platform2_preinstall.sh
diff --git a/metrics/serialization/metric_sample.cc b/metricsd/serialization/metric_sample.cc
similarity index 98%
rename from metrics/serialization/metric_sample.cc
rename to metricsd/serialization/metric_sample.cc
index 5447497..bc6583d 100644
--- a/metrics/serialization/metric_sample.cc
+++ b/metricsd/serialization/metric_sample.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/serialization/metric_sample.h"
+#include "serialization/metric_sample.h"
#include <string>
#include <vector>
diff --git a/metrics/serialization/metric_sample.h b/metricsd/serialization/metric_sample.h
similarity index 100%
rename from metrics/serialization/metric_sample.h
rename to metricsd/serialization/metric_sample.h
diff --git a/metrics/serialization/serialization_utils.cc b/metricsd/serialization/serialization_utils.cc
similarity index 98%
rename from metrics/serialization/serialization_utils.cc
rename to metricsd/serialization/serialization_utils.cc
index 9aa076a..d18dcd7 100644
--- a/metrics/serialization/serialization_utils.cc
+++ b/metricsd/serialization/serialization_utils.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/serialization/serialization_utils.h"
+#include "serialization/serialization_utils.h"
#include <sys/file.h>
@@ -17,7 +17,7 @@
#include "base/memory/scoped_vector.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
-#include "metrics/serialization/metric_sample.h"
+#include "serialization/metric_sample.h"
#define READ_WRITE_ALL_FILE_FLAGS \
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
diff --git a/metrics/serialization/serialization_utils.h b/metricsd/serialization/serialization_utils.h
similarity index 100%
rename from metrics/serialization/serialization_utils.h
rename to metricsd/serialization/serialization_utils.h
diff --git a/metrics/serialization/serialization_utils_unittest.cc b/metricsd/serialization/serialization_utils_unittest.cc
similarity index 98%
rename from metrics/serialization/serialization_utils_unittest.cc
rename to metricsd/serialization/serialization_utils_unittest.cc
index 34d76cf..fb802bc 100644
--- a/metrics/serialization/serialization_utils_unittest.cc
+++ b/metricsd/serialization/serialization_utils_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/serialization/serialization_utils.h"
+#include "serialization/serialization_utils.h"
#include <base/files/file_util.h>
#include <base/files/scoped_temp_dir.h>
@@ -10,7 +10,7 @@
#include <base/strings/stringprintf.h>
#include <gtest/gtest.h>
-#include "metrics/serialization/metric_sample.h"
+#include "serialization/metric_sample.h"
namespace metrics {
namespace {
diff --git a/metrics/syslog_parser.sh b/metricsd/syslog_parser.sh
similarity index 100%
rename from metrics/syslog_parser.sh
rename to metricsd/syslog_parser.sh
diff --git a/metrics/timer.cc b/metricsd/timer.cc
similarity index 98%
rename from metrics/timer.cc
rename to metricsd/timer.cc
index 99f68fe..ce4bf67 100644
--- a/metrics/timer.cc
+++ b/metricsd/timer.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/timer.h"
+#include "timer.h"
#include <string>
diff --git a/metrics/timer.h b/metricsd/timer.h
similarity index 100%
rename from metrics/timer.h
rename to metricsd/timer.h
diff --git a/metrics/timer_mock.h b/metricsd/timer_mock.h
similarity index 97%
rename from metrics/timer_mock.h
rename to metricsd/timer_mock.h
index 2f2d0f4..ed76f12 100644
--- a/metrics/timer_mock.h
+++ b/metricsd/timer_mock.h
@@ -9,7 +9,7 @@
#include <gmock/gmock.h>
-#include "metrics/timer.h"
+#include "timer.h"
namespace chromeos_metrics {
diff --git a/metrics/timer_test.cc b/metricsd/timer_test.cc
similarity index 99%
rename from metrics/timer_test.cc
rename to metricsd/timer_test.cc
index ec6c6bd..b1689bf 100644
--- a/metrics/timer_test.cc
+++ b/metricsd/timer_test.cc
@@ -8,9 +8,9 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-#include "metrics/metrics_library_mock.h"
-#include "metrics/timer.h"
-#include "metrics/timer_mock.h"
+#include "metrics_library_mock.h"
+#include "timer.h"
+#include "timer_mock.h"
using ::testing::_;
using ::testing::Return;
diff --git a/metrics/uploader/metrics_hashes.cc b/metricsd/uploader/metrics_hashes.cc
similarity index 95%
rename from metrics/uploader/metrics_hashes.cc
rename to metricsd/uploader/metrics_hashes.cc
index 87405a3..f9d0cfe 100644
--- a/metrics/uploader/metrics_hashes.cc
+++ b/metricsd/uploader/metrics_hashes.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/metrics_hashes.h"
+#include "uploader/metrics_hashes.h"
#include "base/logging.h"
#include "base/md5.h"
diff --git a/metrics/uploader/metrics_hashes.h b/metricsd/uploader/metrics_hashes.h
similarity index 100%
rename from metrics/uploader/metrics_hashes.h
rename to metricsd/uploader/metrics_hashes.h
diff --git a/metrics/uploader/metrics_hashes_unittest.cc b/metricsd/uploader/metrics_hashes_unittest.cc
similarity index 94%
rename from metrics/uploader/metrics_hashes_unittest.cc
rename to metricsd/uploader/metrics_hashes_unittest.cc
index f7e390f..8cdc7a9 100644
--- a/metrics/uploader/metrics_hashes_unittest.cc
+++ b/metricsd/uploader/metrics_hashes_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/metrics_hashes.h"
+#include "uploader/metrics_hashes.h"
#include <base/format_macros.h>
#include <base/macros.h>
diff --git a/metrics/uploader/metrics_log.cc b/metricsd/uploader/metrics_log.cc
similarity index 96%
rename from metrics/uploader/metrics_log.cc
rename to metricsd/uploader/metrics_log.cc
index 4d493b8..6f11f8a 100644
--- a/metrics/uploader/metrics_log.cc
+++ b/metricsd/uploader/metrics_log.cc
@@ -6,7 +6,7 @@
#include <string>
-#include "metrics/uploader/proto/system_profile.pb.h"
+#include "uploader/proto/system_profile.pb.h"
#include "uploader/system_profile_setter.h"
// We use default values for the MetricsLogBase constructor as the setter will
diff --git a/metrics/uploader/metrics_log.h b/metricsd/uploader/metrics_log.h
similarity index 96%
rename from metrics/uploader/metrics_log.h
rename to metricsd/uploader/metrics_log.h
index 5796325..a62798f 100644
--- a/metrics/uploader/metrics_log.h
+++ b/metricsd/uploader/metrics_log.h
@@ -9,7 +9,7 @@
#include <base/macros.h>
-#include "metrics/uploader/metrics_log_base.h"
+#include "uploader/metrics_log_base.h"
// This file defines a set of user experience metrics data recorded by
// the MetricsService. This is the unit of data that is sent to the server.
diff --git a/metrics/uploader/metrics_log_base.cc b/metricsd/uploader/metrics_log_base.cc
similarity index 94%
rename from metrics/uploader/metrics_log_base.cc
rename to metricsd/uploader/metrics_log_base.cc
index 7fe1ae1..3ae01e8 100644
--- a/metrics/uploader/metrics_log_base.cc
+++ b/metricsd/uploader/metrics_log_base.cc
@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/metrics_log_base.h"
+#include "uploader/metrics_log_base.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_samples.h"
-#include "metrics/uploader/metrics_hashes.h"
-#include "metrics/uploader/proto/histogram_event.pb.h"
-#include "metrics/uploader/proto/system_profile.pb.h"
-#include "metrics/uploader/proto/user_action_event.pb.h"
+#include "uploader/metrics_hashes.h"
+#include "uploader/proto/histogram_event.pb.h"
+#include "uploader/proto/system_profile.pb.h"
+#include "uploader/proto/user_action_event.pb.h"
using base::Histogram;
using base::HistogramBase;
diff --git a/metrics/uploader/metrics_log_base.h b/metricsd/uploader/metrics_log_base.h
similarity index 97%
rename from metrics/uploader/metrics_log_base.h
rename to metricsd/uploader/metrics_log_base.h
index e871c0f..4173335 100644
--- a/metrics/uploader/metrics_log_base.h
+++ b/metricsd/uploader/metrics_log_base.h
@@ -13,7 +13,7 @@
#include "base/macros.h"
#include "base/metrics/histogram.h"
#include "base/time/time.h"
-#include "metrics/uploader/proto/chrome_user_metrics_extension.pb.h"
+#include "uploader/proto/chrome_user_metrics_extension.pb.h"
namespace base {
class HistogramSamples;
diff --git a/metrics/uploader/metrics_log_base_unittest.cc b/metricsd/uploader/metrics_log_base_unittest.cc
similarity index 97%
rename from metrics/uploader/metrics_log_base_unittest.cc
rename to metricsd/uploader/metrics_log_base_unittest.cc
index 5da428a..dc03f00 100644
--- a/metrics/uploader/metrics_log_base_unittest.cc
+++ b/metricsd/uploader/metrics_log_base_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/metrics_log_base.h"
+#include "uploader/metrics_log_base.h"
#include <string>
@@ -10,7 +10,7 @@
#include <base/metrics/sample_vector.h>
#include <gtest/gtest.h>
-#include "metrics/uploader/proto/chrome_user_metrics_extension.pb.h"
+#include "uploader/proto/chrome_user_metrics_extension.pb.h"
namespace metrics {
diff --git a/metrics/uploader/mock/mock_system_profile_setter.h b/metricsd/uploader/mock/mock_system_profile_setter.h
similarity index 100%
rename from metrics/uploader/mock/mock_system_profile_setter.h
rename to metricsd/uploader/mock/mock_system_profile_setter.h
diff --git a/metrics/uploader/mock/sender_mock.cc b/metricsd/uploader/mock/sender_mock.cc
similarity index 100%
rename from metrics/uploader/mock/sender_mock.cc
rename to metricsd/uploader/mock/sender_mock.cc
diff --git a/metrics/uploader/mock/sender_mock.h b/metricsd/uploader/mock/sender_mock.h
similarity index 95%
rename from metrics/uploader/mock/sender_mock.h
rename to metricsd/uploader/mock/sender_mock.h
index 159b645..0a15d61 100644
--- a/metrics/uploader/mock/sender_mock.h
+++ b/metricsd/uploader/mock/sender_mock.h
@@ -8,7 +8,7 @@
#include <string>
#include "base/compiler_specific.h"
-#include "metrics/uploader/proto/chrome_user_metrics_extension.pb.h"
+#include "uploader/proto/chrome_user_metrics_extension.pb.h"
#include "uploader/sender.h"
class SenderMock : public Sender {
diff --git a/metrics/uploader/proto/README b/metricsd/uploader/proto/README
similarity index 100%
rename from metrics/uploader/proto/README
rename to metricsd/uploader/proto/README
diff --git a/metrics/uploader/proto/chrome_user_metrics_extension.proto b/metricsd/uploader/proto/chrome_user_metrics_extension.proto
similarity index 91%
rename from metrics/uploader/proto/chrome_user_metrics_extension.proto
rename to metricsd/uploader/proto/chrome_user_metrics_extension.proto
index f712fc9..d4d4f24 100644
--- a/metrics/uploader/proto/chrome_user_metrics_extension.proto
+++ b/metricsd/uploader/proto/chrome_user_metrics_extension.proto
@@ -14,9 +14,9 @@
package metrics;
-import "histogram_event.proto";
-import "system_profile.proto";
-import "user_action_event.proto";
+import "system/core/metricsd/uploader/proto/histogram_event.proto";
+import "system/core/metricsd/uploader/proto/system_profile.proto";
+import "system/core/metricsd/uploader/proto/user_action_event.proto";
// Next tag: 13
message ChromeUserMetricsExtension {
diff --git a/metrics/uploader/proto/histogram_event.proto b/metricsd/uploader/proto/histogram_event.proto
similarity index 100%
rename from metrics/uploader/proto/histogram_event.proto
rename to metricsd/uploader/proto/histogram_event.proto
diff --git a/metrics/uploader/proto/system_profile.proto b/metricsd/uploader/proto/system_profile.proto
similarity index 100%
rename from metrics/uploader/proto/system_profile.proto
rename to metricsd/uploader/proto/system_profile.proto
diff --git a/metrics/uploader/proto/user_action_event.proto b/metricsd/uploader/proto/user_action_event.proto
similarity index 100%
rename from metrics/uploader/proto/user_action_event.proto
rename to metricsd/uploader/proto/user_action_event.proto
diff --git a/metrics/uploader/sender.h b/metricsd/uploader/sender.h
similarity index 100%
rename from metrics/uploader/sender.h
rename to metricsd/uploader/sender.h
diff --git a/metrics/uploader/sender_http.cc b/metricsd/uploader/sender_http.cc
similarity index 96%
rename from metrics/uploader/sender_http.cc
rename to metricsd/uploader/sender_http.cc
index 8488b66..a740310 100644
--- a/metrics/uploader/sender_http.cc
+++ b/metricsd/uploader/sender_http.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/sender_http.h"
+#include "uploader/sender_http.h"
#include <string>
diff --git a/metrics/uploader/sender_http.h b/metricsd/uploader/sender_http.h
similarity index 95%
rename from metrics/uploader/sender_http.h
rename to metricsd/uploader/sender_http.h
index 4880b28..380cad8 100644
--- a/metrics/uploader/sender_http.h
+++ b/metricsd/uploader/sender_http.h
@@ -9,7 +9,7 @@
#include <base/macros.h>
-#include "metrics/uploader/sender.h"
+#include "uploader/sender.h"
// Sender implemented using http_utils from libchromeos
class HttpSender : public Sender {
diff --git a/metricsd/uploader/system_profile_cache.cc b/metricsd/uploader/system_profile_cache.cc
new file mode 100644
index 0000000..adbe0ae
--- /dev/null
+++ b/metricsd/uploader/system_profile_cache.cc
@@ -0,0 +1,152 @@
+// Copyright 2014 The Chromium OS 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 "uploader/system_profile_cache.h"
+
+#include <base/files/file_util.h>
+#include <base/guid.h>
+#include <base/logging.h>
+#include <base/strings/string_number_conversions.h>
+#include <base/strings/string_util.h>
+#include <base/sys_info.h>
+#include <string>
+#include <vector>
+
+#include "constants.h"
+#include "persistent_integer.h"
+#include "uploader/metrics_log_base.h"
+#include "uploader/proto/chrome_user_metrics_extension.pb.h"
+
+namespace {
+
+const char kPersistentSessionIdFilename[] = "Sysinfo.SessionId";
+
+} // namespace
+
+std::string ChannelToString(
+ const metrics::SystemProfileProto_Channel& channel) {
+ switch (channel) {
+ case metrics::SystemProfileProto::CHANNEL_STABLE:
+ return "STABLE";
+ case metrics::SystemProfileProto::CHANNEL_DEV:
+ return "DEV";
+ case metrics::SystemProfileProto::CHANNEL_BETA:
+ return "BETA";
+ case metrics::SystemProfileProto::CHANNEL_CANARY:
+ return "CANARY";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+SystemProfileCache::SystemProfileCache()
+ : initialized_(false),
+ testing_(false),
+ config_root_("/"),
+ session_id_(new chromeos_metrics::PersistentInteger(
+ kPersistentSessionIdFilename)) {
+}
+
+SystemProfileCache::SystemProfileCache(bool testing,
+ const std::string& config_root)
+ : initialized_(false),
+ testing_(testing),
+ config_root_(config_root),
+ session_id_(new chromeos_metrics::PersistentInteger(
+ kPersistentSessionIdFilename)) {
+}
+
+bool SystemProfileCache::Initialize() {
+ CHECK(!initialized_)
+ << "this should be called only once in the metrics_daemon lifetime.";
+
+ if (!base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID",
+ &profile_.build_target_id)) {
+ LOG(ERROR) << "Could not initialize system profile.";
+ return false;
+ }
+
+ std::string channel;
+ if (!base::SysInfo::GetLsbReleaseValue("BRILLO_CHANNEL", &channel) ||
+ !base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &profile_.version)) {
+ // If the channel or version is missing, the image is not official.
+ // In this case, set the channel to unknown and the version to 0.0.0.0 to
+ // avoid polluting the production data.
+ channel = "";
+ profile_.version = metrics::kDefaultVersion;
+
+ }
+ profile_.client_id =
+ testing_ ? "client_id_test" :
+ GetPersistentGUID(metrics::kMetricsGUIDFilePath);
+ profile_.hardware_class = "unknown";
+ profile_.channel = ProtoChannelFromString(channel);
+
+ // Increment the session_id everytime we initialize this. If metrics_daemon
+ // does not crash, this should correspond to the number of reboots of the
+ // system.
+ session_id_->Add(1);
+ profile_.session_id = static_cast<int32_t>(session_id_->Get());
+
+ initialized_ = true;
+ return initialized_;
+}
+
+bool SystemProfileCache::InitializeOrCheck() {
+ return initialized_ || Initialize();
+}
+
+void SystemProfileCache::Populate(
+ metrics::ChromeUserMetricsExtension* metrics_proto) {
+ CHECK(metrics_proto);
+ CHECK(InitializeOrCheck())
+ << "failed to initialize system information.";
+
+ // The client id is hashed before being sent.
+ metrics_proto->set_client_id(
+ metrics::MetricsLogBase::Hash(profile_.client_id));
+ metrics_proto->set_session_id(profile_.session_id);
+
+ // Sets the product id.
+ metrics_proto->set_product(9);
+
+ metrics::SystemProfileProto* profile_proto =
+ metrics_proto->mutable_system_profile();
+ profile_proto->mutable_hardware()->set_hardware_class(
+ profile_.hardware_class);
+ profile_proto->set_app_version(profile_.version);
+ profile_proto->set_channel(profile_.channel);
+ metrics::SystemProfileProto_BrilloDeviceData* device_data =
+ profile_proto->mutable_brillo();
+ device_data->set_build_target_id(profile_.build_target_id);
+}
+
+std::string SystemProfileCache::GetPersistentGUID(
+ const std::string& filename) {
+ std::string guid;
+ base::FilePath filepath(filename);
+ if (!base::ReadFileToString(filepath, &guid)) {
+ guid = base::GenerateGUID();
+ // If we can't read or write the file, the guid will not be preserved during
+ // the next reboot. Crash.
+ CHECK(base::WriteFile(filepath, guid.c_str(), guid.size()));
+ }
+ return guid;
+}
+
+metrics::SystemProfileProto_Channel SystemProfileCache::ProtoChannelFromString(
+ const std::string& channel) {
+ if (channel == "stable") {
+ return metrics::SystemProfileProto::CHANNEL_STABLE;
+ } else if (channel == "dev") {
+ return metrics::SystemProfileProto::CHANNEL_DEV;
+ } else if (channel == "beta") {
+ return metrics::SystemProfileProto::CHANNEL_BETA;
+ } else if (channel == "canary") {
+ return metrics::SystemProfileProto::CHANNEL_CANARY;
+ }
+
+ DLOG(INFO) << "unknown channel: " << channel;
+ return metrics::SystemProfileProto::CHANNEL_UNKNOWN;
+}
diff --git a/metrics/uploader/system_profile_cache.h b/metricsd/uploader/system_profile_cache.h
similarity index 67%
rename from metrics/uploader/system_profile_cache.h
rename to metricsd/uploader/system_profile_cache.h
index e7a7337..b6ff337 100644
--- a/metrics/uploader/system_profile_cache.h
+++ b/metricsd/uploader/system_profile_cache.h
@@ -12,24 +12,21 @@
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
-#include "chromeos/osrelease_reader.h"
-#include "metrics/persistent_integer.h"
-#include "metrics/uploader/proto/system_profile.pb.h"
-#include "metrics/uploader/system_profile_setter.h"
+#include "persistent_integer.h"
+#include "uploader/proto/system_profile.pb.h"
+#include "uploader/system_profile_setter.h"
namespace metrics {
class ChromeUserMetricsExtension;
}
struct SystemProfile {
- std::string os_name;
- std::string os_version;
- metrics::SystemProfileProto::Channel channel;
- std::string app_version;
+ std::string version;
std::string hardware_class;
std::string client_id;
- int32_t session_id;
- int32_t product_id;
+ int session_id;
+ metrics::SystemProfileProto::Channel channel;
+ std::string build_target_id;
};
// Retrieves general system informations needed by the protobuf for context and
@@ -43,9 +40,9 @@
SystemProfileCache(bool testing, const std::string& config_root);
// Populates the ProfileSystem protobuf with system information.
- void Populate(metrics::ChromeUserMetricsExtension* profile_proto) override;
+ void Populate(metrics::ChromeUserMetricsExtension* metrics_proto) override;
- // Converts a string representation of the channel (|channel|-channel) to a
+ // Converts a string representation of the channel to a
// SystemProfileProto_Channel
static metrics::SystemProfileProto_Channel ProtoChannelFromString(
const std::string& channel);
@@ -66,21 +63,6 @@
// Initializes |profile_| only if it has not been yet initialized.
bool InitializeOrCheck();
- // Gets the hardware ID using crossystem
- bool GetHardwareId(std::string* hwid);
-
- // Gets the product ID from the GOOGLE_METRICS_PRODUCT_ID field.
- bool GetProductId(int* product_id) const;
-
- // Generate the formatted chromeos version from the fields in
- // /etc/lsb-release. The format is A.B.C.D where A, B, C and D are positive
- // integer representing:
- // * the chrome milestone
- // * the build number
- // * the branch number
- // * the patch number
- bool GetChromeOSVersion(std::string* version);
-
bool initialized_;
bool testing_;
std::string config_root_;
diff --git a/metrics/uploader/system_profile_setter.h b/metricsd/uploader/system_profile_setter.h
similarity index 100%
rename from metrics/uploader/system_profile_setter.h
rename to metricsd/uploader/system_profile_setter.h
diff --git a/metrics/uploader/upload_service.cc b/metricsd/uploader/upload_service.cc
similarity index 95%
rename from metrics/uploader/upload_service.cc
rename to metricsd/uploader/upload_service.cc
index 92c9e10..3411004 100644
--- a/metrics/uploader/upload_service.cc
+++ b/metricsd/uploader/upload_service.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics/uploader/upload_service.h"
+#include "uploader/upload_service.h"
#include <string>
@@ -17,11 +17,11 @@
#include <base/metrics/statistics_recorder.h>
#include <base/sha1.h>
-#include "metrics/serialization/metric_sample.h"
-#include "metrics/serialization/serialization_utils.h"
-#include "metrics/uploader/metrics_log.h"
-#include "metrics/uploader/sender_http.h"
-#include "metrics/uploader/system_profile_cache.h"
+#include "serialization/metric_sample.h"
+#include "serialization/serialization_utils.h"
+#include "uploader/metrics_log.h"
+#include "uploader/sender_http.h"
+#include "uploader/system_profile_setter.h"
const int UploadService::kMaxFailedUpload = 10;
diff --git a/metrics/uploader/upload_service.h b/metricsd/uploader/upload_service.h
similarity index 97%
rename from metrics/uploader/upload_service.h
rename to metricsd/uploader/upload_service.h
index ebbb54f..c08fc1a 100644
--- a/metrics/uploader/upload_service.h
+++ b/metricsd/uploader/upload_service.h
@@ -12,9 +12,9 @@
#include "base/metrics/histogram_snapshot_manager.h"
#include "metrics/metrics_library.h"
-#include "metrics/uploader/metrics_log.h"
-#include "metrics/uploader/sender.h"
-#include "metrics/uploader/system_profile_cache.h"
+#include "uploader/metrics_log.h"
+#include "uploader/sender.h"
+#include "uploader/system_profile_cache.h"
namespace metrics {
class ChromeUserMetricsExtension;
diff --git a/metrics/uploader/upload_service_test.cc b/metricsd/uploader/upload_service_test.cc
similarity index 92%
rename from metrics/uploader/upload_service_test.cc
rename to metricsd/uploader/upload_service_test.cc
index ee17e15..efd0a56 100644
--- a/metrics/uploader/upload_service_test.cc
+++ b/metricsd/uploader/upload_service_test.cc
@@ -9,19 +9,16 @@
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/sys_info.h"
-#include "metrics/metrics_library_mock.h"
-#include "metrics/serialization/metric_sample.h"
-#include "metrics/uploader/metrics_log.h"
-#include "metrics/uploader/mock/mock_system_profile_setter.h"
-#include "metrics/uploader/mock/sender_mock.h"
-#include "metrics/uploader/proto/chrome_user_metrics_extension.pb.h"
-#include "metrics/uploader/proto/histogram_event.pb.h"
-#include "metrics/uploader/proto/system_profile.pb.h"
-#include "metrics/uploader/system_profile_cache.h"
-#include "metrics/uploader/upload_service.h"
-
-static const char kMetricsServer[] = "https://clients4.google.com/uma/v2";
-static const char kMetricsFilePath[] = "/var/run/metrics/uma-events";
+#include "metrics_library_mock.h"
+#include "serialization/metric_sample.h"
+#include "uploader/metrics_log.h"
+#include "uploader/mock/mock_system_profile_setter.h"
+#include "uploader/mock/sender_mock.h"
+#include "uploader/proto/chrome_user_metrics_extension.pb.h"
+#include "uploader/proto/histogram_event.pb.h"
+#include "uploader/proto/system_profile.pb.h"
+#include "uploader/system_profile_cache.h"
+#include "uploader/upload_service.h"
class UploadServiceTest : public testing::Test {
protected: