Chromium Code Reviews| Index: chromeos/printing/ppd_provider.h |
| diff --git a/chromeos/printing/ppd_provider.h b/chromeos/printing/ppd_provider.h |
| index 0e8f354fb23bf2875becb3c99b1fe4b6dc7e8100..f9a699376fefed9c72c684b6d52f3bcc0d80f075 100644 |
| --- a/chromeos/printing/ppd_provider.h |
| +++ b/chromeos/printing/ppd_provider.h |
| @@ -16,6 +16,8 @@ |
| #include "chromeos/chromeos_export.h" |
| #include "chromeos/printing/printer_configuration.h" |
| +// chrome/browser/browser_process.h for GetApplicationLocale |
|
skau
2017/01/05 20:38:46
what is this for?
Carlson
2017/01/26 21:59:36
It was a note to myself that I forgot to cleanup.
|
| + |
| namespace net { |
| class URLRequestContextGetter; |
| } |
| @@ -30,10 +32,10 @@ class PpdCache; |
| // user previously identified for use, and falls back to querying quirksserver |
| // based on manufacturer/model of the printer. |
| // |
| -// This class can be accessed from any thread. |
| -class CHROMEOS_EXPORT PpdProvider { |
| +// All functions in this class must be called from a sequenced context. |
| +class CHROMEOS_EXPORT PpdProvider : public base::RefCounted<PpdProvider> { |
| public: |
| - // Possible result codes of a Resolve() or QueryAvailable() call. |
| + // Possible result codes of a Resolve*() call. |
| enum CallbackResultCode { |
| SUCCESS, |
| @@ -48,73 +50,103 @@ class CHROMEOS_EXPORT PpdProvider { |
| INTERNAL_ERROR, |
| }; |
| - // Result of a Resolve(). If the result code is SUCCESS, then FilePath holds |
| - // the path to a PPD file (that may or may not be gzipped). Otherwise, the |
| - // FilePath will be empty. |
| - using ResolveCallback = |
| - base::Callback<void(CallbackResultCode, base::FilePath)>; |
| - |
| - // Available printers are represented as a map from manufacturer to |
| - // list-of-printer-models. |
| - using AvailablePrintersMap = std::map<std::string, std::vector<std::string>>; |
| - |
| - // Result of a QueryAvailable. If the result code is SUCCESS, then |
| - // AvailablePrintersMap holds a map from manufacturer name to list of printer |
| - // names. Otherwise the map will be empty. |
| - using QueryAvailableCallback = |
| - base::Callback<void(CallbackResultCode, const AvailablePrintersMap&)>; |
| - |
| // Construction-time options. Everything in this structure should have |
| // a sane default. |
| struct Options { |
| Options() {} |
| - // hostname of quirks server to query. |
| - std::string quirks_server = "chromeosquirksserver-pa.googleapis.com"; |
| + // Root of the ppd serving hierarchy. |
| + std::string ppd_server_root = "https://www.gstatic.com/chromeos_printing"; |
| // Maximum size of the contents of a PPD file, in bytes. Trying to use a |
| // PPD file bigger than this will cause INTERNAL_ERRORs at resolution time. |
| size_t max_ppd_contents_size_ = 100 * 1024; |
| }; |
| + // This is a pseudo-opaque type; you shouldn't depend on the contents. |
| + struct ManufacturerReference { |
| + std::string key; |
| + }; |
| + |
| + // Map from (localized) manufacturer names to references for finding models |
| + // for that manufacturer. |
| + using ManufacturerMap = std::map<std::string, ManufacturerReference>; |
| + |
| + // Map from printer model names to PpdReferences for resolving the ppd for |
| + // each model. This is a per-manufacturers structure. |
| + using PrinterMap = std::map<std::string, Printer::PpdReference>; |
| + |
| + // Result of a ResolvePpd() call. If the result code is SUCCESS, then the |
| + // string holds the contents of a PPD (that may or may not be gzipped). |
| + // Otherwise, the string will be empty. |
| + using ResolvePpdCallback = |
| + base::Callback<void(CallbackResultCode, const std::string&)>; |
| + |
| + // Result of a ResolveManufacturers() call. If the result code is SUCCESS, |
| + // then the map contains entries for each manufacturer for which we have at |
| + // least one printer driver. |
| + using ResolveManufacturersCallback = |
| + base::Callback<void(CallbackResultCode, const ManufacturerMap&)>; |
| + |
| + // Result of a ResolvePrinters() call. If the result code is SUCCESS, then |
| + // the map contains entries for each model for which we can resolve a driver. |
| + using ResolvePrintersCallback = |
| + base::Callback<void(CallbackResultCode, const PrinterMap&)>; |
| + |
| // Create and return a new PpdProvider with the given cache and options. |
| - // |io_task_runner| is used to run operations that are long latency and should |
| - // not be on the UI thread. References to |url_context_getter| and |
| - // |io_task_runner| are taken. |
| - static std::unique_ptr<PpdProvider> Create( |
| - const std::string& api_key, |
| + // A references to |url_context_getter| is taken. |
| + static scoped_refptr<PpdProvider> Create( |
| + const std::string& browser_locale, |
| scoped_refptr<net::URLRequestContextGetter> url_context_getter, |
| - scoped_refptr<base::SequencedTaskRunner> io_task_runner, |
| - std::unique_ptr<PpdCache> cache, |
| + scoped_refptr<PpdCache> cache, |
| const Options& options = Options()); |
| - virtual ~PpdProvider() {} |
| - |
| - // Given a PpdReference, attempt to resolve the PPD for printing. |
| + // Get all manufacturers for which we have drivers. Keys of the map will be |
| + // localized in the default browser locale or the closest available fallback. |
| // |
| - // Must be called from a Sequenced Task context (i.e. |
| - // base::SequencedTaskRunnerHandle::IsSet() must be true). |
| + // |cb| will be called on the invoking thread, and will be sequenced. If |
| + // ResolveManufacturers is called when a previous callback has not yet been |
| + // invoked the outstanding will be cancelled before the function returns. |
| + virtual void ResolveManufacturers(const ResolveManufacturersCallback& cb) = 0; |
| + |
| + // Get all models from a given manufacturer, localized in the default browser |
| + // locale or the closest available fallback. |manufacturer_key| must be |
| + // a value from a ManufacturerMap from a successful ResolveManufacturers() |
| + // call. |
| // |
| - // |cb| will only be called after the task invoking Resolve() is finished. |
| - virtual void Resolve(const Printer::PpdReference& ppd_reference, |
| - const ResolveCallback& cb) = 0; |
| - |
| - // Get all the printer makes and models we can support. |
| + // |cb| will be called on the invoking thread, and will be sequenced. If |
| + // ResolvePrinters() is called when a previous callback has not yet been |
| + // invoked the outstanding callback will be cancelled before the function |
| + // returns. |
| + virtual void ResolvePrinters(const ManufacturerReference& manufacturer, |
| + const ResolvePrintersCallback& cb) = 0; |
| + |
| + // Given an effective model (which should be a value from a PrinterMap), |
| + // attempt to get the PPD for printing. |
| // |
| - // Must be called from a Sequenced Task context (i.e. |
| - // base::SequencedTaskRunnerHandle::IsSet() must be true). |
| - // |
| - // |cb| will only be called after the task invoking QueryAvailable() is |
| - // finished. |
| - virtual void QueryAvailable(const QueryAvailableCallback& cb) = 0; |
| + // |cb| will be called on the invoking thread, and will be sequenced. If |
| + // ResolvePpd() is called when a previous callback has not yet been |
| + // invoked the outstanding callback will be cancelled before the function |
| + // returns. |
| + virtual void ResolvePpd(const Printer::PpdReference& reference, |
| + const ResolvePpdCallback& cb) = 0; |
| // Most of the time, the cache is just an invisible backend to the Provider, |
| // consulted at Resolve time, but in the case of the user doing "Add Printer" |
| // and "Select PPD" locally, then we get into a state where we want to put |
| // whatever they give us directly into the cache without doing a resolve. |
| - // This hook lets is do that. |
| - virtual bool CachePpd(const Printer::PpdReference& ppd_reference, |
| - const base::FilePath& ppd_path) = 0; |
| + // This hook lets is do that. Note there's no callback here -- the caching |
| + // operation will complete asynchronously without notification. |
| + virtual void CachePpd(const Printer::PpdReference& ppd_reference, |
| + const std::string& ppd_contents) = 0; |
| + |
| + // Hook for testing. Returns true if there are no API calls that have not |
| + // yet completed. |
| + virtual bool Idle() const = 0; |
| + |
| + protected: |
| + friend class base::RefCounted<PpdProvider>; |
| + virtual ~PpdProvider() {} |
| }; |
| } // namespace printing |