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..2165f6f90cc021eafc64310b90176a641fe5024d |
--- /dev/null |
+++ b/cloud_print/gcp20/prototype/print_job_handler.cc |
@@ -0,0 +1,73 @@ |
+// 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" |
+#if defined(OS_WIN) |
+#include "base/strings/utf_string_conversions.h" |
+#endif // OS_WIN |
+ |
+namespace { |
+ |
+const base::FilePath::CharType kJobsPath[] = FILE_PATH_LITERAL("printjobs"); |
+ |
+base::FilePath GetPath(const std::string& path) { |
+#if defined(OS_WIN) |
+ return base::FilePath(base::UTF8ToWide(path)); |
Vitaly Buka (NO REVIEWS)
2013/07/22 23:46:02
Remove function
maksymb
2013/07/23 00:40:38
Done.
|
+#elif defined(OS_POSIX) |
+ return base::FilePath(path); |
+#endif |
+} |
+ |
+} // 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 + "\""; |
+ |
+ if (!base::DirectoryExists(GetPath(kJobsPath))) |
+ if (!file_util::CreateDirectory(GetPath(kJobsPath))) { |
+ LOG(WARNING) << "Cannot create directory: " << kJobsPath; |
+ return false; |
+ } |
+ |
+ std::string directory = |
Vitaly Buka (NO REVIEWS)
2013/07/22 23:46:02
std::string directory -> FilePath directory
maksymb
2013/07/23 00:40:38
Done.
|
+ base::StringPrintf("%s/%s", kJobsPath, job_name.c_str()); |
+ |
+ if (!base::DirectoryExists(GetPath(directory))) |
+ if (!file_util::CreateDirectory(GetPath(directory))) { |
+ LOG(WARNING) << "Cannot create directory: " << directory; |
+ return false; |
+ } |
+ |
+ int written = file_util::WriteFile( |
+ GetPath(directory + "/ticket.xml"), ticket.data(), ticket.size()); |
Vitaly Buka (NO REVIEWS)
2013/07/22 23:46:02
FilePath::Append
maksymb
2013/07/23 00:40:38
Done.
|
+ if (static_cast<size_t>(written) != ticket.size()) { |
+ LOG(WARNING) << "Cannot save ticket."; |
+ return false; |
+ } |
+ |
+ written = file_util::WriteFile( |
+ GetPath(directory + "/data.pdf"), data.data(), data.size()); |
Vitaly Buka (NO REVIEWS)
2013/07/22 23:46:02
FilePath::Append
maksymb
2013/07/23 00:40:38
Done.
|
+ if (static_cast<size_t>(written) != data.size()) { |
+ LOG(WARNING) << "Cannot save data."; |
+ return false; |
+ } |
+ |
+ LOG(INFO) << "Saved prinjob: " << job_name; |
+ |
+ return true; |
+} |
+ |