blob: 8df5cd0bb3e578ad97efd59e8b7771a904c69f65 [file] [log] [blame]
// 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 <stdint.h>
#include <memory>
#include <string>
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "brillo/osrelease_reader.h"
#include "metrics/persistent_integer.h"
#include "metrics/uploader/proto/system_profile.pb.h"
#include "metrics/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 hardware_class;
std::string client_id;
int32_t session_id;
int32_t product_id;
// Retrieves general system informations needed by the protobuf for context and
// remembers them to avoid expensive calls.
// The cache is populated lazily. The only method needed is Populate.
class SystemProfileCache : public SystemProfileSetter {
SystemProfileCache(bool testing, const std::string& config_root);
// Populates the ProfileSystem protobuf with system information.
void Populate(metrics::ChromeUserMetricsExtension* profile_proto) override;
// Converts a string representation of the channel (|channel|-channel) to a
// SystemProfileProto_Channel
static metrics::SystemProfileProto_Channel ProtoChannelFromString(
const std::string& channel);
// Gets the persistent GUID and create it if it has not been created yet.
static std::string GetPersistentGUID(const std::string& filename);
friend class UploadServiceTest;
FRIEND_TEST(UploadServiceTest, ExtractChannelFromDescription);
FRIEND_TEST(UploadServiceTest, ReadKeyValueFromFile);
FRIEND_TEST(UploadServiceTest, SessionIdIncrementedAtInitialization);
FRIEND_TEST(UploadServiceTest, ValuesInConfigFileAreSent);
// Fetches all informations and populates |profile_|
bool Initialize();
// 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_;
std::unique_ptr<chromeos_metrics::PersistentInteger> session_id_;
SystemProfile profile_;