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

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

Issue 19866002: GCP2.0 Device: Receiving printjobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@confirmation
Patch Set: 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
Index: cloud_print/gcp20/prototype/printjob_handler.cc
diff --git a/cloud_print/gcp20/prototype/printjob_handler.cc b/cloud_print/gcp20/prototype/printjob_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ca82e2be62e0eec89a90907f40fa14d1f0e107f1
--- /dev/null
+++ b/cloud_print/gcp20/prototype/printjob_handler.cc
@@ -0,0 +1,62 @@
+// 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/printjob_handler.h"
Vitaly Buka (NO REVIEWS) 2013/07/22 03:57:31 print_job_handler.h"
maksymb 2013/07/22 22:56:53 Done.
+
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/strings/stringprintf.h"
+
+namespace {
+
+const char* jobspath = "printjobs";
+
+} // namespace
+
+PrintjobHandler::PrintjobHandler() {
+}
+
+PrintjobHandler::~PrintjobHandler() {
+}
+
+bool PrintjobHandler::SavePrintjob(const std::string& data,
+ const std::string& ticket,
+ const std::string& jobname,
+ const std::string& title) {
+ VLOG(1) << "Printing printjob: \"" + title + "\"";
+
+ if (!base::DirectoryExists(base::FilePath(jobname)))
+ if (!file_util::CreateDirectory(base::FilePath(jobspath))) {
+ LOG(WARNING) << "Cannot create directory: " << jobspath;
+ return false;
+ }
+
+ std::string directory = base::StringPrintf("%s/%s", jobspath,
+ jobname.c_str());
+
+ if (!base::DirectoryExists(base::FilePath(directory)))
+ if (!file_util::CreateDirectory(base::FilePath(directory))) {
+ LOG(WARNING) << "Cannot create directory: " << directory;
+ return false;
+ }
+
+ int written = file_util::WriteFile(
+ base::FilePath(directory + "/ticket.xml"), ticket.data(), ticket.size());
+ if (static_cast<size_t>(written) != ticket.size()) {
+ LOG(WARNING) << "Cannot save ticket.";
+ return false;
+ }
+
+ written = file_util::WriteFile(
+ base::FilePath(directory + "/data.pdf"), data.data(), data.size());
+ if (static_cast<size_t>(written) != data.size()) {
+ LOG(WARNING) << "Cannot save data.";
+ return false;
+ }
+
+ LOG(INFO) << "Saved prinjob: " << jobname;
+
+ return true;
+}
+

Powered by Google App Engine
This is Rietveld 408576698