Index: chromeos/printing/ppd_cache.h |
diff --git a/chromeos/printing/ppd_cache.h b/chromeos/printing/ppd_cache.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f3f051fad918492ebe53f7003f30f2519d7b984a |
--- /dev/null |
+++ b/chromeos/printing/ppd_cache.h |
@@ -0,0 +1,62 @@ |
+// 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_CACHE_H_ |
+#define CHROMEOS_PRINTING_PPD_CACHE_H_ |
+ |
+#include <memory> |
+#include <string> |
+ |
+#include "base/files/file_path.h" |
+#include "base/optional.h" |
+#include "chromeos/chromeos_export.h" |
+#include "chromeos/printing/printer_configuration.h" |
+ |
+namespace chromeos { |
+namespace printing { |
+ |
+// PpdCache manages a cache of locally-stored ppd files. At its core, |
Lei Zhang
2016/10/17 17:54:06
PPD
Carlson
2016/10/18 19:05:01
Done.
|
+// it operates like a persistent hash from PpdReference to files. If |
+// you give the same PpdReference to Find that was previously passed |
Lei Zhang
2016/10/17 17:54:06
Find()
Carlson
2016/10/18 19:05:01
Done.
|
+// to |
+class CHROMEOS_EXPORT PpdCache { |
+ public: |
+ // Construction-time optional parameters. These should all have defaults that |
+ // are sane. |
+ struct Options { |
Lei Zhang
2016/10/17 17:54:06
Can you add this once you actually have options?
Carlson
2016/10/18 19:05:01
Done.
|
+ // Nothing here yet. We may want to add ttl-style options here eventually |
Lei Zhang
2016/10/17 17:54:06
Some people do not like using "we" in comments bec
Carlson
2016/10/18 19:05:01
Not sure if use of vague "some people" in comment
|
+ // so the cache doesn't grow without bound. |
+ }; |
+ |
+ // Create and return a Ppdcache that uses cache_dir to store state. |
+ static std::unique_ptr<PpdCache> Create(const base::FilePath& cache_base_dir, |
+ const Options& options = Options()); |
+ virtual ~PpdCache() {} |
+ |
+ // Find a PPD that was previously cached with the given reference. Note that |
+ // all fields of the reference must be the same, otherwise we'll miss in the |
+ // cache and re-run resolution for the PPD. |
+ // |
+ // If a FilePath is returned, it is guaranteed to remain valid until the next |
+ // Store() call. |
+ virtual base::Optional<base::FilePath> Find( |
Lei Zhang
2016/10/17 17:54:07
Do you need the Optional? Can an empty FilePath re
Carlson
2016/10/18 19:05:01
We could do that, but I'm generally against specia
Lei Zhang
2016/10/18 19:37:00
Where do you draw the line there? Does malloc() re
Carlson
2016/10/18 20:06:28
If you want to litigate Optional as a useful tool,
Lei Zhang
2016/10/18 22:25:34
You wrote "happy to take any suggestions" so I'm g
Carlson
2016/10/18 23:54:31
Social subtleties don't always come across well in
|
+ const Printer::PpdReference& reference) const = 0; |
+ |
+ // Take the contents of a ppd file, store it to the cache, and return the |
+ // path to the stored file keyed on reference. |
+ // |
+ // If a different ppd was previously Stored for the given reference, it |
+ // will be replaced. |
+ // |
+ // On success, the returned FilePath is guaranteed to remain valid until the |
+ // next Store* call. |
+ virtual base::Optional<base::FilePath> Store( |
+ const Printer::PpdReference& reference, |
+ const std::string& ppd_contents) = 0; |
+}; |
+ |
+} // namespace printing |
+} // namespace chromeos |
+ |
+#endif // CHROMEOS_PRINTING_PPD_CACHE_H_ |