File: local_printer_ash.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 (164 lines) | stat: -rw-r--r-- 6,910 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
156
157
158
159
160
161
162
163
164
// Copyright 2021 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_CROSAPI_LOCAL_PRINTER_ASH_H_
#define CHROME_BROWSER_ASH_CROSAPI_LOCAL_PRINTER_ASH_H_

#include <string>
#include <vector>

#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/ash/printing/cups_print_job.h"
#include "chrome/browser/ash/printing/cups_print_job_manager.h"
#include "chrome/browser/ash/printing/cups_printers_manager.h"
#include "chrome/browser/ash/printing/print_servers_manager.h"
#include "chrome/browser/profiles/profile_manager_observer.h"
#include "chromeos/crosapi/mojom/local_printer.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote_set.h"

class Profile;
class ProfileManager;

namespace ash {
struct PrintServersConfig;

namespace printing {
class IppClientInfoCalculator;
}
}  // namespace ash

namespace chromeos {
class PpdProvider;
}  // namespace chromeos

namespace crosapi {

// Implements the crosapi interface for LocalPrinter. Lives in Ash-Chrome on the
// UI thread.
class LocalPrinterAsh : public mojom::LocalPrinter,
                        public ProfileManagerObserver,
                        public ash::CupsPrintJobManager::Observer,
                        public ash::PrintServersManager::Observer,
                        public ash::CupsPrintersManager::LocalPrintersObserver {
 public:
  LocalPrinterAsh();
  LocalPrinterAsh(const LocalPrinterAsh&) = delete;
  LocalPrinterAsh& operator=(const LocalPrinterAsh&) = delete;

  // As it observes browser context keyed services, this object must
  // be destroyed after said services are destroyed (which occurs in
  // ChromeBrowserMainParts::PostMainMessageLoopRun()). CrosapiAsh
  // is destroyed in ~ChromeBrowserMainParts() which occurs after
  // all browser context keyed services have been destroyed.
  ~LocalPrinterAsh() override;

  // The mojom PrintServersConfig object contains all information in the
  // PrintServersConfig object.
  static mojom::PrintServersConfigPtr ConfigToMojom(
      const ash::PrintServersConfig& config);

  void BindReceiver(mojo::PendingReceiver<mojom::LocalPrinter> receiver);

  // ProfileManagerObserver:
  void OnProfileAdded(Profile* profile) override;
  void OnProfileManagerDestroying() override;

  // ash::CupsPrintJobManager::Observer:
  void OnPrintJobCreated(base::WeakPtr<ash::CupsPrintJob> job) override;
  void OnPrintJobStarted(base::WeakPtr<ash::CupsPrintJob> job) override;
  void OnPrintJobUpdated(base::WeakPtr<ash::CupsPrintJob> job) override;
  void OnPrintJobSuspended(base::WeakPtr<ash::CupsPrintJob> job) override;
  void OnPrintJobResumed(base::WeakPtr<ash::CupsPrintJob> job) override;
  void OnPrintJobDone(base::WeakPtr<ash::CupsPrintJob> job) override;
  void OnPrintJobError(base::WeakPtr<ash::CupsPrintJob> job) override;
  void OnPrintJobCancelled(base::WeakPtr<ash::CupsPrintJob> job) override;

  // chromeos::PrintServersManager::Observer:
  void OnPrintServersChanged(const ash::PrintServersConfig& config) override;
  void OnServerPrintersChanged(
      const std::vector<ash::PrinterDetector::DetectedPrinter>&) override;

  // CupsPrintersManager::LocalPrintersObserver:
  void OnLocalPrintersUpdated() override;

  // crosapi::mojom::LocalPrinter:
  void GetPrinters(GetPrintersCallback callback) override;
  void GetCapability(const std::string& printer_id,
                     GetCapabilityCallback callback) override;
  void GetEulaUrl(const std::string& printer_id,
                  GetEulaUrlCallback callback) override;
  void GetStatus(const std::string& printer_id,
                 GetStatusCallback callback) override;
  void ShowSystemPrintSettings(
      ShowSystemPrintSettingsCallback callback) override;
  void CreatePrintJob(mojom::PrintJobPtr job,
                      CreatePrintJobCallback callback) override;
  void CancelPrintJob(const std::string& printer_id,
                      unsigned int job_id,
                      CancelPrintJobCallback callback) override;
  void GetPrintServersConfig(GetPrintServersConfigCallback callback) override;
  void ChoosePrintServers(const std::vector<std::string>& print_server_ids,
                          ChoosePrintServersCallback callback) override;
  void AddPrintServerObserver(
      mojo::PendingRemote<mojom::PrintServerObserver> remote,
      AddPrintServerObserverCallback callback) override;
  void GetPolicies(GetPoliciesCallback callback) override;
  void GetUsernamePerPolicy(GetUsernamePerPolicyCallback callback) override;
  void GetPrinterTypeDenyList(GetPrinterTypeDenyListCallback callback) override;
  void AddPrintJobObserver(mojo::PendingRemote<mojom::PrintJobObserver> remote,
                           mojom::PrintJobSource source,
                           AddPrintJobObserverCallback callback) override;
  void AddLocalPrintersObserver(
      mojo::PendingRemote<mojom::LocalPrintersObserver> remote,
      AddLocalPrintersObserverCallback callback) override;
  void GetOAuthAccessToken(const std::string& printer_id,
                           GetOAuthAccessTokenCallback callback) override;
  void GetIppClientInfo(const std::string& printer_id,
                        GetIppClientInfoCallback callback) override;

 private:
  void NotifyPrintJobUpdate(base::WeakPtr<ash::CupsPrintJob> job,
                            mojom::PrintJobStatus status);

  // Exposed so that unit tests can override them.
  virtual Profile* GetProfile();
  virtual scoped_refptr<chromeos::PpdProvider> CreatePpdProvider(
      Profile* profile);
  virtual ash::printing::IppClientInfoCalculator* GetIppClientInfoCalculator();

  base::ScopedObservation<ProfileManager, LocalPrinterAsh>
      profile_manager_observer_{this};

  bool observers_registered_ = false;

  std::unique_ptr<ash::printing::IppClientInfoCalculator>
      ipp_client_info_calculator_;

  // This class supports any number of connections. This allows the client to
  // have multiple, potentially thread-affine, remotes.
  mojo::ReceiverSet<mojom::LocalPrinter> receivers_;

  mojo::RemoteSet<mojom::PrintServerObserver> print_server_remotes_;

  // Remotes which observe all print jobs.
  mojo::RemoteSet<mojom::PrintJobObserver> print_job_remotes_;

  // Remotes which observe only extension print jobs.
  mojo::RemoteSet<mojom::PrintJobObserver> extension_print_job_remotes_;

  // Remotes which observe only IWA print jobs.
  mojo::RemoteSet<mojom::PrintJobObserver> iwa_print_job_remotes_;

  // Remotes which observe local printer updates.
  mojo::RemoteSet<mojom::LocalPrintersObserver>
      local_printers_observer_remotes_;
};

}  // namespace crosapi

#endif  // CHROME_BROWSER_ASH_CROSAPI_LOCAL_PRINTER_ASH_H_