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; |
+} |
+ |