File: lorgnette_scanner_manager.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (155 lines) | stat: -rw-r--r-- 7,226 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_SCANNING_LORGNETTE_SCANNER_MANAGER_H_
#define CHROME_BROWSER_ASH_SCANNING_LORGNETTE_SCANNER_MANAGER_H_

#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>

#include "base/functional/callback.h"
#include "chromeos/ash/components/dbus/lorgnette/lorgnette_service.pb.h"
#include "chromeos/ash/components/dbus/lorgnette_manager/lorgnette_manager_client.h"
#include "components/keyed_service/core/keyed_service.h"

class Profile;

namespace ash {

class ZeroconfScannerDetector;

// Top-level manager of available scanners in Chrome OS. All functions in this
// class must be called from a sequenced context.
class LorgnetteScannerManager : public KeyedService {
 public:
  using GetScannerNamesCallback =
      base::OnceCallback<void(std::vector<std::string> scanner_names)>;
  using GetScannerInfoListCallback = base::OnceCallback<void(
      const std::optional<lorgnette::ListScannersResponse>& response)>;
  using GetScannerCapabilitiesCallback = base::OnceCallback<void(
      const std::optional<lorgnette::ScannerCapabilities>& capabilities)>;
  using OpenScannerCallback = base::OnceCallback<void(
      const std::optional<lorgnette::OpenScannerResponse>& response)>;
  using CloseScannerCallback = base::OnceCallback<void(
      const std::optional<lorgnette::CloseScannerResponse>& response)>;
  using SetOptionsCallback = base::OnceCallback<void(
      const std::optional<lorgnette::SetOptionsResponse>& response)>;
  using GetCurrentConfigCallback = base::OnceCallback<void(
      const std::optional<lorgnette::GetCurrentConfigResponse>& response)>;
  using StartPreparedScanCallback = base::OnceCallback<void(
      const std::optional<lorgnette::StartPreparedScanResponse>& response)>;
  using ReadScanDataCallback = base::OnceCallback<void(
      const std::optional<lorgnette::ReadScanDataResponse>& response)>;
  using ProgressCallback =
      base::RepeatingCallback<void(uint32_t progress_percent,
                                   uint32_t page_number)>;
  using PageCallback = base::RepeatingCallback<void(std::string scan_data,
                                                    uint32_t page_number)>;
  using CompletionCallback =
      base::OnceCallback<void(lorgnette::ScanFailureMode failure_mode)>;
  using CancelCallback = base::OnceCallback<void(bool success)>;
  using CancelScanCallback = base::OnceCallback<void(
      const std::optional<lorgnette::CancelScanResponse>& response)>;

  enum class LocalScannerFilter {
    kLocalScannersOnly = 0,
    kIncludeNetworkScanners
  };

  enum class SecureScannerFilter {
    kSecureScannersOnly = 0,
    kIncludeUnsecureScanners
  };

  ~LorgnetteScannerManager() override = default;

  static std::unique_ptr<LorgnetteScannerManager> Create(
      std::unique_ptr<ZeroconfScannerDetector> zeroconf_scanner_detector,
      Profile* profile);

  // Returns the names of all available, deduplicated scanners.
  virtual void GetScannerNames(GetScannerNamesCallback callback) = 0;

  // Returns ScannerInfo objects for all of the available lorgnette scanners and
  // zeroconf scanners, filtered by |local_only| and |secure_only|.
  virtual void GetScannerInfoList(const std::string& client_id,
                                  LocalScannerFilter local_only,
                                  SecureScannerFilter secure_only,
                                  GetScannerInfoListCallback callback) = 0;

  // Returns the capabilities of the scanner specified by |scanner_name|. If
  // |scanner_name| does not correspond to a known scanner, std::nullopt is
  // returned in the callback.
  virtual void GetScannerCapabilities(
      const std::string& scanner_name,
      GetScannerCapabilitiesCallback callback) = 0;

  // Opens the scanner described by |request|.  If an error occurs,
  // std::nullopt is returned in the callback.
  virtual void OpenScanner(const lorgnette::OpenScannerRequest& request,
                           OpenScannerCallback callback) = 0;

  // Closes the scanner described by |request|.  If an error occurs,
  // std::nullopt is returned in the callback.
  virtual void CloseScanner(const lorgnette::CloseScannerRequest& request,
                            CloseScannerCallback callback) = 0;

  // Sets the options described by |request|.  If an error occurs, std::nullopt
  // is returned in the callback.
  virtual void SetOptions(const lorgnette::SetOptionsRequest& request,
                          SetOptionsCallback callback) = 0;

  // Gets the config for the scanner described by |request|.  If an error
  // occurs, std::nullopt is returned in the callback.
  virtual void GetCurrentConfig(
      const lorgnette::GetCurrentConfigRequest& request,
      GetCurrentConfigCallback callback) = 0;

  // Starts a scan using information in |request| and returns the result using
  // the provided |callback|.  If an error occurs, std::nullopt is returned in
  // the callback.
  virtual void StartPreparedScan(
      const lorgnette::StartPreparedScanRequest& request,
      StartPreparedScanCallback callback) = 0;

  // Reads the scan data described by |request|.  If an error occurs,
  // std::nullopt is returned in the callback.
  virtual void ReadScanData(const lorgnette::ReadScanDataRequest& request,
                            ReadScanDataCallback callback) = 0;

  // Returns whether or not an ADF scanner that flips alternate pages was
  // selected based on |scanner_name| and |source_name|.
  virtual bool IsRotateAlternate(const std::string& scanner_name,
                                 const std::string& source_name) = 0;

  // Performs a scan with the scanner specified by |scanner_name| using the
  // given |scan_properties|. As each page is scanned, |progress_callback| is
  // called with the current progress percent from 0 to 100. As each scanned
  // page is completed, |page_callback| is called with the image data for that
  // page. If |scanner_name| does not correspond to a known scanner, false is
  // returned in |completion_callback|. After the scan has completed,
  // |completion_callback| will be called with argument success=true.
  virtual void Scan(const std::string& scanner_name,
                    const lorgnette::ScanSettings& settings,
                    ProgressCallback progress_callback,
                    PageCallback page_callback,
                    CompletionCallback completion_callback) = 0;

  // Request to cancel the currently running scan job. This function makes the
  // assumption that LorgnetteManagerClient only has one scan running at a time.
  virtual void CancelScan(CancelCallback cancel_callback) = 0;

  // Request to cancel the scan specified by the JobHandle in |request| and
  // return the result using the provided |callback|.  If an error occurs,
  // std::nullopt is returned in the callback.
  virtual void CancelScan(const lorgnette::CancelScanRequest& request,
                          CancelScanCallback callback) = 0;
};

}  // namespace ash

#endif  // CHROME_BROWSER_ASH_SCANNING_LORGNETTE_SCANNER_MANAGER_H_