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

Unified Diff: cloud_print/gcp20/prototype/print_job_handler.cc

Issue 19866002: GCP2.0 Device: Receiving printjobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@confirmation
Patch Set: static_cast<int> Created 7 years, 5 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
« no previous file with comments | « cloud_print/gcp20/prototype/print_job_handler.h ('k') | cloud_print/gcp20/prototype/printer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cloud_print/gcp20/prototype/print_job_handler.cc
diff --git a/cloud_print/gcp20/prototype/print_job_handler.cc b/cloud_print/gcp20/prototype/print_job_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c7549e401209081f179f5004215f7dffc5db9888
--- /dev/null
+++ b/cloud_print/gcp20/prototype/print_job_handler.cc
@@ -0,0 +1,63 @@
+// Copyright 2013 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 "cloud_print/gcp20/prototype/print_job_handler.h"
+
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/strings/stringprintf.h"
+
+namespace {
+
+const base::FilePath::CharType kJobsPath[] = FILE_PATH_LITERAL("printjobs");
+
+} // namespace
+
+PrintJobHandler::PrintJobHandler() {
+}
+
+PrintJobHandler::~PrintJobHandler() {
+}
+
+bool PrintJobHandler::SavePrintJob(const std::string& data,
+ const std::string& ticket,
+ const std::string& job_name,
+ const std::string& title) {
+ VLOG(1) << "Printing printjob: \"" + title + "\"";
+ base::FilePath directory(kJobsPath);
+
+ using file_util::CreateDirectory;
+
+ if (!base::DirectoryExists(directory) && !CreateDirectory(directory)) {
+ LOG(WARNING) << "Cannot create directory: " << directory.value();
+ return false;
+ }
+
+ directory = directory.AppendASCII(job_name);
+
+ if (!base::DirectoryExists(directory) && !CreateDirectory(directory)) {
+ LOG(WARNING) << "Cannot create directory: " << directory.value();
+ return false;
+ }
+
+ int written = file_util::WriteFile(directory.AppendASCII("ticket.xml"),
+ ticket.data(),
+ static_cast<int>(ticket.size()));
+ if (static_cast<size_t>(written) != ticket.size()) {
+ LOG(WARNING) << "Cannot save ticket.";
+ return false;
+ }
+
+ written = file_util::WriteFile(directory.AppendASCII("data.pdf"),
+ data.data(),
+ static_cast<int>(data.size()));
+ if (static_cast<size_t>(written) != data.size()) {
+ LOG(WARNING) << "Cannot save data.";
+ return false;
+ }
+
+ LOG(INFO) << "Saved printjob: " << job_name;
+ return true;
+}
+
« no previous file with comments | « cloud_print/gcp20/prototype/print_job_handler.h ('k') | cloud_print/gcp20/prototype/printer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698