chromium/extensions/browser/api/printer_provider/printer_provider_api.cc

// Copyright 2015 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/printer_provider/printer_provider_api.h"

#include <stddef.h>

#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include "base/functional/bind.h"
#include "base/i18n/rtl.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/device_event_log/device_event_log.h"
#include "extensions/browser/api/printer_provider/printer_provider_internal_api.h"
#include "extensions/browser/api/printer_provider/printer_provider_internal_api_observer.h"
#include "extensions/browser/api/printer_provider/printer_provider_print_job.h"
#include "extensions/browser/api/usb/usb_device_manager.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/unloaded_extension_reason.h"
#include "extensions/common/api/printer_provider.h"
#include "extensions/common/api/printer_provider_internal.h"
#include "extensions/common/api/usb.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/mojom/event_dispatcher.mojom-forward.h"

namespace extensions {

namespace {

// The separator between extension id and the extension's internal printer id
// used when generating a printer id unique across extensions.
const char kPrinterIdSeparator =;

// Given an extension ID and an ID of a printer reported by the extension, it
// generates a ID for the printer unique across extensions (assuming that the
// printer id is unique in the extension's space).
std::string GeneratePrinterId(const ExtensionId& extension_id,
                              const std::string& internal_printer_id) {}

// Parses an ID created using |GeneratePrinterId| to it's components:
// the extension ID and the printer ID internal to the extension.
// Returns whenter the ID was succesfully parsed.
bool ParsePrinterId(const std::string& printer_id,
                    std::string* extension_id,
                    std::string* internal_printer_id) {}

void UpdatePrinterWithExtensionInfo(base::Value::Dict* printer,
                                    const Extension* extension) {}

// Holds information about a pending onGetPrintersRequested request;
// in particular, the list of extensions to which the event was dispatched but
// which haven't yet responded, and the |GetPrinters| callback associated with
// the event.
class GetPrintersRequest {};

// Keeps track of pending chrome.printerProvider.onGetPrintersRequested
// requests.
class PendingGetPrintersRequests {};

// Keeps track of pending chrome.printerProvider.onGetCapabilityRequested
// requests for an extension.
class PendingGetCapabilityRequests {};

constexpr base::TimeDelta PendingGetCapabilityRequests::kGetCapabilityTimeout;

// Keeps track of pending chrome.printerProvider.onPrintRequested requests
// for an extension.
class PendingPrintRequests {};

// Keeps track of pending chrome.printerProvider.onGetUsbPrinterInfoRequested
// requests for an extension.
class PendingUsbPrinterInfoRequests {};

// Implements chrome.printerProvider API events.
class PrinterProviderAPIImpl : public PrinterProviderAPI,
                               public PrinterProviderInternalAPIObserver,
                               public ExtensionRegistryObserver {};

GetPrintersRequest::GetPrintersRequest(
    const PrinterProviderAPI::GetPrintersCallback& callback)
    :{}

GetPrintersRequest::~GetPrintersRequest() {}

void GetPrintersRequest::AddSource(const ExtensionId& extension_id) {}

bool GetPrintersRequest::IsDone() const {}

void GetPrintersRequest::ReportForExtension(const ExtensionId& extension_id,
                                            base::Value::List printers) {}

PendingGetPrintersRequests::PendingGetPrintersRequests() :{}

PendingGetPrintersRequests::~PendingGetPrintersRequests() {}

int PendingGetPrintersRequests::Add(
    const PrinterProviderAPI::GetPrintersCallback& callback) {}

bool PendingGetPrintersRequests::CompleteForExtension(
    const ExtensionId& extension_id,
    int request_id,
    base::Value::List result) {}

void PendingGetPrintersRequests::FailAllForExtension(
    const ExtensionId& extension_id) {}

bool PendingGetPrintersRequests::AddSource(int request_id,
                                           const ExtensionId& extension_id) {}

PendingGetCapabilityRequests::PendingGetCapabilityRequests()
    :{}

PendingGetCapabilityRequests::~PendingGetCapabilityRequests() {}

int PendingGetCapabilityRequests::Add(
    PrinterProviderAPI::GetCapabilityCallback callback) {}

void PendingGetCapabilityRequests::Complete(int request_id,
                                            base::Value::Dict response) {}

void PendingGetCapabilityRequests::FailAll() {}

PendingPrintRequests::PendingPrintRequests() :{}

PendingPrintRequests::~PendingPrintRequests() {}

int PendingPrintRequests::Add(PrinterProviderPrintJob job,
                              PrinterProviderAPI::PrintCallback callback) {}

bool PendingPrintRequests::Complete(
    int request_id,
    api::printer_provider_internal::PrintError error) {}

const PrinterProviderPrintJob* PendingPrintRequests::GetPrintJob(
    int request_id) const {}

void PendingPrintRequests::FailAll() {}

PendingUsbPrinterInfoRequests::PendingUsbPrinterInfoRequests() {}

PendingUsbPrinterInfoRequests::~PendingUsbPrinterInfoRequests() {}

int PendingUsbPrinterInfoRequests::Add(
    PrinterProviderAPI::GetPrinterInfoCallback callback) {}

void PendingUsbPrinterInfoRequests::Complete(int request_id,
                                             base::Value::Dict printer_info) {}

void PendingUsbPrinterInfoRequests::FailAll() {}

PrinterProviderAPIImpl::PrinterProviderAPIImpl(
    content::BrowserContext* browser_context)
    :{}

PrinterProviderAPIImpl::~PrinterProviderAPIImpl() {}

void PrinterProviderAPIImpl::DispatchGetPrintersRequested(
    const GetPrintersCallback& callback) {}

void PrinterProviderAPIImpl::DispatchGetCapabilityRequested(
    const std::string& printer_id,
    GetCapabilityCallback callback) {}

void PrinterProviderAPIImpl::DispatchPrintRequested(PrinterProviderPrintJob job,
                                                    PrintCallback callback) {}

const PrinterProviderPrintJob* PrinterProviderAPIImpl::GetPrintJob(
    const Extension* extension,
    int request_id) const {}

void PrinterProviderAPIImpl::DispatchGetUsbPrinterInfoRequested(
    const ExtensionId& extension_id,
    const device::mojom::UsbDeviceInfo& device,
    GetPrinterInfoCallback callback) {}

void PrinterProviderAPIImpl::OnGetPrintersResult(
    const Extension* extension,
    int request_id,
    const PrinterProviderInternalAPIObserver::PrinterInfoVector& result) {}

void PrinterProviderAPIImpl::OnGetCapabilityResult(const Extension* extension,
                                                   int request_id,
                                                   base::Value::Dict result) {}

void PrinterProviderAPIImpl::OnPrintResult(
    const Extension* extension,
    int request_id,
    api::printer_provider_internal::PrintError error) {}

void PrinterProviderAPIImpl::OnGetUsbPrinterInfoResult(
    const Extension* extension,
    int request_id,
    const api::printer_provider::PrinterInfo* result) {}

void PrinterProviderAPIImpl::OnExtensionUnloaded(
    content::BrowserContext* browser_context,
    const Extension* extension,
    UnloadedExtensionReason reason) {}

bool PrinterProviderAPIImpl::WillRequestPrinters(
    int request_id,
    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) {}

}  // namespace

// static
PrinterProviderAPI* PrinterProviderAPI::Create(
    content::BrowserContext* context) {}

// static
std::string PrinterProviderAPI::GetDefaultPrintError() {}

}  // namespace extensions