| 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..b3ac11bc4f5ee8b3d99da3ae703a4d4b5b12a6d9
|
| --- /dev/null
|
| +++ b/cloud_print/gcp20/prototype/print_job_handler.cc
|
| @@ -0,0 +1,61 @@
|
| +// 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(), 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(), data.size());
|
| + if (static_cast<size_t>(written) != data.size()) {
|
| + LOG(WARNING) << "Cannot save data.";
|
| + return false;
|
| + }
|
| +
|
| + LOG(INFO) << "Saved prinjob: " << job_name;
|
| + return true;
|
| +}
|
| +
|
|
|