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

Unified Diff: chromeos/printing/ppd_cache.cc

Issue 2343983004: Add PPDProvider barebones implementation and associated cache skeleton. (Closed)
Patch Set: Remove extra includes Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/printing/ppd_cache.cc
diff --git a/chromeos/printing/ppd_cache.cc b/chromeos/printing/ppd_cache.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aaf99679045c84247073cf1152ed90cf52c5113c
--- /dev/null
+++ b/chromeos/printing/ppd_cache.cc
@@ -0,0 +1,76 @@
+// 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.
+
+#include "base/files/file_util.h"
+#include "base/memory/ptr_util.h"
+#include "base/strings/stringprintf.h"
+#include "chromeos/printing/ppd_cache.h"
+
+using std::string;
+using std::unique_ptr;
+
+namespace chromeos {
+namespace printing {
+namespace {
+
+// Placeholder cache.
+class PPDCacheImpl : public PPDCache {
+ public:
+ PPDCacheImpl(const PPDCache::Options& options) : options_(options) {}
+ ~PPDCacheImpl() override {}
+
+ // Public API functions.
+ std::unique_ptr<Printer::PPDFile> Lookup(const string& manufacturer,
+ const string& model) const override {
+ // Not yet implemented, so everything is a cache miss.
+ return unique_ptr<Printer::PPDFile>();
+ }
+
+ // Eventually this should store the contents into the cache and return a
+ // reference to that, but for now, just store the ppd file to a temporary file
+ // and return that.
+ std::unique_ptr<Printer::PPDFile> Store(
+ const string& manufacturer,
+ const string& model,
+ int64_t time_added_ms,
+ int64_t last_updated_time_ms,
+ const string& compressed_ppd_contents) override {
+ base::FilePath contents_path = options_.cache_directory.Append(
+ ::base::StringPrintf("%s_%s.ppd", manufacturer.c_str(), model.c_str()));
+ CHECK(base::WriteFile(contents_path, compressed_ppd_contents.data(),
+ compressed_ppd_contents.size()) > 0);
+ std::unique_ptr<Printer::PPDFile> ret(new Printer::PPDFile);
skau 2016/09/17 00:59:59 ret = base::MakeUnique<PPDFile>(). Raw use of new
Carlson 2016/10/06 15:56:05 Done.
+ ret->file_name = contents_path.value();
+ ret->from_quirks_server = true;
+ return ret;
+ }
+
+ private:
+ const PPDCache::Options options_;
+};
+
+} // namespace
+
+// static
+PPDCache::Options PPDCache::Defaults() {
+ PPDCache::Options ret;
+ // TODO(justincarlson) - Set a default directory here. Probably need to get
+ // PathService involved.
+ // TODO(justincarlson) - Should we be creating the directory if it doesn't
+ // exist?
skau 2016/09/17 00:59:59 We'll need to hook back into Chrome for the direct
Carlson 2016/10/06 15:56:05 This seems to fit nicely in what PathService provi
+ return ret;
+}
+
+// static
+unique_ptr<PPDCache> PPDCache::Create(const PPDCache::Options& options) {
+ return ::base::MakeUnique<PPDCacheImpl>(options);
+}
+
+// static
+unique_ptr<PPDCache> PPDCache::Create() {
+ return ::base::MakeUnique<PPDCacheImpl>(Defaults());
+}
+
+} // namespace printing
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698