#include "extensions/browser/api/usb/usb_device_manager.h"
#include <functional>
#include <memory>
#include <optional>
#include <utility>
#include "base/containers/contains.h"
#include "base/lazy_instance.h"
#include "base/observer_list.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "build/build_config.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/device_service.h"
#include "extensions/browser/api/device_permissions_manager.h"
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/event_router_factory.h"
#include "extensions/common/api/usb.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/mojom/event_dispatcher.mojom-forward.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/permissions/usb_device_permission.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
usb;
BrowserThread;
namespace extensions {
namespace {
constexpr int kUsbClassMassStorage = …;
bool IsMassStorageInterface(const device::mojom::UsbInterfaceInfo& interface) { … }
bool ShouldExposeDevice(const device::mojom::UsbDeviceInfo& device_info) { … }
bool WillDispatchDeviceEvent(
const device::mojom::UsbDeviceInfo& device_info,
content::BrowserContext* browser_context,
mojom::ContextType target_context,
const Extension* extension,
const base::Value::Dict* listener_filter,
std::optional<base::Value::List>& event_args_out,
mojom::EventFilteringInfoPtr& event_filtering_info_out) { … }
base::LazyInstance<BrowserContextKeyedAPIFactory<UsbDeviceManager>>::Leaky
g_event_router_factory = …;
}
UsbDeviceManager* UsbDeviceManager::Get(
content::BrowserContext* browser_context) { … }
BrowserContextKeyedAPIFactory<UsbDeviceManager>*
UsbDeviceManager::GetFactoryInstance() { … }
void UsbDeviceManager::Observer::OnDeviceAdded(
const device::mojom::UsbDeviceInfo& device_info) { … }
void UsbDeviceManager::Observer::OnDeviceRemoved(
const device::mojom::UsbDeviceInfo& device_info) { … }
void UsbDeviceManager::Observer::OnDeviceManagerConnectionError() { … }
UsbDeviceManager::UsbDeviceManager(content::BrowserContext* browser_context)
: … { … }
UsbDeviceManager::~UsbDeviceManager() = default;
void UsbDeviceManager::AddObserver(Observer* observer) { … }
void UsbDeviceManager::RemoveObserver(Observer* observer) { … }
int UsbDeviceManager::GetIdFromGuid(const std::string& guid) { … }
bool UsbDeviceManager::GetGuidFromId(int id, std::string* guid) { … }
void UsbDeviceManager::GetApiDevice(
const device::mojom::UsbDeviceInfo& device_in,
api::usb::Device* device_out) { … }
void UsbDeviceManager::GetDevices(
device::mojom::UsbDeviceManager::GetDevicesCallback callback) { … }
void UsbDeviceManager::GetDevice(
const std::string& guid,
mojo::PendingReceiver<device::mojom::UsbDevice> device_receiver) { … }
const device::mojom::UsbDeviceInfo* UsbDeviceManager::GetDeviceInfo(
const std::string& guid) { … }
bool UsbDeviceManager::UpdateActiveConfig(const std::string& guid,
uint8_t config_value) { … }
#if BUILDFLAG(IS_CHROMEOS)
void UsbDeviceManager::CheckAccess(
const std::string& guid,
device::mojom::UsbDeviceManager::CheckAccessCallback callback) {
EnsureConnectionWithDeviceManager();
device_manager_->CheckAccess(guid, std::move(callback));
}
#endif
void UsbDeviceManager::EnsureConnectionWithDeviceManager() { … }
void UsbDeviceManager::SetDeviceManagerForTesting(
mojo::PendingRemote<device::mojom::UsbDeviceManager> fake_device_manager) { … }
void UsbDeviceManager::Shutdown() { … }
void UsbDeviceManager::OnListenerAdded(const EventListenerInfo& details) { … }
void UsbDeviceManager::OnDeviceAdded(
device::mojom::UsbDeviceInfoPtr device_info) { … }
void UsbDeviceManager::OnDeviceRemoved(
device::mojom::UsbDeviceInfoPtr device_info) { … }
void UsbDeviceManager::SetUpDeviceManagerConnection() { … }
void UsbDeviceManager::InitDeviceList(
std::vector<device::mojom::UsbDeviceInfoPtr> devices) { … }
void UsbDeviceManager::OnDeviceManagerConnectionError() { … }
void UsbDeviceManager::DispatchEvent(
const std::string& event_name,
const device::mojom::UsbDeviceInfo& device_info) { … }
template <>
void BrowserContextKeyedAPIFactory<
UsbDeviceManager>::DeclareFactoryDependencies() { … }
}