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

Side by Side Diff: chrome/browser/safe_browsing/protocol_manager.cc

Issue 1579083002: Add UMA metric for GetHash parsing errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@osb-pm-2
Patch Set: Rebase Created 4 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/protocol_manager.h" 5 #include "chrome/browser/safe_browsing/protocol_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 void SafeBrowsingProtocolManager::RecordGetHashResult(bool is_download, 210 void SafeBrowsingProtocolManager::RecordGetHashResult(bool is_download,
211 ResultType result_type) { 211 ResultType result_type) {
212 if (is_download) { 212 if (is_download) {
213 UMA_HISTOGRAM_ENUMERATION("SB2.GetHashResultDownload", result_type, 213 UMA_HISTOGRAM_ENUMERATION("SB2.GetHashResultDownload", result_type,
214 GET_HASH_RESULT_MAX); 214 GET_HASH_RESULT_MAX);
215 } else { 215 } else {
216 UMA_HISTOGRAM_ENUMERATION("SB2.GetHashResult", result_type, 216 UMA_HISTOGRAM_ENUMERATION("SB2.GetHashResult", result_type,
217 GET_HASH_RESULT_MAX); 217 GET_HASH_RESULT_MAX);
218 } 218 }
219 } 219 }
220 void SafeBrowsingProtocolManager::RecordParseGetHashResult(
221 ParseResultType result_type) {
222 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.ParseV4HashResult", result_type,
223 PARSE_GET_HASH_RESULT_MAX);
224 }
220 225
221 // static 226 // static
222 void SafeBrowsingProtocolManager::RecordGetV4HashResult( 227 void SafeBrowsingProtocolManager::RecordGetV4HashResult(
223 ResultType result_type) { 228 ResultType result_type) {
224 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.GetV4HashResult", result_type, 229 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.GetV4HashResult", result_type,
225 GET_HASH_RESULT_MAX); 230 GET_HASH_RESULT_MAX);
226 } 231 }
227 232
228 void SafeBrowsingProtocolManager::RecordHttpResponseOrErrorCode( 233 void SafeBrowsingProtocolManager::RecordHttpResponseOrErrorCode(
229 const char* metric_name, 234 const char* metric_name,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 return req_base64; 312 return req_base64;
308 } 313 }
309 314
310 bool SafeBrowsingProtocolManager::ParseV4HashResponse( 315 bool SafeBrowsingProtocolManager::ParseV4HashResponse(
311 const std::string& data, 316 const std::string& data,
312 std::vector<SBFullHashResult>* full_hashes, 317 std::vector<SBFullHashResult>* full_hashes,
313 base::TimeDelta* negative_cache_duration) { 318 base::TimeDelta* negative_cache_duration) {
314 FindFullHashesResponse response; 319 FindFullHashesResponse response;
315 320
316 if (!response.ParseFromString(data)) { 321 if (!response.ParseFromString(data)) {
317 // TODO(kcarattini): Add UMA. 322 RecordParseGetHashResult(PARSE_FROM_STRING_ERROR);
318 return false; 323 return false;
319 } 324 }
320 325
321 if (response.has_negative_cache_duration()) { 326 if (response.has_negative_cache_duration()) {
322 // Seconds resolution is good enough so we ignore the nanos field. 327 // Seconds resolution is good enough so we ignore the nanos field.
323 *negative_cache_duration = base::TimeDelta::FromSeconds( 328 *negative_cache_duration = base::TimeDelta::FromSeconds(
324 response.negative_cache_duration().seconds()); 329 response.negative_cache_duration().seconds());
325 } 330 }
326 331
327 if (response.has_minimum_wait_duration()) { 332 if (response.has_minimum_wait_duration()) {
328 // Seconds resolution is good enough so we ignore the nanos field. 333 // Seconds resolution is good enough so we ignore the nanos field.
329 next_gethash_v4_time_ = Time::Now() + base::TimeDelta::FromSeconds( 334 next_gethash_v4_time_ = Time::Now() + base::TimeDelta::FromSeconds(
330 response.minimum_wait_duration().seconds()); 335 response.minimum_wait_duration().seconds());
331 } 336 }
332 337
333 // Loop over the threat matches and fill in full_hashes. 338 // Loop over the threat matches and fill in full_hashes.
334 for (const ThreatMatch& match : response.matches()) { 339 for (const ThreatMatch& match : response.matches()) {
335 // Make sure the platform and threat entry type match. 340 // Make sure the platform and threat entry type match.
336 if (!(match.has_threat_entry_type() && 341 if (!(match.has_threat_entry_type() &&
337 match.threat_entry_type() == URL_EXPRESSION && 342 match.threat_entry_type() == URL_EXPRESSION &&
338 match.has_threat())) { 343 match.has_threat())) {
344 RecordParseGetHashResult(UNEXPECTED_THREAT_ENTRY_TYPE_ERROR);
339 continue; 345 continue;
340 } 346 }
341 347
342 // Fill in the full hash. 348 // Fill in the full hash.
343 SBFullHashResult result; 349 SBFullHashResult result;
344 result.hash = StringToSBFullHash(match.threat().hash()); 350 result.hash = StringToSBFullHash(match.threat().hash());
345 351
346 if (match.has_cache_duration()) { 352 if (match.has_cache_duration()) {
347 // Seconds resolution is good enough so we ignore the nanos field. 353 // Seconds resolution is good enough so we ignore the nanos field.
348 result.cache_duration = base::TimeDelta::FromSeconds( 354 result.cache_duration = base::TimeDelta::FromSeconds(
349 match.cache_duration().seconds()); 355 match.cache_duration().seconds());
350 } 356 }
351 357
352 // Different threat types will handle the metadata differently. 358 // Different threat types will handle the metadata differently.
353 if (match.has_threat_type() && match.threat_type() == API_ABUSE && 359 if (match.has_threat_type() && match.threat_type() == API_ABUSE) {
354 match.has_platform_type() && 360 if (match.has_platform_type() &&
355 match.platform_type() == CHROME_PLATFORM && 361 match.platform_type() == CHROME_PLATFORM) {
356 match.has_threat_entry_metadata()) { 362 if (match.has_threat_entry_metadata()) {
357 // For API Abuse, store a csv of the returned permissions. 363 // For API Abuse, store a csv of the returned permissions.
358 for (const ThreatEntryMetadata::MetadataEntry& m : 364 for (const ThreatEntryMetadata::MetadataEntry& m :
359 match.threat_entry_metadata().entries()) { 365 match.threat_entry_metadata().entries()) {
360 if (m.key() == "permission") { 366 if (m.key() == "permission") {
361 result.metadata += m.value() + ","; 367 result.metadata += m.value() + ",";
368 }
369 }
370 } else {
371 RecordParseGetHashResult(NO_METADATA_ERROR);
362 } 372 }
373 } else {
374 RecordParseGetHashResult(UNEXPECTED_PLATFORM_TYPE_ERROR);
363 } 375 }
364 } else { 376 } else {
365 // TODO(kcarattini): Add UMA for unexpected threat type match. 377 RecordParseGetHashResult(UNEXPECTED_THREAT_TYPE_ERROR);
366 return false; 378 return false;
Nathan Parker 2016/01/15 19:34:42 Why does this this one return and the rest dont?
kcarattini 2016/01/20 04:02:05 I made them all return false, that way there is on
367 } 379 }
368 380
369 full_hashes->push_back(result); 381 full_hashes->push_back(result);
370 } 382 }
371 return true; 383 return true;
372 } 384 }
373 385
374 void SafeBrowsingProtocolManager::GetV4FullHashes( 386 void SafeBrowsingProtocolManager::GetV4FullHashes(
375 const std::vector<SBPrefix>& prefixes, 387 const std::vector<SBPrefix>& prefixes,
376 const std::vector<PlatformType>& platforms, 388 const std::vector<PlatformType>& platforms,
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 SafeBrowsingProtocolManager::FullHashDetails::FullHashDetails( 1046 SafeBrowsingProtocolManager::FullHashDetails::FullHashDetails(
1035 FullHashCallback callback, 1047 FullHashCallback callback,
1036 bool is_download) 1048 bool is_download)
1037 : callback(callback), is_download(is_download) {} 1049 : callback(callback), is_download(is_download) {}
1038 1050
1039 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() {} 1051 SafeBrowsingProtocolManager::FullHashDetails::~FullHashDetails() {}
1040 1052
1041 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() {} 1053 SafeBrowsingProtocolManagerDelegate::~SafeBrowsingProtocolManagerDelegate() {}
1042 1054
1043 } // namespace safe_browsing 1055 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698