Chromium Code Reviews| Index: base/prefs/json_pref_store.cc |
| diff --git a/base/prefs/json_pref_store.cc b/base/prefs/json_pref_store.cc |
| index 8ce59745536d02fe4af6279a3d85312966a34937..4f7f3472001ea1cd5ccfcb3b3dedba3d0546c154 100644 |
| --- a/base/prefs/json_pref_store.cc |
| +++ b/base/prefs/json_pref_store.cc |
| @@ -158,6 +158,7 @@ JsonPrefStore::JsonPrefStore( |
| pref_filter_(pref_filter.Pass()), |
| initialized_(false), |
| filtering_in_progress_(false), |
| + pending_lossy_write_(false), |
| read_error_(PREF_READ_ERROR_NONE), |
| write_count_histogram_(writer_.commit_interval(), path_) { |
| DCHECK(!path_.empty()); |
| @@ -252,8 +253,7 @@ void JsonPrefStore::SetValueSilently(const std::string& key, |
| prefs_->Get(key, &old_value); |
| if (!old_value || !value->Equals(old_value)) { |
| prefs_->Set(key, new_value.release()); |
| - if (!read_only_) |
| - writer_.ScheduleWrite(this); |
| + ScheduleWrite(flags); |
| } |
| } |
| @@ -268,8 +268,7 @@ void JsonPrefStore::RemoveValueSilently(const std::string& key, uint32 flags) { |
| DCHECK(CalledOnValidThread()); |
| prefs_->RemovePath(key, NULL); |
| - if (!read_only_) |
| - writer_.ScheduleWrite(this); |
| + ScheduleWrite(flags); |
| } |
| bool JsonPrefStore::ReadOnly() const { |
| @@ -309,6 +308,11 @@ void JsonPrefStore::ReadPrefsAsync(ReadErrorDelegate* error_delegate) { |
| void JsonPrefStore::CommitPendingWrite() { |
| DCHECK(CalledOnValidThread()); |
| + // Schedule a write for any lossy writes that are outstanding to ensure that |
| + // they get flushed when this function is called. |
| + if (pending_lossy_write_) |
| + writer_.ScheduleWrite(this); |
| + |
| if (writer_.HasPendingWrite() && !read_only_) |
| writer_.DoScheduledWrite(); |
| } |
| @@ -321,8 +325,7 @@ void JsonPrefStore::ReportValueChanged(const std::string& key, uint32 flags) { |
| FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key)); |
| - if (!read_only_) |
| - writer_.ScheduleWrite(this); |
| + ScheduleWrite(flags); |
| } |
| void JsonPrefStore::RegisterOnNextSuccessfulWriteCallback( |
| @@ -401,6 +404,8 @@ JsonPrefStore::~JsonPrefStore() { |
| bool JsonPrefStore::SerializeData(std::string* output) { |
| DCHECK(CalledOnValidThread()); |
| + pending_lossy_write_ = false; |
| + |
| write_count_histogram_.RecordWriteOccured(); |
| if (pref_filter_) |
| @@ -432,8 +437,8 @@ void JsonPrefStore::FinalizeFileRead(bool initialization_successful, |
| initialized_ = true; |
| - if (schedule_write && !read_only_) |
| - writer_.ScheduleWrite(this); |
| + if (schedule_write) |
| + ScheduleWrite(DEFAULT_PREF_WRITE_FLAGS); |
| if (error_delegate_ && read_error_ != PREF_READ_ERROR_NONE) |
| error_delegate_->OnError(read_error_); |
| @@ -445,6 +450,17 @@ void JsonPrefStore::FinalizeFileRead(bool initialization_successful, |
| return; |
| } |
| +void JsonPrefStore::ScheduleWrite(uint32 flags) { |
| + if (read_only_) |
| + return; |
| + |
| + if (flags & LOSSY_PREF_WRITE_FLAG) { |
|
Mattias Nissler (ping if slow)
2015/05/06 07:26:04
This file doesn't use braces for single-line condi
raymes
2015/05/07 05:45:41
Done.
|
| + pending_lossy_write_ = true; |
| + } else { |
| + writer_.ScheduleWrite(this); |
| + } |
| +} |
| + |
| // NOTE: This value should NOT be changed without renaming the histogram |
| // otherwise it will create incompatible buckets. |
| const int32_t |