diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-09 21:19:37 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-09 21:19:37 +0000 |
commit | db342d53be64c145c73a8d687c475f03464dc9db (patch) | |
tree | 53a41c425e8d0c48e4a5f0829674069846ac57bc /chrome | |
parent | 20448a1990372714ec98cbfdb2a051c40bd30316 (diff) | |
download | chromium_src-db342d53be64c145c73a8d687c475f03464dc9db.zip chromium_src-db342d53be64c145c73a8d687c475f03464dc9db.tar.gz chromium_src-db342d53be64c145c73a8d687c475f03464dc9db.tar.bz2 |
Add GetMachineStatistic to SystemLibrary.
BUG=chromeos:3949 (http://code.google.com/p/chromium-os/issues/detail?id=3949)
TEST=Run a version of chrome with the corresponding changes. Ensure that reporting is enabled. Check that the report "hardware_class" value is valid.
See also: http://codereview.chromium.org/3067003/show
Review URL: http://codereview.chromium.org/3069002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55471 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/cros/mock_system_library.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/system_library.cc | 46 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/system_library.h | 5 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_service.cc | 23 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_service_unittest.cc | 10 |
5 files changed, 53 insertions, 33 deletions
diff --git a/chrome/browser/chromeos/cros/mock_system_library.h b/chrome/browser/chromeos/cros/mock_system_library.h index 47352fd..a851238 100644 --- a/chrome/browser/chromeos/cros/mock_system_library.h +++ b/chrome/browser/chromeos/cros/mock_system_library.h @@ -19,9 +19,9 @@ class MockSystemLibrary : public SystemLibrary { MOCK_METHOD1(RemoveObserver, void(Observer*)); MOCK_METHOD0(GetTimezone, const icu::TimeZone&()); MOCK_METHOD1(SetTimezone, void(const icu::TimeZone*)); + MOCK_METHOD2(GetMachineStatistic, bool(const std::string&, std::string*)); }; } // namespace chromeos #endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_SYSTEM_LIBRARY_H_ - diff --git a/chrome/browser/chromeos/cros/system_library.cc b/chrome/browser/chromeos/cros/system_library.cc index e09172b..b14e38e 100644 --- a/chrome/browser/chromeos/cros/system_library.cc +++ b/chrome/browser/chromeos/cros/system_library.cc @@ -4,6 +4,8 @@ #include "chrome/browser/chromeos/cros/system_library.h" +#include <map> + #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/cros/cros_library.h" @@ -11,7 +13,12 @@ namespace chromeos { class SystemLibraryImpl : public SystemLibrary { public: + typedef std::map<std::string, std::string> StringMap; + SystemLibraryImpl() { + // Get Statistics + UpdateMachineStatistics(); + // Get Timezone std::string id = "US/Pacific"; if (CrosLibrary::Get()->EnsureLoaded()) { std::string timezone_id = chromeos::GetTimezoneID(); @@ -54,11 +61,37 @@ class SystemLibraryImpl : public SystemLibrary { FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(*timezone)); } - private: - scoped_ptr<icu::TimeZone> timezone_; - ObserverList<Observer> observers_; + bool GetMachineStatistic(const std::string& name, std::string* result) { + StringMap::iterator iter = machine_info_.find(name); + if (iter != machine_info_.end()) { + *result = iter->second; + return true; + } + return false; + } - DISALLOW_COPY_AND_ASSIGN(SystemLibraryImpl); + private: + void UpdateMachineStatistics() { + if (CrosLibrary::Get()->EnsureLoaded()) { + chromeos::MachineInfo* machine_info = chromeos::GetMachineInfo(); + if (!machine_info) { + LOG(ERROR) << "Error calling chromeos::GetMachineInfo()."; + return; + } + // Get Name Value pairs. + for (int i = 0; i<machine_info->name_value_size; ++i) { + const chromeos::MachineInfo::NVPair& nv = machine_info->name_values[i]; + machine_info_[nv.name] = nv.value; + } + chromeos::FreeMachineInfo(machine_info); + } + } + + scoped_ptr<icu::TimeZone> timezone_; + ObserverList<Observer> observers_; + StringMap machine_info_; + + DISALLOW_COPY_AND_ASSIGN(SystemLibraryImpl); }; class SystemLibraryStubImpl : public SystemLibrary { @@ -78,6 +111,11 @@ class SystemLibraryStubImpl : public SystemLibrary { } void SetTimezone(const icu::TimeZone* timezone) {} + bool GetMachineStatistic(const std::string& name, std::string* result) { + *result = "Stub Statistic:" + name; + return true; + } + private: scoped_ptr<icu::TimeZone> timezone_; DISALLOW_COPY_AND_ASSIGN(SystemLibraryStubImpl); diff --git a/chrome/browser/chromeos/cros/system_library.h b/chrome/browser/chromeos/cros/system_library.h index b81cc4c..bcce31e 100644 --- a/chrome/browser/chromeos/cros/system_library.h +++ b/chrome/browser/chromeos/cros/system_library.h @@ -34,6 +34,11 @@ class SystemLibrary { // Sets the current timezone. |timezone| must be non-null. virtual void SetTimezone(const icu::TimeZone* timezone) = 0; + // Retrieve the named machine statistic (e.g. "hardware_class"). + // This does not update the statistcs (i.e. does not call into libcros). + virtual bool GetMachineStatistic(const std::string& name, + std::string* result) = 0; + // Get library implementation. static SystemLibrary* GetImpl(bool stub); }; diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index 442306f..1dcc6df 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -201,10 +201,9 @@ #endif #if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/system_library.h" #include "chrome/browser/chromeos/external_metrics.h" - -static const char kHardwareClassTool[] = "/usr/bin/hardware_class"; -static const char kUnknownHardwareClass[] = "unknown"; #endif namespace { @@ -368,7 +367,9 @@ class MetricsService::InitTask : public Task { NPAPI::PluginList::Singleton()->GetPlugins(false, &plugins); std::string hardware_class; // Empty string by default. #if defined(OS_CHROMEOS) - hardware_class = MetricsService::GetHardwareClass(); + chromeos::SystemLibrary* system_library = + chromeos::CrosLibrary::Get()->GetSystemLibrary(); + system_library->GetMachineStatistic("hardware_class", &hardware_class); #endif // OS_CHROMEOS callback_loop_->PostTask(FROM_HERE, new InitTaskComplete( hardware_class, plugins)); @@ -1940,20 +1941,6 @@ static bool IsSingleThreaded() { } #if defined(OS_CHROMEOS) -// static -std::string MetricsService::GetHardwareClass() { - DCHECK(!ChromeThread::CurrentlyOn(ChromeThread::UI)); - std::string hardware_class; - FilePath tool(kHardwareClassTool); - CommandLine command(tool); - if (base::GetAppOutput(command, &hardware_class)) { - TrimWhitespaceASCII(hardware_class, TRIM_ALL, &hardware_class); - } else { - hardware_class = kUnknownHardwareClass; - } - return hardware_class; -} - void MetricsService::StartExternalMetrics() { external_metrics_ = new chromeos::ExternalMetrics; external_metrics_->Start(); diff --git a/chrome/browser/metrics/metrics_service_unittest.cc b/chrome/browser/metrics/metrics_service_unittest.cc index 6a1026c..a5ec080 100644 --- a/chrome/browser/metrics/metrics_service_unittest.cc +++ b/chrome/browser/metrics/metrics_service_unittest.cc @@ -40,16 +40,6 @@ TEST(MetricsServiceTest, ClientIdCorrectlyFormatted) { } #endif -#if defined(OS_CHROMEOS) -TEST(MetricsServiceTest, GetHardwareClass) { - // The assumption is that unit tests run on the build host rather - // than on the Chrome OS device so the hardware_class tool is not - // available. - std::string hardware_class = MetricsService::GetHardwareClass(); - EXPECT_EQ("unknown", hardware_class); -} -#endif // OS_CHROMEOS - class MetricsServiceTest : public ::testing::Test { }; |