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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/files/file_util.h"
6 #include "base/memory/ptr_util.h"
7 #include "base/strings/stringprintf.h"
8 #include "chromeos/printing/ppd_cache.h"
9
10 using std::string;
11 using std::unique_ptr;
12
13 namespace chromeos {
14 namespace printing {
15 namespace {
16
17 // Placeholder cache.
18 class PPDCacheImpl : public PPDCache {
19 public:
20 PPDCacheImpl(const PPDCache::Options& options) : options_(options) {}
21 ~PPDCacheImpl() override {}
22
23 // Public API functions.
24 std::unique_ptr<Printer::PPDFile> Lookup(const string& manufacturer,
25 const string& model) const override {
26 // Not yet implemented, so everything is a cache miss.
27 return unique_ptr<Printer::PPDFile>();
28 }
29
30 // Eventually this should store the contents into the cache and return a
31 // reference to that, but for now, just store the ppd file to a temporary file
32 // and return that.
33 std::unique_ptr<Printer::PPDFile> Store(
34 const string& manufacturer,
35 const string& model,
36 int64_t time_added_ms,
37 int64_t last_updated_time_ms,
38 const string& compressed_ppd_contents) override {
39 base::FilePath contents_path = options_.cache_directory.Append(
40 ::base::StringPrintf("%s_%s.ppd", manufacturer.c_str(), model.c_str()));
41 CHECK(base::WriteFile(contents_path, compressed_ppd_contents.data(),
42 compressed_ppd_contents.size()) > 0);
43 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.
44 ret->file_name = contents_path.value();
45 ret->from_quirks_server = true;
46 return ret;
47 }
48
49 private:
50 const PPDCache::Options options_;
51 };
52
53 } // namespace
54
55 // static
56 PPDCache::Options PPDCache::Defaults() {
57 PPDCache::Options ret;
58 // TODO(justincarlson) - Set a default directory here. Probably need to get
59 // PathService involved.
60 // TODO(justincarlson) - Should we be creating the directory if it doesn't
61 // 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
62 return ret;
63 }
64
65 // static
66 unique_ptr<PPDCache> PPDCache::Create(const PPDCache::Options& options) {
67 return ::base::MakeUnique<PPDCacheImpl>(options);
68 }
69
70 // static
71 unique_ptr<PPDCache> PPDCache::Create() {
72 return ::base::MakeUnique<PPDCacheImpl>(Defaults());
73 }
74
75 } // namespace printing
76 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698