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 <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
11 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" | 12 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" |
12 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident.h" | 13 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident.h" |
13 #include "chrome/common/safe_browsing/csd.pb.h" | 14 #include "chrome/common/safe_browsing/csd.pb.h" |
14 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" | 15 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" |
15 #include "components/user_prefs/tracked/tracked_preference_helper.h" | 16 #include "components/user_prefs/tracked/tracked_preference_helper.h" |
16 | 17 |
17 namespace safe_browsing { | 18 namespace safe_browsing { |
(...skipping 18 matching lines...) Expand all Loading... |
36 default: | 37 default: |
37 return TPIncident::UNKNOWN; | 38 return TPIncident::UNKNOWN; |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
41 } // namespace | 42 } // namespace |
42 | 43 |
43 PreferenceValidationDelegate::PreferenceValidationDelegate( | 44 PreferenceValidationDelegate::PreferenceValidationDelegate( |
44 Profile* profile, | 45 Profile* profile, |
45 scoped_ptr<IncidentReceiver> incident_receiver) | 46 scoped_ptr<IncidentReceiver> incident_receiver) |
46 : profile_(profile), | 47 : profile_(profile), incident_receiver_(std::move(incident_receiver)) {} |
47 incident_receiver_(incident_receiver.Pass()) { | |
48 } | |
49 | 48 |
50 PreferenceValidationDelegate::~PreferenceValidationDelegate() { | 49 PreferenceValidationDelegate::~PreferenceValidationDelegate() { |
51 } | 50 } |
52 | 51 |
53 void PreferenceValidationDelegate::OnAtomicPreferenceValidation( | 52 void PreferenceValidationDelegate::OnAtomicPreferenceValidation( |
54 const std::string& pref_path, | 53 const std::string& pref_path, |
55 const base::Value* value, | 54 const base::Value* value, |
56 PrefHashStoreTransaction::ValueState value_state, | 55 PrefHashStoreTransaction::ValueState value_state, |
57 bool is_personal) { | 56 bool is_personal) { |
58 TPIncident_ValueState proto_value_state = MapValueState(value_state); | 57 TPIncident_ValueState proto_value_state = MapValueState(value_state); |
59 if (proto_value_state != TPIncident::UNKNOWN) { | 58 if (proto_value_state != TPIncident::UNKNOWN) { |
60 scoped_ptr<TPIncident> incident( | 59 scoped_ptr<TPIncident> incident( |
61 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); | 60 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); |
62 incident->set_path(pref_path); | 61 incident->set_path(pref_path); |
63 if (!value || | 62 if (!value || |
64 (!value->GetAsString(incident->mutable_atomic_value()) && | 63 (!value->GetAsString(incident->mutable_atomic_value()) && |
65 !base::JSONWriter::Write(*value, incident->mutable_atomic_value()))) { | 64 !base::JSONWriter::Write(*value, incident->mutable_atomic_value()))) { |
66 incident->clear_atomic_value(); | 65 incident->clear_atomic_value(); |
67 } | 66 } |
68 incident->set_value_state(proto_value_state); | 67 incident->set_value_state(proto_value_state); |
69 incident_receiver_->AddIncidentForProfile( | 68 incident_receiver_->AddIncidentForProfile( |
70 profile_, make_scoped_ptr(new TrackedPreferenceIncident(incident.Pass(), | 69 profile_, make_scoped_ptr(new TrackedPreferenceIncident( |
71 is_personal))); | 70 std::move(incident), is_personal))); |
72 } | 71 } |
73 } | 72 } |
74 | 73 |
75 void PreferenceValidationDelegate::OnSplitPreferenceValidation( | 74 void PreferenceValidationDelegate::OnSplitPreferenceValidation( |
76 const std::string& pref_path, | 75 const std::string& pref_path, |
77 const base::DictionaryValue* /* dict_value */, | 76 const base::DictionaryValue* /* dict_value */, |
78 const std::vector<std::string>& invalid_keys, | 77 const std::vector<std::string>& invalid_keys, |
79 PrefHashStoreTransaction::ValueState value_state, | 78 PrefHashStoreTransaction::ValueState value_state, |
80 bool is_personal) { | 79 bool is_personal) { |
81 TPIncident_ValueState proto_value_state = MapValueState(value_state); | 80 TPIncident_ValueState proto_value_state = MapValueState(value_state); |
82 if (proto_value_state != TPIncident::UNKNOWN) { | 81 if (proto_value_state != TPIncident::UNKNOWN) { |
83 scoped_ptr<ClientIncidentReport_IncidentData_TrackedPreferenceIncident> | 82 scoped_ptr<ClientIncidentReport_IncidentData_TrackedPreferenceIncident> |
84 incident( | 83 incident( |
85 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); | 84 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); |
86 incident->set_path(pref_path); | 85 incident->set_path(pref_path); |
87 for (std::vector<std::string>::const_iterator scan(invalid_keys.begin()); | 86 for (std::vector<std::string>::const_iterator scan(invalid_keys.begin()); |
88 scan != invalid_keys.end(); | 87 scan != invalid_keys.end(); |
89 ++scan) { | 88 ++scan) { |
90 incident->add_split_key(*scan); | 89 incident->add_split_key(*scan); |
91 } | 90 } |
92 incident->set_value_state(proto_value_state); | 91 incident->set_value_state(proto_value_state); |
93 incident_receiver_->AddIncidentForProfile( | 92 incident_receiver_->AddIncidentForProfile( |
94 profile_, make_scoped_ptr(new TrackedPreferenceIncident(incident.Pass(), | 93 profile_, make_scoped_ptr(new TrackedPreferenceIncident( |
95 is_personal))); | 94 std::move(incident), is_personal))); |
96 } | 95 } |
97 } | 96 } |
98 | 97 |
99 } // namespace safe_browsing | 98 } // namespace safe_browsing |
OLD | NEW |