chromium/services/device/public/cpp/test/fake_usb_device_manager.cc

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

#include "services/device/public/cpp/test/fake_usb_device_manager.h"

#include <string>
#include <utility>
#include <vector>

#include "base/containers/contains.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "services/device/public/cpp/test/fake_usb_device.h"
#include "services/device/public/cpp/test/mock_usb_mojo_device.h"
#include "services/device/public/cpp/usb/usb_utils.h"
#include "services/device/public/mojom/usb_enumeration_options.mojom.h"
#include "services/device/public/mojom/usb_manager_client.mojom.h"

namespace device {

FakeUsbDeviceManager::FakeUsbDeviceManager() {}

FakeUsbDeviceManager::~FakeUsbDeviceManager() {}

void FakeUsbDeviceManager::EnumerateDevicesAndSetClient(
    mojo::PendingAssociatedRemote<mojom::UsbDeviceManagerClient> client,
    EnumerateDevicesAndSetClientCallback callback) {}

// mojom::UsbDeviceManager implementation:
void FakeUsbDeviceManager::GetDevices(mojom::UsbEnumerationOptionsPtr options,
                                      GetDevicesCallback callback) {}

void FakeUsbDeviceManager::GetDevice(
    const std::string& guid,
    const std::vector<uint8_t>& blocked_interface_classes,
    mojo::PendingReceiver<device::mojom::UsbDevice> device_receiver,
    mojo::PendingRemote<mojom::UsbDeviceClient> device_client) {}

void FakeUsbDeviceManager::GetSecurityKeyDevice(
    const std::string& guid,
    mojo::PendingReceiver<device::mojom::UsbDevice> device_receiver,
    mojo::PendingRemote<mojom::UsbDeviceClient> device_client) {}

#if BUILDFLAG(IS_ANDROID)
void FakeUsbDeviceManager::RefreshDeviceInfo(
    const std::string& guid,
    RefreshDeviceInfoCallback callback) {
  auto it = devices_.find(guid);
  if (it == devices_.end()) {
    std::move(callback).Run(nullptr);
    return;
  }

  std::move(callback).Run(it->second->GetDeviceInfo().Clone());
}
#endif

#if BUILDFLAG(IS_CHROMEOS)
void FakeUsbDeviceManager::CheckAccess(const std::string& guid,
                                       CheckAccessCallback callback) {
  std::move(callback).Run(true);
}

void FakeUsbDeviceManager::OpenFileDescriptor(
    const std::string& guid,
    uint32_t drop_privileges_mask,
    mojo::PlatformHandle lifeline_fd,
    OpenFileDescriptorCallback callback) {
  std::move(callback).Run(base::File(
      base::FilePath(FILE_PATH_LITERAL("/dev/null")),
      base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_WRITE));
}
#endif  // BUILDFLAG(IS_CHROMEOS)

void FakeUsbDeviceManager::SetClient(
    mojo::PendingAssociatedRemote<mojom::UsbDeviceManagerClient> client) {}

void FakeUsbDeviceManager::AddReceiver(
    mojo::PendingReceiver<mojom::UsbDeviceManager> receiver) {}

mojom::UsbDeviceInfoPtr FakeUsbDeviceManager::AddDevice(
    scoped_refptr<FakeUsbDeviceInfo> device) {}

void FakeUsbDeviceManager::RemoveDevice(
    scoped_refptr<FakeUsbDeviceInfo> device) {}

void FakeUsbDeviceManager::RemoveDevice(const std::string& guid) {}

void FakeUsbDeviceManager::RemoveAllDevices() {}

const device::mojom::UsbDeviceInfo* FakeUsbDeviceManager::GetDeviceInfo(
    const std::string& guid) {}

bool FakeUsbDeviceManager::SetMockForDevice(const std::string& guid,
                                            MockUsbMojoDevice* mock_device) {}

}  // namespace device