Commit b496a82b authored by Gavin Williams's avatar Gavin Williams Committed by Chromium LUCI CQ

scanning: Create histogram for scan job failure reasons

Create a histogram to record the reason for a scan job not succeeding.

Bug: 1059779
Change-Id: Ibdf6806b314292ae79b87eb20e6a892553525f15
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2596253Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Reviewed-by: default avatarJesse Schettler <jschettler@chromium.org>
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841644}
parent 7f9bf210
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/location.h" #include "base/location.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/optional.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/chromeos/scanning/lorgnette_scanner_manager.h" #include "chrome/browser/chromeos/scanning/lorgnette_scanner_manager.h"
#include "chrome/browser/chromeos/scanning/scanning_type_converters.h" #include "chrome/browser/chromeos/scanning/scanning_type_converters.h"
#include "chromeos/components/scanning/scanning_uma.h"
#include "third_party/skia/include/codec/SkCodec.h" #include "third_party/skia/include/codec/SkCodec.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkData.h" #include "third_party/skia/include/core/SkData.h"
...@@ -221,11 +223,21 @@ base::FilePath SavePage(const base::FilePath& scan_to_path, ...@@ -221,11 +223,21 @@ base::FilePath SavePage(const base::FilePath& scan_to_path,
return scan_to_path.Append(filename); return scan_to_path.Append(filename);
} }
// Records the histograms for scan job success and number of pages scanned. // Records the histograms based on the scan job result.
void RecordScanJobResult(bool success, int num_pages_scanned) { void RecordScanJobResult(
bool success,
const base::Optional<scanning::ScanJobFailureReason>& failure_reason,
int num_pages_scanned) {
base::UmaHistogramBoolean("Scanning.ScanJobSuccessful", success); base::UmaHistogramBoolean("Scanning.ScanJobSuccessful", success);
if (success) if (success) {
base::UmaHistogramCounts100("Scanning.NumPagesScanned", num_pages_scanned); base::UmaHistogramCounts100("Scanning.NumPagesScanned", num_pages_scanned);
return;
}
if (failure_reason.has_value()) {
base::UmaHistogramEnumeration("Scanning.ScanJobFailureReason",
failure_reason.value());
}
} }
} // namespace } // namespace
...@@ -272,9 +284,18 @@ void ScanService::StartScan( ...@@ -272,9 +284,18 @@ void ScanService::StartScan(
mojo::PendingRemote<mojo_ipc::ScanJobObserver> observer, mojo::PendingRemote<mojo_ipc::ScanJobObserver> observer,
StartScanCallback callback) { StartScanCallback callback) {
const std::string scanner_name = GetScannerName(scanner_id); const std::string scanner_name = GetScannerName(scanner_id);
if (scanner_name.empty() || !FilePathSupported(settings->scan_to_path)) { if (scanner_name.empty()) {
std::move(callback).Run(false); std::move(callback).Run(false);
RecordScanJobResult(false, /*not used*/ 0); RecordScanJobResult(false, scanning::ScanJobFailureReason::kScannerNotFound,
/*not used*/ 0);
return;
}
if (!FilePathSupported(settings->scan_to_path)) {
std::move(callback).Run(false);
RecordScanJobResult(false,
scanning::ScanJobFailureReason::kUnsupportedScanToPath,
/*not used*/ 0);
return; return;
} }
...@@ -431,25 +452,33 @@ void ScanService::OnCancelCompleted(bool success) { ...@@ -431,25 +452,33 @@ void ScanService::OnCancelCompleted(bool success) {
} }
void ScanService::OnPdfSaved(const bool success) { void ScanService::OnPdfSaved(const bool success) {
save_failed_ = !success; page_save_failed_ = !success;
} }
void ScanService::OnPageSaved(const base::FilePath& saved_file_path) { void ScanService::OnPageSaved(const base::FilePath& saved_file_path) {
save_failed_ = save_failed_ || saved_file_path.empty(); page_save_failed_ = page_save_failed_ || saved_file_path.empty();
last_scanned_file_path_ = save_failed_ ? base::FilePath() : saved_file_path; last_scanned_file_path_ =
page_save_failed_ ? base::FilePath() : saved_file_path;
} }
void ScanService::OnAllPagesSaved(bool success) { void ScanService::OnAllPagesSaved(bool success) {
save_failed_ = !success || save_failed_; base::Optional<scanning::ScanJobFailureReason> failure_reason = base::nullopt;
if (save_failed_) if (!success) {
failure_reason = scanning::ScanJobFailureReason::kUnknownScannerError;
last_scanned_file_path_.clear();
} else if (page_save_failed_) {
failure_reason = scanning::ScanJobFailureReason::kSaveToDiskFailed;
last_scanned_file_path_.clear(); last_scanned_file_path_.clear();
}
scan_job_observer_->OnScanComplete(!save_failed_, last_scanned_file_path_); scan_job_observer_->OnScanComplete(success && !page_save_failed_,
RecordScanJobResult(!save_failed_, num_pages_scanned_); last_scanned_file_path_);
RecordScanJobResult(success && !page_save_failed_, failure_reason,
num_pages_scanned_);
} }
void ScanService::ClearScanState() { void ScanService::ClearScanState() {
save_failed_ = false; page_save_failed_ = false;
last_scanned_file_path_.clear(); last_scanned_file_path_.clear();
scanned_images_.clear(); scanned_images_.clear();
num_pages_scanned_ = 0; num_pages_scanned_ = 0;
......
...@@ -143,7 +143,7 @@ class ScanService : public scanning::mojom::ScanService, public KeyedService { ...@@ -143,7 +143,7 @@ class ScanService : public scanning::mojom::ScanService, public KeyedService {
base::FilePath google_drive_path_; base::FilePath google_drive_path_;
// Indicates whether there was a failure to save scanned images. // Indicates whether there was a failure to save scanned images.
bool save_failed_; bool page_save_failed_;
// The scanned images used to create a multipage PDF. // The scanned images used to create a multipage PDF.
std::vector<std::string> scanned_images_; std::vector<std::string> scanned_images_;
......
...@@ -8,16 +8,24 @@ ...@@ -8,16 +8,24 @@
namespace chromeos { namespace chromeos {
namespace scanning { namespace scanning {
// These are used in histograms, do not remove/renumber entries. If you're // The enums below are used in histograms, do not remove/renumber entries. If
// adding to this enum with the intention that it will be logged, update the // you're adding to any of these enums, update the corresponding enum listing in
// ScanAppEntryPoint enum listing in
// tools/metrics/histograms/enums.xml. // tools/metrics/histograms/enums.xml.
enum class ScanAppEntryPoint { enum class ScanAppEntryPoint {
kSettings = 0, kSettings = 0,
kLauncher = 1, kLauncher = 1,
kMaxValue = kLauncher, kMaxValue = kLauncher,
}; };
enum class ScanJobFailureReason {
kUnknownScannerError = 0,
kScannerNotFound = 1,
kUnsupportedScanToPath = 2,
kSaveToDiskFailed = 3,
kMaxValue = kSaveToDiskFailed,
};
// Records ScanAppEntryPoint histogram value. // Records ScanAppEntryPoint histogram value.
void RecordScanAppEntryPoint(ScanAppEntryPoint entry_point); void RecordScanAppEntryPoint(ScanAppEntryPoint entry_point);
......
...@@ -66418,6 +66418,13 @@ https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf ...@@ -66418,6 +66418,13 @@ https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
<int value="1" label="Launcher"/> <int value="1" label="Launcher"/>
</enum> </enum>
<enum name="ScanJobFailureReason">
<int value="0" label="Unknown scanner error"/>
<int value="1" label="Scanner not found"/>
<int value="2" label="Unsupported Scan To path"/>
<int value="3" label="Save to disk failed"/>
</enum>
<enum name="ScheduledNavigationType"> <enum name="ScheduledNavigationType">
<obsolete> <obsolete>
Deprecated August 2018 Deprecated August 2018
...@@ -63,6 +63,14 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -63,6 +63,14 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary> </summary>
</histogram> </histogram>
<histogram name="Scanning.ScanJobFailureReason" enum="ScanJobFailureReason"
expires_after="2021-12-04">
<owner>gavinwill@chromium.org</owner>
<owner>jschettler@chromium.org</owner>
<owner>cros-peripherals@google.com</owner>
<summary>Records the reason a scan job failed.</summary>
</histogram>
<histogram name="Scanning.ScanJobSuccessful" enum="Boolean" <histogram name="Scanning.ScanJobSuccessful" enum="Boolean"
expires_after="2021-12-04"> expires_after="2021-12-04">
<owner>gavinwill@chromium.org</owner> <owner>gavinwill@chromium.org</owner>
......
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