Commit 0197d5df authored by bauerb's avatar bauerb Committed by Commit bot

Handle unsucessful JsonPrefStore initialization in SupervisedUserSettingsService.

According to crash reports, it's not very common but still possible for the JsonPrefStore used by SupervisedUserSettingsService to fail initialization (which happens if the profile directory doesn't exist).

BUG=425785

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

Cr-Commit-Position: refs/heads/master@{#318460}
parent e37b8be6
......@@ -50,7 +50,10 @@ bool SettingShouldApplyToPrefs(const std::string& name) {
} // namespace
SupervisedUserSettingsService::SupervisedUserSettingsService()
: active_(false), local_settings_(new base::DictionaryValue) {}
: active_(false),
initialization_failed_(false),
local_settings_(new base::DictionaryValue) {
}
SupervisedUserSettingsService::~SupervisedUserSettingsService() {}
......@@ -97,7 +100,9 @@ void SupervisedUserSettingsService::SetActive(bool active) {
}
bool SupervisedUserSettingsService::IsReady() {
return store_->IsInitializationComplete();
// Initialization cannot be complete but have failed at the same time.
DCHECK(!(store_->IsInitializationComplete() && initialization_failed_));
return initialization_failed_ || store_->IsInitializationComplete();
}
void SupervisedUserSettingsService::Clear() {
......@@ -299,9 +304,16 @@ void SupervisedUserSettingsService::OnPrefValueChanged(const std::string& key) {
}
void SupervisedUserSettingsService::OnInitializationCompleted(bool success) {
if (!success) {
// If this happens, it means the profile directory was not found. There is
// not much we can do, but the whole profile will probably be useless
// anyway. Just mark initialization as failed and continue otherwise,
// because subscribers might still expect to be called back.
initialization_failed_ = true;
}
// TODO(bauerb): Temporary CHECK while investigating https://crbug.com/425785.
// Remove (or change back to DCHECK) once the bug is fixed.
CHECK(success);
CHECK(IsReady());
InformSubscribers();
}
......@@ -354,7 +366,7 @@ base::DictionaryValue* SupervisedUserSettingsService::GetDictionaryAndSplitKey(
scoped_ptr<base::DictionaryValue> SupervisedUserSettingsService::GetSettings() {
DCHECK(IsReady());
if (!active_)
if (!active_ || initialization_failed_)
return scoped_ptr<base::DictionaryValue>();
scoped_ptr<base::DictionaryValue> settings(local_settings_->DeepCopy());
......
......@@ -152,6 +152,8 @@ class SupervisedUserSettingsService : public KeyedService,
bool active_;
bool initialization_failed_;
// A set of local settings that are fixed and not configured remotely.
scoped_ptr<base::DictionaryValue> local_settings_;
......
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