Commit 4f3a803c authored by bauerb's avatar bauerb Committed by Commit bot

Reland "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).

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

This reverts commit 3490af83.

TBR=treib@chromium.org
BUG=463646

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

Cr-Commit-Position: refs/heads/master@{#322105}
parent 3b26c1d2
...@@ -50,7 +50,10 @@ bool SettingShouldApplyToPrefs(const std::string& name) { ...@@ -50,7 +50,10 @@ bool SettingShouldApplyToPrefs(const std::string& name) {
} // namespace } // namespace
SupervisedUserSettingsService::SupervisedUserSettingsService() SupervisedUserSettingsService::SupervisedUserSettingsService()
: active_(false), local_settings_(new base::DictionaryValue) {} : active_(false),
initialization_failed_(false),
local_settings_(new base::DictionaryValue) {
}
SupervisedUserSettingsService::~SupervisedUserSettingsService() {} SupervisedUserSettingsService::~SupervisedUserSettingsService() {}
...@@ -97,7 +100,9 @@ void SupervisedUserSettingsService::SetActive(bool active) { ...@@ -97,7 +100,9 @@ void SupervisedUserSettingsService::SetActive(bool active) {
} }
bool SupervisedUserSettingsService::IsReady() { 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() { void SupervisedUserSettingsService::Clear() {
...@@ -299,9 +304,16 @@ void SupervisedUserSettingsService::OnPrefValueChanged(const std::string& key) { ...@@ -299,9 +304,16 @@ void SupervisedUserSettingsService::OnPrefValueChanged(const std::string& key) {
} }
void SupervisedUserSettingsService::OnInitializationCompleted(bool success) { 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. // TODO(bauerb): Temporary CHECK while investigating https://crbug.com/425785.
// Remove (or change back to DCHECK) once the bug is fixed. // Remove (or change back to DCHECK) once the bug is fixed.
CHECK(success);
CHECK(IsReady()); CHECK(IsReady());
InformSubscribers(); InformSubscribers();
} }
...@@ -354,7 +366,7 @@ base::DictionaryValue* SupervisedUserSettingsService::GetDictionaryAndSplitKey( ...@@ -354,7 +366,7 @@ base::DictionaryValue* SupervisedUserSettingsService::GetDictionaryAndSplitKey(
scoped_ptr<base::DictionaryValue> SupervisedUserSettingsService::GetSettings() { scoped_ptr<base::DictionaryValue> SupervisedUserSettingsService::GetSettings() {
DCHECK(IsReady()); DCHECK(IsReady());
if (!active_) if (!active_ || initialization_failed_)
return scoped_ptr<base::DictionaryValue>(); return scoped_ptr<base::DictionaryValue>();
scoped_ptr<base::DictionaryValue> settings(local_settings_->DeepCopy()); scoped_ptr<base::DictionaryValue> settings(local_settings_->DeepCopy());
......
...@@ -152,6 +152,8 @@ class SupervisedUserSettingsService : public KeyedService, ...@@ -152,6 +152,8 @@ class SupervisedUserSettingsService : public KeyedService,
bool active_; bool active_;
bool initialization_failed_;
// A set of local settings that are fixed and not configured remotely. // A set of local settings that are fixed and not configured remotely.
scoped_ptr<base::DictionaryValue> local_settings_; 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