OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_
delegate.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/preference_validation_
delegate.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" | 13 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" |
14 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident.h" | 14 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident.h" |
15 #include "components/safe_browsing/csd.pb.h" | 15 #include "components/safe_browsing/csd.pb.h" |
16 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" | 16 #include "services/preferences/public/interfaces/tracked_preference_validation_d
elegate.mojom.h" |
17 #include "components/user_prefs/tracked/tracked_preference_helper.h" | |
18 | 17 |
19 namespace safe_browsing { | 18 namespace safe_browsing { |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident TPIncident; | 22 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident TPIncident; |
24 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState | 23 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState |
25 TPIncident_ValueState; | 24 TPIncident_ValueState; |
26 | 25 |
| 26 using ValueState = |
| 27 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState; |
| 28 |
27 // Maps a primary PrefHashStoreTransaction::ValueState and an external | 29 // Maps a primary PrefHashStoreTransaction::ValueState and an external |
28 // validation state to a TrackedPreferenceIncident::ValueState. | 30 // validation state to a TrackedPreferenceIncident::ValueState. |
29 TPIncident_ValueState MapValueState( | 31 TPIncident_ValueState MapValueState( |
30 PrefHashStoreTransaction::ValueState value_state, | 32 ValueState value_state, |
31 PrefHashStoreTransaction::ValueState external_validation_value_state) { | 33 ValueState external_validation_value_state) { |
32 switch (value_state) { | 34 switch (value_state) { |
33 case PrefHashStoreTransaction::CLEARED: | 35 case ValueState::CLEARED: |
34 return TPIncident::CLEARED; | 36 return TPIncident::CLEARED; |
35 case PrefHashStoreTransaction::CHANGED: | 37 case ValueState::CHANGED: |
36 return TPIncident::CHANGED; | 38 return TPIncident::CHANGED; |
37 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: | 39 case ValueState::UNTRUSTED_UNKNOWN_VALUE: |
38 return TPIncident::UNTRUSTED_UNKNOWN_VALUE; | 40 return TPIncident::UNTRUSTED_UNKNOWN_VALUE; |
39 default: | 41 default: |
40 switch (external_validation_value_state) { | 42 switch (external_validation_value_state) { |
41 case PrefHashStoreTransaction::CLEARED: | 43 case ValueState::CLEARED: |
42 return TPIncident::BYPASS_CLEARED; | 44 return TPIncident::BYPASS_CLEARED; |
43 case PrefHashStoreTransaction::CHANGED: | 45 case ValueState::CHANGED: |
44 return TPIncident::BYPASS_CHANGED; | 46 return TPIncident::BYPASS_CHANGED; |
45 default: | 47 default: |
46 return TPIncident::UNKNOWN; | 48 return TPIncident::UNKNOWN; |
47 } | 49 } |
48 } | 50 } |
49 } | 51 } |
50 | 52 |
51 } // namespace | 53 } // namespace |
52 | 54 |
53 PreferenceValidationDelegate::PreferenceValidationDelegate( | 55 PreferenceValidationDelegate::PreferenceValidationDelegate( |
54 Profile* profile, | 56 Profile* profile, |
55 std::unique_ptr<IncidentReceiver> incident_receiver) | 57 std::unique_ptr<IncidentReceiver> incident_receiver) |
56 : profile_(profile), incident_receiver_(std::move(incident_receiver)) {} | 58 : profile_(profile), incident_receiver_(std::move(incident_receiver)) {} |
57 | 59 |
58 PreferenceValidationDelegate::~PreferenceValidationDelegate() { | 60 PreferenceValidationDelegate::~PreferenceValidationDelegate() { |
59 } | 61 } |
60 | 62 |
61 void PreferenceValidationDelegate::OnAtomicPreferenceValidation( | 63 void PreferenceValidationDelegate::OnAtomicPreferenceValidation( |
62 const std::string& pref_path, | 64 const std::string& pref_path, |
63 std::unique_ptr<base::Value> value, | 65 std::unique_ptr<base::Value> value, |
64 PrefHashStoreTransaction::ValueState value_state, | 66 ValueState value_state, |
65 PrefHashStoreTransaction::ValueState external_validation_value_state, | 67 ValueState external_validation_value_state, |
66 bool is_personal) { | 68 bool is_personal) { |
67 TPIncident_ValueState proto_value_state = | 69 TPIncident_ValueState proto_value_state = |
68 MapValueState(value_state, external_validation_value_state); | 70 MapValueState(value_state, external_validation_value_state); |
69 if (proto_value_state != TPIncident::UNKNOWN) { | 71 if (proto_value_state != TPIncident::UNKNOWN) { |
70 std::unique_ptr<TPIncident> incident( | 72 std::unique_ptr<TPIncident> incident( |
71 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); | 73 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); |
72 incident->set_path(pref_path); | 74 incident->set_path(pref_path); |
73 if (!value || | 75 if (!value || |
74 (!value->GetAsString(incident->mutable_atomic_value()) && | 76 (!value->GetAsString(incident->mutable_atomic_value()) && |
75 !base::JSONWriter::Write(*value, incident->mutable_atomic_value()))) { | 77 !base::JSONWriter::Write(*value, incident->mutable_atomic_value()))) { |
76 incident->clear_atomic_value(); | 78 incident->clear_atomic_value(); |
77 } | 79 } |
78 incident->set_value_state(proto_value_state); | 80 incident->set_value_state(proto_value_state); |
79 incident_receiver_->AddIncidentForProfile( | 81 incident_receiver_->AddIncidentForProfile( |
80 profile_, base::MakeUnique<TrackedPreferenceIncident>( | 82 profile_, base::MakeUnique<TrackedPreferenceIncident>( |
81 std::move(incident), is_personal)); | 83 std::move(incident), is_personal)); |
82 } | 84 } |
83 } | 85 } |
84 | 86 |
85 void PreferenceValidationDelegate::OnSplitPreferenceValidation( | 87 void PreferenceValidationDelegate::OnSplitPreferenceValidation( |
86 const std::string& pref_path, | 88 const std::string& pref_path, |
87 const std::vector<std::string>& invalid_keys, | 89 const std::vector<std::string>& invalid_keys, |
88 const std::vector<std::string>& external_validation_invalid_keys, | 90 const std::vector<std::string>& external_validation_invalid_keys, |
89 PrefHashStoreTransaction::ValueState value_state, | 91 ValueState value_state, |
90 PrefHashStoreTransaction::ValueState external_validation_value_state, | 92 ValueState external_validation_value_state, |
91 bool is_personal) { | 93 bool is_personal) { |
92 TPIncident_ValueState proto_value_state = | 94 TPIncident_ValueState proto_value_state = |
93 MapValueState(value_state, external_validation_value_state); | 95 MapValueState(value_state, external_validation_value_state); |
94 if (proto_value_state != TPIncident::UNKNOWN) { | 96 if (proto_value_state != TPIncident::UNKNOWN) { |
95 std::unique_ptr<ClientIncidentReport_IncidentData_TrackedPreferenceIncident> | 97 std::unique_ptr<ClientIncidentReport_IncidentData_TrackedPreferenceIncident> |
96 incident( | 98 incident( |
97 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); | 99 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); |
98 incident->set_path(pref_path); | 100 incident->set_path(pref_path); |
99 if (proto_value_state == TPIncident::BYPASS_CLEARED || | 101 if (proto_value_state == TPIncident::BYPASS_CLEARED || |
100 proto_value_state == TPIncident::BYPASS_CHANGED) { | 102 proto_value_state == TPIncident::BYPASS_CHANGED) { |
101 for (std::vector<std::string>::const_iterator scan( | 103 for (std::vector<std::string>::const_iterator scan( |
102 external_validation_invalid_keys.begin()); | 104 external_validation_invalid_keys.begin()); |
103 scan != external_validation_invalid_keys.end(); ++scan) { | 105 scan != external_validation_invalid_keys.end(); ++scan) { |
104 incident->add_split_key(*scan); | 106 incident->add_split_key(*scan); |
105 } | 107 } |
106 } else { | 108 } else { |
107 for (std::vector<std::string>::const_iterator scan(invalid_keys.begin()); | 109 for (std::vector<std::string>::const_iterator scan(invalid_keys.begin()); |
108 scan != invalid_keys.end(); ++scan) { | 110 scan != invalid_keys.end(); ++scan) { |
109 incident->add_split_key(*scan); | 111 incident->add_split_key(*scan); |
110 } | 112 } |
111 } | 113 } |
112 incident->set_value_state(proto_value_state); | 114 incident->set_value_state(proto_value_state); |
113 incident_receiver_->AddIncidentForProfile( | 115 incident_receiver_->AddIncidentForProfile( |
114 profile_, base::MakeUnique<TrackedPreferenceIncident>( | 116 profile_, base::MakeUnique<TrackedPreferenceIncident>( |
115 std::move(incident), is_personal)); | 117 std::move(incident), is_personal)); |
116 } | 118 } |
117 } | 119 } |
118 | 120 |
119 } // namespace safe_browsing | 121 } // namespace safe_browsing |
OLD | NEW |