Index: cloud_print/gcp20/prototype/print_job_handler.h |
diff --git a/cloud_print/gcp20/prototype/print_job_handler.h b/cloud_print/gcp20/prototype/print_job_handler.h |
index fc48a1eb7eaa5e403359ee686b84fe58dc44d016..fe59c7fe64d6838a5bf7e845c45c3f8850229dc3 100644 |
--- a/cloud_print/gcp20/prototype/print_job_handler.h |
+++ b/cloud_print/gcp20/prototype/print_job_handler.h |
@@ -5,9 +5,12 @@ |
#ifndef CLOUD_PRINT_GCP20_PROTOTYPE_PRINT_JOB_HANDLER_H_ |
#define CLOUD_PRINT_GCP20_PROTOTYPE_PRINT_JOB_HANDLER_H_ |
+#include <map> |
#include <string> |
#include "base/basictypes.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
#include "cloud_print/gcp20/prototype/local_print_job.h" |
namespace base { |
@@ -17,18 +20,39 @@ class Time; |
} // namespace base |
-class PrintJobHandler { |
+class PrintJobHandler : public base::SupportsWeakPtr<PrintJobHandler> { |
public: |
PrintJobHandler(); |
~PrintJobHandler(); |
- LocalPrintJob::CreateResult CreatePrintJob(std::string* job_id, |
- int* expires_in); |
- LocalPrintJob::SaveResult SaveLocalPrintJob(const LocalPrintJob& job, |
- std::string* job_id, |
- std::string* error_description, |
- int* timeout); |
+ // Creates printer job draft |
+ LocalPrintJob::CreateResult CreatePrintJob( |
+ const std::string& ticket, |
+ std::string* job_id_out, |
+ int* expires_in_out, |
+ int* error_timeout_out, |
+ std::string* error_description_out); |
+ // Creates printer job with empty ticket and "prints" it |
+ LocalPrintJob::SaveResult SaveLocalPrintJob( |
+ const LocalPrintJob& job, |
+ std::string* job_id_out, |
+ int* expires_in_out, |
+ std::string* error_description_out, |
+ int* timeout_out); |
+ |
+ // Completes printer job from draft |
+ LocalPrintJob::SaveResult CompleteLocalPrintJob( |
+ const LocalPrintJob& job, |
+ const std::string& job_id, |
+ int* expires_in_out, |
+ std::string* error_description_out, |
+ int* timeout_out); |
+ |
+ // Gives info about job |
+ bool GetJobState(const std::string& id, LocalPrintJob::Info* info_out); |
+ |
+ // Saving print job directly to drive |
bool SavePrintJob(const std::string& content, |
const std::string& ticket, |
const base::Time& create_time, |
@@ -38,6 +62,34 @@ class PrintJobHandler { |
const std::string& file_extension); |
private: |
+ // Contains ticket info and job info together |
+ struct LocalPrintJobExtended; |
+ |
+ // Contains job ticket |
+ struct LocalPrintJobDraft; |
+ |
+ // Contains all unexpired drafts |
+ std::map<std::string, LocalPrintJobDraft> drafts; // id -> draft |
+ |
+ // Contains all unexpired jobs |
+ std::map<std::string, LocalPrintJobExtended> jobs; // id -> printjob |
+ |
+ // Changes job state and creates timeouts to delete old jobs from memory |
+ void SetJobState(const std::string& id, LocalPrintJob::State); |
+ |
+ // Moves draft to jobs |
+ void CompleteDraft(const std::string& id, const LocalPrintJob& job); |
+ |
+ // Calculates expiration for job |
+ // TODO(maksymb): Use base::Time for expiration |
+ base::TimeDelta GetJobExpiration(const std::string& id) const; |
+ |
+ // Erases draft from memory |
+ void ForgetDraft(const std::string& id); |
+ |
+ // Erases job from memory |
+ void ForgetLocalJob(const std::string& id); |
+ |
DISALLOW_COPY_AND_ASSIGN(PrintJobHandler); |
}; |