Chromium Code Reviews| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 void Init() OVERRIDE; |
| 74 virtual void StartLoadingMachineStatistics() OVERRIDE; | |
| 74 virtual bool GetMachineStatistic(const std::string& name, | 75 virtual bool GetMachineStatistic(const std::string& name, |
| 75 std::string* result) OVERRIDE; | 76 std::string* result) OVERRIDE; |
| 76 | 77 |
| 77 static StatisticsProviderImpl* GetInstance(); | 78 static StatisticsProviderImpl* GetInstance(); |
| 78 | 79 |
| 79 private: | 80 private: |
| 80 friend struct DefaultSingletonTraits<StatisticsProviderImpl>; | 81 friend struct DefaultSingletonTraits<StatisticsProviderImpl>; |
| 81 | 82 |
| 82 StatisticsProviderImpl(); | 83 StatisticsProviderImpl(); |
| 83 | 84 |
| 84 // Loads the machine info file, which is necessary to get the Chrome channel. | 85 // Loads the machine info file, which is necessary to get the Chrome channel. |
| 85 // Treat MachineOSInfoFile specially, as distribution channel information | 86 // Treat MachineOSInfoFile specially, as distribution channel information |
| 86 // (stable, beta, dev, canary) is required at earlier stage than everything | 87 // (stable, beta, dev, canary) is required at earlier stage than everything |
| 87 // else. Rather than posting a delayed task, read and parse the machine OS | 88 // else. Rather than posting a delayed task, read and parse the machine OS |
| 88 // info file immediately. | 89 // info file immediately. |
| 89 void LoadMachineOSInfoFile(); | 90 void LoadMachineOSInfoFile(); |
| 90 | 91 |
| 91 // Starts loading the machine statistcs. | |
| 92 void StartLoadingMachineStatistics(); | |
| 93 | |
| 94 // Loads the machine statistcs by examining the system. | 92 // Loads the machine statistcs by examining the system. |
| 95 void LoadMachineStatistics(); | 93 void LoadMachineStatistics(); |
| 96 | 94 |
| 97 bool initialized_; | 95 bool initialized_; |
| 98 NameValuePairsParser::NameValueMap machine_info_; | 96 NameValuePairsParser::NameValueMap machine_info_; |
| 99 base::WaitableEvent on_statistics_loaded_; | 97 base::WaitableEvent on_statistics_loaded_; |
| 100 | 98 |
| 101 DISALLOW_COPY_AND_ASSIGN(StatisticsProviderImpl); | 99 DISALLOW_COPY_AND_ASSIGN(StatisticsProviderImpl); |
| 102 }; | 100 }; |
| 103 | 101 |
| 104 void StatisticsProviderImpl::Init() { | 102 void StatisticsProviderImpl::Init() { |
| 105 DCHECK(!initialized_); | 103 DCHECK(!initialized_); |
| 106 initialized_ = true; | 104 initialized_ = true; |
| 107 | 105 |
| 108 // Load the machine info file immediately to get the channel info and delay | 106 // Load the machine info file immediately to get the channel info. |
| 109 // loading the remaining statistics. | |
| 110 LoadMachineOSInfoFile(); | 107 LoadMachineOSInfoFile(); |
| 111 StartLoadingMachineStatistics(); | |
| 112 } | 108 } |
| 113 | 109 |
| 114 bool StatisticsProviderImpl::GetMachineStatistic( | 110 bool StatisticsProviderImpl::GetMachineStatistic( |
| 115 const std::string& name, std::string* result) { | 111 const std::string& name, std::string* result) { |
| 116 DCHECK(initialized_); | 112 DCHECK(initialized_); |
| 117 | 113 |
| 118 VLOG(1) << "Statistic is requested for " << name; | 114 VLOG(1) << "Statistic is requested for " << name; |
| 119 // Block if the statistics are not loaded yet. Per LOG(WARNING) below, | 115 // Block if the statistics are not loaded yet. Per LOG(WARNING) below, |
| 120 // the statistics are loaded before requested as of now. For regular | 116 // the statistics are loaded before requested as of now. For regular |
| 121 // sessions (i.e. not OOBE), statistics are first requested when the | 117 // sessions (i.e. not OOBE), statistics are first requested when the |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 #if defined(GOOGLE_CHROME_BUILD) | 159 #if defined(GOOGLE_CHROME_BUILD) |
| 164 const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK"; | 160 const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK"; |
| 165 NameValuePairsParser::NameValueMap::iterator iter = | 161 NameValuePairsParser::NameValueMap::iterator iter = |
| 166 machine_info_.find(kChromeOSReleaseTrack); | 162 machine_info_.find(kChromeOSReleaseTrack); |
| 167 if (iter != machine_info_.end()) | 163 if (iter != machine_info_.end()) |
| 168 chrome::VersionInfo::SetChannel(iter->second); | 164 chrome::VersionInfo::SetChannel(iter->second); |
| 169 #endif | 165 #endif |
| 170 } | 166 } |
| 171 } | 167 } |
| 172 | 168 |
| 173 void StatisticsProviderImpl::StartLoadingMachineStatistics() { | 169 void StatisticsProviderImpl::StartLoadingMachineStatistics() { |
|
Alexei Svitkine (slow)
2013/01/07 19:24:06
Can you add a DCHECK to ensure this doesn't get ca
hshi1
2013/01/07 19:32:06
Done.
| |
| 174 VLOG(1) << "Started loading statistics"; | 170 VLOG(1) << "Started loading statistics"; |
| 175 BrowserThread::PostBlockingPoolTask( | 171 BrowserThread::PostBlockingPoolTask( |
| 176 FROM_HERE, | 172 FROM_HERE, |
| 177 base::Bind(&StatisticsProviderImpl::LoadMachineStatistics, | 173 base::Bind(&StatisticsProviderImpl::LoadMachineStatistics, |
| 178 base::Unretained(this))); | 174 base::Unretained(this))); |
| 179 } | 175 } |
| 180 | 176 |
| 181 void StatisticsProviderImpl::LoadMachineStatistics() { | 177 void StatisticsProviderImpl::LoadMachineStatistics() { |
| 182 NameValuePairsParser parser(&machine_info_); | 178 NameValuePairsParser parser(&machine_info_); |
| 183 | 179 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 212 | 208 |
| 213 StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() { | 209 StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() { |
| 214 return Singleton<StatisticsProviderImpl, | 210 return Singleton<StatisticsProviderImpl, |
| 215 DefaultSingletonTraits<StatisticsProviderImpl> >::get(); | 211 DefaultSingletonTraits<StatisticsProviderImpl> >::get(); |
| 216 } | 212 } |
| 217 | 213 |
| 218 // The stub StatisticsProvider implementation used on Linux desktop. | 214 // The stub StatisticsProvider implementation used on Linux desktop. |
| 219 class StatisticsProviderStubImpl : public StatisticsProvider { | 215 class StatisticsProviderStubImpl : public StatisticsProvider { |
| 220 public: | 216 public: |
| 221 // StatisticsProvider implementation: | 217 // StatisticsProvider implementation: |
| 222 virtual void Init() OVERRIDE { | 218 virtual void Init() OVERRIDE {} |
| 223 } | 219 |
| 220 virtual void StartLoadingMachineStatistics() OVERRIDE {} | |
| 224 | 221 |
| 225 virtual bool GetMachineStatistic(const std::string& name, | 222 virtual bool GetMachineStatistic(const std::string& name, |
| 226 std::string* result) OVERRIDE { | 223 std::string* result) OVERRIDE { |
| 227 if (name == "CHROMEOS_RELEASE_BOARD") { | 224 if (name == "CHROMEOS_RELEASE_BOARD") { |
| 228 // Note: syncer::GetSessionNameSynchronously() also uses the mechanism | 225 // Note: syncer::GetSessionNameSynchronously() also uses the mechanism |
| 229 // below to determine the CrOs release board. However, it cannot include | 226 // below to determine the CrOs release board. However, it cannot include |
| 230 // statistics_provider.h and use this method because of the mutual | 227 // statistics_provider.h and use this method because of the mutual |
| 231 // dependency that creates between sync.gyp:sync and chrome.gyp:browser. | 228 // dependency that creates between sync.gyp:sync and chrome.gyp:browser. |
| 232 // TODO(rsimha): Update syncer::GetSessionNameSynchronously() if this code | 229 // TODO(rsimha): Update syncer::GetSessionNameSynchronously() if this code |
| 233 // is ever moved into base/. See http://crbug.com/126732. | 230 // is ever moved into base/. See http://crbug.com/126732. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 258 StatisticsProvider* StatisticsProvider::GetInstance() { | 255 StatisticsProvider* StatisticsProvider::GetInstance() { |
| 259 if (base::chromeos::IsRunningOnChromeOS()) { | 256 if (base::chromeos::IsRunningOnChromeOS()) { |
| 260 return StatisticsProviderImpl::GetInstance(); | 257 return StatisticsProviderImpl::GetInstance(); |
| 261 } else { | 258 } else { |
| 262 return StatisticsProviderStubImpl::GetInstance(); | 259 return StatisticsProviderStubImpl::GetInstance(); |
| 263 } | 260 } |
| 264 } | 261 } |
| 265 | 262 |
| 266 } // namespace system | 263 } // namespace system |
| 267 } // namespace chromeos | 264 } // namespace chromeos |
| OLD | NEW |