| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "chrome/browser/prefs/tracked/pref_hash_store_transaction.h" | 12 #include "chrome/browser/prefs/tracked/pref_hash_store_transaction.h" |
| 13 #include "chrome/browser/prefs/tracked/tracked_preference_helper.h" | 13 #include "chrome/browser/prefs/tracked/tracked_preference_helper.h" |
| 14 #include "chrome/browser/safe_browsing/incident_reporting/tracked_preference_inc
ident.h" |
| 14 #include "chrome/common/safe_browsing/csd.pb.h" | 15 #include "chrome/common/safe_browsing/csd.pb.h" |
| 15 | 16 |
| 16 namespace safe_browsing { | 17 namespace safe_browsing { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident TPIncident; | 21 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident TPIncident; |
| 21 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState | 22 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState |
| 22 TPIncident_ValueState; | 23 TPIncident_ValueState; |
| 23 | 24 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 47 PreferenceValidationDelegate::~PreferenceValidationDelegate() { | 48 PreferenceValidationDelegate::~PreferenceValidationDelegate() { |
| 48 } | 49 } |
| 49 | 50 |
| 50 void PreferenceValidationDelegate::OnAtomicPreferenceValidation( | 51 void PreferenceValidationDelegate::OnAtomicPreferenceValidation( |
| 51 const std::string& pref_path, | 52 const std::string& pref_path, |
| 52 const base::Value* value, | 53 const base::Value* value, |
| 53 PrefHashStoreTransaction::ValueState value_state, | 54 PrefHashStoreTransaction::ValueState value_state, |
| 54 TrackedPreferenceHelper::ResetAction /* reset_action */) { | 55 TrackedPreferenceHelper::ResetAction /* reset_action */) { |
| 55 TPIncident_ValueState proto_value_state = MapValueState(value_state); | 56 TPIncident_ValueState proto_value_state = MapValueState(value_state); |
| 56 if (proto_value_state != TPIncident::UNKNOWN) { | 57 if (proto_value_state != TPIncident::UNKNOWN) { |
| 57 scoped_ptr<ClientIncidentReport_IncidentData> incident_data( | 58 scoped_ptr<TPIncident> incident( |
| 58 new ClientIncidentReport_IncidentData()); | 59 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); |
| 59 TPIncident* incident = incident_data->mutable_tracked_preference(); | |
| 60 incident->set_path(pref_path); | 60 incident->set_path(pref_path); |
| 61 if (!value || | 61 if (!value || |
| 62 (!value->GetAsString(incident->mutable_atomic_value()) && | 62 (!value->GetAsString(incident->mutable_atomic_value()) && |
| 63 !base::JSONWriter::Write(value, incident->mutable_atomic_value()))) { | 63 !base::JSONWriter::Write(value, incident->mutable_atomic_value()))) { |
| 64 incident->clear_atomic_value(); | 64 incident->clear_atomic_value(); |
| 65 } | 65 } |
| 66 incident->set_value_state(proto_value_state); | 66 incident->set_value_state(proto_value_state); |
| 67 add_incident_.Run(incident_data.Pass()); | 67 add_incident_.Run( |
| 68 make_scoped_ptr(new TrackedPreferenceIncident(incident.Pass()))); |
| 68 } | 69 } |
| 69 } | 70 } |
| 70 | 71 |
| 71 void PreferenceValidationDelegate::OnSplitPreferenceValidation( | 72 void PreferenceValidationDelegate::OnSplitPreferenceValidation( |
| 72 const std::string& pref_path, | 73 const std::string& pref_path, |
| 73 const base::DictionaryValue* /* dict_value */, | 74 const base::DictionaryValue* /* dict_value */, |
| 74 const std::vector<std::string>& invalid_keys, | 75 const std::vector<std::string>& invalid_keys, |
| 75 PrefHashStoreTransaction::ValueState value_state, | 76 PrefHashStoreTransaction::ValueState value_state, |
| 76 TrackedPreferenceHelper::ResetAction /* reset_action */) { | 77 TrackedPreferenceHelper::ResetAction /* reset_action */) { |
| 77 TPIncident_ValueState proto_value_state = MapValueState(value_state); | 78 TPIncident_ValueState proto_value_state = MapValueState(value_state); |
| 78 if (proto_value_state != TPIncident::UNKNOWN) { | 79 if (proto_value_state != TPIncident::UNKNOWN) { |
| 79 scoped_ptr<ClientIncidentReport_IncidentData> incident_data( | 80 scoped_ptr<ClientIncidentReport_IncidentData_TrackedPreferenceIncident> |
| 80 new ClientIncidentReport_IncidentData()); | 81 incident( |
| 81 TPIncident* incident = incident_data->mutable_tracked_preference(); | 82 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); |
| 82 incident->set_path(pref_path); | 83 incident->set_path(pref_path); |
| 83 for (std::vector<std::string>::const_iterator scan(invalid_keys.begin()); | 84 for (std::vector<std::string>::const_iterator scan(invalid_keys.begin()); |
| 84 scan != invalid_keys.end(); | 85 scan != invalid_keys.end(); |
| 85 ++scan) { | 86 ++scan) { |
| 86 incident->add_split_key(*scan); | 87 incident->add_split_key(*scan); |
| 87 } | 88 } |
| 88 incident->set_value_state(proto_value_state); | 89 incident->set_value_state(proto_value_state); |
| 89 add_incident_.Run(incident_data.Pass()); | 90 add_incident_.Run( |
| 91 make_scoped_ptr(new TrackedPreferenceIncident(incident.Pass()))); |
| 90 } | 92 } |
| 91 } | 93 } |
| 92 | 94 |
| 93 } // namespace safe_browsing | 95 } // namespace safe_browsing |
| OLD | NEW |