Juan Garza Sanchez | 696d4319 | 2023-07-11 21:58:06 | [diff] [blame] | 1 | // Copyright 2023 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/usb/usb_system_tray_icon.h" |
| 6 | |
| 7 | #include "base/functional/bind.h" |
| 8 | #include "base/strings/utf_string_conversions.h" |
| 9 | #include "chrome/app/vector_icons/vector_icons.h" |
| 10 | #include "chrome/browser/device_notifications/device_system_tray_icon_renderer.h" |
| 11 | #include "chrome/browser/usb/usb_connection_tracker_factory.h" |
Henrique Ferreiro | d78ab26 | 2023-09-13 11:21:43 | [diff] [blame] | 12 | #include "chrome/grit/branded_strings.h" |
Juan Garza Sanchez | 696d4319 | 2023-07-11 21:58:06 | [diff] [blame] | 13 | #include "chrome/grit/generated_resources.h" |
| 14 | #include "extensions/buildflags/buildflags.h" |
| 15 | #include "ui/base/l10n/l10n_util.h" |
| 16 | #include "ui/gfx/paint_vector_icon.h" |
| 17 | |
| 18 | // static |
Jack Hsieh | 13a0a3d8 | 2024-06-04 22:09:22 | [diff] [blame] | 19 | const gfx::VectorIcon& UsbSystemTrayIcon::GetIcon() { |
| 20 | return kTabUsbConnectedIcon; |
Juan Garza Sanchez | 696d4319 | 2023-07-11 21:58:06 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | // static |
| 24 | std::u16string UsbSystemTrayIcon::GetTitleLabel(size_t num_origins, |
| 25 | size_t num_connections) { |
| 26 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 27 | return l10n_util::GetPluralStringFUTF16(IDS_WEBUSB_SYSTEM_TRAY_ICON_TITLE, |
| 28 | static_cast<int>(num_connections)); |
Arthur Eubanks | 00f279b | 2024-05-29 22:20:17 | [diff] [blame] | 29 | #else |
Peter Boström | 01ab59a | 2024-08-15 02:39:49 | [diff] [blame] | 30 | NOTREACHED(); |
Arthur Eubanks | 00f279b | 2024-05-29 22:20:17 | [diff] [blame] | 31 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Juan Garza Sanchez | 696d4319 | 2023-07-11 21:58:06 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | // static |
| 35 | std::u16string UsbSystemTrayIcon::GetContentSettingsLabel() { |
| 36 | return l10n_util::GetStringUTF16(IDS_WEBUSB_SYSTEM_TRAY_ICON_USB_SETTINGS); |
| 37 | } |
| 38 | |
| 39 | UsbSystemTrayIcon::UsbSystemTrayIcon( |
| 40 | std::unique_ptr<DeviceSystemTrayIconRenderer> icon_renderer) |
| 41 | : DeviceSystemTrayIcon(std::move(icon_renderer)) {} |
| 42 | |
| 43 | UsbSystemTrayIcon::~UsbSystemTrayIcon() = default; |
| 44 | |
| 45 | DeviceConnectionTracker* UsbSystemTrayIcon::GetConnectionTracker( |
| 46 | base::WeakPtr<Profile> profile) { |
| 47 | if (!profile) { |
| 48 | return nullptr; |
| 49 | } |
| 50 | return UsbConnectionTrackerFactory::GetForProfile(profile.get(), |
| 51 | /*create=*/false); |
| 52 | } |