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

Unified Diff: chromeos/printing/ppd_cache.cc

Issue 2516513002: Lazily create PPDCache directory on first store. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « chromeos/printing/ppd_cache.h ('k') | chromeos/printing/ppd_cache_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/printing/ppd_cache.cc
diff --git a/chromeos/printing/ppd_cache.cc b/chromeos/printing/ppd_cache.cc
index 6671780b68d3438371efec6d34b1e00b0d45c8aa..2726b8ac95ecf3f678fd3c76d9fbd02ca14a039e 100644
--- a/chromeos/printing/ppd_cache.cc
+++ b/chromeos/printing/ppd_cache.cc
@@ -68,6 +68,10 @@ class PpdCacheImpl : public PpdCache {
base::Optional<base::FilePath> Store(
const Printer::PpdReference& reference,
const std::string& ppd_contents) override {
+ base::ThreadRestrictions::AssertIOAllowed();
+ if (!EnsureCacheDirectoryExists()) {
+ return base::nullopt;
+ }
base::Optional<base::FilePath> ret;
base::FilePath contents_path =
GetCachePathBase(reference).AddExtension(".ppd");
@@ -141,6 +145,10 @@ class PpdCacheImpl : public PpdCache {
// values seems reasonable.
void StoreAvailablePrinters(std::unique_ptr<PpdProvider::AvailablePrintersMap>
available_printers) override {
+ base::ThreadRestrictions::AssertIOAllowed();
+ if (!EnsureCacheDirectoryExists()) {
+ return;
+ }
available_printers_ = std::move(available_printers);
available_printers_timestamp_ = base::Time::Now();
// Convert the map to Values, in preparation for jsonification.
@@ -168,6 +176,18 @@ class PpdCacheImpl : public PpdCache {
}
private:
+ // Create the cache directory if it doesn't already exist. Returns true
+ // on success.
+ bool EnsureCacheDirectoryExists() {
+ if (base::PathExists(cache_base_dir_) ||
+ base::CreateDirectory(cache_base_dir_)) {
+ return true;
+ }
+ LOG(ERROR) << "Failed to create ppd cache directory "
+ << cache_base_dir_.MaybeAsASCII();
+ return false;
+ }
+
// Get the file path at which we expect to find a PPD if it's cached.
//
// This is, ultimately, just a hash function. It's extremely infrequently
« no previous file with comments | « chromeos/printing/ppd_cache.h ('k') | chromeos/printing/ppd_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698