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

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 PPDs that a
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 Options() {}
58
59 // hostname of quirks server to query.
60 std::string quirks_server = "chromeosquirksserver-pa.googleapis.com";
61
62 // Maximum size of the contents of a PPD file. Trying to use a PPD file
63 // bigger than this will cause INTERNAL_ERRORs at resolution time.
64 size_t max_ppd_contents_size_ = 100 * 1024;
65 };
66
67 // Create and return a new PpdProvider with the given cache and options.
68 static std::unique_ptr<PpdProvider> Create(
69 const std::string& api_key,
70 scoped_refptr<net::URLRequestContextGetter> url_context_getter,
71 std::unique_ptr<PpdCache> cache,
72 const Options& options = Options());
73
74 virtual ~PpdProvider() {}
75
76 // Given a PpdReference, attempt to resolve the ppd for printing.
77 //
78 // cb will be called on the Network thread with the result of the lookup.
Lei Zhang 2016/10/17 17:54:07 |cb|
Carlson 2016/10/18 19:05:01 Done.
79 //
80 // Only one Resolve call should be outstanding at a time.
81 virtual void Resolve(const Printer::PpdReference& ppd_reference,
82 ResolveCallback cb) = 0;
83
84 // Abort any outstanding Resolve call. After this returns, it is guaranteed
85 // that all no ResolveCallback will be called until the next time Resolve is
86 // called. It is a nop to call this if no Resolve is outstanding.
87 virtual void AbortResolve() = 0;
88
89 // Most of the time, the cache is just an invisible backend to the Provider,
90 // consulted at Resolve time, but in the case of the user doing "Add Printer"
91 // and "Select PPD" locally, then we get into a state where we want to put
92 // whatever they give us directly into the cache without doing a resolve.
93 // This hook lets is do that.
94 virtual bool CachePpd(const Printer::PpdReference& ppd_reference,
95 const base::FilePath& ppd_path) = 0;
96 };
97
98 } // namespace printing
99 } // namespace chromeos
100
101 #endif // CHROMEOS_PRINTING_PPD_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698