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

Side by Side Diff: components/safe_browsing/password_protection/password_protection_request.cc

Issue 2869253002: Add UMA metrics to phishguard pings (Closed)
Patch Set: resolve comments on histograms.xml Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #include "components/safe_browsing/password_protection/password_protection_reque st.h" 4 #include "components/safe_browsing/password_protection/password_protection_reque st.h"
5 5
6 #include "base/memory/ptr_util.h" 6 #include "base/memory/ptr_util.h"
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "components/data_use_measurement/core/data_use_user_data.h" 9 #include "components/data_use_measurement/core/data_use_user_data.h"
10 #include "components/safe_browsing_db/database_manager.h" 10 #include "components/safe_browsing_db/database_manager.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 base::Unretained(password_protection_service_), 53 base::Unretained(password_protection_service_),
54 main_frame_url_, match_whitelist), 54 main_frame_url_, match_whitelist),
55 base::Bind(&PasswordProtectionRequest::OnWhitelistCheckDone, this, 55 base::Bind(&PasswordProtectionRequest::OnWhitelistCheckDone, this,
56 base::Owned(match_whitelist))); 56 base::Owned(match_whitelist)));
57 } 57 }
58 58
59 void PasswordProtectionRequest::OnWhitelistCheckDone( 59 void PasswordProtectionRequest::OnWhitelistCheckDone(
60 const bool* match_whitelist) { 60 const bool* match_whitelist) {
61 DCHECK_CURRENTLY_ON(BrowserThread::UI); 61 DCHECK_CURRENTLY_ON(BrowserThread::UI);
62 if (*match_whitelist) 62 if (*match_whitelist)
63 Finish(RequestOutcome::MATCHED_WHITELIST, nullptr); 63 Finish(PasswordProtectionService::MATCHED_WHITELIST, nullptr);
64 else 64 else
65 CheckCachedVerdicts(); 65 CheckCachedVerdicts();
66 } 66 }
67 67
68 void PasswordProtectionRequest::CheckCachedVerdicts() { 68 void PasswordProtectionRequest::CheckCachedVerdicts() {
69 DCHECK_CURRENTLY_ON(BrowserThread::UI); 69 DCHECK_CURRENTLY_ON(BrowserThread::UI);
70 if (!password_protection_service_) { 70 if (!password_protection_service_) {
71 Finish(RequestOutcome::SERVICE_DESTROYED, nullptr); 71 Finish(PasswordProtectionService::SERVICE_DESTROYED, nullptr);
72 return; 72 return;
73 } 73 }
74 74
75 std::unique_ptr<LoginReputationClientResponse> cached_response = 75 std::unique_ptr<LoginReputationClientResponse> cached_response =
76 base::MakeUnique<LoginReputationClientResponse>(); 76 base::MakeUnique<LoginReputationClientResponse>();
77 auto verdict = password_protection_service_->GetCachedVerdict( 77 auto verdict = password_protection_service_->GetCachedVerdict(
78 main_frame_url_, cached_response.get()); 78 main_frame_url_, cached_response.get());
79 if (verdict != LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED) 79 if (verdict != LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED)
80 Finish(RequestOutcome::RESPONSE_ALREADY_CACHED, std::move(cached_response)); 80 Finish(PasswordProtectionService::RESPONSE_ALREADY_CACHED,
81 std::move(cached_response));
81 else 82 else
82 SendRequest(); 83 SendRequest();
83 } 84 }
84 85
85 void PasswordProtectionRequest::FillRequestProto() { 86 void PasswordProtectionRequest::FillRequestProto() {
86 request_proto_ = base::MakeUnique<LoginReputationClientRequest>(); 87 request_proto_ = base::MakeUnique<LoginReputationClientRequest>();
87 request_proto_->set_page_url(main_frame_url_.spec()); 88 request_proto_->set_page_url(main_frame_url_.spec());
88 request_proto_->set_trigger_type(request_type_); 89 request_proto_->set_trigger_type(request_type_);
89 password_protection_service_->FillUserPopulation(request_type_, 90 password_protection_service_->FillUserPopulation(request_type_,
90 request_proto_.get()); 91 request_proto_.get());
(...skipping 22 matching lines...) Expand all
113 // TODO(jialiul): Fill more frame specific info when Safe Browsing backend 114 // TODO(jialiul): Fill more frame specific info when Safe Browsing backend
114 // is ready to handle these pieces of information. 115 // is ready to handle these pieces of information.
115 } 116 }
116 117
117 void PasswordProtectionRequest::SendRequest() { 118 void PasswordProtectionRequest::SendRequest() {
118 DCHECK_CURRENTLY_ON(BrowserThread::UI); 119 DCHECK_CURRENTLY_ON(BrowserThread::UI);
119 FillRequestProto(); 120 FillRequestProto();
120 121
121 std::string serialized_request; 122 std::string serialized_request;
122 if (!request_proto_->SerializeToString(&serialized_request)) { 123 if (!request_proto_->SerializeToString(&serialized_request)) {
123 Finish(RequestOutcome::REQUEST_MALFORMED, nullptr); 124 Finish(PasswordProtectionService::REQUEST_MALFORMED, nullptr);
124 return; 125 return;
125 } 126 }
126 127
127 // In case the request take too long, we set a timer to cancel this request. 128 // In case the request take too long, we set a timer to cancel this request.
128 StartTimeout(); 129 StartTimeout();
129 130
130 fetcher_ = net::URLFetcher::Create( 131 fetcher_ = net::URLFetcher::Create(
131 0, PasswordProtectionService::GetPasswordProtectionRequestUrl(), 132 0, PasswordProtectionService::GetPasswordProtectionRequestUrl(),
132 net::URLFetcher::POST, this); 133 net::URLFetcher::POST, this);
133 data_use_measurement::DataUseUserData::AttachToFetcher( 134 data_use_measurement::DataUseUserData::AttachToFetcher(
(...skipping 25 matching lines...) Expand all
159 DCHECK_CURRENTLY_ON(BrowserThread::UI); 160 DCHECK_CURRENTLY_ON(BrowserThread::UI);
160 net::URLRequestStatus status = source->GetStatus(); 161 net::URLRequestStatus status = source->GetStatus();
161 const bool is_success = status.is_success(); 162 const bool is_success = status.is_success();
162 const int response_code = source->GetResponseCode(); 163 const int response_code = source->GetResponseCode();
163 164
164 UMA_HISTOGRAM_SPARSE_SLOWLY( 165 UMA_HISTOGRAM_SPARSE_SLOWLY(
165 "PasswordProtection.PasswordProtectionResponseOrErrorCode", 166 "PasswordProtection.PasswordProtectionResponseOrErrorCode",
166 is_success ? response_code : status.error()); 167 is_success ? response_code : status.error());
167 168
168 if (!is_success || net::HTTP_OK != response_code) { 169 if (!is_success || net::HTTP_OK != response_code) {
169 Finish(RequestOutcome::FETCH_FAILED, nullptr); 170 Finish(PasswordProtectionService::FETCH_FAILED, nullptr);
170 return; 171 return;
171 } 172 }
172 173
173 std::unique_ptr<LoginReputationClientResponse> response = 174 std::unique_ptr<LoginReputationClientResponse> response =
174 base::MakeUnique<LoginReputationClientResponse>(); 175 base::MakeUnique<LoginReputationClientResponse>();
175 std::string response_body; 176 std::string response_body;
176 bool received_data = source->GetResponseAsString(&response_body); 177 bool received_data = source->GetResponseAsString(&response_body);
177 DCHECK(received_data); 178 DCHECK(received_data);
178 fetcher_.reset(); // We don't need it anymore. 179 fetcher_.reset(); // We don't need it anymore.
179 UMA_HISTOGRAM_TIMES("PasswordProtection.RequestNetworkDuration", 180 UMA_HISTOGRAM_TIMES("PasswordProtection.RequestNetworkDuration",
180 base::TimeTicks::Now() - request_start_time_); 181 base::TimeTicks::Now() - request_start_time_);
181 if (response->ParseFromString(response_body)) 182 if (response->ParseFromString(response_body))
182 Finish(RequestOutcome::SUCCEEDED, std::move(response)); 183 Finish(PasswordProtectionService::SUCCEEDED, std::move(response));
183 else 184 else
184 Finish(RequestOutcome::RESPONSE_MALFORMED, nullptr); 185 Finish(PasswordProtectionService::RESPONSE_MALFORMED, nullptr);
185 } 186 }
186 187
187 void PasswordProtectionRequest::Finish( 188 void PasswordProtectionRequest::Finish(
188 RequestOutcome outcome, 189 PasswordProtectionService::RequestOutcome outcome,
189 std::unique_ptr<LoginReputationClientResponse> response) { 190 std::unique_ptr<LoginReputationClientResponse> response) {
190 DCHECK_CURRENTLY_ON(BrowserThread::UI); 191 DCHECK_CURRENTLY_ON(BrowserThread::UI);
191 tracker_.TryCancelAll(); 192 tracker_.TryCancelAll();
192 193
193 UMA_HISTOGRAM_ENUMERATION("PasswordProtection.RequestOutcome", outcome, 194 if (request_type_ == LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE) {
194 RequestOutcome::MAX_OUTCOME); 195 UMA_HISTOGRAM_ENUMERATION(kPasswordOnFocusRequestOutcomeHistogramName,
196 outcome, PasswordProtectionService::MAX_OUTCOME);
197 } else {
198 UMA_HISTOGRAM_ENUMERATION(kPasswordEntryRequestOutcomeHistogramName,
199 outcome, PasswordProtectionService::MAX_OUTCOME);
200 }
195 201
196 if (response) { 202 if (response) {
197 switch (request_type_) { 203 switch (request_type_) {
198 case LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE: 204 case LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE:
199 UMA_HISTOGRAM_ENUMERATION( 205 UMA_HISTOGRAM_ENUMERATION(
200 "PasswordProtection.UnfamiliarLoginPageVerdict", 206 "PasswordProtection.Verdict.PasswordFieldOnFocus",
201 response->verdict_type(), 207 response->verdict_type(),
202 LoginReputationClientResponse_VerdictType_VerdictType_MAX + 1); 208 LoginReputationClientResponse_VerdictType_VerdictType_MAX + 1);
203 break; 209 break;
204 case LoginReputationClientRequest::PASSWORD_REUSE_EVENT: 210 case LoginReputationClientRequest::PASSWORD_REUSE_EVENT:
205 UMA_HISTOGRAM_ENUMERATION( 211 UMA_HISTOGRAM_ENUMERATION(
206 "PasswordProtection.PasswordReuseEventVerdict", 212 "PasswordProtection.Verdict.ProtectedPasswordEntry",
207 response->verdict_type(), 213 response->verdict_type(),
208 LoginReputationClientResponse_VerdictType_VerdictType_MAX + 1); 214 LoginReputationClientResponse_VerdictType_VerdictType_MAX + 1);
209 break; 215 break;
210 default: 216 default:
211 NOTREACHED(); 217 NOTREACHED();
212 } 218 }
213 } 219 }
214 220
215 DCHECK(password_protection_service_); 221 DCHECK(password_protection_service_);
216 password_protection_service_->RequestFinished(this, std::move(response)); 222 password_protection_service_->RequestFinished(this, std::move(response));
217 } 223 }
218 224
219 void PasswordProtectionRequest::Cancel(bool timed_out) { 225 void PasswordProtectionRequest::Cancel(bool timed_out) {
220 DCHECK_CURRENTLY_ON(BrowserThread::UI); 226 DCHECK_CURRENTLY_ON(BrowserThread::UI);
221 fetcher_.reset(); 227 fetcher_.reset();
222 228
223 Finish(timed_out ? TIMEDOUT : CANCELED, nullptr); 229 Finish(timed_out ? PasswordProtectionService::TIMEDOUT
230 : PasswordProtectionService::CANCELED,
231 nullptr);
224 } 232 }
225 233
226 } // namespace safe_browsing 234 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698