Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMEOS_PRINTING_PPD_PROVIDER_H_ | 5 #ifndef CHROMEOS_PRINTING_PPD_PROVIDER_H_ |
| 6 #define CHROMEOS_PRINTING_PPD_PROVIDER_H_ | 6 #define CHROMEOS_PRINTING_PPD_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 namespace chromeos { | 23 namespace chromeos { |
| 24 namespace printing { | 24 namespace printing { |
| 25 | 25 |
| 26 class PpdCache; | 26 class PpdCache; |
| 27 | 27 |
| 28 // PpdProvider is responsible for mapping printer descriptions to | 28 // PpdProvider is responsible for mapping printer descriptions to |
| 29 // CUPS-PostScript Printer Description (PPD) files. It provides PPDs that a | 29 // CUPS-PostScript Printer Description (PPD) files. It provides PPDs that a |
| 30 // user previously identified for use, and falls back to querying quirksserver | 30 // user previously identified for use, and falls back to querying quirksserver |
| 31 // based on manufacturer/model of the printer. | 31 // based on manufacturer/model of the printer. |
| 32 // | 32 // |
| 33 // This class can be accessed from any thread. | 33 // All functions in this class must be called from a sequenced context. |
| 34 class CHROMEOS_EXPORT PpdProvider { | 34 class CHROMEOS_EXPORT PpdProvider : public base::RefCounted<PpdProvider> { |
| 35 public: | 35 public: |
| 36 // Possible result codes of a Resolve() or QueryAvailable() call. | 36 // Possible result codes of a Resolve*() call. |
| 37 enum CallbackResultCode { | 37 enum CallbackResultCode { |
| 38 SUCCESS, | 38 SUCCESS, |
| 39 | 39 |
| 40 // Looked for a PPD for this configuration, but couldn't find a match. | 40 // Looked for a PPD for this configuration, but couldn't find a match. |
| 41 // Never returned for QueryAvailable(). | 41 // Never returned for QueryAvailable(). |
| 42 NOT_FOUND, | 42 NOT_FOUND, |
| 43 | 43 |
| 44 // Failed to contact an external server needed to finish resolution. | 44 // Failed to contact an external server needed to finish resolution. |
| 45 SERVER_ERROR, | 45 SERVER_ERROR, |
| 46 | 46 |
| 47 // Other error that is not expected to be transient. | 47 // Other error that is not expected to be transient. |
| 48 INTERNAL_ERROR, | 48 INTERNAL_ERROR, |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // Result of a Resolve(). If the result code is SUCCESS, then FilePath holds | |
| 52 // the path to a PPD file (that may or may not be gzipped). Otherwise, the | |
| 53 // FilePath will be empty. | |
| 54 using ResolveCallback = | |
| 55 base::Callback<void(CallbackResultCode, base::FilePath)>; | |
| 56 | |
| 57 // Available printers are represented as a map from manufacturer to | |
| 58 // list-of-printer-models. | |
| 59 using AvailablePrintersMap = std::map<std::string, std::vector<std::string>>; | |
| 60 | |
| 61 // Result of a QueryAvailable. If the result code is SUCCESS, then | |
| 62 // AvailablePrintersMap holds a map from manufacturer name to list of printer | |
| 63 // names. Otherwise the map will be empty. | |
| 64 using QueryAvailableCallback = | |
| 65 base::Callback<void(CallbackResultCode, const AvailablePrintersMap&)>; | |
| 66 | |
| 67 // Construction-time options. Everything in this structure should have | 51 // Construction-time options. Everything in this structure should have |
| 68 // a sane default. | 52 // a sane default. |
| 69 struct Options { | 53 struct Options { |
| 70 Options() {} | 54 Options() {} |
| 71 | 55 |
| 72 // hostname of quirks server to query. | 56 // Root of the ppd serving hierarchy. |
| 73 std::string quirks_server = "chromeosquirksserver-pa.googleapis.com"; | 57 std::string ppd_server_root = "https://www.gstatic.com/chromeos_printing"; |
| 74 | 58 |
| 75 // Maximum size of the contents of a PPD file, in bytes. Trying to use a | 59 // Maximum size of the contents of a PPD file, in bytes. Trying to use a |
| 76 // PPD file bigger than this will cause INTERNAL_ERRORs at resolution time. | 60 // PPD file bigger than this will cause INTERNAL_ERRORs at resolution time. |
| 77 size_t max_ppd_contents_size_ = 100 * 1024; | 61 size_t max_ppd_contents_size_ = 100 * 1024; |
|
skau
2017/01/27 01:37:01
Is this parameter still used by the cache?
Carlson
2017/01/27 18:48:43
This is actually used in the provider to reject th
skau
2017/01/27 19:16:10
Doesn't the PpdProviderImpl construct the cache?
Carlson
2017/01/27 22:56:22
No, it's passed in at construction time because de
| |
| 78 }; | 62 }; |
| 79 | 63 |
| 64 // Result of a ResolvePpd() call. If the result code is SUCCESS, then the | |
| 65 // string holds the contents of a PPD (that may or may not be gzipped). | |
| 66 // Otherwise, the string will be empty. | |
| 67 using ResolvePpdCallback = | |
| 68 base::Callback<void(CallbackResultCode, const std::string&)>; | |
| 69 | |
| 70 // Result of a ResolveManufacturers() call. If the result code is SUCCESS, | |
| 71 // then the vector contains a sorted list of manufacturers for which we have | |
| 72 // at least one printer driver. | |
| 73 using ResolveManufacturersCallback = | |
| 74 base::Callback<void(CallbackResultCode, const std::vector<std::string>&)>; | |
| 75 | |
| 76 // Result of a ResolvePrinters() call. If the result code is SUCCESS, then | |
| 77 // the vector contains a sorted list of all printer models from the given | |
| 78 // manufacturer for which we have a driver. | |
| 79 using ResolvePrintersCallback = | |
| 80 base::Callback<void(CallbackResultCode, const std::vector<std::string>&)>; | |
| 81 | |
| 80 // Create and return a new PpdProvider with the given cache and options. | 82 // Create and return a new PpdProvider with the given cache and options. |
| 81 // |io_task_runner| is used to run operations that are long latency and should | 83 // A references to |url_context_getter| is taken. |
| 82 // not be on the UI thread. References to |url_context_getter| and | 84 static scoped_refptr<PpdProvider> Create( |
| 83 // |io_task_runner| are taken. | 85 const std::string& browser_locale, |
| 84 static std::unique_ptr<PpdProvider> Create( | |
| 85 const std::string& api_key, | |
| 86 scoped_refptr<net::URLRequestContextGetter> url_context_getter, | 86 scoped_refptr<net::URLRequestContextGetter> url_context_getter, |
| 87 scoped_refptr<base::SequencedTaskRunner> io_task_runner, | 87 scoped_refptr<PpdCache> cache, |
| 88 std::unique_ptr<PpdCache> cache, | |
| 89 const Options& options = Options()); | 88 const Options& options = Options()); |
| 90 | 89 |
| 90 // Get all manufacturers for which we have drivers. Keys of the map will be | |
| 91 // localized in the default browser locale or the closest available fallback. | |
| 92 // | |
| 93 // |cb| will be called on the invoking thread, and will be sequenced. If | |
| 94 // ResolveManufacturers is called when a previous callback has not yet been | |
| 95 // invoked the outstanding will be cancelled before the function returns. | |
| 96 virtual void ResolveManufacturers(const ResolveManufacturersCallback& cb) = 0; | |
| 97 | |
| 98 // Get all models from a given manufacturer, localized in the default browser | |
| 99 // locale or the closest available fallback. |manufacturer| must be a value | |
| 100 // returned from a successful ResolveManufacturers() call performed from this | |
| 101 // PpdProvider instance. | |
| 102 // | |
| 103 // |cb| will be called on the invoking thread, and will be sequenced. If | |
|
skau
2017/01/27 01:37:01
I don't see any cancellation behavior in the impl.
Carlson
2017/01/27 18:48:43
You're right, it was stale. We new queue ALL THE
| |
| 104 // ResolvePrinters() is called when a previous callback has not yet been | |
| 105 // invoked the outstanding callback will be cancelled before the function | |
| 106 // returns. | |
| 107 virtual void ResolvePrinters(const std::string& manufacturer, | |
| 108 const ResolvePrintersCallback& cb) = 0; | |
| 109 | |
| 110 // Given a |manufacturer| from ResolveManufacturers() and a |printer| from | |
| 111 // a ResolvePrinters() call for that manufacturer, fill in |reference| | |
| 112 // with the information needed to resolve the Ppd for this printer. Returns | |
| 113 // true on success and overwrites the contents of |reference|. On failure, | |
| 114 // |reference| is unchanged. | |
| 115 // | |
| 116 // Note that, unlike the other functions in this class, |reference| can be | |
| 117 // saved and given to ResolvePpd() in a different PpdProvider instance without | |
| 118 // first resolving manufactuerers or printers. | |
| 119 virtual bool GetPpdReference(const std::string& manufacturer, | |
| 120 const std::string& printer, | |
| 121 Printer::PpdReference* reference) const = 0; | |
| 122 | |
| 123 // Given a PpdReference, attempt to get the PPD for printing. | |
| 124 // | |
| 125 // |cb| will be called on the invoking thread, and will be sequenced. If | |
| 126 // ResolvePpd() is called when a previous callback has not yet been | |
| 127 // invoked the outstanding callback will be cancelled before the function | |
| 128 // returns. | |
| 129 virtual void ResolvePpd(const Printer::PpdReference& reference, | |
| 130 const ResolvePpdCallback& cb) = 0; | |
| 131 | |
| 132 // Hook for testing. Returns true if there are no API calls that have not | |
| 133 // yet completed. | |
| 134 virtual bool Idle() const = 0; | |
| 135 | |
| 136 protected: | |
| 137 friend class base::RefCounted<PpdProvider>; | |
| 91 virtual ~PpdProvider() {} | 138 virtual ~PpdProvider() {} |
| 92 | |
| 93 // Given a PpdReference, attempt to resolve the PPD for printing. | |
| 94 // | |
| 95 // Must be called from a Sequenced Task context (i.e. | |
| 96 // base::SequencedTaskRunnerHandle::IsSet() must be true). | |
| 97 // | |
| 98 // |cb| will only be called after the task invoking Resolve() is finished. | |
| 99 virtual void Resolve(const Printer::PpdReference& ppd_reference, | |
| 100 const ResolveCallback& cb) = 0; | |
| 101 | |
| 102 // Get all the printer makes and models we can support. | |
| 103 // | |
| 104 // Must be called from a Sequenced Task context (i.e. | |
| 105 // base::SequencedTaskRunnerHandle::IsSet() must be true). | |
| 106 // | |
| 107 // |cb| will only be called after the task invoking QueryAvailable() is | |
| 108 // finished. | |
| 109 virtual void QueryAvailable(const QueryAvailableCallback& cb) = 0; | |
| 110 | |
| 111 // Most of the time, the cache is just an invisible backend to the Provider, | |
| 112 // consulted at Resolve time, but in the case of the user doing "Add Printer" | |
| 113 // and "Select PPD" locally, then we get into a state where we want to put | |
| 114 // whatever they give us directly into the cache without doing a resolve. | |
| 115 // This hook lets is do that. | |
| 116 virtual bool CachePpd(const Printer::PpdReference& ppd_reference, | |
| 117 const base::FilePath& ppd_path) = 0; | |
| 118 }; | 139 }; |
| 119 | 140 |
| 120 } // namespace printing | 141 } // namespace printing |
| 121 } // namespace chromeos | 142 } // namespace chromeos |
| 122 | 143 |
| 123 #endif // CHROMEOS_PRINTING_PPD_PROVIDER_H_ | 144 #endif // CHROMEOS_PRINTING_PPD_PROVIDER_H_ |
| OLD | NEW |