cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / components / user_prefs / tracked / tracked_split_preference.cc
blob37bac10b760a01ebd011bb1283d813a7f8718eb5
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/user_prefs/tracked/tracked_split_preference.h"
7 #include <vector>
9 #include "base/logging.h"
10 #include "base/values.h"
11 #include "components/user_prefs/tracked/pref_hash_store_transaction.h"
12 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h"
14 TrackedSplitPreference::TrackedSplitPreference(
15 const std::string& pref_path,
16 size_t reporting_id,
17 size_t reporting_ids_count,
18 PrefHashFilter::EnforcementLevel enforcement_level,
19 PrefHashFilter::ValueType value_type,
20 TrackedPreferenceValidationDelegate* delegate)
21 : pref_path_(pref_path),
22 helper_(pref_path,
23 reporting_id,
24 reporting_ids_count,
25 enforcement_level,
26 value_type),
27 delegate_(delegate) {
30 void TrackedSplitPreference::OnNewValue(
31 const base::Value* value,
32 PrefHashStoreTransaction* transaction) const {
33 const base::DictionaryValue* dict_value = NULL;
34 if (value && !value->GetAsDictionary(&dict_value)) {
35 NOTREACHED();
36 return;
38 transaction->StoreSplitHash(pref_path_, dict_value);
41 bool TrackedSplitPreference::EnforceAndReport(
42 base::DictionaryValue* pref_store_contents,
43 PrefHashStoreTransaction* transaction) const {
44 base::DictionaryValue* dict_value = NULL;
45 if (!pref_store_contents->GetDictionary(pref_path_, &dict_value) &&
46 pref_store_contents->Get(pref_path_, NULL)) {
47 // There should be a dictionary or nothing at |pref_path_|.
48 NOTREACHED();
49 return false;
52 std::vector<std::string> invalid_keys;
53 PrefHashStoreTransaction::ValueState value_state =
54 transaction->CheckSplitValue(pref_path_, dict_value, &invalid_keys);
56 if (value_state == PrefHashStoreTransaction::CHANGED)
57 helper_.ReportSplitPreferenceChangedCount(invalid_keys.size());
59 helper_.ReportValidationResult(value_state);
61 TrackedPreferenceHelper::ResetAction reset_action =
62 helper_.GetAction(value_state);
63 if (delegate_) {
64 delegate_->OnSplitPreferenceValidation(pref_path_, dict_value, invalid_keys,
65 value_state, helper_.IsPersonal());
67 helper_.ReportAction(reset_action);
69 bool was_reset = false;
70 if (reset_action == TrackedPreferenceHelper::DO_RESET) {
71 if (value_state == PrefHashStoreTransaction::CHANGED) {
72 DCHECK(!invalid_keys.empty());
74 for (std::vector<std::string>::const_iterator it = invalid_keys.begin();
75 it != invalid_keys.end(); ++it) {
76 dict_value->Remove(*it, NULL);
78 } else {
79 pref_store_contents->RemovePath(pref_path_, NULL);
81 was_reset = true;
84 if (value_state != PrefHashStoreTransaction::UNCHANGED) {
85 // Store the hash for the new value (whether it was reset or not).
86 const base::DictionaryValue* new_dict_value = NULL;
87 pref_store_contents->GetDictionary(pref_path_, &new_dict_value);
88 transaction->StoreSplitHash(pref_path_, new_dict_value);
91 return was_reset;