blob: 058602ef0e3cce74b9e296c9c899678f81d5877b [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"
12#include "chrome/grit/chromium_strings.h"
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
19gfx::ImageSkia UsbSystemTrayIcon::GetIcon() {
20 return gfx::CreateVectorIcon(kTabUsbConnectedIcon, gfx::kGoogleGrey300);
21}
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));
29#endif // BUILDFLAG(ENABLE_EXTENSIONS)
30 NOTREACHED_NORETURN();
31}
32
33// static
34std::u16string UsbSystemTrayIcon::GetContentSettingsLabel() {
35 return l10n_util::GetStringUTF16(IDS_WEBUSB_SYSTEM_TRAY_ICON_USB_SETTINGS);
36}
37
38UsbSystemTrayIcon::UsbSystemTrayIcon(
39 std::unique_ptr<DeviceSystemTrayIconRenderer> icon_renderer)
40 : DeviceSystemTrayIcon(std::move(icon_renderer)) {}
41
42UsbSystemTrayIcon::~UsbSystemTrayIcon() = default;
43
44DeviceConnectionTracker* UsbSystemTrayIcon::GetConnectionTracker(
45 base::WeakPtr<Profile> profile) {
46 if (!profile) {
47 return nullptr;
48 }
49 return UsbConnectionTrackerFactory::GetForProfile(profile.get(),
50 /*create=*/false);
51}