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

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, 1 month 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
« no previous file with comments | « chromeos/printing/ppd_cache_unittest.cc ('k') | chromeos/printing/ppd_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 filepath
50 // holds the path to a PPD file (that may or may not be gzipped). Otherwise,
51 // the 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, in bytes. Trying to use a
63 // PPD file 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 // Must be called from a Sequenced Task context (i.e.
79 // base::SequencedTaskRunnerHandle::IsSet() must be true).
80 //
81 // |cb| will only be called after the task invoking Resolve() is finished.
82 //
83 // Only one Resolve call should be outstanding at a time.
84 virtual void Resolve(const Printer::PpdReference& ppd_reference,
85 ResolveCallback cb) = 0;
86
87 // Abort any outstanding Resolve call. After this returns, it is guaranteed
88 // that all no ResolveCallback will be called until the next time Resolve is
89 // called. It is a nop to call this if no Resolve is outstanding.
90 virtual void AbortResolve() = 0;
91
92 // Most of the time, the cache is just an invisible backend to the Provider,
93 // consulted at Resolve time, but in the case of the user doing "Add Printer"
94 // and "Select PPD" locally, then we get into a state where we want to put
95 // whatever they give us directly into the cache without doing a resolve.
96 // This hook lets is do that.
97 virtual bool CachePpd(const Printer::PpdReference& ppd_reference,
98 const base::FilePath& ppd_path) = 0;
99 };
100
101 } // namespace printing
102 } // namespace chromeos
103
104 #endif // CHROMEOS_PRINTING_PPD_PROVIDER_H_
OLDNEW
« no previous file with comments | « chromeos/printing/ppd_cache_unittest.cc ('k') | chromeos/printing/ppd_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698