Commit 11a9b47a authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Commit Bot

Refactor BinaryUploadService::Result -> string code

Change-Id: I3f47dadec2c1619ed4b4a3131c52fe1a6bef7d5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2068053
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744269}
parent 90dcda95
......@@ -149,6 +149,9 @@ void RecordDeepScanMetrics(DeepScanAccessPoint access_point,
int64_t total_bytes,
const BinaryUploadService::Result& result,
const DeepScanningClientResponse& response) {
// Don't record UMA metrics for this result.
if (result == BinaryUploadService::Result::UNAUTHORIZED)
return;
bool dlp_verdict_success = response.has_dlp_scan_verdict()
? response.dlp_scan_verdict().status() ==
DlpDeepScanningVerdict::SUCCESS
......@@ -159,39 +162,7 @@ void RecordDeepScanMetrics(DeepScanAccessPoint access_point,
MalwareDeepScanningVerdict::VERDICT_UNSPECIFIED
: true;
bool success = dlp_verdict_success && malware_verdict_success;
std::string result_value;
switch (result) {
case BinaryUploadService::Result::SUCCESS:
if (success)
result_value = "Success";
else
result_value = "FailedToGetVerdict";
break;
case BinaryUploadService::Result::UPLOAD_FAILURE:
result_value = "UploadFailure";
break;
case BinaryUploadService::Result::TIMEOUT:
result_value = "Timeout";
break;
case BinaryUploadService::Result::FILE_TOO_LARGE:
result_value = "FileTooLarge";
break;
case BinaryUploadService::Result::FAILED_TO_GET_TOKEN:
result_value = "FailedToGetToken";
break;
case BinaryUploadService::Result::UNKNOWN:
result_value = "Unknown";
break;
case BinaryUploadService::Result::UNAUTHORIZED:
// Don't record UMA metrics for this result.
return;
case BinaryUploadService::Result::FILE_ENCRYPTED:
result_value = "FileEncrypted";
break;
case BinaryUploadService::Result::UNSUPPORTED_FILE_TYPE:
result_value = "UnsupportedFileType";
break;
}
std::string result_value = BinaryUploadServiceResultToString(result, success);
// Update |success| so non-SUCCESS results don't log the bytes/sec metric.
success &= (result == BinaryUploadService::Result::SUCCESS);
......@@ -308,4 +279,32 @@ DeepScanningClientResponse SimpleDeepScanningClientResponseForTesting(
return response;
}
std::string BinaryUploadServiceResultToString(
const BinaryUploadService::Result& result,
bool success) {
switch (result) {
case BinaryUploadService::Result::SUCCESS:
if (success)
return "Success";
else
return "FailedToGetVerdict";
case BinaryUploadService::Result::UPLOAD_FAILURE:
return "UploadFailure";
case BinaryUploadService::Result::TIMEOUT:
return "Timeout";
case BinaryUploadService::Result::FILE_TOO_LARGE:
return "FileTooLarge";
case BinaryUploadService::Result::FAILED_TO_GET_TOKEN:
return "FailedToGetToken";
case BinaryUploadService::Result::UNKNOWN:
return "Unknown";
case BinaryUploadService::Result::UNAUTHORIZED:
return "";
case BinaryUploadService::Result::FILE_ENCRYPTED:
return "FileEncrypted";
case BinaryUploadService::Result::UNSUPPORTED_FILE_TYPE:
return "UnsupportedFileType";
}
}
} // namespace safe_browsing
......@@ -77,6 +77,12 @@ DeepScanningClientResponse SimpleDeepScanningClientResponseForTesting(
base::Optional<bool> dlp_success,
base::Optional<bool> malware_success);
// Helper function to convert a BinaryUploadService::Result to a CamelCase
// string.
std::string BinaryUploadServiceResultToString(
const BinaryUploadService::Result& result,
bool success);
} // namespace safe_browsing
#endif // CHROME_BROWSER_SAFE_BROWSING_CLOUD_CONTENT_SCANNING_DEEP_SCANNING_UTILS_H_
......@@ -33,33 +33,6 @@ constexpr base::TimeDelta kDuration = base::TimeDelta::FromSeconds(10);
constexpr base::TimeDelta kInvalidDuration = base::TimeDelta::FromSeconds(0);
std::string ResultToString(const BinaryUploadService::Result& result,
bool success) {
switch (result) {
case BinaryUploadService::Result::SUCCESS:
if (success)
return "Success";
else
return "FailedToGetVerdict";
case BinaryUploadService::Result::UPLOAD_FAILURE:
return "UploadFailure";
case BinaryUploadService::Result::TIMEOUT:
return "Timeout";
case BinaryUploadService::Result::FILE_TOO_LARGE:
return "FileTooLarge";
case BinaryUploadService::Result::FAILED_TO_GET_TOKEN:
return "FailedToGetToken";
case BinaryUploadService::Result::UNKNOWN:
return "Unknown";
case BinaryUploadService::Result::UNAUTHORIZED:
return "";
case BinaryUploadService::Result::FILE_ENCRYPTED:
return "FileEncrypted";
case BinaryUploadService::Result::UNSUPPORTED_FILE_TYPE:
return "UnsupportedFileType";
}
}
} // namespace
class DeepScanningUtilsUMATest
......@@ -81,7 +54,7 @@ class DeepScanningUtilsUMATest
}
std::string result_value(bool success) const {
return ResultToString(result(), success);
return BinaryUploadServiceResultToString(result(), success);
}
const base::HistogramTester& histograms() const { return histograms_; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment