blob: 588b088d36edf3b70febef8952050a0cfd654011 [file] [log] [blame]
Juan Garza Sanchez696d43192023-07-11 21:58:061// 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 Ferreirod78ab262023-09-13 11:21:4312#include "chrome/grit/branded_strings.h"
Juan Garza Sanchez696d43192023-07-11 21:58:0613#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 Hsieh13a0a3d82024-06-04 22:09:2219const gfx::VectorIcon& UsbSystemTrayIcon::GetIcon() {
20 return kTabUsbConnectedIcon;
Juan Garza Sanchez696d43192023-07-11 21:58:0621}
22
23// static
24std::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 Eubanks00f279b2024-05-29 22:20:1729#else
Peter Boström01ab59a2024-08-15 02:39:4930 NOTREACHED();
Arthur Eubanks00f279b2024-05-29 22:20:1731#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Juan Garza Sanchez696d43192023-07-11 21:58:0632}
33
34// static
35std::u16string UsbSystemTrayIcon::GetContentSettingsLabel() {
36 return l10n_util::GetStringUTF16(IDS_WEBUSB_SYSTEM_TRAY_ICON_USB_SETTINGS);
37}
38
39UsbSystemTrayIcon::UsbSystemTrayIcon(
40 std::unique_ptr<DeviceSystemTrayIconRenderer> icon_renderer)
41 : DeviceSystemTrayIcon(std::move(icon_renderer)) {}
42
43UsbSystemTrayIcon::~UsbSystemTrayIcon() = default;
44
45DeviceConnectionTracker* UsbSystemTrayIcon::GetConnectionTracker(
46 base::WeakPtr<Profile> profile) {
47 if (!profile) {
48 return nullptr;
49 }
50 return UsbConnectionTrackerFactory::GetForProfile(profile.get(),
51 /*create=*/false);
52}