Skip to content

Commit

Permalink
Track printer protocol usage for CUPS printers.
Browse files Browse the repository at this point in the history
Add a metric called CUPS.PrinterProtocol that records the protocol for
a selected printer. This will be used to track usage of the various
protocols to prioritize effort.

BUG=726103

Review-Url: https://codereview.chromium.org/2903113002
Cr-Commit-Position: refs/heads/master@{#474859}
  • Loading branch information
skau authored and Commit bot committed May 26, 2017
1 parent 96bd408 commit d86afbe
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/task_scheduler/post_task.h"
#include "base/values.h"
#include "chrome/browser/chromeos/printing/cups_print_job_manager.h"
Expand Down Expand Up @@ -123,6 +124,11 @@ class PrinterBackendProxyChromeos : public PrinterBackendProxy {
return;
}

// Log printer configuration for selected printer.
UMA_HISTOGRAM_ENUMERATION("Printing.CUPS.ProtocolUsed",
printer->GetProtocol(),
chromeos::Printer::kProtocolMax);

if (prefs_->IsConfigurationCurrent(*printer)) {
// Skip setup if the printer is already installed.
HandlePrinterSetup(std::move(printer), cb, chromeos::SUCCESS);
Expand Down
28 changes: 28 additions & 0 deletions chromeos/printing/printer_configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>

#include "base/guid.h"
#include "base/strings/string_piece.h"

namespace chromeos {

Expand All @@ -30,4 +31,31 @@ bool Printer::IsIppEverywhere() const {
return ppd_reference_.autoconf;
}

Printer::PrinterProtocol Printer::GetProtocol() const {
const base::StringPiece uri(uri_);

if (uri.starts_with("usb:"))
return PrinterProtocol::kUsb;

if (uri.starts_with("ipp:"))
return PrinterProtocol::kIpp;

if (uri.starts_with("ipps:"))
return PrinterProtocol::kIpps;

if (uri.starts_with("http:"))
return PrinterProtocol::kHttp;

if (uri.starts_with("https:"))
return PrinterProtocol::kHttps;

if (uri.starts_with("socket:"))
return PrinterProtocol::kSocket;

if (uri.starts_with("lpd:"))
return PrinterProtocol::kLpd;

return PrinterProtocol::kUnknown;
}

} // namespace chromeos
17 changes: 17 additions & 0 deletions chromeos/printing/printer_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ class CHROMEOS_EXPORT Printer {
SRC_POLICY,
};

// An enumeration of printer protocols. Do not change these values as they
// are used in enums.xml.
enum PrinterProtocol {
kUnknown = 0,
kUsb = 1,
kIpp = 2,
kIpps = 3,
kHttp = 4,
kHttps = 5,
kSocket = 6,
kLpd = 7,
kProtocolMax
};

// Constructs a printer object that is completely empty.
Printer();

Expand Down Expand Up @@ -94,6 +108,9 @@ class CHROMEOS_EXPORT Printer {
// |uri_|.
bool IsIppEverywhere() const;

// Returns the printer protocol the printer is configured with.
Printer::PrinterProtocol GetProtocol() const;

Source source() const { return source_; }
void set_source(const Source source) { source_ = source; }

Expand Down
11 changes: 11 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29130,6 +29130,17 @@ from previous Chrome versions.
<int value="1" label="The user chose to reload the full page."/>
</enum>

<enum name="PrinterProtocol" type="int">
<int value="0" label="Unknown"/>
<int value="1" label="Universal Serial Bus (usb)"/>
<int value="2" label="Internet Print Protocol (ipp)"/>
<int value="3" label="Internet Print Protocol Secure (ipps)"/>
<int value="4" label="HyperText Transfer Protocol (http)"/>
<int value="5" label="HyperText Transfer Protocol Secure (https)"/>
<int value="6" label="App Socket (socket)"/>
<int value="7" label="Line Print Daemon (lpd)"/>
</enum>

<enum name="PrinterServiceEventType" type="int">
<int value="0" label="Printer added"/>
<int value="1" label="Page displayed (Deprecated)"/>
Expand Down
10 changes: 10 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57061,6 +57061,16 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>

<histogram name="Printing.CUPS.ProtocolUsed" enum="PrinterProtocol">
<owner>skau@chromium.org</owner>
<summary>
Records the protocol for a selected printer in Chrome OS. Used to track
usage of the various printer protocols. Since a selection occurs when print
preview is opened, this will count at least one every time that happens if a
CUPS printer was selected.
</summary>
</histogram>

<histogram name="PrintPreview.DestinationAction"
enum="PrintPreviewPrintDestinationBuckets">
<owner>vitalybuka@chromium.org</owner>
Expand Down

0 comments on commit d86afbe

Please sign in to comment.