Commit 2a95da4f authored by hshi@google.com's avatar hshi@google.com

Decouple loading of channel info and the rest of machine statistics.

Related CL: crrev.com/173507 - that CL calls StatisticsProvider::Init()
in PreEarlyInitialization stage to obtain channel info early. However
it also has a side-effect to load machine statistics early. After this CL
we start to observe that sometimes the crossystem tool hangs.

Ideally the tool hang should be root caused but it is timing sensitive
and also extremely rare.

The current CL makes StatisticsProvider::StartLoadingMachineStatistics()
a separate and explicit call, so that the crossystem tool can be invoked
later at PostBrowserStart stage. Hopefully by restoring the timing we
can eliminate the tool hang.

BUG=167671
TEST=CQ, manually verified that machine statistics is still available
under chrome://settings in the "bios_info" section.

Review URL: https://codereview.chromium.org/11778025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175434 0039d316-1c4b-4281-b951-d872f2087c98
parent dd0d2138
......@@ -625,6 +625,11 @@ void ChromeBrowserMainPartsChromeos::PreBrowserStart() {
}
void ChromeBrowserMainPartsChromeos::PostBrowserStart() {
// Start loading the machine statistics. Note: if we start loading machine
// statistics early in PreEarlyInitialization() then the crossystem tool
// sometimes hangs for unknown reasons, see http://crbug.com/167671.
system::StatisticsProvider::GetInstance()->StartLoadingMachineStatistics();
// These are dependent on the ash::Shell singleton already having been
// initialized.
power_button_observer_.reset(new PowerButtonObserver);
......
......@@ -18,6 +18,7 @@ class MockStatisticsProvider : public system::StatisticsProvider {
virtual ~MockStatisticsProvider();
MOCK_METHOD0(Init, void());
MOCK_METHOD0(StartLoadingMachineStatistics, void());
MOCK_METHOD2(GetMachineStatistic, bool(const std::string& name,
std::string* result));
......
......@@ -71,6 +71,7 @@ class StatisticsProviderImpl : public StatisticsProvider {
public:
// StatisticsProvider implementation:
virtual void Init() OVERRIDE;
virtual void StartLoadingMachineStatistics() OVERRIDE;
virtual bool GetMachineStatistic(const std::string& name,
std::string* result) OVERRIDE;
......@@ -88,13 +89,11 @@ class StatisticsProviderImpl : public StatisticsProvider {
// info file immediately.
void LoadMachineOSInfoFile();
// Starts loading the machine statistcs.
void StartLoadingMachineStatistics();
// Loads the machine statistcs by examining the system.
void LoadMachineStatistics();
bool initialized_;
bool load_statistics_started_;
NameValuePairsParser::NameValueMap machine_info_;
base::WaitableEvent on_statistics_loaded_;
......@@ -105,15 +104,14 @@ void StatisticsProviderImpl::Init() {
DCHECK(!initialized_);
initialized_ = true;
// Load the machine info file immediately to get the channel info and delay
// loading the remaining statistics.
// Load the machine info file immediately to get the channel info.
LoadMachineOSInfoFile();
StartLoadingMachineStatistics();
}
bool StatisticsProviderImpl::GetMachineStatistic(
const std::string& name, std::string* result) {
DCHECK(initialized_);
DCHECK(load_statistics_started_);
VLOG(1) << "Statistic is requested for " << name;
// Block if the statistics are not loaded yet. Per LOG(WARNING) below,
......@@ -151,6 +149,7 @@ bool StatisticsProviderImpl::GetMachineStatistic(
// manual_reset needs to be true, as we want to keep the signaled state.
StatisticsProviderImpl::StatisticsProviderImpl()
: initialized_(false),
load_statistics_started_(false),
on_statistics_loaded_(true /* manual_reset */,
false /* initially_signaled */) {
}
......@@ -171,6 +170,10 @@ void StatisticsProviderImpl::LoadMachineOSInfoFile() {
}
void StatisticsProviderImpl::StartLoadingMachineStatistics() {
DCHECK(initialized_);
DCHECK(!load_statistics_started_);
load_statistics_started_ = true;
VLOG(1) << "Started loading statistics";
BrowserThread::PostBlockingPoolTask(
FROM_HERE,
......@@ -219,8 +222,9 @@ StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() {
class StatisticsProviderStubImpl : public StatisticsProvider {
public:
// StatisticsProvider implementation:
virtual void Init() OVERRIDE {
}
virtual void Init() OVERRIDE {}
virtual void StartLoadingMachineStatistics() OVERRIDE {}
virtual bool GetMachineStatistic(const std::string& name,
std::string* result) OVERRIDE {
......
......@@ -16,6 +16,9 @@ class StatisticsProvider {
// Initializes the statistics provider.
virtual void Init() = 0;
// Starts loading the machine statistcs.
virtual void StartLoadingMachineStatistics() = 0;
// Retrieve the named machine statistic (e.g. "hardware_class").
// This does not update the statistcs. If the |name| is not set, |result|
// preserves old value.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment