| Index: chromeos/printing/ppd_provider.h
|
| diff --git a/chromeos/printing/ppd_provider.h b/chromeos/printing/ppd_provider.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9bc6e49550a3648b360a7e9fd9e748e4343181e6
|
| --- /dev/null
|
| +++ b/chromeos/printing/ppd_provider.h
|
| @@ -0,0 +1,114 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CHROMEOS_PRINTING_PPD_PROVIDER_H_
|
| +#define CHROMEOS_PRINTING_PPD_PROVIDER_H_
|
| +
|
| +#include <memory>
|
| +#include <string>
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/files/file_path.h"
|
| +#include "chromeos/chromeos_export.h"
|
| +
|
| +namespace net {
|
| +class URLRequestContextGetter;
|
| +}
|
| +
|
| +namespace chromeos {
|
| +namespace printing {
|
| +
|
| +class PPDCache;
|
| +
|
| +// PPDProvider is responsible for mapping printer descriptions
|
| +// to CUPS-PostScript Printer Description (PPD) files. The
|
| +// provider is a caching client to
|
| +class CHROMEOS_EXPORT PPDProvider {
|
| + public:
|
| + // Possible results of a Resolve* call.
|
| + enum ResolveResult {
|
| + // Found a PPD
|
| + SUCCESS,
|
| +
|
| + // TODO(justincarlson) - Should we have a "FALLBACK" result here indicating
|
| + // we found a ppd that we think will work, but wasn't an exact match?
|
| +
|
| + // Looked for a ppd for this configuration, but couldn't find a match.
|
| + NOT_FOUND,
|
| +
|
| + // Failed to contact the Quirks server to look for a PPD.
|
| + SERVER_ERROR,
|
| +
|
| + // Other error.
|
| + INTERNAL_ERROR,
|
| + };
|
| +
|
| + // Result of a resolve function. If ResolveResult is SUCCESS, then
|
| + // filepath holds the path to the compressed ppd file. Otherwise, the
|
| + // FilePath will be empty.
|
| + using ResolveCallback = base::Callback<void(ResolveResult, base::FilePath)>;
|
| +
|
| + // Construction-time options. Everything in this structure should have
|
| + // a sane default.
|
| + struct Options {
|
| + // hostname of quirks server to query. Default is
|
| + // "chromeosquirksserver-pa.googleapis.com".
|
| + std::string quirks_server;
|
| +
|
| + // TODO(justincarlson) - Add a limit to the size of data we'll download for
|
| + // a single printer. There doesn't seem to actually be a simple way to
|
| + // enforce this, though? See
|
| + // https://groups.google.com/a/chromium.org/d/topic/chromium-dev/niK2rVMoMuo/discussion
|
| + };
|
| +
|
| + // Return a sane set of default options.
|
| + static Options Defaults();
|
| +
|
| + // Create and return a new PPDProvider with the given cache and options.
|
| + static std::unique_ptr<PPDProvider> Create(
|
| + const std::string& api_key,
|
| + scoped_refptr<net::URLRequestContextGetter> url_context_getter,
|
| + std::unique_ptr<PPDCache> cache,
|
| + const Options& options);
|
| +
|
| + // Convenience overload to create a provider with default options.
|
| + static std::unique_ptr<PPDProvider> Create(
|
| + const std::string& api_key,
|
| + scoped_refptr<::net::URLRequestContextGetter> url_context_getter,
|
| + std::unique_ptr<PPDCache> cache);
|
| +
|
| + virtual ~PPDProvider() {}
|
| +
|
| + // Given a manufacturer name and model name, attempt to get a PPD file for
|
| + // that printer.
|
| + //
|
| + // cb will be called on the Network thread with the result of the lookup.
|
| + //
|
| + // Only one Resolve* call should be outstanding at a time.
|
| + virtual void Resolve(const std::string& manufacturer,
|
| + const std::string& model,
|
| + ResolveCallback cb) = 0;
|
| +
|
| + // Store a ppd that has been provided by the user for the printer
|
| + // with this id. Note PPDProvider just considers ppd_file as
|
| + // a binary blob and does not attempt to validate the contents
|
| + // of what's being stored via this hook.
|
| + //
|
| + // Returns true on success, false if the file cannot be stored.
|
| + virtual bool StoreLocal(const std::string& printer_id,
|
| + base::FilePath ppd_file) = 0;
|
| +
|
| + // Retrieve a file that was previously added by StoreLocal.
|
| + //
|
| + // cb will be called on the Network thread with the result of the lookup.
|
| + //
|
| + // Only one Resolve* call should be outstanding at a time.
|
| + virtual void ResolveLocal(const std::string& printer_id,
|
| + ResolveCallback cb) = 0;
|
| +};
|
| +
|
| +} // namespace printing
|
| +} // namespace chromeos
|
| +
|
| +#endif // CHROMEOS_PRINTING_PPD_PROVIDER_H_
|
|
|