Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/preference_validation_delegate.cc

Issue 2384213002: Send a TrackedPreference incident when registry pref validation fails. (Closed)
Patch Set: Address comments on patch set 4 Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/common/safe_browsing/csd.pb.h" 15 #include "chrome/common/safe_browsing/csd.pb.h"
16 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" 16 #include "components/user_prefs/tracked/pref_hash_store_transaction.h"
17 #include "components/user_prefs/tracked/tracked_preference_helper.h" 17 #include "components/user_prefs/tracked/tracked_preference_helper.h"
18 18
19 namespace safe_browsing { 19 namespace safe_browsing {
20 20
21 namespace { 21 namespace {
22 22
23 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident TPIncident; 23 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident TPIncident;
24 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState 24 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState
25 TPIncident_ValueState; 25 TPIncident_ValueState;
26 26
27 // Maps a PrefHashStoreTransaction::ValueState to a 27 // Maps a primary PrefHashStoreTransaction::ValueState and an external
28 // TrackedPreferenceIncident::ValueState. 28 // validation state to a TrackedPreferenceIncident::ValueState.
29 TPIncident_ValueState MapValueState( 29 TPIncident_ValueState MapValueState(
30 PrefHashStoreTransaction::ValueState value_state) { 30 PrefHashStoreTransaction::ValueState value_state,
31 PrefHashStoreTransaction::ValueState external_validation_value_state) {
31 switch (value_state) { 32 switch (value_state) {
32 case PrefHashStoreTransaction::CLEARED: 33 case PrefHashStoreTransaction::CLEARED:
33 return TPIncident::CLEARED; 34 return TPIncident::CLEARED;
34 case PrefHashStoreTransaction::CHANGED: 35 case PrefHashStoreTransaction::CHANGED:
35 return TPIncident::CHANGED; 36 return TPIncident::CHANGED;
36 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: 37 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE:
37 return TPIncident::UNTRUSTED_UNKNOWN_VALUE; 38 return TPIncident::UNTRUSTED_UNKNOWN_VALUE;
38 default: 39 default:
39 return TPIncident::UNKNOWN; 40 switch (external_validation_value_state) {
41 case PrefHashStoreTransaction::CLEARED:
42 return TPIncident::BYPASS_CLEARED;
43 case PrefHashStoreTransaction::CHANGED:
44 return TPIncident::BYPASS_CHANGED;
45 default:
46 return TPIncident::UNKNOWN;
47 }
40 } 48 }
41 } 49 }
42 50
43 } // namespace 51 } // namespace
44 52
45 PreferenceValidationDelegate::PreferenceValidationDelegate( 53 PreferenceValidationDelegate::PreferenceValidationDelegate(
46 Profile* profile, 54 Profile* profile,
47 std::unique_ptr<IncidentReceiver> incident_receiver) 55 std::unique_ptr<IncidentReceiver> incident_receiver)
48 : profile_(profile), incident_receiver_(std::move(incident_receiver)) {} 56 : profile_(profile), incident_receiver_(std::move(incident_receiver)) {}
49 57
50 PreferenceValidationDelegate::~PreferenceValidationDelegate() { 58 PreferenceValidationDelegate::~PreferenceValidationDelegate() {
51 } 59 }
52 60
53 void PreferenceValidationDelegate::OnAtomicPreferenceValidation( 61 void PreferenceValidationDelegate::OnAtomicPreferenceValidation(
54 const std::string& pref_path, 62 const std::string& pref_path,
55 const base::Value* value, 63 const base::Value* value,
56 PrefHashStoreTransaction::ValueState value_state, 64 PrefHashStoreTransaction::ValueState value_state,
65 PrefHashStoreTransaction::ValueState external_validation_value_state,
57 bool is_personal) { 66 bool is_personal) {
58 TPIncident_ValueState proto_value_state = MapValueState(value_state); 67 TPIncident_ValueState proto_value_state =
68 MapValueState(value_state, external_validation_value_state);
59 if (proto_value_state != TPIncident::UNKNOWN) { 69 if (proto_value_state != TPIncident::UNKNOWN) {
60 std::unique_ptr<TPIncident> incident( 70 std::unique_ptr<TPIncident> incident(
61 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); 71 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident());
62 incident->set_path(pref_path); 72 incident->set_path(pref_path);
63 if (!value || 73 if (!value ||
64 (!value->GetAsString(incident->mutable_atomic_value()) && 74 (!value->GetAsString(incident->mutable_atomic_value()) &&
65 !base::JSONWriter::Write(*value, incident->mutable_atomic_value()))) { 75 !base::JSONWriter::Write(*value, incident->mutable_atomic_value()))) {
66 incident->clear_atomic_value(); 76 incident->clear_atomic_value();
67 } 77 }
68 incident->set_value_state(proto_value_state); 78 incident->set_value_state(proto_value_state);
69 incident_receiver_->AddIncidentForProfile( 79 incident_receiver_->AddIncidentForProfile(
70 profile_, base::MakeUnique<TrackedPreferenceIncident>( 80 profile_, base::MakeUnique<TrackedPreferenceIncident>(
71 std::move(incident), is_personal)); 81 std::move(incident), is_personal));
72 } 82 }
73 } 83 }
74 84
75 void PreferenceValidationDelegate::OnSplitPreferenceValidation( 85 void PreferenceValidationDelegate::OnSplitPreferenceValidation(
76 const std::string& pref_path, 86 const std::string& pref_path,
77 const base::DictionaryValue* /* dict_value */, 87 const base::DictionaryValue* /* dict_value */,
78 const std::vector<std::string>& invalid_keys, 88 const std::vector<std::string>& invalid_keys,
89 const std::vector<std::string>& external_validation_invalid_keys,
79 PrefHashStoreTransaction::ValueState value_state, 90 PrefHashStoreTransaction::ValueState value_state,
91 PrefHashStoreTransaction::ValueState external_validation_value_state,
80 bool is_personal) { 92 bool is_personal) {
81 TPIncident_ValueState proto_value_state = MapValueState(value_state); 93 TPIncident_ValueState proto_value_state =
94 MapValueState(value_state, external_validation_value_state);
82 if (proto_value_state != TPIncident::UNKNOWN) { 95 if (proto_value_state != TPIncident::UNKNOWN) {
83 std::unique_ptr<ClientIncidentReport_IncidentData_TrackedPreferenceIncident> 96 std::unique_ptr<ClientIncidentReport_IncidentData_TrackedPreferenceIncident>
84 incident( 97 incident(
85 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); 98 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident());
86 incident->set_path(pref_path); 99 incident->set_path(pref_path);
87 for (std::vector<std::string>::const_iterator scan(invalid_keys.begin()); 100 if (proto_value_state == TPIncident::BYPASS_CLEARED ||
88 scan != invalid_keys.end(); 101 proto_value_state == TPIncident::BYPASS_CHANGED) {
89 ++scan) { 102 for (std::vector<std::string>::const_iterator scan(
90 incident->add_split_key(*scan); 103 external_validation_invalid_keys.begin());
104 scan != external_validation_invalid_keys.end(); ++scan) {
105 incident->add_split_key(*scan);
106 }
107 } else {
108 for (std::vector<std::string>::const_iterator scan(invalid_keys.begin());
109 scan != invalid_keys.end(); ++scan) {
110 incident->add_split_key(*scan);
111 }
91 } 112 }
92 incident->set_value_state(proto_value_state); 113 incident->set_value_state(proto_value_state);
93 incident_receiver_->AddIncidentForProfile( 114 incident_receiver_->AddIncidentForProfile(
94 profile_, base::MakeUnique<TrackedPreferenceIncident>( 115 profile_, base::MakeUnique<TrackedPreferenceIncident>(
95 std::move(incident), is_personal)); 116 std::move(incident), is_personal));
96 } 117 }
97 } 118 }
98 119
99 } // namespace safe_browsing 120 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698