chromium/content/browser/service_worker/service_worker_hid_delegate_observer.h

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

#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HID_DELEGATE_OBSERVER_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HID_DELEGATE_OBSERVER_H_

#include "base/memory/weak_ptr.h"
#include "base/scoped_observation_traits.h"
#include "content/browser/hid/hid_service.h"
#include "content/browser/service_worker/service_worker_device_delegate_observer.h"
#include "content/public/browser/hid_delegate.h"

namespace content {

class ServiceWorkerContextCore;

// ServiceWorkerHidDelegateObserver acts as a broker between the
// content::HidService and content::HidDelegate when the HidService is created
// for a service worker.
// Each ServiceWorkerContextCore has one ServiceWorkerHidDelegateObserver,
// which is used to track all of the ServiceWorkerRegistration objects whose
// script uses the WebHID API.
// Furthermore, when a device event happens, the
// ServiceWorkerHidDelegateObserver's HidDelegate::Observer methods will be
// invoked and deliver the device events to the service worker that has a device
// event handler registered.
// For more information, please see go/usb-hid-extension-access.
class CONTENT_EXPORT ServiceWorkerHidDelegateObserver
    : public ServiceWorkerDeviceDelegateObserver,
      public HidDelegate::Observer {};

}  // namespace content

namespace base {

template <>
struct ScopedObservationTraits<content::HidDelegate,
                               content::ServiceWorkerHidDelegateObserver> {};

}  // namespace base

#endif  // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_HID_DELEGATE_OBSERVER_H_