Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(533)

Unified Diff: chrome/browser/chromeos/system_access.cc

Issue 6899021: HWID and VPD values should be accessible via SystemAccess::GetMachineStatistic (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unit_test Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/system_access.cc
diff --git a/chrome/browser/chromeos/system_access.cc b/chrome/browser/chromeos/system_access.cc
index 1a121445109ad2129336e1bc88dfac0d05560cad..410b8b89e648f4d6016f5ba2c79d7b6583e29021 100644
--- a/chrome/browser/chromeos/system_access.cc
+++ b/chrome/browser/chromeos/system_access.cc
@@ -4,47 +4,81 @@
#include "chrome/browser/chromeos/system_access.h"
-#include "base/basictypes.h"
-#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
-#include "base/process_util.h"
-#include "base/string_tokenizer.h"
-#include "base/string_util.h"
-#include "base/threading/thread_restrictions.h"
+#include "base/observer_list.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/singleton.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/chromeos/name_value_pairs_parser.h"
namespace chromeos { // NOLINT
namespace { // NOLINT
// The filepath to the timezone file that symlinks to the actual timezone file.
-static const char kTimezoneSymlink[] = "/var/lib/timezone/localtime";
-static const char kTimezoneSymlink2[] = "/var/lib/timezone/localtime2";
+const char kTimezoneSymlink[] = "/var/lib/timezone/localtime";
+const char kTimezoneSymlink2[] = "/var/lib/timezone/localtime2";
// The directory that contains all the timezone files. So for timezone
// "US/Pacific", the actual timezone file is: "/usr/share/zoneinfo/US/Pacific"
-static const char kTimezoneFilesDir[] = "/usr/share/zoneinfo/";
+const char kTimezoneFilesDir[] = "/usr/share/zoneinfo/";
// The system command that returns the hardware class.
-static const char kHardwareClassKey[] = "hardware_class";
-static const char* kHardwareClassTool[] = { "/usr/bin/hardware_class" };
-static const char kUnknownHardwareClass[] = "unknown";
+const char kHardwareClassKey[] = "hardware_class";
+const char* kHardwareClassTool[] = { "/usr/bin/hardware_class" };
+const char kUnknownHardwareClass[] = "unknown";
// Command to get machine hardware info and key/value delimiters.
// /tmp/machine-info is generated by platform/init/chromeos_startup.
-static const char* kMachineHardwareInfoTool[] = { "cat", "/tmp/machine-info" };
-static const char kMachineHardwareInfoEq[] = "=";
-static const char kMachineHardwareInfoDelim[] = " \n";
+const char* kMachineHardwareInfoTool[] = { "cat", "/tmp/machine-info" };
+const char kMachineHardwareInfoEq[] = "=";
+const char kMachineHardwareInfoDelim[] = " \n";
// Command to get machine OS info and key/value delimiters.
-static const char* kMachineOSInfoTool[] = { "cat", "/etc/lsb-release" };
-static const char kMachineOSInfoEq[] = "=";
-static const char kMachineOSInfoDelim[] = "\n";
+const char* kMachineOSInfoTool[] = { "cat", "/etc/lsb-release" };
+const char kMachineOSInfoEq[] = "=";
+const char kMachineOSInfoDelim[] = "\n";
+
+// Command to get HWID and key.
+const char kHwidKey[] = "hwid";
petkov 2011/05/18 22:31:24 this is equivalent of hardware_class above. also,
+const char* kHwidTool[] = { "cat", "/sys/devices/platform/chromeos_acpi/HWID" };
+
+// Command to get VPD info and key/value delimiters.
+const char* kVpdTool[] = { "cat", "/var/log/vpd_2.0.txt" };
+const char kVpdEq[] = "=";
+const char kVpdDelim[] = "\n";
// Fallback time zone ID used in case of an unexpected error.
-static const char kFallbackTimeZoneId[] = "America/Los_Angeles";
+const char kFallbackTimeZoneId[] = "America/Los_Angeles";
+
+class SystemAccessImpl : public SystemAccess {
+ public:
+ // SystemAccess.implementation:
+ virtual const icu::TimeZone& GetTimezone();
+ virtual void SetTimezone(const icu::TimeZone& timezone);
+ virtual bool GetMachineStatistic(const std::string& name,
+ std::string* result);
+ virtual void AddObserver(Observer* observer);
+ virtual void RemoveObserver(Observer* observer);
+
+ static SystemAccessImpl* GetInstance();
+
+ private:
+ friend struct DefaultSingletonTraits<SystemAccessImpl>;
+
+ SystemAccessImpl();
+
+ // Updates the machine statistcs by examining the system.
+ void UpdateMachineStatistics();
+
+ scoped_ptr<icu::TimeZone> timezone_;
+ ObserverList<Observer> observers_;
+ NameValuePairsParser::NameValueMap machine_info_;
+
+ DISALLOW_COPY_AND_ASSIGN(SystemAccessImpl);
+};
std::string GetTimezoneIDAsString() {
// Look at kTimezoneSymlink, see which timezone we are symlinked to.
@@ -103,17 +137,11 @@ void SetTimezoneIDFromString(const std::string& id) {
}
}
-} // namespace
-
-SystemAccess* SystemAccess::GetInstance() {
- return Singleton<SystemAccess, DefaultSingletonTraits<SystemAccess> >::get();
-}
-
-const icu::TimeZone& SystemAccess::GetTimezone() {
+const icu::TimeZone& SystemAccessImpl::GetTimezone() {
return *timezone_.get();
}
-void SystemAccess::SetTimezone(const icu::TimeZone& timezone) {
+void SystemAccessImpl::SetTimezone(const icu::TimeZone& timezone) {
timezone_.reset(timezone.clone());
icu::UnicodeString unicode;
timezone.getID(unicode);
@@ -125,9 +153,9 @@ void SystemAccess::SetTimezone(const icu::TimeZone& timezone) {
FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(timezone));
}
-bool SystemAccess::GetMachineStatistic(
+bool SystemAccessImpl::GetMachineStatistic(
const std::string& name, std::string* result) {
- MachineInfo::iterator iter = machine_info_.find(name);
+ NameValuePairsParser::NameValueMap::iterator iter = machine_info_.find(name);
if (iter != machine_info_.end()) {
*result = iter->second;
return true;
@@ -135,15 +163,15 @@ bool SystemAccess::GetMachineStatistic(
return false;
}
-void SystemAccess::AddObserver(Observer* observer) {
+void SystemAccessImpl::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
-void SystemAccess::RemoveObserver(Observer* observer) {
+void SystemAccessImpl::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
-SystemAccess::SystemAccess() {
+SystemAccessImpl::SystemAccessImpl() {
// Get Statistics
UpdateMachineStatistics();
// Get Timezone
@@ -159,7 +187,7 @@ SystemAccess::SystemAccess() {
VLOG(1) << "Timezone is " << id;
}
-void SystemAccess::UpdateMachineStatistics() {
+void SystemAccessImpl::UpdateMachineStatistics() {
NameValuePairsParser parser(&machine_info_);
if (!parser.GetSingleValueFromTool(arraysize(kHardwareClassTool),
kHardwareClassTool,
@@ -175,87 +203,20 @@ void SystemAccess::UpdateMachineStatistics() {
kMachineOSInfoTool,
kMachineOSInfoEq,
kMachineOSInfoDelim);
+ parser.GetSingleValueFromTool(arraysize(kHwidTool), kHwidTool, kHwidKey);
+ parser.ParseNameValuePairsFromTool(
+ arraysize(kVpdTool), kVpdTool, kVpdEq, kVpdDelim);
}
-NameValuePairsParser::NameValuePairsParser(MachineInfo* machine_info)
- : machine_info_(machine_info) {
-}
-
-void NameValuePairsParser::AddNameValuePair(const std::string& key,
- const std::string& value) {
- (*machine_info_)[key] = value;
- VLOG(1) << "name: " << key << ", value: " << value;
-}
-
-bool NameValuePairsParser::ParseNameValuePairs(const std::string& in_string,
- const std::string& eq,
- const std::string& delim) {
- // Set up the pair tokenizer.
- StringTokenizer pair_toks(in_string, delim);
- pair_toks.set_quote_chars("\"");
- // Process token pairs.
- while (pair_toks.GetNext()) {
- std::string pair(pair_toks.token());
- if (pair.find(eq) == 0) {
- LOG(WARNING) << "Empty key: '" << pair << "'. Aborting.";
- return false;
- }
- StringTokenizer keyvalue(pair, eq);
- std::string key,value;
- if (keyvalue.GetNext()) {
- key = keyvalue.token();
- if (keyvalue.GetNext()) {
- value = keyvalue.token();
- if (keyvalue.GetNext()) {
- LOG(WARNING) << "Multiple key tokens: '" << pair << "'. Aborting.";
- return false;
- }
- }
- }
- if (key.empty()) {
- LOG(WARNING) << "Invalid token pair: '" << pair << "'. Aborting.";
- return false;
- }
- AddNameValuePair(key, value);
- }
- return true;
+SystemAccessImpl* SystemAccessImpl::GetInstance() {
+ return Singleton<SystemAccessImpl,
+ DefaultSingletonTraits<SystemAccessImpl> >::get();
}
-bool NameValuePairsParser::GetSingleValueFromTool(int argc,
- const char* argv[],
- const std::string& key) {
- CommandLine command_line(argc, argv);
- std::string output_string;
- // TODO(stevenjb,satorux): Make this non blocking: crosbug.com/5603.
- base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join;
- if (argc < 1 || !base::GetAppOutput(command_line, &output_string)) {
- LOG(WARNING) << "Error excuting: " << command_line.command_line_string();
- return false;
- }
- TrimWhitespaceASCII(output_string, TRIM_ALL, &output_string);
- AddNameValuePair(key, output_string);
- return true;
-}
+} // namespace
-bool NameValuePairsParser::ParseNameValuePairsFromTool(
- int argc,
- const char* argv[],
- const std::string& eq,
- const std::string& delim) {
- CommandLine command_line(argc, argv);
- std::string output_string;
- // TODO(stevenjb,satorux): Make this non blocking: crosbug.com/5603.
- base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join;
- if (argc < 1 || !base::GetAppOutput(command_line, &output_string)) {
- LOG(WARNING) << "Error excuting: " << command_line.command_line_string();
- return false;
- }
- if (!ParseNameValuePairs(output_string, eq, delim)) {
- LOG(WARNING) << "Error parsing values while excuting: "
- << command_line.command_line_string();
- return false;
- }
- return true;
+SystemAccess* SystemAccess::GetInstance() {
+ return SystemAccessImpl::GetInstance();
}
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/system_access.h ('k') | chrome/browser/extensions/extension_info_private_api_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698