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

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

Issue 2343983004: Add PPDProvider barebones implementation and associated cache skeleton. (Closed)
Patch Set: Initial PPDProvider/PPDCache implementation. Also, add associated unittests. This doesn't plumb th… Created 4 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROMEOS_PRINTING_PPD_PROVIDER_H_
6 #define CHROMEOS_PRINTING_PPD_PROVIDER_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "chromeos/chromeos_export.h"
14 #include "chromeos/printing/printer_configuration.h"
15
16 namespace net {
17 class URLRequestContextGetter;
18 }
19
20 namespace chromeos {
21 namespace printing {
22
23 class PpdCache;
24
25 // PpdProvider is responsible for mapping printer descriptions to
26 // CUPS-PostScript Printer Description (PPD) files. It provides ppd's that a
skau 2016/10/14 22:10:17 ppds. No apostrophe.
Carlson 2016/10/14 23:05:56 Done.
27 // user previously identified for use, and falls back to querying quirksserver
28 // based on manufacturer/model of the printer.
29 class CHROMEOS_EXPORT PpdProvider {
30 public:
31 // Possible results of a Resolve* call.
32 enum ResolveResult {
33 // Found a PPD
34 SUCCESS,
35
36 // TODO(justincarlson) - Should we have a "FALLBACK" result here indicating
37 // we found a ppd that we think will work, but wasn't an exact match?
38
39 // Looked for a ppd for this configuration, but couldn't find a match.
40 NOT_FOUND,
41
42 // Failed to contact an external server needed to finish resolution.
43 SERVER_ERROR,
44
45 // Other error that is not expected to be transient.
46 INTERNAL_ERROR,
47 };
48
49 // Result of a resolve function. If ResolveResult is SUCCESS, then
50 // filepath holds the path to the compressed ppd file. Otherwise, the
51 // FilePath will be empty.
52 using ResolveCallback = base::Callback<void(ResolveResult, base::FilePath)>;
53
54 // Construction-time options. Everything in this structure should have
55 // a sane default.
56 struct Options {
57 // hostname of quirks server to query. Default is
58 // "chromeosquirksserver-pa.googleapis.com".
59 std::string quirks_server;
60
61 // Maximum size of the contents of a PPD file. Trying to use a PPD file
62 // bigger than this will cause INTERNAL_ERRORs at resolution time.
63 size_t max_ppd_contents_size_;
64 };
65
66 // Return a sane set of default options.
67 static Options Defaults();
68
69 // Create and return a new PpdProvider with the given cache and options.
70 static std::unique_ptr<PpdProvider> Create(
71 const std::string& api_key,
72 scoped_refptr<net::URLRequestContextGetter> url_context_getter,
73 std::unique_ptr<PpdCache> cache,
74 const Options& options = Defaults());
75
76 virtual ~PpdProvider() {}
77
78 // Given a PpdReference, attempt to resolve the ppd for printing.
79 //
80 // cb will be called on the Network thread with the result of the lookup.
81 //
82 // Only one Resolve call should be outstanding at a time.
83 virtual void Resolve(const Printer::PpdReference& ppd_reference,
84 ResolveCallback cb) = 0;
85
86 // Abort any outstanding Resolve call. After this returns, it is guaranteed
87 // that all no ResolveCallback will be called until the next time Resolve is
88 // called. It is a nop to call this if no Resolve is outstanding.
89 virtual void AbortResolve() = 0;
90
91 // Most of the time, the cache is just an invisible backend to the Provider,
92 // consulted at Resolve time, but in the case of the user doing "Add Printer"
93 // and "Select PPD" locally, then we get into a state where we want to put
94 // whatever they give us directly into the cache without doing a resolve.
95 // This hook lets is do that.
96 virtual bool CachePpd(const Printer::PpdReference& ppd_reference,
97 const base::FilePath& ppd_path) = 0;
98 };
99
100 } // namespace printing
101 } // namespace chromeos
102
103 #endif // CHROMEOS_PRINTING_PPD_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698