Commit fbfa5e4d authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Printing: Add metrics for PDF to PWG Raster conversions.

BUG=792308

Change-Id: I151965cc99c4bd757176c3af87971e28f6c347da
Reviewed-on: https://chromium-review.googlesource.com/1069560Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarJay Civelli <jcivelli@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561599}
parent 8c53a1c2
...@@ -776,7 +776,7 @@ TEST_P(PrivetCapabilitiesTest, BadToken) { ...@@ -776,7 +776,7 @@ TEST_P(PrivetCapabilitiesTest, BadToken) {
// request is uploading a file that is based on this pattern. // request is uploading a file that is based on this pattern.
class FakePwgRasterConverter : public printing::PwgRasterConverter { class FakePwgRasterConverter : public printing::PwgRasterConverter {
public: public:
void Start(base::RefCountedMemory* data, void Start(const base::RefCountedMemory* data,
const printing::PdfRenderSettings& conversion_settings, const printing::PdfRenderSettings& conversion_settings,
const printing::PwgRasterSettings& bitmap_settings, const printing::PwgRasterSettings& bitmap_settings,
ResultCallback callback) override { ResultCallback callback) override {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/cancelable_callback.h" #include "base/cancelable_callback.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/histogram_macros.h"
#include "chrome/services/printing/public/mojom/constants.mojom.h" #include "chrome/services/printing/public/mojom/constants.mojom.h"
#include "chrome/services/printing/public/mojom/pdf_to_pwg_raster_converter.mojom.h" #include "chrome/services/printing/public/mojom/pdf_to_pwg_raster_converter.mojom.h"
#include "components/cloud_devices/common/cloud_device_description.h" #include "components/cloud_devices/common/cloud_device_description.h"
...@@ -40,7 +41,7 @@ class PwgRasterConverterHelper ...@@ -40,7 +41,7 @@ class PwgRasterConverterHelper
PwgRasterConverterHelper(const PdfRenderSettings& settings, PwgRasterConverterHelper(const PdfRenderSettings& settings,
const PwgRasterSettings& bitmap_settings); const PwgRasterSettings& bitmap_settings);
void Convert(base::RefCountedMemory* data, void Convert(const base::RefCountedMemory* data,
PwgRasterConverter::ResultCallback callback); PwgRasterConverter::ResultCallback callback);
private: private:
...@@ -48,7 +49,8 @@ class PwgRasterConverterHelper ...@@ -48,7 +49,8 @@ class PwgRasterConverterHelper
~PwgRasterConverterHelper(); ~PwgRasterConverterHelper();
void RunCallback(base::ReadOnlySharedMemoryRegion region); void RunCallback(base::ReadOnlySharedMemoryRegion region,
uint32_t page_count);
PdfRenderSettings settings_; PdfRenderSettings settings_;
PwgRasterSettings bitmap_settings_; PwgRasterSettings bitmap_settings_;
...@@ -71,7 +73,7 @@ PwgRasterConverterHelper::~PwgRasterConverterHelper() { ...@@ -71,7 +73,7 @@ PwgRasterConverterHelper::~PwgRasterConverterHelper() {
} }
void PwgRasterConverterHelper::Convert( void PwgRasterConverterHelper::Convert(
base::RefCountedMemory* data, const base::RefCountedMemory* data,
PwgRasterConverter::ResultCallback callback) { PwgRasterConverter::ResultCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -84,12 +86,12 @@ void PwgRasterConverterHelper::Convert( ...@@ -84,12 +86,12 @@ void PwgRasterConverterHelper::Convert(
pdf_to_pwg_raster_converter_ptr_.set_connection_error_handler( pdf_to_pwg_raster_converter_ptr_.set_connection_error_handler(
base::BindOnce(&PwgRasterConverterHelper::RunCallback, this, base::BindOnce(&PwgRasterConverterHelper::RunCallback, this,
base::ReadOnlySharedMemoryRegion())); base::ReadOnlySharedMemoryRegion(), /*page_count=*/0));
base::MappedReadOnlyRegion memory = base::MappedReadOnlyRegion memory =
base::ReadOnlySharedMemoryRegion::Create(data->size()); base::ReadOnlySharedMemoryRegion::Create(data->size());
if (!memory.IsValid()) { if (!memory.IsValid()) {
RunCallback(base::ReadOnlySharedMemoryRegion()); RunCallback(base::ReadOnlySharedMemoryRegion(), /*page_count=*/0);
return; return;
} }
...@@ -102,10 +104,21 @@ void PwgRasterConverterHelper::Convert( ...@@ -102,10 +104,21 @@ void PwgRasterConverterHelper::Convert(
} }
void PwgRasterConverterHelper::RunCallback( void PwgRasterConverterHelper::RunCallback(
base::ReadOnlySharedMemoryRegion region) { base::ReadOnlySharedMemoryRegion region,
uint32_t page_count) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (callback_) if (callback_) {
if (region.IsValid() && page_count > 0) {
size_t average_page_size_in_kb = region.GetSize() / 1024;
average_page_size_in_kb /= page_count;
UMA_HISTOGRAM_MEMORY_KB("Printing.ConversionSize.Pwg",
average_page_size_in_kb);
std::move(callback_).Run(std::move(region)); std::move(callback_).Run(std::move(region));
} else {
// TODO(thestig): Consider adding UMA to track failure rates.
std::move(callback_).Run(base::ReadOnlySharedMemoryRegion());
}
}
pdf_to_pwg_raster_converter_ptr_.reset(); pdf_to_pwg_raster_converter_ptr_.reset();
} }
...@@ -114,7 +127,7 @@ class PwgRasterConverterImpl : public PwgRasterConverter { ...@@ -114,7 +127,7 @@ class PwgRasterConverterImpl : public PwgRasterConverter {
PwgRasterConverterImpl(); PwgRasterConverterImpl();
~PwgRasterConverterImpl() override; ~PwgRasterConverterImpl() override;
void Start(base::RefCountedMemory* data, void Start(const base::RefCountedMemory* data,
const PdfRenderSettings& conversion_settings, const PdfRenderSettings& conversion_settings,
const PwgRasterSettings& bitmap_settings, const PwgRasterSettings& bitmap_settings,
ResultCallback callback) override; ResultCallback callback) override;
...@@ -122,9 +135,9 @@ class PwgRasterConverterImpl : public PwgRasterConverter { ...@@ -122,9 +135,9 @@ class PwgRasterConverterImpl : public PwgRasterConverter {
private: private:
scoped_refptr<PwgRasterConverterHelper> utility_client_; scoped_refptr<PwgRasterConverterHelper> utility_client_;
// Cancelable version of ResultCallback. // Cancelable version of PwgRasterConverter::ResultCallback.
base::CancelableOnceCallback<void(base::ReadOnlySharedMemoryRegion)> base::CancelableOnceCallback<void(base::ReadOnlySharedMemoryRegion)>
callback_; cancelable_callback_;
DISALLOW_COPY_AND_ASSIGN(PwgRasterConverterImpl); DISALLOW_COPY_AND_ASSIGN(PwgRasterConverterImpl);
}; };
...@@ -133,14 +146,14 @@ PwgRasterConverterImpl::PwgRasterConverterImpl() = default; ...@@ -133,14 +146,14 @@ PwgRasterConverterImpl::PwgRasterConverterImpl() = default;
PwgRasterConverterImpl::~PwgRasterConverterImpl() = default; PwgRasterConverterImpl::~PwgRasterConverterImpl() = default;
void PwgRasterConverterImpl::Start(base::RefCountedMemory* data, void PwgRasterConverterImpl::Start(const base::RefCountedMemory* data,
const PdfRenderSettings& conversion_settings, const PdfRenderSettings& conversion_settings,
const PwgRasterSettings& bitmap_settings, const PwgRasterSettings& bitmap_settings,
ResultCallback callback) { ResultCallback callback) {
callback_.Reset(std::move(callback)); cancelable_callback_.Reset(std::move(callback));
utility_client_ = base::MakeRefCounted<PwgRasterConverterHelper>( utility_client_ = base::MakeRefCounted<PwgRasterConverterHelper>(
conversion_settings, bitmap_settings); conversion_settings, bitmap_settings);
utility_client_->Convert(data, callback_.callback()); utility_client_->Convert(data, cancelable_callback_.callback());
} }
} // namespace } // namespace
......
...@@ -49,7 +49,7 @@ class PwgRasterConverter { ...@@ -49,7 +49,7 @@ class PwgRasterConverter {
const cloud_devices::CloudDeviceDescription& printer_capabilities, const cloud_devices::CloudDeviceDescription& printer_capabilities,
const cloud_devices::CloudDeviceDescription& ticket); const cloud_devices::CloudDeviceDescription& ticket);
virtual void Start(base::RefCountedMemory* data, virtual void Start(const base::RefCountedMemory* data,
const PdfRenderSettings& conversion_settings, const PdfRenderSettings& conversion_settings,
const PwgRasterSettings& bitmap_settings, const PwgRasterSettings& bitmap_settings,
ResultCallback callback) = 0; ResultCallback callback) = 0;
......
...@@ -80,7 +80,7 @@ class PdfToPwgRasterBrowserTest : public InProcessBrowserTest { ...@@ -80,7 +80,7 @@ class PdfToPwgRasterBrowserTest : public InProcessBrowserTest {
: converter_(PwgRasterConverter::CreateDefault()) {} : converter_(PwgRasterConverter::CreateDefault()) {}
~PdfToPwgRasterBrowserTest() override {} ~PdfToPwgRasterBrowserTest() override {}
void Convert(base::RefCountedMemory* pdf_data, void Convert(const base::RefCountedMemory* pdf_data,
const PdfRenderSettings& conversion_settings, const PdfRenderSettings& conversion_settings,
const PwgRasterSettings& bitmap_settings, const PwgRasterSettings& bitmap_settings,
bool expect_success, bool expect_success,
......
...@@ -281,7 +281,7 @@ class FakePwgRasterConverter : public PwgRasterConverter { ...@@ -281,7 +281,7 @@ class FakePwgRasterConverter : public PwgRasterConverter {
// PwgRasterConverter implementation. It writes |data| to shared memory. // PwgRasterConverter implementation. It writes |data| to shared memory.
// Also, remembers conversion and bitmap settings passed into the method. // Also, remembers conversion and bitmap settings passed into the method.
void Start(base::RefCountedMemory* data, void Start(const base::RefCountedMemory* data,
const printing::PdfRenderSettings& conversion_settings, const printing::PdfRenderSettings& conversion_settings,
const printing::PwgRasterSettings& bitmap_settings, const printing::PwgRasterSettings& bitmap_settings,
ResultCallback callback) override { ResultCallback callback) override {
......
...@@ -22,7 +22,8 @@ namespace { ...@@ -22,7 +22,8 @@ namespace {
base::ReadOnlySharedMemoryRegion RenderPdfPagesToPwgRaster( base::ReadOnlySharedMemoryRegion RenderPdfPagesToPwgRaster(
base::ReadOnlySharedMemoryRegion pdf_region, base::ReadOnlySharedMemoryRegion pdf_region,
const PdfRenderSettings& settings, const PdfRenderSettings& settings,
const PwgRasterSettings& bitmap_settings) { const PwgRasterSettings& bitmap_settings,
uint32_t* page_count) {
base::ReadOnlySharedMemoryRegion invalid_pwg_region; base::ReadOnlySharedMemoryRegion invalid_pwg_region;
base::ReadOnlySharedMemoryMapping pdf_mapping = pdf_region.Map(); base::ReadOnlySharedMemoryMapping pdf_mapping = pdf_region.Map();
if (!pdf_mapping.IsValid()) if (!pdf_mapping.IsValid())
...@@ -101,6 +102,7 @@ base::ReadOnlySharedMemoryRegion RenderPdfPagesToPwgRaster( ...@@ -101,6 +102,7 @@ base::ReadOnlySharedMemoryRegion RenderPdfPagesToPwgRaster(
if (!region_mapping.IsValid()) if (!region_mapping.IsValid())
return invalid_pwg_region; return invalid_pwg_region;
*page_count = total_page_count;
memcpy(region_mapping.mapping.memory(), pwg_data.data(), pwg_data.size()); memcpy(region_mapping.mapping.memory(), pwg_data.data(), pwg_data.size());
return std::move(region_mapping.region); return std::move(region_mapping.region);
} }
...@@ -118,8 +120,10 @@ void PdfToPwgRasterConverter::Convert( ...@@ -118,8 +120,10 @@ void PdfToPwgRasterConverter::Convert(
const PdfRenderSettings& pdf_settings, const PdfRenderSettings& pdf_settings,
const PwgRasterSettings& pwg_raster_settings, const PwgRasterSettings& pwg_raster_settings,
ConvertCallback callback) { ConvertCallback callback) {
std::move(callback).Run(RenderPdfPagesToPwgRaster( uint32_t page_count = 0;
std::move(pdf_region), pdf_settings, pwg_raster_settings)); base::ReadOnlySharedMemoryRegion region = RenderPdfPagesToPwgRaster(
std::move(pdf_region), pdf_settings, pwg_raster_settings, &page_count);
std::move(callback).Run(std::move(region), page_count);
} }
} // namespace printing } // namespace printing
...@@ -32,5 +32,6 @@ interface PdfToPwgRasterConverter { ...@@ -32,5 +32,6 @@ interface PdfToPwgRasterConverter {
Convert(mojo_base.mojom.ReadOnlySharedMemoryRegion pdf_region, Convert(mojo_base.mojom.ReadOnlySharedMemoryRegion pdf_region,
PdfRenderSettings pdf_settings, PdfRenderSettings pdf_settings,
PwgRasterSettings pwg_raster_settings) PwgRasterSettings pwg_raster_settings)
=> (mojo_base.mojom.ReadOnlySharedMemoryRegion? pwg_raster_region); => (mojo_base.mojom.ReadOnlySharedMemoryRegion? pwg_raster_region,
uint32 page_count);
}; };
...@@ -73411,6 +73411,14 @@ uploading your change for review. ...@@ -73411,6 +73411,14 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="Printing.ConversionSize.Pwg" units="KB">
<owner>thestig@chromium.org</owner>
<summary>
On desktop, the average size of a printed page after converting to PWG
Raster format.
</summary>
</histogram>
<histogram name="Printing.CUPS.AddressResolutionResult" enum="BooleanSuccess"> <histogram name="Printing.CUPS.AddressResolutionResult" enum="BooleanSuccess">
<owner>skau@chromium.org</owner> <owner>skau@chromium.org</owner>
<summary> <summary>
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