chromium/extensions/browser/api/device_permissions_manager.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/browser/api/device_permissions_manager.h"

#include <stddef.h>

#include <optional>
#include <utility>

#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/singleton.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/api/hid/hid_device_manager.h"
#include "extensions/browser/api/usb/usb_device_manager.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/permissions/api_permission.h"
#include "extensions/strings/grit/extensions_strings.h"
#include "services/device/public/cpp/usb/usb_ids.h"
#include "ui/base/l10n/l10n_util.h"

namespace extensions {

BrowserContext;
BrowserThread;
APIPermission;
Extension;
ExtensionHost;
ExtensionPrefs;

namespace {

// Preference keys

// The device that the app has permission to access.
const char kDevices[] =;

// The type of device saved.
const char kDeviceType[] =;

// Type identifier for USB devices.
const char kDeviceTypeUsb[] =;

// Type identifier for HID devices.
const char kDeviceTypeHid[] =;

// The vendor ID of the device that the app had permission to access.
const char kDeviceVendorId[] =;

// The product ID of the device that the app had permission to access.
const char kDeviceProductId[] =;

// The serial number of the device that the app has permission to access.
const char kDeviceSerialNumber[] =;

// The manufacturer string read from the device that the app has permission to
// access.
const char kDeviceManufacturerString[] =;

// The product string read from the device that the app has permission to
// access.
const char kDeviceProductString[] =;

// Serialized timestamp of the last time when the device was opened by the app.
const char kDeviceLastUsed[] =;

// Converts a DevicePermissionEntry::Type to a string for the prefs file.
const char* TypeToString(DevicePermissionEntry::Type type) {}

// Persists a DevicePermissionEntry in ExtensionPrefs.
void SaveDevicePermissionEntry(BrowserContext* context,
                               const ExtensionId& extension_id,
                               scoped_refptr<DevicePermissionEntry> entry) {}

bool MatchesDevicePermissionEntry(const base::Value::Dict& value,
                                  scoped_refptr<DevicePermissionEntry> entry) {}

// Updates the timestamp stored in ExtensionPrefs for the given
// DevicePermissionEntry.
void UpdateDevicePermissionEntry(BrowserContext* context,
                                 const ExtensionId& extension_id,
                                 scoped_refptr<DevicePermissionEntry> entry) {}

// Removes the given DevicePermissionEntry from ExtensionPrefs.
void RemoveDevicePermissionEntry(BrowserContext* context,
                                 const ExtensionId& extension_id,
                                 scoped_refptr<DevicePermissionEntry> entry) {}

// Clears all DevicePermissionEntries for the app from ExtensionPrefs.
void ClearDevicePermissionEntries(ExtensionPrefs* prefs,
                                  const ExtensionId& extension_id) {}

scoped_refptr<DevicePermissionEntry> ReadDevicePermissionEntry(
    const base::Value::Dict& entry) {}

// Returns all DevicePermissionEntries for the app.
std::set<scoped_refptr<DevicePermissionEntry>> GetDevicePermissionEntries(
    ExtensionPrefs* prefs,
    const ExtensionId& extension_id) {}

}  // namespace

DevicePermissionEntry::DevicePermissionEntry(
    const device::mojom::UsbDeviceInfo& device)
    :{}

DevicePermissionEntry::DevicePermissionEntry(
    const device::mojom::HidDeviceInfo& device)
    :{}

DevicePermissionEntry::DevicePermissionEntry(
    Type type,
    uint16_t vendor_id,
    uint16_t product_id,
    const std::u16string& serial_number,
    const std::u16string& manufacturer_string,
    const std::u16string& product_string,
    const base::Time& last_used)
    :{}

DevicePermissionEntry::~DevicePermissionEntry() {}

bool DevicePermissionEntry::IsPersistent() const {}

base::Value::Dict DevicePermissionEntry::ToValue() const {}

std::u16string DevicePermissionEntry::GetPermissionMessageString() const {}

DevicePermissions::~DevicePermissions() {}

scoped_refptr<DevicePermissionEntry> DevicePermissions::FindUsbDeviceEntry(
    const device::mojom::UsbDeviceInfo& device) const {}

scoped_refptr<DevicePermissionEntry> DevicePermissions::FindHidDeviceEntry(
    const device::mojom::HidDeviceInfo& device) const {}

DevicePermissions::DevicePermissions(BrowserContext* context,
                                     const ExtensionId& extension_id) {}

// static
DevicePermissionsManager* DevicePermissionsManager::Get(
    BrowserContext* context) {}

// static
std::u16string DevicePermissionsManager::GetPermissionMessage(
    uint16_t vendor_id,
    uint16_t product_id,
    const std::u16string& manufacturer_string,
    const std::u16string& product_string,
    const std::u16string& serial_number,
    bool always_include_manufacturer) {}

DevicePermissions* DevicePermissionsManager::GetForExtension(
    const ExtensionId& extension_id) {}

std::vector<std::u16string>
DevicePermissionsManager::GetPermissionMessageStrings(
    const ExtensionId& extension_id) const {}

void DevicePermissionsManager::AllowUsbDevice(
    const ExtensionId& extension_id,
    const device::mojom::UsbDeviceInfo& device_info) {}

void DevicePermissionsManager::AllowHidDevice(
    const ExtensionId& extension_id,
    const device::mojom::HidDeviceInfo& device) {}

void DevicePermissionsManager::UpdateLastUsed(
    const ExtensionId& extension_id,
    scoped_refptr<DevicePermissionEntry> entry) {}

void DevicePermissionsManager::RemoveEntry(
    const ExtensionId& extension_id,
    scoped_refptr<DevicePermissionEntry> entry) {}

void DevicePermissionsManager::Clear(const ExtensionId& extension_id) {}

DevicePermissionsManager::DevicePermissionsManager(
    content::BrowserContext* context)
    :{}

DevicePermissionsManager::~DevicePermissionsManager() {}

DevicePermissions* DevicePermissionsManager::GetInternal(
    const ExtensionId& extension_id) const {}

void DevicePermissionsManager::RemoveEntryByDeviceGUID(
    DevicePermissionEntry::Type type,
    const std::string& guid) {}

// static
DevicePermissionsManager* DevicePermissionsManagerFactory::GetForBrowserContext(
    content::BrowserContext* context) {}

// static
DevicePermissionsManagerFactory*
DevicePermissionsManagerFactory::GetInstance() {}

DevicePermissionsManagerFactory::DevicePermissionsManagerFactory()
    :{}

DevicePermissionsManagerFactory::~DevicePermissionsManagerFactory() {}

std::unique_ptr<KeyedService>
DevicePermissionsManagerFactory::BuildServiceInstanceForBrowserContext(
    content::BrowserContext* context) const {}

BrowserContext* DevicePermissionsManagerFactory::GetBrowserContextToUse(
    BrowserContext* context) const {}

}  // namespace extensions