X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fchrome%2Fbrowser%2Fprefs%2Fpref_hash_filter.cc;h=4ba42e3d8855b934a0b883e09d2aef371eb089eb;hb=004985e17e624662a4c85c76a7654039dc83f028;hp=381fbace615328531738d57fd6b13025bba6487c;hpb=2f108dbacb161091e42a3479f4e171339b7e7623;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/chrome/browser/prefs/pref_hash_filter.cc b/src/chrome/browser/prefs/pref_hash_filter.cc index 381fbac..4ba42e3 100644 --- a/src/chrome/browser/prefs/pref_hash_filter.cc +++ b/src/chrome/browser/prefs/pref_hash_filter.cc @@ -8,7 +8,6 @@ #include "base/logging.h" #include "base/metrics/histogram.h" -#include "base/prefs/persistent_pref_store.h" #include "base/prefs/pref_service.h" #include "base/prefs/pref_store.h" #include "base/strings/string_number_conversions.h" @@ -92,42 +91,6 @@ void PrefHashFilter::ClearResetTime(PrefService* user_prefs) { user_prefs->ClearPref(prefs::kPreferenceResetTime); } -void PrefHashFilter::MigrateValues(PersistentPrefStore* source, - PersistentPrefStore* destination) { - scoped_ptr transaction = - pref_hash_store_->BeginTransaction(); - for (TrackedPreferencesMap::const_iterator it = tracked_paths_.begin(); - it != tracked_paths_.end(); - ++it) { - const base::Value* source_value = NULL; - if (source->GetValue(it->first, &source_value) && - !destination->GetValue(it->first, NULL)) { - base::DictionaryValue temp_dictionary; - // Copy the value from |source| into a suitable place for a - // TrackedPreference to act on it. - temp_dictionary.Set(it->first, source_value->DeepCopy()); - // Check whether the value is correct according to our MAC. May remove the - // value from |temp_dictionary|. - it->second->EnforceAndReport(&temp_dictionary, transaction.get()); - // Now take the value as it appears in |temp_dictionary| and put it in - // |destination|. - scoped_ptr checked_value; - if (temp_dictionary.Remove(it->first, &checked_value)) - destination->SetValue(it->first, checked_value.release()); - } - source->RemoveValue(it->first); - } - - // Order these such that a crash at any point is still recoverable. We assume - // that they are configured such that the writes will occur on worker threads - // in the order that we asked for them. - destination->CommitPendingWrite(); - transaction.reset(); - // If we crash here, we will just delete the values from |source| in a future - // invocation of MigrateValues. - source->CommitPendingWrite(); -} - void PrefHashFilter::Initialize(const PrefStore& pref_store) { scoped_ptr hash_store_transaction( pref_hash_store_->BeginTransaction()); @@ -141,38 +104,6 @@ void PrefHashFilter::Initialize(const PrefStore& pref_store) { } } -// Validates loaded preference values according to stored hashes, reports -// validation results via UMA, and updates hashes in case of mismatch. -void PrefHashFilter::FilterOnLoad(base::DictionaryValue* pref_store_contents) { - DCHECK(pref_store_contents); - base::TimeTicks checkpoint = base::TimeTicks::Now(); - - bool did_reset = false; - { - scoped_ptr hash_store_transaction( - pref_hash_store_->BeginTransaction()); - for (TrackedPreferencesMap::const_iterator it = tracked_paths_.begin(); - it != tracked_paths_.end(); ++it) { - if (it->second->EnforceAndReport(pref_store_contents, - hash_store_transaction.get())) { - did_reset = true; - } - } - } - - if (did_reset) { - pref_store_contents->Set(prefs::kPreferenceResetTime, - new base::StringValue(base::Int64ToString( - base::Time::Now().ToInternalValue()))); - } - - // TODO(gab): Remove this histogram by Feb 21 2014; after sufficient timing - // data has been gathered from the wild to be confident this doesn't - // significantly affect startup. - UMA_HISTOGRAM_TIMES("Settings.FilterOnLoadTime", - base::TimeTicks::Now() - checkpoint); -} - // Marks |path| has having changed if it is part of |tracked_paths_|. A new hash // will be stored for it the next time FilterSerializeData() is invoked. void PrefHashFilter::FilterUpdate(const std::string& path) { @@ -207,4 +138,55 @@ void PrefHashFilter::FilterSerializeData( UMA_HISTOGRAM_TIMES("Settings.FilterSerializeDataTime", base::TimeTicks::Now() - checkpoint); } + + // Flush the |pref_hash_store_| to disk if it has pending writes. This is done + // here in an effort to flush the hash store to disk as close as possible to + // its matching value store (currently being flushed) to reduce the likelihood + // of MAC corruption in race condition scenarios where a crash occurs in the + // 10 seconds window where it would typically be possible that only one + // of the two stores has been flushed to disk (this now explicitly makes this + // race window as small as possible). + // Note that, if the |pref_hash_store_| has pending writes, this call will + // force serialization of its store to disk. As FilterSerializeData is already + // intercepting the serialization of its value store this would result in an + // infinite loop should the hash store also be the value store -- thus this + // should be removed when we move to such a model (where it will no longer be + // necessary anyways). + pref_hash_store_->CommitPendingWrite(); +} + +void PrefHashFilter::FinalizeFilterOnLoad( + const PostFilterOnLoadCallback& post_filter_on_load_callback, + scoped_ptr pref_store_contents, + bool prefs_altered) { + DCHECK(pref_store_contents); + base::TimeTicks checkpoint = base::TimeTicks::Now(); + + bool did_reset = false; + { + scoped_ptr hash_store_transaction( + pref_hash_store_->BeginTransaction()); + for (TrackedPreferencesMap::const_iterator it = tracked_paths_.begin(); + it != tracked_paths_.end(); ++it) { + if (it->second->EnforceAndReport(pref_store_contents.get(), + hash_store_transaction.get())) { + did_reset = true; + prefs_altered = true; + } + } + } + + if (did_reset) { + pref_store_contents->Set(prefs::kPreferenceResetTime, + new base::StringValue(base::Int64ToString( + base::Time::Now().ToInternalValue()))); + } + + // TODO(gab): Remove this histogram by Feb 21 2014; after sufficient timing + // data has been gathered from the wild to be confident this doesn't + // significantly affect startup. + UMA_HISTOGRAM_TIMES("Settings.FilterOnLoadTime", + base::TimeTicks::Now() - checkpoint); + + post_filter_on_load_callback.Run(pref_store_contents.Pass(), prefs_altered); }