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

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

Issue 891793002: Take a Profile when adding an incident to the incident reporting service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: this time Created 5 years, 10 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 <vector> 8 #include <vector>
9 9
10 #include "base/callback.h"
11 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
12 #include "chrome/browser/prefs/tracked/pref_hash_store_transaction.h" 11 #include "chrome/browser/prefs/tracked/pref_hash_store_transaction.h"
13 #include "chrome/browser/prefs/tracked/tracked_preference_helper.h" 12 #include "chrome/browser/prefs/tracked/tracked_preference_helper.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 16
17 namespace safe_browsing { 17 namespace safe_browsing {
18 18
19 namespace { 19 namespace {
20 20
21 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident TPIncident; 21 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident TPIncident;
22 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState 22 typedef ClientIncidentReport_IncidentData_TrackedPreferenceIncident_ValueState
23 TPIncident_ValueState; 23 TPIncident_ValueState;
(...skipping 10 matching lines...) Expand all
34 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE: 34 case PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE:
35 return TPIncident::UNTRUSTED_UNKNOWN_VALUE; 35 return TPIncident::UNTRUSTED_UNKNOWN_VALUE;
36 default: 36 default:
37 return TPIncident::UNKNOWN; 37 return TPIncident::UNKNOWN;
38 } 38 }
39 } 39 }
40 40
41 } // namespace 41 } // namespace
42 42
43 PreferenceValidationDelegate::PreferenceValidationDelegate( 43 PreferenceValidationDelegate::PreferenceValidationDelegate(
44 const AddIncidentCallback& add_incident) 44 Profile* profile,
45 : add_incident_(add_incident) { 45 scoped_ptr<IncidentReceiver> incident_receiver)
46 : profile_(profile),
47 incident_receiver_(incident_receiver.Pass()) {
46 } 48 }
47 49
48 PreferenceValidationDelegate::~PreferenceValidationDelegate() { 50 PreferenceValidationDelegate::~PreferenceValidationDelegate() {
49 } 51 }
50 52
51 void PreferenceValidationDelegate::OnAtomicPreferenceValidation( 53 void PreferenceValidationDelegate::OnAtomicPreferenceValidation(
52 const std::string& pref_path, 54 const std::string& pref_path,
53 const base::Value* value, 55 const base::Value* value,
54 PrefHashStoreTransaction::ValueState value_state, 56 PrefHashStoreTransaction::ValueState value_state,
55 bool is_personal) { 57 bool is_personal) {
56 TPIncident_ValueState proto_value_state = MapValueState(value_state); 58 TPIncident_ValueState proto_value_state = MapValueState(value_state);
57 if (proto_value_state != TPIncident::UNKNOWN) { 59 if (proto_value_state != TPIncident::UNKNOWN) {
58 scoped_ptr<TPIncident> incident( 60 scoped_ptr<TPIncident> incident(
59 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); 61 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident());
60 incident->set_path(pref_path); 62 incident->set_path(pref_path);
61 if (!value || 63 if (!value ||
62 (!value->GetAsString(incident->mutable_atomic_value()) && 64 (!value->GetAsString(incident->mutable_atomic_value()) &&
63 !base::JSONWriter::Write(value, incident->mutable_atomic_value()))) { 65 !base::JSONWriter::Write(value, incident->mutable_atomic_value()))) {
64 incident->clear_atomic_value(); 66 incident->clear_atomic_value();
65 } 67 }
66 incident->set_value_state(proto_value_state); 68 incident->set_value_state(proto_value_state);
67 add_incident_.Run(make_scoped_ptr( 69 incident_receiver_->AddIncidentForProfile(
68 new TrackedPreferenceIncident(incident.Pass(), is_personal))); 70 profile_, make_scoped_ptr(new TrackedPreferenceIncident(incident.Pass(),
71 is_personal)));
69 } 72 }
70 } 73 }
71 74
72 void PreferenceValidationDelegate::OnSplitPreferenceValidation( 75 void PreferenceValidationDelegate::OnSplitPreferenceValidation(
73 const std::string& pref_path, 76 const std::string& pref_path,
74 const base::DictionaryValue* /* dict_value */, 77 const base::DictionaryValue* /* dict_value */,
75 const std::vector<std::string>& invalid_keys, 78 const std::vector<std::string>& invalid_keys,
76 PrefHashStoreTransaction::ValueState value_state, 79 PrefHashStoreTransaction::ValueState value_state,
77 bool is_personal) { 80 bool is_personal) {
78 TPIncident_ValueState proto_value_state = MapValueState(value_state); 81 TPIncident_ValueState proto_value_state = MapValueState(value_state);
79 if (proto_value_state != TPIncident::UNKNOWN) { 82 if (proto_value_state != TPIncident::UNKNOWN) {
80 scoped_ptr<ClientIncidentReport_IncidentData_TrackedPreferenceIncident> 83 scoped_ptr<ClientIncidentReport_IncidentData_TrackedPreferenceIncident>
81 incident( 84 incident(
82 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident()); 85 new ClientIncidentReport_IncidentData_TrackedPreferenceIncident());
83 incident->set_path(pref_path); 86 incident->set_path(pref_path);
84 for (std::vector<std::string>::const_iterator scan(invalid_keys.begin()); 87 for (std::vector<std::string>::const_iterator scan(invalid_keys.begin());
85 scan != invalid_keys.end(); 88 scan != invalid_keys.end();
86 ++scan) { 89 ++scan) {
87 incident->add_split_key(*scan); 90 incident->add_split_key(*scan);
88 } 91 }
89 incident->set_value_state(proto_value_state); 92 incident->set_value_state(proto_value_state);
90 add_incident_.Run(make_scoped_ptr( 93 incident_receiver_->AddIncidentForProfile(
91 new TrackedPreferenceIncident(incident.Pass(), is_personal))); 94 profile_, make_scoped_ptr(new TrackedPreferenceIncident(incident.Pass(),
95 is_personal)));
92 } 96 }
93 } 97 }
94 98
95 } // namespace safe_browsing 99 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698