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

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

Issue 23588009: Parse /etc/lsb-release only once on ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 2 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
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/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chromeos/app_mode/kiosk_oem_manifest_parser.h" 17 #include "chromeos/app_mode/kiosk_oem_manifest_parser.h"
18 #include "chromeos/chromeos_constants.h" 18 #include "chromeos/chromeos_constants.h"
19 #include "chromeos/chromeos_switches.h" 19 #include "chromeos/chromeos_switches.h"
20 #include "chromeos/system/name_value_pairs_parser.h" 20 #include "chromeos/system/name_value_pairs_parser.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 22
23 #if defined(GOOGLE_CHROME_BUILD)
24 // TODO(phajdan.jr): Drop that dependency, http://crbug.com/180711 .
25 #include "chrome/common/chrome_version_info.h"
26 #endif
27
28 using content::BrowserThread; 23 using content::BrowserThread;
29 24
30 namespace chromeos { 25 namespace chromeos {
31 namespace system { 26 namespace system {
32 namespace { 27 namespace {
33 28
34 // Path to the tool used to get system info, and delimiters for the output 29 // Path to the tool used to get system info, and delimiters for the output
35 // format of the tool. 30 // format of the tool.
36 const char* kCrosSystemTool[] = { "/usr/bin/crossystem" }; 31 const char* kCrosSystemTool[] = { "/usr/bin/crossystem" };
37 const char kCrosSystemEq[] = "="; 32 const char kCrosSystemEq[] = "=";
(...skipping 11 matching lines...) Expand all
49 const char kMachineHardwareInfoFile[] = "/tmp/machine-info"; 44 const char kMachineHardwareInfoFile[] = "/tmp/machine-info";
50 const char kMachineHardwareInfoEq[] = "="; 45 const char kMachineHardwareInfoEq[] = "=";
51 const char kMachineHardwareInfoDelim[] = " \n"; 46 const char kMachineHardwareInfoDelim[] = " \n";
52 47
53 // File to get ECHO coupon info from, and key/value delimiters of 48 // File to get ECHO coupon info from, and key/value delimiters of
54 // the file. 49 // the file.
55 const char kEchoCouponFile[] = "/var/cache/echo/vpd_echo.txt"; 50 const char kEchoCouponFile[] = "/var/cache/echo/vpd_echo.txt";
56 const char kEchoCouponEq[] = "="; 51 const char kEchoCouponEq[] = "=";
57 const char kEchoCouponDelim[] = "\n"; 52 const char kEchoCouponDelim[] = "\n";
58 53
59 // File to get machine OS info from, and key/value delimiters of the file.
60 const char kMachineOSInfoFile[] = "/etc/lsb-release";
61 const char kMachineOSInfoEq[] = "=";
62 const char kMachineOSInfoDelim[] = "\n";
63
64 // File to get VPD info from, and key/value delimiters of the file. 54 // File to get VPD info from, and key/value delimiters of the file.
65 const char kVpdFile[] = "/var/log/vpd_2.0.txt"; 55 const char kVpdFile[] = "/var/log/vpd_2.0.txt";
66 const char kVpdEq[] = "="; 56 const char kVpdEq[] = "=";
67 const char kVpdDelim[] = "\n"; 57 const char kVpdDelim[] = "\n";
68 58
69 // Timeout that we should wait for statistics to get loaded 59 // Timeout that we should wait for statistics to get loaded
70 const int kTimeoutSecs = 3; 60 const int kTimeoutSecs = 3;
71 61
72 // The location of OEM manifest file used to trigger OOBE flow for kiosk mode. 62 // The location of OEM manifest file used to trigger OOBE flow for kiosk mode.
73 const CommandLine::CharType kOemManifestFilePath[] = 63 const CommandLine::CharType kOemManifestFilePath[] =
74 FILE_PATH_LITERAL("/usr/share/oem/oobe/manifest.json"); 64 FILE_PATH_LITERAL("/usr/share/oem/oobe/manifest.json");
75 65
76 } // namespace 66 } // namespace
77 67
78 // Key values for GetMachineStatistic()/GetMachineFlag() calls. 68 // Key values for GetMachineStatistic()/GetMachineFlag() calls.
79 const char kDevSwitchBootMode[] = "devsw_boot"; 69 const char kDevSwitchBootMode[] = "devsw_boot";
80 const char kHardwareClass[] = "hardware_class"; 70 const char kHardwareClass[] = "hardware_class";
81 const char kMachineInfoBoard[] =
82 "CHROMEOS_RELEASE_BOARD";
83 const char kOffersCouponCodeKey[] = "ubind_attribute"; 71 const char kOffersCouponCodeKey[] = "ubind_attribute";
84 const char kOffersGroupCodeKey[] = "gbind_attribute"; 72 const char kOffersGroupCodeKey[] = "gbind_attribute";
85 const char kOemCanExitEnterpriseEnrollmentKey[] = 73 const char kOemCanExitEnterpriseEnrollmentKey[] =
86 "oem_can_exit_enrollment"; 74 "oem_can_exit_enrollment";
87 const char kOemDeviceRequisitionKey[] = 75 const char kOemDeviceRequisitionKey[] =
88 "oem_device_requisition"; 76 "oem_device_requisition";
89 const char kOemIsEnterpriseManagedKey[] = 77 const char kOemIsEnterpriseManagedKey[] =
90 "oem_enterprise_managed"; 78 "oem_enterprise_managed";
91 const char kOemKeyboardDrivenOobeKey[] = 79 const char kOemKeyboardDrivenOobeKey[] =
92 "oem_keyboard_driven_oobe"; 80 "oem_keyboard_driven_oobe";
(...skipping 13 matching lines...) Expand all
106 static StatisticsProviderImpl* GetInstance(); 94 static StatisticsProviderImpl* GetInstance();
107 95
108 protected: 96 protected:
109 StatisticsProviderImpl(); 97 StatisticsProviderImpl();
110 void LoadOemManifestFromFile(const base::FilePath& file); 98 void LoadOemManifestFromFile(const base::FilePath& file);
111 99
112 private: 100 private:
113 typedef std::map<std::string, bool> MachineFlags; 101 typedef std::map<std::string, bool> MachineFlags;
114 friend struct DefaultSingletonTraits<StatisticsProviderImpl>; 102 friend struct DefaultSingletonTraits<StatisticsProviderImpl>;
115 103
116 // Loads the machine info file, which is necessary to get the Chrome channel.
117 // Treat MachineOSInfoFile specially, as distribution channel information
118 // (stable, beta, dev, canary) is required at earlier stage than everything
119 // else. Rather than posting a delayed task, read and parse the machine OS
120 // info file immediately.
121 void LoadMachineOSInfoFile();
122
123 // Loads the machine statistcs by examining the system. 104 // Loads the machine statistcs by examining the system.
124 void LoadMachineStatistics(); 105 void LoadMachineStatistics();
125 106
126 bool initialized_; 107 bool initialized_;
127 bool load_statistics_started_; 108 bool load_statistics_started_;
128 NameValuePairsParser::NameValueMap machine_info_; 109 NameValuePairsParser::NameValueMap machine_info_;
129 MachineFlags machine_flags_; 110 MachineFlags machine_flags_;
130 base::WaitableEvent on_statistics_loaded_; 111 base::WaitableEvent on_statistics_loaded_;
131 112
132 DISALLOW_COPY_AND_ASSIGN(StatisticsProviderImpl); 113 DISALLOW_COPY_AND_ASSIGN(StatisticsProviderImpl);
133 }; 114 };
134 115
135 void StatisticsProviderImpl::Init() { 116 void StatisticsProviderImpl::Init() {
136 DCHECK(!initialized_); 117 DCHECK(!initialized_);
137 initialized_ = true; 118 initialized_ = true;
138
139 // Load the machine info file immediately to get the channel info.
140 LoadMachineOSInfoFile();
141 } 119 }
142 120
143 bool StatisticsProviderImpl::GetMachineStatistic( 121 bool StatisticsProviderImpl::GetMachineStatistic(
144 const std::string& name, std::string* result) { 122 const std::string& name, std::string* result) {
145 DCHECK(initialized_); 123 DCHECK(initialized_);
146 DCHECK(load_statistics_started_); 124 DCHECK(load_statistics_started_);
147 125
148 VLOG(1) << "Statistic is requested for " << name; 126 VLOG(1) << "Statistic is requested for " << name;
149 // Block if the statistics are not loaded yet. Per LOG(WARNING) below, 127 // Block if the statistics are not loaded yet. Per LOG(WARNING) below,
150 // the statistics are loaded before requested as of now. For regular 128 // the statistics are loaded before requested as of now. For regular
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 172 }
195 173
196 // manual_reset needs to be true, as we want to keep the signaled state. 174 // manual_reset needs to be true, as we want to keep the signaled state.
197 StatisticsProviderImpl::StatisticsProviderImpl() 175 StatisticsProviderImpl::StatisticsProviderImpl()
198 : initialized_(false), 176 : initialized_(false),
199 load_statistics_started_(false), 177 load_statistics_started_(false),
200 on_statistics_loaded_(true /* manual_reset */, 178 on_statistics_loaded_(true /* manual_reset */,
201 false /* initially_signaled */) { 179 false /* initially_signaled */) {
202 } 180 }
203 181
204 void StatisticsProviderImpl::LoadMachineOSInfoFile() {
205 NameValuePairsParser parser(&machine_info_);
206 if (parser.GetNameValuePairsFromFile(base::FilePath(kMachineOSInfoFile),
207 kMachineOSInfoEq,
208 kMachineOSInfoDelim)) {
209 #if defined(GOOGLE_CHROME_BUILD)
210 const char kChromeOSReleaseTrack[] = "CHROMEOS_RELEASE_TRACK";
211 NameValuePairsParser::NameValueMap::iterator iter =
212 machine_info_.find(kChromeOSReleaseTrack);
213 if (iter != machine_info_.end())
214 chrome::VersionInfo::SetChannel(iter->second);
215 #endif
216 }
217 }
218
219 void StatisticsProviderImpl::StartLoadingMachineStatistics() { 182 void StatisticsProviderImpl::StartLoadingMachineStatistics() {
220 DCHECK(initialized_); 183 DCHECK(initialized_);
221 DCHECK(!load_statistics_started_); 184 DCHECK(!load_statistics_started_);
222 load_statistics_started_ = true; 185 load_statistics_started_ = true;
223 186
224 VLOG(1) << "Started loading statistics"; 187 VLOG(1) << "Started loading statistics";
225 BrowserThread::PostBlockingPoolTask( 188 BrowserThread::PostBlockingPoolTask(
226 FROM_HERE, 189 FROM_HERE,
227 base::Bind(&StatisticsProviderImpl::LoadMachineStatistics, 190 base::Bind(&StatisticsProviderImpl::LoadMachineStatistics,
228 base::Unretained(this))); 191 base::Unretained(this)));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 StatisticsProvider* StatisticsProvider::GetInstance() { 297 StatisticsProvider* StatisticsProvider::GetInstance() {
335 if (base::chromeos::IsRunningOnChromeOS()) { 298 if (base::chromeos::IsRunningOnChromeOS()) {
336 return StatisticsProviderImpl::GetInstance(); 299 return StatisticsProviderImpl::GetInstance();
337 } else { 300 } else {
338 return StatisticsProviderStubImpl::GetInstance(); 301 return StatisticsProviderStubImpl::GetInstance();
339 } 302 }
340 } 303 }
341 304
342 } // namespace system 305 } // namespace system
343 } // namespace chromeos 306 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/system/statistics_provider.h ('k') | chrome/browser/chromeos/system_logs/lsb_release_log_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698