Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chromeos/printing/ppd_provider.h

Issue 2613683004: Completely rewrite the PpdProvider/PpdCache to use the SCS backend. Along the way, clean it up a l… (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROMEOS_PRINTING_PPD_PROVIDER_H_ 5 #ifndef CHROMEOS_PRINTING_PPD_PROVIDER_H_
6 #define CHROMEOS_PRINTING_PPD_PROVIDER_H_ 6 #define CHROMEOS_PRINTING_PPD_PROVIDER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/sequenced_task_runner.h" 15 #include "base/sequenced_task_runner.h"
16 #include "chromeos/chromeos_export.h" 16 #include "chromeos/chromeos_export.h"
17 #include "chromeos/printing/printer_configuration.h" 17 #include "chromeos/printing/printer_configuration.h"
18 18
19 // chrome/browser/browser_process.h for GetApplicationLocale
skau 2017/01/05 20:38:46 what is this for?
Carlson 2017/01/26 21:59:36 It was a note to myself that I forgot to cleanup.
20
19 namespace net { 21 namespace net {
20 class URLRequestContextGetter; 22 class URLRequestContextGetter;
21 } 23 }
22 24
23 namespace chromeos { 25 namespace chromeos {
24 namespace printing { 26 namespace printing {
25 27
26 class PpdCache; 28 class PpdCache;
27 29
28 // PpdProvider is responsible for mapping printer descriptions to 30 // PpdProvider is responsible for mapping printer descriptions to
29 // CUPS-PostScript Printer Description (PPD) files. It provides PPDs that a 31 // CUPS-PostScript Printer Description (PPD) files. It provides PPDs that a
30 // user previously identified for use, and falls back to querying quirksserver 32 // user previously identified for use, and falls back to querying quirksserver
31 // based on manufacturer/model of the printer. 33 // based on manufacturer/model of the printer.
32 // 34 //
33 // This class can be accessed from any thread. 35 // All functions in this class must be called from a sequenced context.
34 class CHROMEOS_EXPORT PpdProvider { 36 class CHROMEOS_EXPORT PpdProvider : public base::RefCounted<PpdProvider> {
35 public: 37 public:
36 // Possible result codes of a Resolve() or QueryAvailable() call. 38 // Possible result codes of a Resolve*() call.
37 enum CallbackResultCode { 39 enum CallbackResultCode {
38 SUCCESS, 40 SUCCESS,
39 41
40 // Looked for a PPD for this configuration, but couldn't find a match. 42 // Looked for a PPD for this configuration, but couldn't find a match.
41 // Never returned for QueryAvailable(). 43 // Never returned for QueryAvailable().
42 NOT_FOUND, 44 NOT_FOUND,
43 45
44 // Failed to contact an external server needed to finish resolution. 46 // Failed to contact an external server needed to finish resolution.
45 SERVER_ERROR, 47 SERVER_ERROR,
46 48
47 // Other error that is not expected to be transient. 49 // Other error that is not expected to be transient.
48 INTERNAL_ERROR, 50 INTERNAL_ERROR,
49 }; 51 };
50 52
51 // Result of a Resolve(). If the result code is SUCCESS, then FilePath holds
52 // the path to a PPD file (that may or may not be gzipped). Otherwise, the
53 // FilePath will be empty.
54 using ResolveCallback =
55 base::Callback<void(CallbackResultCode, base::FilePath)>;
56
57 // Available printers are represented as a map from manufacturer to
58 // list-of-printer-models.
59 using AvailablePrintersMap = std::map<std::string, std::vector<std::string>>;
60
61 // Result of a QueryAvailable. If the result code is SUCCESS, then
62 // AvailablePrintersMap holds a map from manufacturer name to list of printer
63 // names. Otherwise the map will be empty.
64 using QueryAvailableCallback =
65 base::Callback<void(CallbackResultCode, const AvailablePrintersMap&)>;
66
67 // Construction-time options. Everything in this structure should have 53 // Construction-time options. Everything in this structure should have
68 // a sane default. 54 // a sane default.
69 struct Options { 55 struct Options {
70 Options() {} 56 Options() {}
71 57
72 // hostname of quirks server to query. 58 // Root of the ppd serving hierarchy.
73 std::string quirks_server = "chromeosquirksserver-pa.googleapis.com"; 59 std::string ppd_server_root = "https://www.gstatic.com/chromeos_printing";
74 60
75 // Maximum size of the contents of a PPD file, in bytes. Trying to use a 61 // Maximum size of the contents of a PPD file, in bytes. Trying to use a
76 // PPD file bigger than this will cause INTERNAL_ERRORs at resolution time. 62 // PPD file bigger than this will cause INTERNAL_ERRORs at resolution time.
77 size_t max_ppd_contents_size_ = 100 * 1024; 63 size_t max_ppd_contents_size_ = 100 * 1024;
78 }; 64 };
79 65
66 // This is a pseudo-opaque type; you shouldn't depend on the contents.
67 struct ManufacturerReference {
68 std::string key;
69 };
70
71 // Map from (localized) manufacturer names to references for finding models
72 // for that manufacturer.
73 using ManufacturerMap = std::map<std::string, ManufacturerReference>;
74
75 // Map from printer model names to PpdReferences for resolving the ppd for
76 // each model. This is a per-manufacturers structure.
77 using PrinterMap = std::map<std::string, Printer::PpdReference>;
78
79 // Result of a ResolvePpd() call. If the result code is SUCCESS, then the
80 // string holds the contents of a PPD (that may or may not be gzipped).
81 // Otherwise, the string will be empty.
82 using ResolvePpdCallback =
83 base::Callback<void(CallbackResultCode, const std::string&)>;
84
85 // Result of a ResolveManufacturers() call. If the result code is SUCCESS,
86 // then the map contains entries for each manufacturer for which we have at
87 // least one printer driver.
88 using ResolveManufacturersCallback =
89 base::Callback<void(CallbackResultCode, const ManufacturerMap&)>;
90
91 // Result of a ResolvePrinters() call. If the result code is SUCCESS, then
92 // the map contains entries for each model for which we can resolve a driver.
93 using ResolvePrintersCallback =
94 base::Callback<void(CallbackResultCode, const PrinterMap&)>;
95
80 // Create and return a new PpdProvider with the given cache and options. 96 // Create and return a new PpdProvider with the given cache and options.
81 // |io_task_runner| is used to run operations that are long latency and should 97 // A references to |url_context_getter| is taken.
82 // not be on the UI thread. References to |url_context_getter| and 98 static scoped_refptr<PpdProvider> Create(
83 // |io_task_runner| are taken. 99 const std::string& browser_locale,
84 static std::unique_ptr<PpdProvider> Create(
85 const std::string& api_key,
86 scoped_refptr<net::URLRequestContextGetter> url_context_getter, 100 scoped_refptr<net::URLRequestContextGetter> url_context_getter,
87 scoped_refptr<base::SequencedTaskRunner> io_task_runner, 101 scoped_refptr<PpdCache> cache,
88 std::unique_ptr<PpdCache> cache,
89 const Options& options = Options()); 102 const Options& options = Options());
90 103
91 virtual ~PpdProvider() {} 104 // Get all manufacturers for which we have drivers. Keys of the map will be
105 // localized in the default browser locale or the closest available fallback.
106 //
107 // |cb| will be called on the invoking thread, and will be sequenced. If
108 // ResolveManufacturers is called when a previous callback has not yet been
109 // invoked the outstanding will be cancelled before the function returns.
110 virtual void ResolveManufacturers(const ResolveManufacturersCallback& cb) = 0;
92 111
93 // Given a PpdReference, attempt to resolve the PPD for printing. 112 // Get all models from a given manufacturer, localized in the default browser
113 // locale or the closest available fallback. |manufacturer_key| must be
114 // a value from a ManufacturerMap from a successful ResolveManufacturers()
115 // call.
94 // 116 //
95 // Must be called from a Sequenced Task context (i.e. 117 // |cb| will be called on the invoking thread, and will be sequenced. If
96 // base::SequencedTaskRunnerHandle::IsSet() must be true). 118 // ResolvePrinters() is called when a previous callback has not yet been
119 // invoked the outstanding callback will be cancelled before the function
120 // returns.
121 virtual void ResolvePrinters(const ManufacturerReference& manufacturer,
122 const ResolvePrintersCallback& cb) = 0;
123
124 // Given an effective model (which should be a value from a PrinterMap),
125 // attempt to get the PPD for printing.
97 // 126 //
98 // |cb| will only be called after the task invoking Resolve() is finished. 127 // |cb| will be called on the invoking thread, and will be sequenced. If
99 virtual void Resolve(const Printer::PpdReference& ppd_reference, 128 // ResolvePpd() is called when a previous callback has not yet been
100 const ResolveCallback& cb) = 0; 129 // invoked the outstanding callback will be cancelled before the function
101 130 // returns.
102 // Get all the printer makes and models we can support. 131 virtual void ResolvePpd(const Printer::PpdReference& reference,
103 // 132 const ResolvePpdCallback& cb) = 0;
104 // Must be called from a Sequenced Task context (i.e.
105 // base::SequencedTaskRunnerHandle::IsSet() must be true).
106 //
107 // |cb| will only be called after the task invoking QueryAvailable() is
108 // finished.
109 virtual void QueryAvailable(const QueryAvailableCallback& cb) = 0;
110 133
111 // Most of the time, the cache is just an invisible backend to the Provider, 134 // Most of the time, the cache is just an invisible backend to the Provider,
112 // consulted at Resolve time, but in the case of the user doing "Add Printer" 135 // consulted at Resolve time, but in the case of the user doing "Add Printer"
113 // and "Select PPD" locally, then we get into a state where we want to put 136 // and "Select PPD" locally, then we get into a state where we want to put
114 // whatever they give us directly into the cache without doing a resolve. 137 // whatever they give us directly into the cache without doing a resolve.
115 // This hook lets is do that. 138 // This hook lets is do that. Note there's no callback here -- the caching
116 virtual bool CachePpd(const Printer::PpdReference& ppd_reference, 139 // operation will complete asynchronously without notification.
117 const base::FilePath& ppd_path) = 0; 140 virtual void CachePpd(const Printer::PpdReference& ppd_reference,
141 const std::string& ppd_contents) = 0;
142
143 // Hook for testing. Returns true if there are no API calls that have not
144 // yet completed.
145 virtual bool Idle() const = 0;
146
147 protected:
148 friend class base::RefCounted<PpdProvider>;
149 virtual ~PpdProvider() {}
118 }; 150 };
119 151
120 } // namespace printing 152 } // namespace printing
121 } // namespace chromeos 153 } // namespace chromeos
122 154
123 #endif // CHROMEOS_PRINTING_PPD_PROVIDER_H_ 155 #endif // CHROMEOS_PRINTING_PPD_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698