Commit 77ddcddc authored by justincarlson's avatar justincarlson Committed by Commit Bot

Remove the legacy (extension-notifier) usb printer detector.

Also, Rename the remaining printerdetector with the less prefix 'Usb' in preparation for other work on printer detection.

BUG=734161

Review-Url: https://codereview.chromium.org/2945653002
Cr-Commit-Position: refs/heads/master@{#480267}
parent ba7d2a42
...@@ -1247,11 +1247,10 @@ source_set("chromeos") { ...@@ -1247,11 +1247,10 @@ source_set("chromeos") {
"power/renderer_freezer.h", "power/renderer_freezer.h",
"preferences.cc", "preferences.cc",
"preferences.h", "preferences.h",
"printer_detector/cups_printer_detector.cc", "printer_detector/usb_printer_detector.cc",
"printer_detector/legacy_printer_detector.cc", "printer_detector/usb_printer_detector.h",
"printer_detector/printer_detector.h", "printer_detector/usb_printer_detector_factory.cc",
"printer_detector/printer_detector_factory.cc", "printer_detector/usb_printer_detector_factory.h",
"printer_detector/printer_detector_factory.h",
"printing/cups_print_job.cc", "printing/cups_print_job.cc",
"printing/cups_print_job.h", "printing/cups_print_job.h",
"printing/cups_print_job_manager.cc", "printing/cups_print_job_manager.cc",
...@@ -1768,7 +1767,6 @@ source_set("unit_tests") { ...@@ -1768,7 +1767,6 @@ source_set("unit_tests") {
"power/power_prefs_unittest.cc", "power/power_prefs_unittest.cc",
"power/renderer_freezer_unittest.cc", "power/renderer_freezer_unittest.cc",
"preferences_unittest.cc", "preferences_unittest.cc",
"printer_detector/printer_detector_unittest.cc",
"printing/printers_manager_unittest.cc", "printing/printers_manager_unittest.cc",
"printing/specifics_translation_unittest.cc", "printing/specifics_translation_unittest.cc",
"profiles/profile_list_chromeos_unittest.cc", "profiles/profile_list_chromeos_unittest.cc",
......
// Copyright 2015 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 <stdint.h>
#include <memory>
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/macros.h"
#include "base/metrics/histogram_macros.h"
#include "base/scoped_observer.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/printer_detector/printer_detector.h"
#include "chrome/browser/chromeos/printing/usb_printer_util.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_delegate.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/common/extensions/api/webstore_widget_private.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "device/base/device_client.h"
#include "device/usb/usb_device.h"
#include "device/usb/usb_ids.h"
#include "device/usb/usb_service.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/api/printer_provider/usb_printer_manifest_data.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/one_shot_event.h"
#include "extensions/common/permissions/api_permission.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/permissions/usb_device_permission.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
namespace webstore_widget_private_api =
extensions::api::webstore_widget_private;
namespace chromeos {
namespace {
const char kPrinterProviderFoundNotificationID[] =
"chrome://settings/printer/printer_app_found";
const char kNoPrinterProviderNotificationID[] =
"chrome://settings/printer/no_printer_app";
enum PrinterServiceEvent {
PRINTER_ADDED,
DEPRECATED_PAGE_DISPLAYED,
NOTIFICATION_SHOWN_PRINTER_SUPPORTED,
NOTIFICATION_SHOWN_PRINTER_NOT_SUPPORTED,
WEBSTORE_WIDGET_APP_LAUNCHED,
PRINTER_SERVICE_EVENT_MAX,
};
base::string16 GetNotificationTitle(uint16_t vendor_id, uint16_t product_id) {
const char* vendor_name = device::UsbIds::GetVendorName(vendor_id);
if (vendor_name) {
return l10n_util::GetStringFUTF16(IDS_PRINTER_DETECTED_NOTIFICATION_TITLE,
base::UTF8ToUTF16(vendor_name));
} else {
return l10n_util::GetStringUTF16(
IDS_PRINTER_DETECTED_NOTIFICATION_TITLE_UNKNOWN_VENDOR);
}
}
std::string GetNotificationTag(const std::string& vendor_id,
const std::string& product_id) {
return vendor_id + ":" + product_id;
}
// Checks if there is an enabled extension with printerProvider permission and
// usbDevices persmission for the USB (vendor_id, product_id) pair.
bool HasAppThatSupportsPrinter(Profile* profile,
const scoped_refptr<device::UsbDevice>& device) {
const extensions::ExtensionSet& enabled_extensions =
extensions::ExtensionRegistry::Get(profile)->enabled_extensions();
for (const auto& extension : enabled_extensions) {
if (!extension->permissions_data() ||
!extension->permissions_data()->HasAPIPermission(
extensions::APIPermission::kPrinterProvider) ||
!extension->permissions_data()->HasAPIPermission(
extensions::APIPermission::kUsb)) {
continue;
}
const extensions::UsbPrinterManifestData* manifest_data =
extensions::UsbPrinterManifestData::Get(extension.get());
if (manifest_data && manifest_data->SupportsDevice(*device)) {
return true;
}
std::unique_ptr<extensions::UsbDevicePermission::CheckParam> param =
extensions::UsbDevicePermission::CheckParam::ForUsbDevice(
extension.get(), device.get());
if (extension->permissions_data()->CheckAPIPermissionWithParam(
extensions::APIPermission::kUsbDevice, param.get())) {
return true;
}
}
return false;
}
// Delegate for notification shown when a printer provider app for the plugged
// in printer is found.
class PrinterProviderExistsNotificationDelegate : public NotificationDelegate {
public:
PrinterProviderExistsNotificationDelegate(const std::string& vendor_id,
const std::string& product_id)
: vendor_id_(vendor_id), product_id_(product_id) {}
std::string id() const override {
return "system.printer.printer_provider_exists/" +
GetNotificationTag(vendor_id_, product_id_);
}
private:
~PrinterProviderExistsNotificationDelegate() override = default;
const std::string vendor_id_;
const std::string product_id_;
DISALLOW_COPY_AND_ASSIGN(PrinterProviderExistsNotificationDelegate);
};
// Delegate for notification shown when there are no printer provider apps that
// support the plugged in printer found.
// The notification is clickable, and clicking it is supposed to launch
// Chrome Web Store widget listing apps that can support the plugged in printer.
// (not implemented yet).
class SearchPrinterAppNotificationDelegate : public NotificationDelegate {
public:
SearchPrinterAppNotificationDelegate(content::BrowserContext* browser_context,
uint16_t vendor_id,
const std::string& vendor_id_str,
uint16_t product_id,
const std::string& product_id_str)
: browser_context_(browser_context),
vendor_id_(vendor_id),
vendor_id_str_(vendor_id_str),
product_id_(product_id),
product_id_str_(product_id_str) {}
std::string id() const override {
return "system.printer.no_printer_provider_found/" +
GetNotificationTag(vendor_id_str_, product_id_str_);
}
bool HasClickedListener() override { return true; }
void Click() override {
UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent",
WEBSTORE_WIDGET_APP_LAUNCHED,
PRINTER_SERVICE_EVENT_MAX);
webstore_widget_private_api::Options options;
options.type = webstore_widget_private_api::TYPE_PRINTER_PROVIDER;
options.usb_id.reset(new webstore_widget_private_api::UsbId());
options.usb_id->vendor_id = vendor_id_;
options.usb_id->product_id = product_id_;
extensions::EventRouter* event_router =
extensions::EventRouter::Get(browser_context_);
std::unique_ptr<extensions::Event> event(new extensions::Event(
extensions::events::WEBSTORE_WIDGET_PRIVATE_ON_SHOW_WIDGET,
webstore_widget_private_api::OnShowWidget::kEventName,
webstore_widget_private_api::OnShowWidget::Create(options)));
event_router->DispatchEventToExtension(extension_misc::kWebstoreWidgetAppId,
std::move(event));
}
private:
~SearchPrinterAppNotificationDelegate() override = default;
content::BrowserContext* browser_context_;
uint16_t vendor_id_;
std::string vendor_id_str_;
uint16_t product_id_;
std::string product_id_str_;
DISALLOW_COPY_AND_ASSIGN(SearchPrinterAppNotificationDelegate);
};
// The PrinterDetector that initiates extension-based USB printer setup:
//
// * if there is a printer provider extension for a detected USB printer
// installed, it shows a notification informing the user the printer is ready to
// be used.
//
// * otherwise, it shows a notification offering the user an option to install a
// printer provider extension for the printer from the Chrome Web Store.
//
// TODO(justincarlson) - Remove this implementation when CUPS support is enabled
// by default.
class LegacyPrinterDetectorImpl : public PrinterDetector,
public device::UsbService::Observer {
public:
explicit LegacyPrinterDetectorImpl(Profile* profile)
: profile_(profile),
notification_ui_manager_(nullptr),
observer_(this),
weak_ptr_factory_(this) {
extensions::ExtensionSystem::Get(profile)->ready().Post(
FROM_HERE, base::Bind(&LegacyPrinterDetectorImpl::Initialize,
weak_ptr_factory_.GetWeakPtr()));
}
~LegacyPrinterDetectorImpl() override = default;
private:
// UsbService::observer override:
void OnDeviceAdded(scoped_refptr<device::UsbDevice> device) override {
const user_manager::User* user =
ProfileHelper::Get()->GetUserByProfile(profile_);
if (!user || !user->HasGaiaAccount() || !user_manager::UserManager::Get() ||
user != user_manager::UserManager::Get()->GetActiveUser()) {
return;
}
if (!UsbDeviceIsPrinter(*device)) {
return;
}
if (notification_ui_manager_ == nullptr) {
notification_ui_manager_ = g_browser_process->notification_ui_manager();
}
UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent",
PRINTER_ADDED, PRINTER_SERVICE_EVENT_MAX);
ShowPrinterPluggedNotification(device);
}
// Initializes the printer detector.
void Initialize() {
device::UsbService* usb_service =
device::DeviceClient::Get()->GetUsbService();
if (!usb_service)
return;
observer_.Add(usb_service);
}
void SetNotificationUIManagerForTesting(
NotificationUIManager* manager) override {
notification_ui_manager_ = manager;
}
// Shows a notification for a plugged in printer.
// If there is a printerProvider app that handles the printer's USB
// (vendor_id, product_id) pair, the notification informs the user that the
// printer is ready to be used, otherwise it offers the user to search the
// Chrome Web Store for an app that can handle the printer.
void ShowPrinterPluggedNotification(
const scoped_refptr<device::UsbDevice>& device) {
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
std::unique_ptr<Notification> notification;
const std::string kVendorIdStr = base::IntToString(device->vendor_id());
const std::string kProductIdStr = base::IntToString(device->product_id());
if (HasAppThatSupportsPrinter(profile_, device)) {
UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent",
NOTIFICATION_SHOWN_PRINTER_SUPPORTED,
PRINTER_SERVICE_EVENT_MAX);
notification.reset(new Notification(
message_center::NOTIFICATION_TYPE_SIMPLE,
GetNotificationTitle(device->vendor_id(), device->product_id()),
l10n_util::GetStringUTF16(
IDS_PRINTER_DETECTED_NOTIFICATION_PRINT_APP_FOUND_BODY),
bundle.GetImageNamed(IDR_PRINTER_NOTIFICATION),
message_center::NotifierId(
message_center::NotifierId::SYSTEM_COMPONENT,
kPrinterProviderFoundNotificationID),
base::string16(), GURL(kPrinterProviderFoundNotificationID),
GetNotificationTag(kVendorIdStr, kProductIdStr),
message_center::RichNotificationData(),
new PrinterProviderExistsNotificationDelegate(kVendorIdStr,
kProductIdStr)));
} else {
UMA_HISTOGRAM_ENUMERATION("PrinterService.PrinterServiceEvent",
NOTIFICATION_SHOWN_PRINTER_NOT_SUPPORTED,
PRINTER_SERVICE_EVENT_MAX);
message_center::RichNotificationData options;
options.clickable = true;
notification.reset(new Notification(
message_center::NOTIFICATION_TYPE_SIMPLE,
GetNotificationTitle(device->vendor_id(), device->product_id()),
l10n_util::GetStringUTF16(
IDS_PRINTER_DETECTED_NOTIFICATION_NO_PRINT_APP_BODY),
bundle.GetImageNamed(IDR_PRINTER_NOTIFICATION),
message_center::NotifierId(
message_center::NotifierId::SYSTEM_COMPONENT,
kNoPrinterProviderNotificationID),
base::string16(), GURL(kNoPrinterProviderNotificationID),
GetNotificationTag(kVendorIdStr, kProductIdStr), options,
new SearchPrinterAppNotificationDelegate(
profile_, device->vendor_id(), kVendorIdStr, device->product_id(),
kProductIdStr)));
}
notification->SetSystemPriority();
notification_ui_manager_->Add(*notification, profile_);
}
std::unique_ptr<Notification> notification_;
Profile* profile_;
NotificationUIManager* notification_ui_manager_;
ScopedObserver<device::UsbService, device::UsbService::Observer> observer_;
base::WeakPtrFactory<LegacyPrinterDetectorImpl> weak_ptr_factory_;
};
} // namespace
// static
std::unique_ptr<PrinterDetector> PrinterDetector::CreateLegacy(
Profile* profile) {
return base::MakeUnique<LegacyPrinterDetectorImpl>(profile);
}
} // namespace chromeos
// Copyright (c) 2012 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/printer_detector/printer_detector.h"
#include <stdint.h>
#include <memory>
#include <utility>
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
#include "chrome/browser/chromeos/printer_detector/printer_detector_factory.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_test_util.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "device/base/mock_device_client.h"
#include "device/usb/mock_usb_device.h"
#include "device/usb/mock_usb_service.h"
#include "device/usb/usb_descriptors.h"
#include "device/usb/usb_service.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/value_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
using extensions::DictionaryBuilder;
using extensions::ListBuilder;
namespace chromeos {
namespace {
const uint8_t kPrinterInterfaceClass = 7;
const char kTestUserId[] = "test_user";
const char kPrinterAppExistsDelegateIDTemplate[] =
"system.printer.printer_provider_exists/%s:%s";
const char kPrinterAppNotFoundDelegateIDTemplate[] =
"system.printer.no_printer_provider_found/%s:%s";
std::unique_ptr<KeyedService> CreatePrinterDetector(
content::BrowserContext* context) {
return PrinterDetector::CreateLegacy(Profile::FromBrowserContext(context));
}
} // namespace
// TODO(tbarzic): Rename this test.
class PrinterDetectorAppSearchEnabledTest : public testing::Test {
public:
PrinterDetectorAppSearchEnabledTest()
: user_manager_(new chromeos::FakeChromeUserManager()),
user_manager_enabler_(user_manager_) {}
~PrinterDetectorAppSearchEnabledTest() override = default;
void SetUp() override {
device_client_.GetUsbService();
// Make sure the profile is created after adding the switch and setting up
// device client.
profile_.reset(new TestingProfile());
chromeos::PrinterDetectorFactory::GetInstance()->SetTestingFactoryAndUse(
profile_.get(), &CreatePrinterDetector);
AddTestUser();
SetExtensionSystemReady(profile_.get());
}
protected:
void SetExtensionSystemReady(TestingProfile* profile) {
extensions::TestExtensionSystem* test_extension_system =
static_cast<extensions::TestExtensionSystem*>(
extensions::ExtensionSystem::Get(profile));
test_extension_system->SetReady();
base::RunLoop().RunUntilIdle();
}
void AddTestUser() {
const user_manager::User* user =
user_manager_->AddUser(AccountId::FromUserEmail(kTestUserId));
profile_->set_profile_name(kTestUserId);
chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(
user, profile_.get());
chromeos::PrinterDetectorFactory::GetInstance()
->Get(profile_.get())
->SetNotificationUIManagerForTesting(&notification_ui_manager_);
}
void InvokeUsbAdded(uint16_t vendor_id,
uint16_t product_id,
uint8_t interface_class) {
device::UsbConfigDescriptor config(1, false, false, 0);
config.interfaces.emplace_back(1, 0, interface_class, 0, 0);
device_client_.usb_service()->AddDevice(
new device::MockUsbDevice(vendor_id, product_id, config));
}
// Creates a test extension with the provided permissions.
scoped_refptr<extensions::Extension> CreateTestExtension(
std::unique_ptr<base::ListValue> permissions_builder,
std::unique_ptr<base::DictionaryValue> usb_printers_builder) {
return extensions::ExtensionBuilder()
.SetID("fake_extension_id")
.SetManifest(
DictionaryBuilder()
.Set("name", "Printer provider extension")
.Set("manifest_version", 2)
.Set("version", "1.0")
// Needed to enable usb API.
.Set("app",
DictionaryBuilder()
.Set("background",
DictionaryBuilder()
.Set("scripts",
ListBuilder().Append("bg.js").Build())
.Build())
.Build())
.Set("permissions", std::move(permissions_builder))
.Set("usb_printers", std::move(usb_printers_builder))
.Build())
.Build();
}
content::TestBrowserThreadBundle thread_bundle_;
StubNotificationUIManager notification_ui_manager_;
chromeos::FakeChromeUserManager* user_manager_;
chromeos::ScopedUserManagerEnabler user_manager_enabler_;
device::MockDeviceClient device_client_;
std::unique_ptr<TestingProfile> profile_;
private:
DISALLOW_COPY_AND_ASSIGN(PrinterDetectorAppSearchEnabledTest);
};
TEST_F(PrinterDetectorAppSearchEnabledTest, ShowFindAppNotification) {
InvokeUsbAdded(123, 456, kPrinterInterfaceClass);
ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount());
const Notification& notification =
notification_ui_manager_.GetNotificationAt(0);
EXPECT_EQ("123:456", notification.tag());
EXPECT_EQ(
base::StringPrintf(kPrinterAppNotFoundDelegateIDTemplate, "123", "456"),
notification.delegate_id());
}
TEST_F(PrinterDetectorAppSearchEnabledTest, ShowAppFoundNotification) {
scoped_refptr<extensions::Extension> extension = CreateTestExtension(
ListBuilder()
.Append("usb")
.Append("printerProvider")
.Append(DictionaryBuilder()
.Set("usbDevices", ListBuilder()
.Append(DictionaryBuilder()
.Set("vendorId", 123)
.Set("productId", 456)
.Build())
.Build())
.Build())
.Build(),
DictionaryBuilder().Set("filters", ListBuilder().Build()).Build());
ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get())
->AddEnabled(extension));
InvokeUsbAdded(123, 456, kPrinterInterfaceClass);
ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount());
const Notification& notification =
notification_ui_manager_.GetNotificationAt(0);
EXPECT_EQ("123:456", notification.tag());
EXPECT_EQ(
base::StringPrintf(kPrinterAppExistsDelegateIDTemplate, "123", "456"),
notification.delegate_id());
}
TEST_F(PrinterDetectorAppSearchEnabledTest,
UsbHandlerExists_NotPrinterProvider) {
scoped_refptr<extensions::Extension> extension = CreateTestExtension(
ListBuilder()
.Append("usb")
.Append(DictionaryBuilder()
.Set("usbDevices", ListBuilder()
.Append(DictionaryBuilder()
.Set("vendorId", 123)
.Set("productId", 756)
.Build())
.Build())
.Build())
.Build(),
DictionaryBuilder().Set("filters", ListBuilder().Build()).Build());
ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get())
->AddEnabled(extension));
InvokeUsbAdded(123, 756, kPrinterInterfaceClass);
ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount());
const Notification& notification =
notification_ui_manager_.GetNotificationAt(0);
EXPECT_EQ("123:756", notification.tag());
EXPECT_EQ(
base::StringPrintf(kPrinterAppNotFoundDelegateIDTemplate, "123", "756"),
notification.delegate_id());
}
TEST_F(PrinterDetectorAppSearchEnabledTest,
PrinterProvider_DifferentUsbProductId) {
scoped_refptr<extensions::Extension> extension = CreateTestExtension(
ListBuilder()
.Append("usb")
.Append("printerProvider")
.Append(DictionaryBuilder()
.Set("usbDevices", ListBuilder()
.Append(DictionaryBuilder()
.Set("vendorId", 123)
.Set("productId", 001)
.Build())
.Build())
.Build())
.Build(),
DictionaryBuilder().Set("filters", ListBuilder().Build()).Build());
ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get())
->AddEnabled(extension));
InvokeUsbAdded(123, 456, kPrinterInterfaceClass);
ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount());
const Notification& notification =
notification_ui_manager_.GetNotificationAt(0);
EXPECT_EQ("123:456", notification.tag());
EXPECT_EQ(
base::StringPrintf(kPrinterAppNotFoundDelegateIDTemplate, "123", "456"),
notification.delegate_id());
}
TEST_F(PrinterDetectorAppSearchEnabledTest,
PrinterProvider_UsbPrinters_NotFound) {
scoped_refptr<extensions::Extension> extension = CreateTestExtension(
ListBuilder().Append("usb").Append("printerProvider").Build(),
DictionaryBuilder()
.Set("filters", ListBuilder()
.Append(DictionaryBuilder()
.Set("vendorId", 123)
.Set("productId", 001)
.Build())
.Build())
.Build());
ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get())
->AddEnabled(extension));
InvokeUsbAdded(123, 456, kPrinterInterfaceClass);
ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount());
const Notification& notification =
notification_ui_manager_.GetNotificationAt(0);
EXPECT_EQ("123:456", notification.tag());
EXPECT_EQ(
base::StringPrintf(kPrinterAppNotFoundDelegateIDTemplate, "123", "456"),
notification.delegate_id());
}
TEST_F(PrinterDetectorAppSearchEnabledTest,
PrinterProvider_UsbPrinters_WithProductId) {
scoped_refptr<extensions::Extension> extension = CreateTestExtension(
ListBuilder().Append("usb").Append("printerProvider").Build(),
DictionaryBuilder()
.Set("filters", ListBuilder()
.Append(DictionaryBuilder()
.Set("vendorId", 123)
.Set("productId", 456)
.Build())
.Build())
.Build());
ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get())
->AddEnabled(extension));
InvokeUsbAdded(123, 456, kPrinterInterfaceClass);
ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount());
const Notification& notification =
notification_ui_manager_.GetNotificationAt(0);
EXPECT_EQ("123:456", notification.tag());
EXPECT_EQ(
base::StringPrintf(kPrinterAppExistsDelegateIDTemplate, "123", "456"),
notification.delegate_id());
}
TEST_F(PrinterDetectorAppSearchEnabledTest,
PrinterProvider_UsbPrinters_WithInterfaceClass) {
scoped_refptr<extensions::Extension> extension = CreateTestExtension(
ListBuilder().Append("usb").Append("printerProvider").Build(),
DictionaryBuilder()
.Set("filters",
ListBuilder()
.Append(DictionaryBuilder()
.Set("vendorId", 123)
.Set("interfaceClass", kPrinterInterfaceClass)
.Build())
.Build())
.Build());
ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get())
->AddEnabled(extension));
InvokeUsbAdded(123, 456, kPrinterInterfaceClass);
ASSERT_EQ(1u, notification_ui_manager_.GetNotificationCount());
const Notification& notification =
notification_ui_manager_.GetNotificationAt(0);
EXPECT_EQ("123:456", notification.tag());
EXPECT_EQ(
base::StringPrintf(kPrinterAppExistsDelegateIDTemplate, "123", "456"),
notification.delegate_id());
}
TEST_F(PrinterDetectorAppSearchEnabledTest, IgnoreNonPrinters) {
scoped_refptr<extensions::Extension> extension = CreateTestExtension(
ListBuilder().Append("usb").Append("printerProvider").Build(),
DictionaryBuilder()
.Set("filters",
ListBuilder()
.Append(DictionaryBuilder()
.Set("vendorId", 123)
.Set("interfaceClass", kPrinterInterfaceClass)
.Build())
.Build())
.Build());
ASSERT_TRUE(extensions::ExtensionRegistry::Get(profile_.get())
->AddEnabled(extension));
InvokeUsbAdded(123, 456, 1);
ASSERT_EQ(0u, notification_ui_manager_.GetNotificationCount());
}
} // namespace chromeos
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#include <stdint.h> #include <stdint.h>
#include <map>
#include <memory> #include <memory>
#include <set>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -18,7 +20,7 @@ ...@@ -18,7 +20,7 @@
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/printer_detector/printer_detector.h" #include "chrome/browser/chromeos/printer_detector/usb_printer_detector.h"
#include "chrome/browser/chromeos/printing/ppd_provider_factory.h" #include "chrome/browser/chromeos/printing/ppd_provider_factory.h"
#include "chrome/browser/chromeos/printing/printer_configurer.h" #include "chrome/browser/chromeos/printing/printer_configurer.h"
#include "chrome/browser/chromeos/printing/printers_manager_factory.h" #include "chrome/browser/chromeos/printing/printers_manager_factory.h"
...@@ -70,32 +72,32 @@ std::string GuessEffectiveMakeAndModel(const device::UsbDevice& device) { ...@@ -70,32 +72,32 @@ std::string GuessEffectiveMakeAndModel(const device::UsbDevice& device) {
// The PrinterDetector that drives the flow for setting up a USB printer to use // The PrinterDetector that drives the flow for setting up a USB printer to use
// CUPS backend. // CUPS backend.
class CupsPrinterDetectorImpl : public PrinterDetector, class UsbPrinterDetectorImpl : public UsbPrinterDetector,
public device::UsbService::Observer { public device::UsbService::Observer {
public: public:
explicit CupsPrinterDetectorImpl(Profile* profile) explicit UsbPrinterDetectorImpl(Profile* profile)
: profile_(profile), : profile_(profile),
usb_observer_(this), usb_observer_(this),
observer_list_( observer_list_(
new base::ObserverListThreadSafe<PrinterDetector::Observer>), new base::ObserverListThreadSafe<UsbPrinterDetector::Observer>),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
device::UsbService* usb_service = device::UsbService* usb_service =
device::DeviceClient::Get()->GetUsbService(); device::DeviceClient::Get()->GetUsbService();
if (usb_service) { if (usb_service) {
usb_observer_.Add(usb_service); usb_observer_.Add(usb_service);
usb_service->GetDevices(base::Bind(&CupsPrinterDetectorImpl::OnGetDevices, usb_service->GetDevices(base::Bind(&UsbPrinterDetectorImpl::OnGetDevices,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
} }
~CupsPrinterDetectorImpl() override = default; ~UsbPrinterDetectorImpl() override = default;
// PrinterDetector interface function. // PrinterDetector interface function.
void AddObserver(PrinterDetector::Observer* observer) override { void AddObserver(UsbPrinterDetector::Observer* observer) override {
observer_list_->AddObserver(observer); observer_list_->AddObserver(observer);
} }
// PrinterDetector interface function. // PrinterDetector interface function.
void RemoveObserver(PrinterDetector::Observer* observer) override { void RemoveObserver(UsbPrinterDetector::Observer* observer) override {
observer_list_->RemoveObserver(observer); observer_list_->RemoveObserver(observer);
} }
...@@ -145,7 +147,8 @@ class CupsPrinterDetectorImpl : public PrinterDetector, ...@@ -145,7 +147,8 @@ class CupsPrinterDetectorImpl : public PrinterDetector,
// We already have pp_lock_, so need to call the pre-locked version of // We already have pp_lock_, so need to call the pre-locked version of
// GetPrinters to prevent deadlock. // GetPrinters to prevent deadlock.
observer_list_->Notify( observer_list_->Notify(
FROM_HERE, &PrinterDetector::Observer::OnAvailableUsbPrintersChanged, FROM_HERE,
&UsbPrinterDetector::Observer::OnAvailableUsbPrintersChanged,
GetPrintersLocked()); GetPrintersLocked());
} else { } else {
// If the device has been removed but it's not in present_printers_, it // If the device has been removed but it's not in present_printers_, it
...@@ -202,7 +205,7 @@ class CupsPrinterDetectorImpl : public PrinterDetector, ...@@ -202,7 +205,7 @@ class CupsPrinterDetectorImpl : public PrinterDetector,
printing::CreateProvider(profile_); printing::CreateProvider(profile_);
ppd_provider->ResolveUsbIds( ppd_provider->ResolveUsbIds(
device->vendor_id(), device->product_id(), device->vendor_id(), device->product_id(),
base::Bind(&CupsPrinterDetectorImpl::ResolveUsbIdsDone, base::Bind(&UsbPrinterDetectorImpl::ResolveUsbIdsDone,
weak_ptr_factory_.GetWeakPtr(), ppd_provider, weak_ptr_factory_.GetWeakPtr(), ppd_provider,
base::Passed(std::move(data)))); base::Passed(std::move(data))));
} }
...@@ -213,7 +216,7 @@ class CupsPrinterDetectorImpl : public PrinterDetector, ...@@ -213,7 +216,7 @@ class CupsPrinterDetectorImpl : public PrinterDetector,
SetUpPrinterData* data_ptr = data.get(); SetUpPrinterData* data_ptr = data.get();
data_ptr->configurer->SetUpPrinter( data_ptr->configurer->SetUpPrinter(
*(data_ptr->printer), *(data_ptr->printer),
base::Bind(&CupsPrinterDetectorImpl::SetUpPrinterDone, base::Bind(&UsbPrinterDetectorImpl::SetUpPrinterDone,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
base::Passed(std::move(data)))); base::Passed(std::move(data))));
} }
...@@ -272,16 +275,12 @@ class CupsPrinterDetectorImpl : public PrinterDetector, ...@@ -272,16 +275,12 @@ class CupsPrinterDetectorImpl : public PrinterDetector,
base::AutoLock auto_lock(pp_lock_); base::AutoLock auto_lock(pp_lock_);
present_printers_.emplace(data->device->guid(), std::move(data->printer)); present_printers_.emplace(data->device->guid(), std::move(data->printer));
observer_list_->Notify( observer_list_->Notify(
FROM_HERE, &PrinterDetector::Observer::OnAvailableUsbPrintersChanged, FROM_HERE,
&UsbPrinterDetector::Observer::OnAvailableUsbPrintersChanged,
GetPrintersLocked()); GetPrintersLocked());
} }
} }
void SetNotificationUIManagerForTesting(
NotificationUIManager* manager) override {
LOG(FATAL) << "Not implemented for CUPS";
}
// Map from USB GUID to Printer that we have detected as being currently // Map from USB GUID to Printer that we have detected as being currently
// plugged in and have finished processing. Note present_printers_ may be // plugged in and have finished processing. Note present_printers_ may be
// accessed from multiple threads, so is protected by pp_lock_. // accessed from multiple threads, so is protected by pp_lock_.
...@@ -296,22 +295,17 @@ class CupsPrinterDetectorImpl : public PrinterDetector, ...@@ -296,22 +295,17 @@ class CupsPrinterDetectorImpl : public PrinterDetector,
Profile* profile_; Profile* profile_;
ScopedObserver<device::UsbService, device::UsbService::Observer> ScopedObserver<device::UsbService, device::UsbService::Observer>
usb_observer_; usb_observer_;
scoped_refptr<base::ObserverListThreadSafe<PrinterDetector::Observer>> scoped_refptr<base::ObserverListThreadSafe<UsbPrinterDetector::Observer>>
observer_list_; observer_list_;
base::WeakPtrFactory<CupsPrinterDetectorImpl> weak_ptr_factory_; base::WeakPtrFactory<UsbPrinterDetectorImpl> weak_ptr_factory_;
}; };
} // namespace } // namespace
// Nop base class implementation of GetPrinters(). Because this is non-empty we
// have to define it out-of-line.
std::vector<Printer> PrinterDetector::GetPrinters() {
return std::vector<Printer>();
}
// static // static
std::unique_ptr<PrinterDetector> PrinterDetector::CreateCups(Profile* profile) { std::unique_ptr<UsbPrinterDetector> UsbPrinterDetector::Create(
return base::MakeUnique<CupsPrinterDetectorImpl>(profile); Profile* profile) {
return base::MakeUnique<UsbPrinterDetectorImpl>(profile);
} }
} // namespace chromeos } // namespace chromeos
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_PRINTER_DETECTOR_H_ #ifndef CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_USB_PRINTER_DETECTOR_H_
#define CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_PRINTER_DETECTOR_H_ #define CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_USB_PRINTER_DETECTOR_H_
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -13,28 +13,14 @@ ...@@ -13,28 +13,14 @@
#include "chromeos/printing/printer_configuration.h" #include "chromeos/printing/printer_configuration.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
class NotificationUIManager;
class Profile; class Profile;
namespace chromeos { namespace chromeos {
// Observes device::UsbService for addition of USB printers (devices with // Observes device::UsbService for addition of USB printers (devices with
// interface class 7). What it does with this depends on whether or not // interface class 7). When a device is detected, it is forwarded to the
// CUPS printing support is enabled. // printing subsystem for either autoconfiguration or user guidance.
// class UsbPrinterDetector : public KeyedService {
// If CUPS is disabled, the Legacy implementation should be used. The legacy
// implementation shows a notification depending on whether there are printer
// provider apps that declared support for the USB device installed. If such
// app exists, the notification notifies the user the printer is ready.
// Otherwise the notification offers user to search Chrome Web Store for apps
// that support the printer. Clicking the notification launches webstore_widget
// app for the printer. The notification is shown only for active user's
// profile.
//
// If CUPS is enabled, the Cups implementation should be used. This
// implementation to guides the user through setting up a new USB printer in the
// CUPS backend.
class PrinterDetector : public KeyedService {
public: public:
class Observer { class Observer {
public: public:
...@@ -45,35 +31,23 @@ class PrinterDetector : public KeyedService { ...@@ -45,35 +31,23 @@ class PrinterDetector : public KeyedService {
const std::vector<Printer>& printers) = 0; const std::vector<Printer>& printers) = 0;
}; };
// Factory function for the Legacy implementation.
static std::unique_ptr<PrinterDetector> CreateLegacy(Profile* profile);
// Factory function for the CUPS implementation. // Factory function for the CUPS implementation.
static std::unique_ptr<PrinterDetector> CreateCups(Profile* profile); static std::unique_ptr<UsbPrinterDetector> Create(Profile* profile);
~PrinterDetector() override {} ~UsbPrinterDetector() override = default;
// Observer management. Note these are only implemented for the cups backend.
// TODO(justincarlson) - Change these all to pure virtual functions when the
// legacy backend is retired.
virtual void AddObserver(Observer* observer) {} virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) {} virtual void RemoveObserver(Observer* observer) = 0;
// Get the current set of detected printers. // Get the current set of detected printers.
virtual std::vector<Printer> GetPrinters(); virtual std::vector<Printer> GetPrinters() = 0;
protected: protected:
PrinterDetector() = default; UsbPrinterDetector() = default;
private: private:
friend class PrinterDetectorAppSearchEnabledTest; DISALLOW_COPY_AND_ASSIGN(UsbPrinterDetector);
virtual void SetNotificationUIManagerForTesting(
NotificationUIManager* manager) = 0;
DISALLOW_COPY_AND_ASSIGN(PrinterDetector);
}; };
} // namespace chromeos } // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_PRINTER_DETECTOR_H_ #endif // CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_USB_PRINTER_DETECTOR_H_
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/chromeos/printer_detector/printer_detector_factory.h" #include "chrome/browser/chromeos/printer_detector/usb_printer_detector_factory.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "chrome/browser/chromeos/printer_detector/printer_detector.h" #include "chrome/browser/chromeos/printer_detector/usb_printer_detector.h"
#include "chrome/browser/chromeos/printing/printers_manager_factory.h" #include "chrome/browser/chromeos/printing/printers_manager_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -17,55 +17,49 @@ namespace chromeos { ...@@ -17,55 +17,49 @@ namespace chromeos {
namespace { namespace {
static base::LazyInstance<PrinterDetectorFactory>::DestructorAtExit g_factory = base::LazyInstance<UsbPrinterDetectorFactory>::DestructorAtExit g_factory =
LAZY_INSTANCE_INITIALIZER; LAZY_INSTANCE_INITIALIZER;
} // namespace } // namespace
// static // static
PrinterDetectorFactory* PrinterDetectorFactory::GetInstance() { UsbPrinterDetectorFactory* UsbPrinterDetectorFactory::GetInstance() {
return g_factory.Pointer(); return g_factory.Pointer();
} }
PrinterDetector* PrinterDetectorFactory::Get(content::BrowserContext* context) { UsbPrinterDetector* UsbPrinterDetectorFactory::Get(
return static_cast<PrinterDetector*>( content::BrowserContext* context) {
return static_cast<UsbPrinterDetector*>(
GetServiceForBrowserContext(context, false)); GetServiceForBrowserContext(context, false));
} }
PrinterDetectorFactory::PrinterDetectorFactory() UsbPrinterDetectorFactory::UsbPrinterDetectorFactory()
: BrowserContextKeyedServiceFactory( : BrowserContextKeyedServiceFactory(
"PrinterDetectorFactory", "UsbPrinterDetectorFactory",
BrowserContextDependencyManager::GetInstance()) { BrowserContextDependencyManager::GetInstance()) {
DependsOn( DependsOn(
extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
DependsOn(PrintersManagerFactory::GetInstance()); DependsOn(PrintersManagerFactory::GetInstance());
} }
PrinterDetectorFactory::~PrinterDetectorFactory() { UsbPrinterDetectorFactory::~UsbPrinterDetectorFactory() {}
}
content::BrowserContext* PrinterDetectorFactory::GetBrowserContextToUse( content::BrowserContext* UsbPrinterDetectorFactory::GetBrowserContextToUse(
content::BrowserContext* context) const { content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context); return chrome::GetBrowserContextRedirectedInIncognito(context);
} }
KeyedService* PrinterDetectorFactory::BuildServiceInstanceFor( KeyedService* UsbPrinterDetectorFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
if (base::CommandLine::ForCurrentProcess()->HasSwitch( return UsbPrinterDetector::Create(Profile::FromBrowserContext(context))
::switches::kDisableNativeCups)) {
return PrinterDetector::CreateLegacy(Profile::FromBrowserContext(context))
.release();
}
return PrinterDetector::CreateCups(Profile::FromBrowserContext(context))
.release(); .release();
} }
bool PrinterDetectorFactory::ServiceIsCreatedWithBrowserContext() const { bool UsbPrinterDetectorFactory::ServiceIsCreatedWithBrowserContext() const {
return true; return true;
} }
bool PrinterDetectorFactory::ServiceIsNULLWhileTesting() const { bool UsbPrinterDetectorFactory::ServiceIsNULLWhileTesting() const {
return true; return true;
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_PRINTER_DETECTOR_FACTORY_H_ #ifndef CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_USB_PRINTER_DETECTOR_FACTORY_H_
#define CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_PRINTER_DETECTOR_FACTORY_H_ #define CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_USB_PRINTER_DETECTOR_FACTORY_H_
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -16,13 +16,13 @@ class BrowserContext; ...@@ -16,13 +16,13 @@ class BrowserContext;
namespace chromeos { namespace chromeos {
class PrinterDetector; class UsbPrinterDetector;
class PrinterDetectorFactory : public BrowserContextKeyedServiceFactory { class UsbPrinterDetectorFactory : public BrowserContextKeyedServiceFactory {
public: public:
static PrinterDetectorFactory* GetInstance(); static UsbPrinterDetectorFactory* GetInstance();
PrinterDetector* Get(content::BrowserContext* context); UsbPrinterDetector* Get(content::BrowserContext* context);
protected: protected:
// BrowserContextKeyedServiceFactory: // BrowserContextKeyedServiceFactory:
...@@ -30,9 +30,9 @@ class PrinterDetectorFactory : public BrowserContextKeyedServiceFactory { ...@@ -30,9 +30,9 @@ class PrinterDetectorFactory : public BrowserContextKeyedServiceFactory {
content::BrowserContext* context) const override; content::BrowserContext* context) const override;
private: private:
friend struct base::LazyInstanceTraitsBase<PrinterDetectorFactory>; friend struct base::LazyInstanceTraitsBase<UsbPrinterDetectorFactory>;
PrinterDetectorFactory(); UsbPrinterDetectorFactory();
~PrinterDetectorFactory() override; ~UsbPrinterDetectorFactory() override;
// BrowserContextKeyedServiceFactory: // BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor( KeyedService* BuildServiceInstanceFor(
...@@ -40,9 +40,9 @@ class PrinterDetectorFactory : public BrowserContextKeyedServiceFactory { ...@@ -40,9 +40,9 @@ class PrinterDetectorFactory : public BrowserContextKeyedServiceFactory {
bool ServiceIsCreatedWithBrowserContext() const override; bool ServiceIsCreatedWithBrowserContext() const override;
bool ServiceIsNULLWhileTesting() const override; bool ServiceIsNULLWhileTesting() const override;
DISALLOW_COPY_AND_ASSIGN(PrinterDetectorFactory); DISALLOW_COPY_AND_ASSIGN(UsbPrinterDetectorFactory);
}; };
} // namespace chromeos } // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_PRINTER_DETECTOR_FACTORY_H_ #endif // CHROME_BROWSER_CHROMEOS_PRINTER_DETECTOR_USB_PRINTER_DETECTOR_FACTORY_H_
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "chrome/browser/chromeos/printer_detector/printer_detector.h" #include "chrome/browser/chromeos/printer_detector/usb_printer_detector.h"
#include "chrome/browser/chromeos/printer_detector/printer_detector_factory.h" #include "chrome/browser/chromeos/printer_detector/usb_printer_detector_factory.h"
#include "chrome/browser/chromeos/printing/printers_manager.h" #include "chrome/browser/chromeos/printing/printers_manager.h"
#include "chrome/browser/chromeos/printing/printers_manager_factory.h" #include "chrome/browser/chromeos/printing/printers_manager_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -22,15 +22,15 @@ namespace { ...@@ -22,15 +22,15 @@ namespace {
// Implementation of PrinterDiscoverer interface. // Implementation of PrinterDiscoverer interface.
class PrinterDiscovererImpl : public PrinterDiscoverer, class PrinterDiscovererImpl : public PrinterDiscoverer,
public PrinterDetector::Observer { public UsbPrinterDetector::Observer {
public: public:
explicit PrinterDiscovererImpl(Profile* profile) explicit PrinterDiscovererImpl(Profile* profile)
: detector_observer_(this), profile_(profile), weak_ptr_factory_(this) { : detector_observer_(this), profile_(profile), weak_ptr_factory_(this) {
PrinterDetector* detector = UsbPrinterDetector* usb_detector =
PrinterDetectorFactory::GetInstance()->Get(profile); UsbPrinterDetectorFactory::GetInstance()->Get(profile);
DCHECK(detector); DCHECK(usb_detector);
detector_observer_.Add(detector); detector_observer_.Add(usb_detector);
usb_printers_ = detector->GetPrinters(); usb_printers_ = usb_detector->GetPrinters();
} }
~PrinterDiscovererImpl() override = default; ~PrinterDiscovererImpl() override = default;
...@@ -103,7 +103,8 @@ class PrinterDiscovererImpl : public PrinterDiscoverer, ...@@ -103,7 +103,8 @@ class PrinterDiscovererImpl : public PrinterDiscoverer,
std::vector<Printer> usb_printers_; std::vector<Printer> usb_printers_;
base::ObserverList<PrinterDiscoverer::Observer> observer_list_; base::ObserverList<PrinterDiscoverer::Observer> observer_list_;
ScopedObserver<PrinterDetector, PrinterDetector::Observer> detector_observer_; ScopedObserver<UsbPrinterDetector, UsbPrinterDetector::Observer>
detector_observer_;
Profile* profile_; Profile* profile_;
base::WeakPtrFactory<PrinterDiscovererImpl> weak_ptr_factory_; base::WeakPtrFactory<PrinterDiscovererImpl> weak_ptr_factory_;
}; };
......
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
#endif #endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/printer_detector/printer_detector_factory.h" #include "chrome/browser/chromeos/printer_detector/usb_printer_detector_factory.h"
#include "chrome/browser/chromeos/printing/cups_print_job_manager_factory.h" #include "chrome/browser/chromeos/printing/cups_print_job_manager_factory.h"
#include "chrome/browser/chromeos/printing/printers_manager_factory.h" #include "chrome/browser/chromeos/printing/printers_manager_factory.h"
#include "chrome/browser/chromeos/tether/tether_service_factory.h" #include "chrome/browser/chromeos/tether/tether_service_factory.h"
...@@ -230,7 +230,7 @@ EnsureBrowserContextKeyedServiceFactoriesBuilt() { ...@@ -230,7 +230,7 @@ EnsureBrowserContextKeyedServiceFactoriesBuilt() {
EnhancedBookmarkKeyServiceFactory::GetInstance(); EnhancedBookmarkKeyServiceFactory::GetInstance();
#endif #endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::PrinterDetectorFactory::GetInstance(); chromeos::UsbPrinterDetectorFactory::GetInstance();
chromeos::CupsPrintJobManagerFactory::GetInstance(); chromeos::CupsPrintJobManagerFactory::GetInstance();
chromeos::PrintersManagerFactory::GetInstance(); chromeos::PrintersManagerFactory::GetInstance();
TetherServiceFactory::GetInstance(); TetherServiceFactory::GetInstance();
......
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