OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/system/statistics_provider.h" | 5 #include "chrome/browser/chromeos/system/statistics_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 const char kMachineOSInfoDelim[] = "\n"; | 43 const char kMachineOSInfoDelim[] = "\n"; |
44 | 44 |
45 // Command to get VPD info and key/value delimiters. | 45 // Command to get VPD info and key/value delimiters. |
46 const char kVpdFile[] = "/var/log/vpd_2.0.txt"; | 46 const char kVpdFile[] = "/var/log/vpd_2.0.txt"; |
47 const char kVpdEq[] = "="; | 47 const char kVpdEq[] = "="; |
48 const char kVpdDelim[] = "\n"; | 48 const char kVpdDelim[] = "\n"; |
49 | 49 |
50 // Timeout that we should wait for statistics to get loaded | 50 // Timeout that we should wait for statistics to get loaded |
51 const int kTimeoutSecs = 3; | 51 const int kTimeoutSecs = 3; |
52 | 52 |
53 // Gets name-value paris from the file using the parser. | |
54 void GetNameValuePairsFromFile(NameValuePairsParser* parser, | |
55 const FilePath& file_path, | |
56 const std::string& eq, | |
57 const std::string& delim) { | |
58 std::string contents; | |
59 if (file_util::ReadFileToString(file_path, &contents)) { | |
60 parser->ParseNameValuePairs(contents, eq, delim); | |
61 } | |
62 } | |
63 | |
64 } // namespace | 53 } // namespace |
65 | 54 |
66 // The StatisticsProvider implementation used in production. | 55 // The StatisticsProvider implementation used in production. |
67 class StatisticsProviderImpl : public StatisticsProvider { | 56 class StatisticsProviderImpl : public StatisticsProvider { |
68 public: | 57 public: |
69 // StatisticsProvider implementation: | 58 // StatisticsProvider implementation: |
70 virtual bool GetMachineStatistic(const std::string& name, | 59 virtual bool GetMachineStatistic(const std::string& name, |
71 std::string* result); | 60 std::string* result); |
72 | 61 |
73 static StatisticsProviderImpl* GetInstance(); | 62 static StatisticsProviderImpl* GetInstance(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 124 } |
136 | 125 |
137 void StatisticsProviderImpl::LoadMachineStatistics() { | 126 void StatisticsProviderImpl::LoadMachineStatistics() { |
138 NameValuePairsParser parser(&machine_info_); | 127 NameValuePairsParser parser(&machine_info_); |
139 if (!parser.GetSingleValueFromTool(arraysize(kHardwareClassTool), | 128 if (!parser.GetSingleValueFromTool(arraysize(kHardwareClassTool), |
140 kHardwareClassTool, | 129 kHardwareClassTool, |
141 kHardwareClassKey)) { | 130 kHardwareClassKey)) { |
142 // Use kUnknownHardwareClass if the hardware class command fails. | 131 // Use kUnknownHardwareClass if the hardware class command fails. |
143 parser.AddNameValuePair(kHardwareClassKey, kUnknownHardwareClass); | 132 parser.AddNameValuePair(kHardwareClassKey, kUnknownHardwareClass); |
144 } | 133 } |
145 GetNameValuePairsFromFile(&parser, | 134 parser.GetNameValuePairsFromFile(FilePath(kMachineHardwareInfoFile), |
146 FilePath(kMachineHardwareInfoFile), | 135 kMachineHardwareInfoEq, |
147 kMachineHardwareInfoEq, | 136 kMachineHardwareInfoDelim); |
148 kMachineHardwareInfoDelim); | 137 parser.GetNameValuePairsFromFile(FilePath(kMachineOSInfoFile), |
149 GetNameValuePairsFromFile(&parser, | 138 kMachineOSInfoEq, |
150 FilePath(kMachineOSInfoFile), | 139 kMachineOSInfoDelim); |
151 kMachineOSInfoEq, | 140 parser.GetNameValuePairsFromFile(FilePath(kVpdFile), kVpdEq, kVpdDelim); |
152 kMachineOSInfoDelim); | |
153 GetNameValuePairsFromFile(&parser, FilePath(kVpdFile), kVpdEq, kVpdDelim); | |
154 | 141 |
155 #if defined(GOOGLE_CHROME_BUILD) | 142 #if defined(GOOGLE_CHROME_BUILD) |
156 // TODO(kochi): This is for providing a channel information to | 143 // TODO(kochi): This is for providing a channel information to |
157 // chrome::VersionInfo::GetChannel()/GetVersionStringModifier(), | 144 // chrome::VersionInfo::GetChannel()/GetVersionStringModifier(), |
158 // but this is still late for some early customers such as | 145 // but this is still late for some early customers such as |
159 // prerender::ConfigurePrefetchAndPrerender() and | 146 // prerender::ConfigurePrefetchAndPrerender() and |
160 // ThreadWatcherList::ParseCommandLine(). | 147 // ThreadWatcherList::ParseCommandLine(). |
161 // See http://crbug.com/107333 . | 148 // See http://crbug.com/107333 . |
162 const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK"; | 149 const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK"; |
163 std::string channel; | 150 std::string channel; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 StatisticsProvider* StatisticsProvider::GetInstance() { | 189 StatisticsProvider* StatisticsProvider::GetInstance() { |
203 if (system::runtime_environment::IsRunningOnChromeOS()) { | 190 if (system::runtime_environment::IsRunningOnChromeOS()) { |
204 return StatisticsProviderImpl::GetInstance(); | 191 return StatisticsProviderImpl::GetInstance(); |
205 } else { | 192 } else { |
206 return StatisticsProviderStubImpl::GetInstance(); | 193 return StatisticsProviderStubImpl::GetInstance(); |
207 } | 194 } |
208 } | 195 } |
209 | 196 |
210 } // namespace system | 197 } // namespace system |
211 } // namespace chromeos | 198 } // namespace chromeos |
OLD | NEW |