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

Side by Side Diff: chrome/browser/chromeos/system/statistics_provider.cc

Issue 11778025: Decouple loading of channel info and the rest of machine statistics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add more comments, DCHECK. Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/system/statistics_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_;
96 bool load_statistics_started_;
98 NameValuePairsParser::NameValueMap machine_info_; 97 NameValuePairsParser::NameValueMap machine_info_;
99 base::WaitableEvent on_statistics_loaded_; 98 base::WaitableEvent on_statistics_loaded_;
100 99
101 DISALLOW_COPY_AND_ASSIGN(StatisticsProviderImpl); 100 DISALLOW_COPY_AND_ASSIGN(StatisticsProviderImpl);
102 }; 101 };
103 102
104 void StatisticsProviderImpl::Init() { 103 void StatisticsProviderImpl::Init() {
105 DCHECK(!initialized_); 104 DCHECK(!initialized_);
106 initialized_ = true; 105 initialized_ = true;
107 106
108 // Load the machine info file immediately to get the channel info and delay 107 // Load the machine info file immediately to get the channel info.
109 // loading the remaining statistics.
110 LoadMachineOSInfoFile(); 108 LoadMachineOSInfoFile();
111 StartLoadingMachineStatistics();
112 } 109 }
113 110
114 bool StatisticsProviderImpl::GetMachineStatistic( 111 bool StatisticsProviderImpl::GetMachineStatistic(
115 const std::string& name, std::string* result) { 112 const std::string& name, std::string* result) {
116 DCHECK(initialized_); 113 DCHECK(initialized_);
114 DCHECK(load_statistics_started_);
117 115
118 VLOG(1) << "Statistic is requested for " << name; 116 VLOG(1) << "Statistic is requested for " << name;
119 // Block if the statistics are not loaded yet. Per LOG(WARNING) below, 117 // Block if the statistics are not loaded yet. Per LOG(WARNING) below,
120 // the statistics are loaded before requested as of now. For regular 118 // the statistics are loaded before requested as of now. For regular
121 // sessions (i.e. not OOBE), statistics are first requested when the 119 // sessions (i.e. not OOBE), statistics are first requested when the
122 // user is logging in so we have plenty of time to load the data 120 // user is logging in so we have plenty of time to load the data
123 // beforehand. 121 // beforehand.
124 // 122 //
125 // If you see the warning appeared for regular sessions, it probably 123 // If you see the warning appeared for regular sessions, it probably
126 // means that there is new client code that uses the statistics in the 124 // means that there is new client code that uses the statistics in the
(...skipping 17 matching lines...) Expand all
144 if (iter != machine_info_.end()) { 142 if (iter != machine_info_.end()) {
145 *result = iter->second; 143 *result = iter->second;
146 return true; 144 return true;
147 } 145 }
148 return false; 146 return false;
149 } 147 }
150 148
151 // manual_reset needs to be true, as we want to keep the signaled state. 149 // manual_reset needs to be true, as we want to keep the signaled state.
152 StatisticsProviderImpl::StatisticsProviderImpl() 150 StatisticsProviderImpl::StatisticsProviderImpl()
153 : initialized_(false), 151 : initialized_(false),
152 load_statistics_started_(false),
154 on_statistics_loaded_(true /* manual_reset */, 153 on_statistics_loaded_(true /* manual_reset */,
155 false /* initially_signaled */) { 154 false /* initially_signaled */) {
156 } 155 }
157 156
158 void StatisticsProviderImpl::LoadMachineOSInfoFile() { 157 void StatisticsProviderImpl::LoadMachineOSInfoFile() {
159 NameValuePairsParser parser(&machine_info_); 158 NameValuePairsParser parser(&machine_info_);
160 if (parser.GetNameValuePairsFromFile(FilePath(kMachineOSInfoFile), 159 if (parser.GetNameValuePairsFromFile(FilePath(kMachineOSInfoFile),
161 kMachineOSInfoEq, 160 kMachineOSInfoEq,
162 kMachineOSInfoDelim)) { 161 kMachineOSInfoDelim)) {
163 #if defined(GOOGLE_CHROME_BUILD) 162 #if defined(GOOGLE_CHROME_BUILD)
164 const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK"; 163 const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK";
165 NameValuePairsParser::NameValueMap::iterator iter = 164 NameValuePairsParser::NameValueMap::iterator iter =
166 machine_info_.find(kChromeOSReleaseTrack); 165 machine_info_.find(kChromeOSReleaseTrack);
167 if (iter != machine_info_.end()) 166 if (iter != machine_info_.end())
168 chrome::VersionInfo::SetChannel(iter->second); 167 chrome::VersionInfo::SetChannel(iter->second);
169 #endif 168 #endif
170 } 169 }
171 } 170 }
172 171
173 void StatisticsProviderImpl::StartLoadingMachineStatistics() { 172 void StatisticsProviderImpl::StartLoadingMachineStatistics() {
Alexei Svitkine (slow) 2013/01/07 19:39:00 Actually, can you also add DCHECK(initialized_); h
hshi1 2013/01/07 19:41:16 Done.
173 DCHECK(!load_statistics_started_);
174 load_statistics_started_ = true;
175
174 VLOG(1) << "Started loading statistics"; 176 VLOG(1) << "Started loading statistics";
175 BrowserThread::PostBlockingPoolTask( 177 BrowserThread::PostBlockingPoolTask(
176 FROM_HERE, 178 FROM_HERE,
177 base::Bind(&StatisticsProviderImpl::LoadMachineStatistics, 179 base::Bind(&StatisticsProviderImpl::LoadMachineStatistics,
178 base::Unretained(this))); 180 base::Unretained(this)));
179 } 181 }
180 182
181 void StatisticsProviderImpl::LoadMachineStatistics() { 183 void StatisticsProviderImpl::LoadMachineStatistics() {
182 NameValuePairsParser parser(&machine_info_); 184 NameValuePairsParser parser(&machine_info_);
183 185
(...skipping 28 matching lines...) Expand all
212 214
213 StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() { 215 StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() {
214 return Singleton<StatisticsProviderImpl, 216 return Singleton<StatisticsProviderImpl,
215 DefaultSingletonTraits<StatisticsProviderImpl> >::get(); 217 DefaultSingletonTraits<StatisticsProviderImpl> >::get();
216 } 218 }
217 219
218 // The stub StatisticsProvider implementation used on Linux desktop. 220 // The stub StatisticsProvider implementation used on Linux desktop.
219 class StatisticsProviderStubImpl : public StatisticsProvider { 221 class StatisticsProviderStubImpl : public StatisticsProvider {
220 public: 222 public:
221 // StatisticsProvider implementation: 223 // StatisticsProvider implementation:
222 virtual void Init() OVERRIDE { 224 virtual void Init() OVERRIDE {}
223 } 225
226 virtual void StartLoadingMachineStatistics() OVERRIDE {}
224 227
225 virtual bool GetMachineStatistic(const std::string& name, 228 virtual bool GetMachineStatistic(const std::string& name,
226 std::string* result) OVERRIDE { 229 std::string* result) OVERRIDE {
227 if (name == "CHROMEOS_RELEASE_BOARD") { 230 if (name == "CHROMEOS_RELEASE_BOARD") {
228 // Note: syncer::GetSessionNameSynchronously() also uses the mechanism 231 // Note: syncer::GetSessionNameSynchronously() also uses the mechanism
229 // below to determine the CrOs release board. However, it cannot include 232 // below to determine the CrOs release board. However, it cannot include
230 // statistics_provider.h and use this method because of the mutual 233 // statistics_provider.h and use this method because of the mutual
231 // dependency that creates between sync.gyp:sync and chrome.gyp:browser. 234 // dependency that creates between sync.gyp:sync and chrome.gyp:browser.
232 // TODO(rsimha): Update syncer::GetSessionNameSynchronously() if this code 235 // TODO(rsimha): Update syncer::GetSessionNameSynchronously() if this code
233 // is ever moved into base/. See http://crbug.com/126732. 236 // is ever moved into base/. See http://crbug.com/126732.
(...skipping 24 matching lines...) Expand all
258 StatisticsProvider* StatisticsProvider::GetInstance() { 261 StatisticsProvider* StatisticsProvider::GetInstance() {
259 if (base::chromeos::IsRunningOnChromeOS()) { 262 if (base::chromeos::IsRunningOnChromeOS()) {
260 return StatisticsProviderImpl::GetInstance(); 263 return StatisticsProviderImpl::GetInstance();
261 } else { 264 } else {
262 return StatisticsProviderStubImpl::GetInstance(); 265 return StatisticsProviderStubImpl::GetInstance();
263 } 266 }
264 } 267 }
265 268
266 } // namespace system 269 } // namespace system
267 } // namespace chromeos 270 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/system/statistics_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698