| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/chromeos_version.h" | 8 #include "base/chromeos/chromeos_version.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // beforehand. | 100 // beforehand. |
| 101 // | 101 // |
| 102 // If you see the warning appeared for regular sessions, it probably | 102 // If you see the warning appeared for regular sessions, it probably |
| 103 // means that there is new client code that uses the statistics in the | 103 // means that there is new client code that uses the statistics in the |
| 104 // very early stage of the browser startup. The statistic name should be | 104 // very early stage of the browser startup. The statistic name should be |
| 105 // helpful to identify the caller. | 105 // helpful to identify the caller. |
| 106 if (!on_statistics_loaded_.IsSignaled()) { | 106 if (!on_statistics_loaded_.IsSignaled()) { |
| 107 LOG(WARNING) << "Waiting to load statistics. Requested statistic: " | 107 LOG(WARNING) << "Waiting to load statistics. Requested statistic: " |
| 108 << name; | 108 << name; |
| 109 on_statistics_loaded_.TimedWait(base::TimeDelta::FromSeconds(kTimeoutSecs)); | 109 on_statistics_loaded_.TimedWait(base::TimeDelta::FromSeconds(kTimeoutSecs)); |
| 110 |
| 111 if (!on_statistics_loaded_.IsSignaled()) { |
| 112 LOG(ERROR) << "Statistics weren't loaded after waiting! " |
| 113 << "Requested statistic: " << name; |
| 114 return false; |
| 115 } |
| 110 } | 116 } |
| 111 | 117 |
| 112 NameValuePairsParser::NameValueMap::iterator iter = machine_info_.find(name); | 118 NameValuePairsParser::NameValueMap::iterator iter = machine_info_.find(name); |
| 113 if (iter != machine_info_.end()) { | 119 if (iter != machine_info_.end()) { |
| 114 *result = iter->second; | 120 *result = iter->second; |
| 115 return true; | 121 return true; |
| 116 } | 122 } |
| 117 return false; | 123 return false; |
| 118 } | 124 } |
| 119 | 125 |
| 120 // manual_reset needs to be true, as we want to keep the signaled state. | 126 // manual_reset needs to be true, as we want to keep the signaled state. |
| 121 StatisticsProviderImpl::StatisticsProviderImpl() | 127 StatisticsProviderImpl::StatisticsProviderImpl() |
| 122 : on_statistics_loaded_(true /* manual_reset */, | 128 : on_statistics_loaded_(true /* manual_reset */, |
| 123 false /* initially_signaled */) { | 129 false /* initially_signaled */) { |
| 124 StartLoadingMachineStatistics(); | 130 StartLoadingMachineStatistics(); |
| 125 } | 131 } |
| 126 | 132 |
| 127 void StatisticsProviderImpl::StartLoadingMachineStatistics() { | 133 void StatisticsProviderImpl::StartLoadingMachineStatistics() { |
| 128 VLOG(1) << "Started loading statistics"; | 134 VLOG(1) << "Started loading statistics"; |
| 129 CHECK(BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) | 135 BrowserThread::PostBlockingPoolTask( |
| 130 << "StatisticsProvider must not be used before FILE thread is created"; | |
| 131 BrowserThread::PostTask( | |
| 132 BrowserThread::FILE, | |
| 133 FROM_HERE, | 136 FROM_HERE, |
| 134 base::Bind(&StatisticsProviderImpl::LoadMachineStatistics, | 137 base::Bind(&StatisticsProviderImpl::LoadMachineStatistics, |
| 135 base::Unretained(this))); | 138 base::Unretained(this))); |
| 136 } | 139 } |
| 137 | 140 |
| 138 void StatisticsProviderImpl::LoadMachineStatistics() { | 141 void StatisticsProviderImpl::LoadMachineStatistics() { |
| 139 NameValuePairsParser parser(&machine_info_); | 142 NameValuePairsParser parser(&machine_info_); |
| 140 | 143 |
| 141 // Parse all of the key/value pairs from the crossystem tool. | 144 // Parse all of the key/value pairs from the crossystem tool. |
| 142 parser.ParseNameValuePairsFromTool( | 145 if (!parser.ParseNameValuePairsFromTool( |
| 143 arraysize(kCrosSystemTool), kCrosSystemTool, kCrosSystemEq, | 146 arraysize(kCrosSystemTool), kCrosSystemTool, kCrosSystemEq, |
| 144 kCrosSystemDelim, kCrosSystemCommentDelim); | 147 kCrosSystemDelim, kCrosSystemCommentDelim)) { |
| 148 LOG(WARNING) << "There were errors parsing the output of " |
| 149 << kCrosSystemTool << "."; |
| 150 } |
| 145 | 151 |
| 146 // Ensure that the hardware class key is present with the expected | 152 // Ensure that the hardware class key is present with the expected |
| 147 // key name, and if it couldn't be retrieved, that the value is "unknown". | 153 // key name, and if it couldn't be retrieved, that the value is "unknown". |
| 148 std::string hardware_class = machine_info_[kHardwareClassCrosSystemKey]; | 154 std::string hardware_class = machine_info_[kHardwareClassCrosSystemKey]; |
| 149 if (hardware_class.empty() || hardware_class == kCrosSystemUnknownValue) | 155 if (hardware_class.empty() || hardware_class == kCrosSystemUnknownValue) |
| 150 machine_info_[kHardwareClassKey] = kUnknownHardwareClass; | 156 machine_info_[kHardwareClassKey] = kUnknownHardwareClass; |
| 151 else | 157 else |
| 152 machine_info_[kHardwareClassKey] = hardware_class; | 158 machine_info_[kHardwareClassKey] = hardware_class; |
| 153 | 159 |
| 154 parser.GetNameValuePairsFromFile(FilePath(kMachineHardwareInfoFile), | 160 parser.GetNameValuePairsFromFile(FilePath(kMachineHardwareInfoFile), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 StatisticsProvider* StatisticsProvider::GetInstance() { | 227 StatisticsProvider* StatisticsProvider::GetInstance() { |
| 222 if (base::chromeos::IsRunningOnChromeOS()) { | 228 if (base::chromeos::IsRunningOnChromeOS()) { |
| 223 return StatisticsProviderImpl::GetInstance(); | 229 return StatisticsProviderImpl::GetInstance(); |
| 224 } else { | 230 } else { |
| 225 return StatisticsProviderStubImpl::GetInstance(); | 231 return StatisticsProviderStubImpl::GetInstance(); |
| 226 } | 232 } |
| 227 } | 233 } |
| 228 | 234 |
| 229 } // namespace system | 235 } // namespace system |
| 230 } // namespace chromeos | 236 } // namespace chromeos |
| OLD | NEW |