Commit 538d022b authored by Vladislav Kuzkokov's avatar Vladislav Kuzkokov Committed by Commit Bot

Make ServerPrintersProvider a service.

This is required so it could be used separately from
CupsPrintersProvider.

Bug: 1060700
Change-Id: Ie5b6c655ca74a325bffaf02849dba6a90eb12554
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2127031Reviewed-by: default avatarPiotr Pawliczek <pawliczek@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Commit-Queue: Vladislav Kuzkokov <vkuzkokov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758803}
parent 25f7d5c9
...@@ -2189,6 +2189,8 @@ source_set("chromeos") { ...@@ -2189,6 +2189,8 @@ source_set("chromeos") {
"printing/server_printers_fetcher.h", "printing/server_printers_fetcher.h",
"printing/server_printers_provider.cc", "printing/server_printers_provider.cc",
"printing/server_printers_provider.h", "printing/server_printers_provider.h",
"printing/server_printers_provider_factory.cc",
"printing/server_printers_provider_factory.h",
"printing/specifics_translation.cc", "printing/specifics_translation.cc",
"printing/specifics_translation.h", "printing/specifics_translation.h",
"printing/synced_printers_manager.cc", "printing/synced_printers_manager.cc",
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "chrome/browser/chromeos/printing/printer_event_tracker_factory.h" #include "chrome/browser/chromeos/printing/printer_event_tracker_factory.h"
#include "chrome/browser/chromeos/printing/printers_map.h" #include "chrome/browser/chromeos/printing/printers_map.h"
#include "chrome/browser/chromeos/printing/server_printers_provider.h" #include "chrome/browser/chromeos/printing/server_printers_provider.h"
#include "chrome/browser/chromeos/printing/server_printers_provider_factory.h"
#include "chrome/browser/chromeos/printing/synced_printers_manager.h" #include "chrome/browser/chromeos/printing/synced_printers_manager.h"
#include "chrome/browser/chromeos/printing/synced_printers_manager_factory.h" #include "chrome/browser/chromeos/printing/synced_printers_manager_factory.h"
#include "chrome/browser/chromeos/printing/usb_printer_detector.h" #include "chrome/browser/chromeos/printing/usb_printer_detector.h"
...@@ -62,7 +63,7 @@ class CupsPrintersManagerImpl ...@@ -62,7 +63,7 @@ class CupsPrintersManagerImpl
std::unique_ptr<PrinterConfigurer> printer_configurer, std::unique_ptr<PrinterConfigurer> printer_configurer,
std::unique_ptr<UsbPrinterNotificationController> std::unique_ptr<UsbPrinterNotificationController>
usb_notification_controller, usb_notification_controller,
std::unique_ptr<ServerPrintersProvider> server_printers_provider, ServerPrintersProvider* server_printers_provider,
std::unique_ptr<EnterprisePrintersProvider> enterprise_printers_provider, std::unique_ptr<EnterprisePrintersProvider> enterprise_printers_provider,
PrinterEventTracker* event_tracker, PrinterEventTracker* event_tracker,
PrefService* pref_service) PrefService* pref_service)
...@@ -75,7 +76,7 @@ class CupsPrintersManagerImpl ...@@ -75,7 +76,7 @@ class CupsPrintersManagerImpl
auto_usb_printer_configurer_(std::move(printer_configurer), auto_usb_printer_configurer_(std::move(printer_configurer),
this, this,
usb_notification_controller_.get()), usb_notification_controller_.get()),
server_printers_provider_(std::move(server_printers_provider)), server_printers_provider_(server_printers_provider),
enterprise_printers_provider_(std::move(enterprise_printers_provider)), enterprise_printers_provider_(std::move(enterprise_printers_provider)),
enterprise_printers_provider_observer_(this), enterprise_printers_provider_observer_(this),
event_tracker_(event_tracker) { event_tracker_(event_tracker) {
...@@ -529,7 +530,8 @@ class CupsPrintersManagerImpl ...@@ -529,7 +530,8 @@ class CupsPrintersManagerImpl
AutomaticUsbPrinterConfigurer auto_usb_printer_configurer_; AutomaticUsbPrinterConfigurer auto_usb_printer_configurer_;
std::unique_ptr<ServerPrintersProvider> server_printers_provider_; // Not owned.
ServerPrintersProvider* server_printers_provider_;
std::unique_ptr<EnterprisePrintersProvider> enterprise_printers_provider_; std::unique_ptr<EnterprisePrintersProvider> enterprise_printers_provider_;
ScopedObserver<EnterprisePrintersProvider, ScopedObserver<EnterprisePrintersProvider,
...@@ -577,7 +579,8 @@ std::unique_ptr<CupsPrintersManager> CupsPrintersManager::Create( ...@@ -577,7 +579,8 @@ std::unique_ptr<CupsPrintersManager> CupsPrintersManager::Create(
UsbPrinterDetector::Create(), ZeroconfPrinterDetector::Create(), UsbPrinterDetector::Create(), ZeroconfPrinterDetector::Create(),
CreatePpdProvider(profile), PrinterConfigurer::Create(profile), CreatePpdProvider(profile), PrinterConfigurer::Create(profile),
UsbPrinterNotificationController::Create(profile), UsbPrinterNotificationController::Create(profile),
ServerPrintersProvider::Create(profile), ServerPrintersProviderFactory::GetInstance()->GetForBrowserContext(
profile),
EnterprisePrintersProvider::Create(CrosSettings::Get(), profile), EnterprisePrintersProvider::Create(CrosSettings::Get(), profile),
PrinterEventTrackerFactory::GetInstance()->GetForBrowserContext(profile), PrinterEventTrackerFactory::GetInstance()->GetForBrowserContext(profile),
profile->GetPrefs()); profile->GetPrefs());
...@@ -592,7 +595,7 @@ std::unique_ptr<CupsPrintersManager> CupsPrintersManager::CreateForTesting( ...@@ -592,7 +595,7 @@ std::unique_ptr<CupsPrintersManager> CupsPrintersManager::CreateForTesting(
std::unique_ptr<PrinterConfigurer> printer_configurer, std::unique_ptr<PrinterConfigurer> printer_configurer,
std::unique_ptr<UsbPrinterNotificationController> std::unique_ptr<UsbPrinterNotificationController>
usb_notification_controller, usb_notification_controller,
std::unique_ptr<ServerPrintersProvider> server_printers_provider, ServerPrintersProvider* server_printers_provider,
std::unique_ptr<EnterprisePrintersProvider> enterprise_printers_provider, std::unique_ptr<EnterprisePrintersProvider> enterprise_printers_provider,
PrinterEventTracker* event_tracker, PrinterEventTracker* event_tracker,
PrefService* pref_service) { PrefService* pref_service) {
...@@ -600,8 +603,8 @@ std::unique_ptr<CupsPrintersManager> CupsPrintersManager::CreateForTesting( ...@@ -600,8 +603,8 @@ std::unique_ptr<CupsPrintersManager> CupsPrintersManager::CreateForTesting(
synced_printers_manager, std::move(usb_detector), synced_printers_manager, std::move(usb_detector),
std::move(zeroconf_detector), std::move(ppd_provider), std::move(zeroconf_detector), std::move(ppd_provider),
std::move(printer_configurer), std::move(usb_notification_controller), std::move(printer_configurer), std::move(usb_notification_controller),
std::move(server_printers_provider), server_printers_provider, std::move(enterprise_printers_provider),
std::move(enterprise_printers_provider), event_tracker, pref_service); event_tracker, pref_service);
} }
// static // static
......
...@@ -65,7 +65,7 @@ class CupsPrintersManager : public PrinterInstallationManager, ...@@ -65,7 +65,7 @@ class CupsPrintersManager : public PrinterInstallationManager,
std::unique_ptr<PrinterConfigurer> printer_configurer, std::unique_ptr<PrinterConfigurer> printer_configurer,
std::unique_ptr<UsbPrinterNotificationController> std::unique_ptr<UsbPrinterNotificationController>
usb_notification_controller, usb_notification_controller,
std::unique_ptr<ServerPrintersProvider> server_printers_provider, ServerPrintersProvider* server_printers_provider,
std::unique_ptr<EnterprisePrintersProvider> enterprise_printers_provider, std::unique_ptr<EnterprisePrintersProvider> enterprise_printers_provider,
PrinterEventTracker* event_tracker, PrinterEventTracker* event_tracker,
PrefService* pref_service); PrefService* pref_service);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "chrome/browser/chromeos/printing/cups_printers_manager.h" #include "chrome/browser/chromeos/printing/cups_printers_manager.h"
#include "chrome/browser/chromeos/printing/cups_printers_manager_proxy.h" #include "chrome/browser/chromeos/printing/cups_printers_manager_proxy.h"
#include "chrome/browser/chromeos/printing/server_printers_provider_factory.h"
#include "chrome/browser/chromeos/printing/synced_printers_manager_factory.h" #include "chrome/browser/chromeos/printing/synced_printers_manager_factory.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/incognito_helpers.h"
...@@ -32,6 +33,7 @@ CupsPrintersManagerFactory::CupsPrintersManagerFactory() ...@@ -32,6 +33,7 @@ CupsPrintersManagerFactory::CupsPrintersManagerFactory()
"CupsPrintersManagerFactory", "CupsPrintersManagerFactory",
BrowserContextDependencyManager::GetInstance()), BrowserContextDependencyManager::GetInstance()),
proxy_(CupsPrintersManagerProxy::Create()) { proxy_(CupsPrintersManagerProxy::Create()) {
DependsOn(chromeos::ServerPrintersProviderFactory::GetInstance());
DependsOn(chromeos::SyncedPrintersManagerFactory::GetInstance()); DependsOn(chromeos::SyncedPrintersManagerFactory::GetInstance());
} }
......
...@@ -357,9 +357,6 @@ class CupsPrintersManagerTest : public testing::Test, ...@@ -357,9 +357,6 @@ class CupsPrintersManagerTest : public testing::Test,
auto usb_notif_controller = auto usb_notif_controller =
std::make_unique<FakeUsbPrinterNotificationController>(); std::make_unique<FakeUsbPrinterNotificationController>();
usb_notif_controller_ = usb_notif_controller.get(); usb_notif_controller_ = usb_notif_controller.get();
auto server_printers_provider =
std::make_unique<FakeServerPrintersProvider>();
server_printers_provider_ = server_printers_provider.get();
auto enterprise_printers_provider = auto enterprise_printers_provider =
std::make_unique<FakeEnterprisePrintersProvider>(); std::make_unique<FakeEnterprisePrintersProvider>();
enterprise_printers_provider_ = enterprise_printers_provider.get(); enterprise_printers_provider_ = enterprise_printers_provider.get();
...@@ -371,9 +368,8 @@ class CupsPrintersManagerTest : public testing::Test, ...@@ -371,9 +368,8 @@ class CupsPrintersManagerTest : public testing::Test,
&synced_printers_manager_, std::move(usb_detector), &synced_printers_manager_, std::move(usb_detector),
std::move(zeroconf_detector), ppd_provider_, std::move(zeroconf_detector), ppd_provider_,
std::move(printer_configurer), std::move(usb_notif_controller), std::move(printer_configurer), std::move(usb_notif_controller),
std::move(server_printers_provider), &server_printers_provider_, std::move(enterprise_printers_provider),
std::move(enterprise_printers_provider), &event_tracker_, &event_tracker_, &pref_service_);
&pref_service_);
manager_->AddObserver(this); manager_->AddObserver(this);
} }
...@@ -414,7 +410,7 @@ class CupsPrintersManagerTest : public testing::Test, ...@@ -414,7 +410,7 @@ class CupsPrintersManagerTest : public testing::Test,
FakePrinterDetector* zeroconf_detector_; // Not owned. FakePrinterDetector* zeroconf_detector_; // Not owned.
TestPrinterConfigurer* printer_configurer_; // Not owned. TestPrinterConfigurer* printer_configurer_; // Not owned.
FakeUsbPrinterNotificationController* usb_notif_controller_; // Not owned. FakeUsbPrinterNotificationController* usb_notif_controller_; // Not owned.
FakeServerPrintersProvider* server_printers_provider_; // Not owned. FakeServerPrintersProvider server_printers_provider_;
scoped_refptr<FakePpdProvider> ppd_provider_; scoped_refptr<FakePpdProvider> ppd_provider_;
// This is unused, it's just here for memory ownership. // This is unused, it's just here for memory ownership.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/chromeos/printing/printer_detector.h" #include "chrome/browser/chromeos/printing/printer_detector.h"
#include "components/keyed_service/core/keyed_service.h"
class Profile; class Profile;
...@@ -21,11 +22,11 @@ namespace chromeos { ...@@ -21,11 +22,11 @@ namespace chromeos {
// printers are signaled through a callback registered with the method // printers are signaled through a callback registered with the method
// RegisterPrintersFoundCallback(...). All methods must be called from the UI // RegisterPrintersFoundCallback(...). All methods must be called from the UI
// sequence, the callback is also called from this sequence. // sequence, the callback is also called from this sequence.
class ServerPrintersProvider { class ServerPrintersProvider : public KeyedService {
public: public:
// |profile| is a user profile, it cannot be nullptr. // |profile| is a user profile, it cannot be nullptr.
static std::unique_ptr<ServerPrintersProvider> Create(Profile* profile); static std::unique_ptr<ServerPrintersProvider> Create(Profile* profile);
virtual ~ServerPrintersProvider() = default; ~ServerPrintersProvider() override = default;
using OnPrintersUpdateCallback = base::RepeatingCallback<void(bool complete)>; using OnPrintersUpdateCallback = base::RepeatingCallback<void(bool complete)>;
......
// Copyright 2020 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/browser/chromeos/printing/server_printers_provider_factory.h"
#include "base/no_destructor.h"
#include "chrome/browser/chromeos/printing/server_printers_provider.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace chromeos {
// static
ServerPrintersProviderFactory* ServerPrintersProviderFactory::GetInstance() {
static base::NoDestructor<ServerPrintersProviderFactory> instance;
return instance.get();
}
// static
ServerPrintersProvider* ServerPrintersProviderFactory::GetForBrowserContext(
content::BrowserContext* context) {
return static_cast<ServerPrintersProvider*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}
ServerPrintersProviderFactory::ServerPrintersProviderFactory()
: BrowserContextKeyedServiceFactory(
"ServerPrintersProviderFactory",
BrowserContextDependencyManager::GetInstance()) {}
ServerPrintersProviderFactory::~ServerPrintersProviderFactory() = default;
KeyedService* ServerPrintersProviderFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
auto* profile = Profile::FromBrowserContext(context);
return ServerPrintersProvider::Create(profile).release();
}
content::BrowserContext* ServerPrintersProviderFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
bool ServerPrintersProviderFactory::ServiceIsNULLWhileTesting() const {
return true;
}
} // namespace chromeos
// Copyright 2020 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_BROWSER_CHROMEOS_PRINTING_SERVER_PRINTERS_PROVIDER_FACTORY_H_
#define CHROME_BROWSER_CHROMEOS_PRINTING_SERVER_PRINTERS_PROVIDER_FACTORY_H_
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace content {
class BrowserContext;
}
namespace base {
template <typename T>
class NoDestructor;
}
namespace chromeos {
class ServerPrintersProvider;
class ServerPrintersProviderFactory : public BrowserContextKeyedServiceFactory {
public:
static ServerPrintersProviderFactory* GetInstance();
static ServerPrintersProvider* GetForBrowserContext(
content::BrowserContext* context);
private:
friend class base::NoDestructor<ServerPrintersProviderFactory>;
ServerPrintersProviderFactory();
~ServerPrintersProviderFactory() override;
// BrowserContextKeyedServiceFactory overrides:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
bool ServiceIsNULLWhileTesting() const override;
DISALLOW_COPY_AND_ASSIGN(ServerPrintersProviderFactory);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_PRINTING_SERVER_PRINTERS_PROVIDER_FACTORY_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