Commit f73d2bc1 authored by Luum Habtemariam's avatar Luum Habtemariam Committed by Commit Bot

Added CupsProxyServiceDelegate

Added delegate provides the service with necessary Chrome printing stack
dependencies, i.e. hooks to the CupsPrintersManager/PrinterConfigurer.

Also adds a helpful fake for unit testing.

Bug: chromium:945409
Test: none
Change-Id: I6bb02592993fd6bb22b33240b2ae8d6e332304cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1621326
Commit-Queue: Luum Habtemariam <luum@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663942}
parent e03e11bf
......@@ -12,6 +12,8 @@ source_set("cups_proxy") {
sources = [
"cups_proxy_service.cpp",
"cups_proxy_service.h",
"cups_proxy_service_delegate.cc",
"cups_proxy_service_delegate.h",
]
deps = [
......@@ -32,3 +34,15 @@ source_set("cups_proxy") {
"//printing",
]
}
static_library("test_support") {
testonly = true
sources = [
"fake_cups_proxy_service_delegate.cc",
"fake_cups_proxy_service_delegate.h",
]
public_deps = [
":cups_proxy",
]
}
include_rules = [
"+chromeos/printing",
]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/services/cups_proxy/cups_proxy_service_delegate.h"
#include <memory>
#include <string>
#include "base/memory/weak_ptr.h"
namespace chromeos {
namespace printing {
CupsProxyServiceDelegate::CupsProxyServiceDelegate() : weak_factory_(this) {}
CupsProxyServiceDelegate::~CupsProxyServiceDelegate() = default;
base::WeakPtr<CupsProxyServiceDelegate> CupsProxyServiceDelegate::GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
} // namespace printing
} // namespace chromeos
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_SERVICES_CUPS_PROXY_CUPS_PROXY_SERVICE_DELEGATE_H_
#define CHROME_SERVICES_CUPS_PROXY_CUPS_PROXY_SERVICE_DELEGATE_H_
#include <memory>
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/printing/printer_configuration.h"
namespace chromeos {
namespace printing {
using PrinterSetupCallback = base::OnceCallback<void(bool)>;
// This delegate grants the CupsProxyService access to the Chrome printing
// stack. This class can be created anywhere but must be accessed from a
// sequenced context.
class CupsProxyServiceDelegate {
public:
CupsProxyServiceDelegate();
virtual ~CupsProxyServiceDelegate();
// Exposing |weak_factory_|.GetWeakPtr method. Needed to share delegate with
// CupsProxyService internal managers.
base::WeakPtr<CupsProxyServiceDelegate> GetWeakPtr();
virtual std::vector<chromeos::Printer> GetPrinters() = 0;
virtual base::Optional<chromeos::Printer> GetPrinter(
const std::string& id) = 0;
virtual bool IsPrinterInstalled(const Printer& printer) = 0;
// |cb| will be run on this delegate's sequenced context.
virtual void SetupPrinter(const Printer& printer,
PrinterSetupCallback cb) = 0;
private:
base::WeakPtrFactory<CupsProxyServiceDelegate> weak_factory_;
};
} // namespace printing
} // namespace chromeos
#endif // CHROME_SERVICES_CUPS_PROXY_CUPS_PROXY_SERVICE_DELEGATE_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/services/cups_proxy/fake_cups_proxy_service_delegate.h"
namespace chromeos {
namespace printing {
std::vector<chromeos::Printer> FakeCupsProxyServiceDelegate::GetPrinters() {
return {};
}
base::Optional<chromeos::Printer> FakeCupsProxyServiceDelegate::GetPrinter(
const std::string& id) {
return base::nullopt;
}
bool FakeCupsProxyServiceDelegate::IsPrinterInstalled(const Printer& printer) {
return false;
}
void FakeCupsProxyServiceDelegate::SetupPrinter(const Printer& printer,
PrinterSetupCallback cb) {}
} // namespace printing
} // namespace chromeos
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_SERVICES_CUPS_PROXY_FAKE_CUPS_PROXY_SERVICE_DELEGATE_H_
#define CHROME_SERVICES_CUPS_PROXY_FAKE_CUPS_PROXY_SERVICE_DELEGATE_H_
#include <memory>
#include <string>
#include <vector>
#include "chrome/services/cups_proxy/cups_proxy_service_delegate.h"
#include "chromeos/printing/printer_configuration.h"
namespace chromeos {
namespace printing {
// Fake implementation for use in unit_tests.
class FakeCupsProxyServiceDelegate : public CupsProxyServiceDelegate {
public:
FakeCupsProxyServiceDelegate() = default;
~FakeCupsProxyServiceDelegate() override = default;
// CupsProxyServiceDelegate overrides.
std::vector<chromeos::Printer> GetPrinters() override;
base::Optional<chromeos::Printer> GetPrinter(const std::string& id) override;
bool IsPrinterInstalled(const Printer& printer) override;
void SetupPrinter(const Printer& printer, PrinterSetupCallback cb) override;
};
} // namespace printing
} // namespace chromeos
#endif // CHROME_SERVICES_CUPS_PROXY_FAKE_CUPS_PROXY_SERVICE_DELEGATE_H_
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