Commit 046cfb5a authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Implement UsbPrinterNotification for saved printer

This change introduces a notification that is displayed when a user
plugs in a USB printer that is saved to their profile, notifying the
user that the printer has been plugged in.

Bug: 951139
Change-Id: I679e8d19f5bacc94e96a10588c792e307259d7f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1594802Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660941}
parent 5380288b
...@@ -138,6 +138,10 @@ class FakeUsbPrinterNotificationController ...@@ -138,6 +138,10 @@ class FakeUsbPrinterNotificationController
open_notifications_.insert(printer.id()); open_notifications_.insert(printer.id());
} }
void ShowSavedNotification(const Printer& printer) override {
NOTIMPLEMENTED();
}
void RemoveNotification(const std::string& printer_id) override { void RemoveNotification(const std::string& printer_id) override {
open_notifications_.erase(printer_id); open_notifications_.erase(printer_id);
} }
......
...@@ -306,13 +306,18 @@ class FakeUsbPrinterNotificationController ...@@ -306,13 +306,18 @@ class FakeUsbPrinterNotificationController
void ShowEphemeralNotification(const Printer& printer) override { void ShowEphemeralNotification(const Printer& printer) override {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
void ShowSavedNotification(const Printer& printer) override {
open_notifications_.insert(printer.id());
}
void RemoveNotification(const std::string& printer_id) override { void RemoveNotification(const std::string& printer_id) override {
NOTIMPLEMENTED(); open_notifications_.erase(printer_id);
} }
bool IsNotification(const std::string& printer_id) const override { bool IsNotification(const std::string& printer_id) const override {
NOTIMPLEMENTED(); return open_notifications_.contains(printer_id);
return false;
} }
private:
base::flat_set<std::string> open_notifications_;
}; };
class CupsPrintersManagerTest : public testing::Test, class CupsPrintersManagerTest : public testing::Test,
......
...@@ -94,6 +94,7 @@ void UsbPrinterNotification::ShowNotification() { ...@@ -94,6 +94,7 @@ void UsbPrinterNotification::ShowNotification() {
void UsbPrinterNotification::UpdateContents() { void UsbPrinterNotification::UpdateContents() {
switch (type_) { switch (type_) {
case Type::kEphemeral: case Type::kEphemeral:
case Type::kSaved:
notification_->set_title(l10n_util::GetStringUTF16( notification_->set_title(l10n_util::GetStringUTF16(
IDS_USB_PRINTER_NOTIFICATION_CONNECTED_TITLE)); IDS_USB_PRINTER_NOTIFICATION_CONNECTED_TITLE));
notification_->set_message(l10n_util::GetStringFUTF16( notification_->set_message(l10n_util::GetStringFUTF16(
......
...@@ -26,7 +26,7 @@ namespace chromeos { ...@@ -26,7 +26,7 @@ namespace chromeos {
// according to its state and respond to the user's action. // according to its state and respond to the user's action.
class UsbPrinterNotification : public message_center::NotificationObserver { class UsbPrinterNotification : public message_center::NotificationObserver {
public: public:
enum class Type { kEphemeral }; enum class Type { kEphemeral, kSaved };
UsbPrinterNotification(const Printer& printer, UsbPrinterNotification(const Printer& printer,
const std::string& notification_id, const std::string& notification_id,
......
...@@ -44,6 +44,20 @@ class UsbPrinterNotificationControllerImpl ...@@ -44,6 +44,20 @@ class UsbPrinterNotificationControllerImpl
return base::ContainsKey(notifications_, printer_id); return base::ContainsKey(notifications_, printer_id);
} }
void ShowSavedNotification(const Printer& printer) override {
if (!base::FeatureList::IsEnabled(features::kStreamlinedUsbPrinterSetup)) {
return;
}
if (base::ContainsKey(notifications_, printer.id())) {
return;
}
notifications_[printer.id()] = std::make_unique<UsbPrinterNotification>(
printer, GetUniqueNotificationId(),
UsbPrinterNotification::Type::kSaved, profile_);
}
private: private:
std::string GetUniqueNotificationId() { std::string GetUniqueNotificationId() {
return base::StringPrintf("usb_printer_notification_%d", return base::StringPrintf("usb_printer_notification_%d",
......
...@@ -29,6 +29,10 @@ class UsbPrinterNotificationController { ...@@ -29,6 +29,10 @@ class UsbPrinterNotificationController {
// is already an existing notification for |printer|. // is already an existing notification for |printer|.
virtual void ShowEphemeralNotification(const Printer& printer) = 0; virtual void ShowEphemeralNotification(const Printer& printer) = 0;
// Creates a notification for a saved printer. This is a no-op if there
// is already an existing notification for |printer|.
virtual void ShowSavedNotification(const Printer& printer) = 0;
// Closes the notification for |printer_id|. This is a no-op if the // Closes the notification for |printer_id|. This is a no-op if the
// notification has already been closed by the user. // notification has already been closed by the user.
virtual void RemoveNotification(const std::string& printer_id) = 0; virtual void RemoveNotification(const std::string& printer_id) = 0;
......
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