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

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
15 namespace net {
16 class URLRequestContextGetter;
17 }
18
19 namespace chromeos {
20 namespace printing {
21
22 class PPDCache;
23
24 // PPDProvider is responsible for mapping printer descriptions
25 // to CUPS-PostScript Printer Description (PPD) files. The
26 // provider is a caching client to
27 class CHROMEOS_EXPORT PPDProvider {
28 public:
29 // Possible results of a Resolve* call.
30 enum ResolveResult {
31 // Found a PPD
32 SUCCESS,
33
34 // TODO(justincarlson) - Should we have a "FALLBACK" result here indicating
35 // we found a ppd that we think will work, but wasn't an exact match?
36
37 // Looked for a ppd for this configuration, but couldn't find a match.
38 NOT_FOUND,
39
40 // Failed to contact the Quirks server to look for a PPD.
41 SERVER_ERROR,
42
43 // Other error.
44 INTERNAL_ERROR,
45 };
46
47 // Result of a resolve function. If ResolveResult is SUCCESS, then
48 // filepath holds the path to the compressed ppd file. Otherwise, the
49 // FilePath will be empty.
50 using ResolveCallback = base::Callback<void(ResolveResult, base::FilePath)>;
51
52 // Construction-time options. Everything in this structure should have
53 // a sane default.
54 struct Options {
55 // hostname of quirks server to query. Default is
56 // "chromeosquirksserver-pa.googleapis.com".
57 std::string quirks_server;
58
59 // TODO(justincarlson) - Add a limit to the size of data we'll download for
60 // a single printer. There doesn't seem to actually be a simple way to
61 // enforce this, though? See
62 // https://groups.google.com/a/chromium.org/d/topic/chromium-dev/niK2rVMoMuo /discussion
63 };
64
65 // Return a sane set of default options.
66 static Options Defaults();
67
68 // Create and return a new PPDProvider with the given cache and options.
69 static std::unique_ptr<PPDProvider> Create(
70 const std::string& api_key,
71 scoped_refptr<net::URLRequestContextGetter> url_context_getter,
72 std::unique_ptr<PPDCache> cache,
73 const Options& options);
74
75 // Convenience overload to create a provider with default options.
76 static std::unique_ptr<PPDProvider> Create(
77 const std::string& api_key,
78 scoped_refptr<::net::URLRequestContextGetter> url_context_getter,
79 std::unique_ptr<PPDCache> cache);
80
81 virtual ~PPDProvider() {}
82
83 // Given a manufacturer name and model name, attempt to get a PPD file for
84 // that printer.
85 //
86 // cb will be called on the Network thread with the result of the lookup.
87 //
88 // Only one Resolve* call should be outstanding at a time.
89 virtual void Resolve(const std::string& manufacturer,
90 const std::string& model,
91 ResolveCallback cb) = 0;
92
93 // Store a ppd that has been provided by the user for the printer
94 // with this id. Note PPDProvider just considers ppd_file as
95 // a binary blob and does not attempt to validate the contents
96 // of what's being stored via this hook.
97 //
98 // Returns true on success, false if the file cannot be stored.
99 virtual bool StoreLocal(const std::string& printer_id,
100 base::FilePath ppd_file) = 0;
101
102 // Retrieve a file that was previously added by StoreLocal.
103 //
104 // cb will be called on the Network thread with the result of the lookup.
105 //
106 // Only one Resolve* call should be outstanding at a time.
107 virtual void ResolveLocal(const std::string& printer_id,
108 ResolveCallback cb) = 0;
109 };
110
111 } // namespace printing
112 } // namespace chromeos
113
114 #endif // CHROMEOS_PRINTING_PPD_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698