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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 | 63 |
64 // Timeout that we should wait for statistics to get loaded | 64 // Timeout that we should wait for statistics to get loaded |
65 const int kTimeoutSecs = 3; | 65 const int kTimeoutSecs = 3; |
66 | 66 |
67 } // namespace | 67 } // namespace |
68 | 68 |
69 // The StatisticsProvider implementation used in production. | 69 // The StatisticsProvider implementation used in production. |
70 class StatisticsProviderImpl : public StatisticsProvider { | 70 class StatisticsProviderImpl : public StatisticsProvider { |
71 public: | 71 public: |
72 // StatisticsProvider implementation: | 72 // StatisticsProvider implementation: |
73 virtual void Init() OVERRIDE; | |
73 virtual bool GetMachineStatistic(const std::string& name, | 74 virtual bool GetMachineStatistic(const std::string& name, |
74 std::string* result) OVERRIDE; | 75 std::string* result) OVERRIDE; |
75 | 76 |
76 static StatisticsProviderImpl* GetInstance(); | 77 static StatisticsProviderImpl* GetInstance(); |
77 | 78 |
78 private: | 79 private: |
79 friend struct DefaultSingletonTraits<StatisticsProviderImpl>; | 80 friend struct DefaultSingletonTraits<StatisticsProviderImpl>; |
80 | 81 |
81 StatisticsProviderImpl(); | 82 StatisticsProviderImpl(); |
82 | 83 |
84 // Loads the machine info file, which is necessary to get the Chrome channel. | |
kochi
2012/12/13 14:17:30
Could you also mention in comment why this has to
Alexei Svitkine (slow)
2012/12/13 15:16:03
Done.
| |
85 void LoadMachineOSInfoFile(); | |
86 | |
83 // Starts loading the machine statistcs. | 87 // Starts loading the machine statistcs. |
84 void StartLoadingMachineStatistics(); | 88 void StartLoadingMachineStatistics(); |
85 | 89 |
86 // Loads the machine statistcs by examining the system. | 90 // Loads the machine statistcs by examining the system. |
87 void LoadMachineStatistics(); | 91 void LoadMachineStatistics(); |
88 | 92 |
89 NameValuePairsParser::NameValueMap machine_info_; | 93 NameValuePairsParser::NameValueMap machine_info_; |
90 base::WaitableEvent on_statistics_loaded_; | 94 base::WaitableEvent on_statistics_loaded_; |
91 | 95 |
92 DISALLOW_COPY_AND_ASSIGN(StatisticsProviderImpl); | 96 DISALLOW_COPY_AND_ASSIGN(StatisticsProviderImpl); |
93 }; | 97 }; |
94 | 98 |
99 void StatisticsProviderImpl::Init() { | |
100 // Load the machine info file immediately to get the channel info and delay | |
101 // loading the remaining statistics. | |
102 LoadMachineOSInfoFile(); | |
103 StartLoadingMachineStatistics(); | |
104 } | |
105 | |
95 bool StatisticsProviderImpl::GetMachineStatistic( | 106 bool StatisticsProviderImpl::GetMachineStatistic( |
96 const std::string& name, std::string* result) { | 107 const std::string& name, std::string* result) { |
97 VLOG(1) << "Statistic is requested for " << name; | 108 VLOG(1) << "Statistic is requested for " << name; |
98 // Block if the statistics are not loaded yet. Per LOG(WARNING) below, | 109 // Block if the statistics are not loaded yet. Per LOG(WARNING) below, |
99 // the statistics are loaded before requested as of now. For regular | 110 // the statistics are loaded before requested as of now. For regular |
100 // sessions (i.e. not OOBE), statistics are first requested when the | 111 // sessions (i.e. not OOBE), statistics are first requested when the |
101 // user is logging in so we have plenty of time to load the data | 112 // user is logging in so we have plenty of time to load the data |
102 // beforehand. | 113 // beforehand. |
103 // | 114 // |
104 // If you see the warning appeared for regular sessions, it probably | 115 // If you see the warning appeared for regular sessions, it probably |
(...skipping 19 matching lines...) Expand all Loading... | |
124 *result = iter->second; | 135 *result = iter->second; |
125 return true; | 136 return true; |
126 } | 137 } |
127 return false; | 138 return false; |
128 } | 139 } |
129 | 140 |
130 // manual_reset needs to be true, as we want to keep the signaled state. | 141 // manual_reset needs to be true, as we want to keep the signaled state. |
131 StatisticsProviderImpl::StatisticsProviderImpl() | 142 StatisticsProviderImpl::StatisticsProviderImpl() |
132 : on_statistics_loaded_(true /* manual_reset */, | 143 : on_statistics_loaded_(true /* manual_reset */, |
133 false /* initially_signaled */) { | 144 false /* initially_signaled */) { |
134 StartLoadingMachineStatistics(); | 145 } |
kochi
2012/12/13 14:17:30
Why do you prefer having another public method Ini
Alexei Svitkine (slow)
2012/12/13 15:16:03
Here's why I prefer the Init() approach:
1. The s
kochi
2012/12/14 02:22:52
Looks good, thanks for explanation!
On 2012/12/13
| |
146 | |
147 void StatisticsProviderImpl::LoadMachineOSInfoFile() { | |
148 NameValuePairsParser parser(&machine_info_); | |
149 if (parser.GetNameValuePairsFromFile(FilePath(kMachineOSInfoFile), | |
150 kMachineOSInfoEq, | |
151 kMachineOSInfoDelim)) { | |
152 #if defined(GOOGLE_CHROME_BUILD) | |
153 const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK"; | |
154 NameValuePairsParser::NameValueMap::iterator iter = | |
155 machine_info_.find(kChromeOSReleaseTrack); | |
156 if (iter != machine_info_.end()) | |
157 chrome::VersionInfo::SetChannel(iter->second); | |
158 #endif | |
159 } | |
135 } | 160 } |
136 | 161 |
137 void StatisticsProviderImpl::StartLoadingMachineStatistics() { | 162 void StatisticsProviderImpl::StartLoadingMachineStatistics() { |
138 VLOG(1) << "Started loading statistics"; | 163 VLOG(1) << "Started loading statistics"; |
139 BrowserThread::PostBlockingPoolTask( | 164 BrowserThread::PostBlockingPoolTask( |
140 FROM_HERE, | 165 FROM_HERE, |
141 base::Bind(&StatisticsProviderImpl::LoadMachineStatistics, | 166 base::Bind(&StatisticsProviderImpl::LoadMachineStatistics, |
142 base::Unretained(this))); | 167 base::Unretained(this))); |
143 } | 168 } |
144 | 169 |
(...skipping 15 matching lines...) Expand all Loading... | |
160 machine_info_[kHardwareClassKey] = kUnknownHardwareClass; | 185 machine_info_[kHardwareClassKey] = kUnknownHardwareClass; |
161 else | 186 else |
162 machine_info_[kHardwareClassKey] = hardware_class; | 187 machine_info_[kHardwareClassKey] = hardware_class; |
163 | 188 |
164 parser.GetNameValuePairsFromFile(FilePath(kMachineHardwareInfoFile), | 189 parser.GetNameValuePairsFromFile(FilePath(kMachineHardwareInfoFile), |
165 kMachineHardwareInfoEq, | 190 kMachineHardwareInfoEq, |
166 kMachineHardwareInfoDelim); | 191 kMachineHardwareInfoDelim); |
167 parser.GetNameValuePairsFromFile(FilePath(kEchoCouponFile), | 192 parser.GetNameValuePairsFromFile(FilePath(kEchoCouponFile), |
168 kEchoCouponEq, | 193 kEchoCouponEq, |
169 kEchoCouponDelim); | 194 kEchoCouponDelim); |
170 parser.GetNameValuePairsFromFile(FilePath(kMachineOSInfoFile), | |
171 kMachineOSInfoEq, | |
172 kMachineOSInfoDelim); | |
173 parser.GetNameValuePairsFromFile(FilePath(kVpdFile), kVpdEq, kVpdDelim); | 195 parser.GetNameValuePairsFromFile(FilePath(kVpdFile), kVpdEq, kVpdDelim); |
174 | 196 |
175 // Finished loading the statistics. | 197 // Finished loading the statistics. |
176 on_statistics_loaded_.Signal(); | 198 on_statistics_loaded_.Signal(); |
177 VLOG(1) << "Finished loading statistics"; | 199 VLOG(1) << "Finished loading statistics"; |
178 | |
179 #if defined(GOOGLE_CHROME_BUILD) | |
180 // TODO(kochi): This is for providing a channel information to | |
181 // chrome::VersionInfo::GetChannel()/GetVersionStringModifier(), | |
182 // but this is still late for some early customers such as | |
183 // prerender::ConfigurePrefetchAndPrerender() and | |
184 // ThreadWatcherList::ParseCommandLine(). | |
185 // See http://crbug.com/107333 . | |
186 const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK"; | |
187 std::string channel; | |
188 if (GetMachineStatistic(kChromeOSReleaseTrack, &channel)) { | |
189 chrome::VersionInfo::SetChannel(channel); | |
190 // Set the product channel for crash reports. We can't just do this in | |
191 // ChromeBrowserMainParts::PreCreateThreads like we do for Linux because | |
192 // the FILE thread hasn't been created yet there so we can't possibly | |
193 // have read this yet. Note that this string isn't exactly the same as | |
194 // 'channel', it's been parsed to be consistent with other platforms | |
195 // (eg. "canary-channel" becomes "canary", "testimage-channel" becomes | |
196 // "unknown"). | |
197 child_process_logging::SetChannel( | |
198 chrome::VersionInfo::GetVersionStringModifier()); | |
199 } | |
200 #endif | |
201 } | 200 } |
202 | 201 |
203 StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() { | 202 StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() { |
204 return Singleton<StatisticsProviderImpl, | 203 return Singleton<StatisticsProviderImpl, |
205 DefaultSingletonTraits<StatisticsProviderImpl> >::get(); | 204 DefaultSingletonTraits<StatisticsProviderImpl> >::get(); |
206 } | 205 } |
207 | 206 |
208 // The stub StatisticsProvider implementation used on Linux desktop. | 207 // The stub StatisticsProvider implementation used on Linux desktop. |
209 class StatisticsProviderStubImpl : public StatisticsProvider { | 208 class StatisticsProviderStubImpl : public StatisticsProvider { |
210 public: | 209 public: |
211 // StatisticsProvider implementation: | 210 // StatisticsProvider implementation: |
211 virtual void Init() OVERRIDE { | |
212 } | |
213 | |
212 virtual bool GetMachineStatistic(const std::string& name, | 214 virtual bool GetMachineStatistic(const std::string& name, |
213 std::string* result) OVERRIDE { | 215 std::string* result) OVERRIDE { |
214 if (name == "CHROMEOS_RELEASE_BOARD") { | 216 if (name == "CHROMEOS_RELEASE_BOARD") { |
215 // Note: syncer::GetSessionNameSynchronously() also uses the mechanism | 217 // Note: syncer::GetSessionNameSynchronously() also uses the mechanism |
216 // below to determine the CrOs release board. However, it cannot include | 218 // below to determine the CrOs release board. However, it cannot include |
217 // statistics_provider.h and use this method because of the mutual | 219 // statistics_provider.h and use this method because of the mutual |
218 // dependency that creates between sync.gyp:sync and chrome.gyp:browser. | 220 // dependency that creates between sync.gyp:sync and chrome.gyp:browser. |
219 // TODO(rsimha): Update syncer::GetSessionNameSynchronously() if this code | 221 // TODO(rsimha): Update syncer::GetSessionNameSynchronously() if this code |
220 // is ever moved into base/. See http://crbug.com/126732. | 222 // is ever moved into base/. See http://crbug.com/126732. |
221 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 223 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
(...skipping 23 matching lines...) Expand all Loading... | |
245 StatisticsProvider* StatisticsProvider::GetInstance() { | 247 StatisticsProvider* StatisticsProvider::GetInstance() { |
246 if (base::chromeos::IsRunningOnChromeOS()) { | 248 if (base::chromeos::IsRunningOnChromeOS()) { |
247 return StatisticsProviderImpl::GetInstance(); | 249 return StatisticsProviderImpl::GetInstance(); |
248 } else { | 250 } else { |
249 return StatisticsProviderStubImpl::GetInstance(); | 251 return StatisticsProviderStubImpl::GetInstance(); |
250 } | 252 } |
251 } | 253 } |
252 | 254 |
253 } // namespace system | 255 } // namespace system |
254 } // namespace chromeos | 256 } // namespace chromeos |
OLD | NEW |