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/browser/chromeos | |
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/browser/chromeos')
-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 |
3 files changed, 48 insertions, 5 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); }; |