| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ | 5 #ifndef CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ |
| 6 #define CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ | 6 #define CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // | | 60 // | |
| 61 // | | 61 // | |
| 62 // Stop | 62 // Stop |
| 63 // (If there are pending tasks go back to Start) | 63 // (If there are pending tasks go back to Start) |
| 64 | 64 |
| 65 class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>, | 65 class PrinterJobHandler : public base::RefCountedThreadSafe<PrinterJobHandler>, |
| 66 public CloudPrintURLFetcherDelegate, | 66 public CloudPrintURLFetcherDelegate, |
| 67 public JobStatusUpdaterDelegate, | 67 public JobStatusUpdaterDelegate, |
| 68 public cloud_print::PrinterWatcherDelegate, | 68 public cloud_print::PrinterWatcherDelegate, |
| 69 public cloud_print::JobSpoolerDelegate { | 69 public cloud_print::JobSpoolerDelegate { |
| 70 enum PrintJobError { | |
| 71 SUCCESS, | |
| 72 JOB_DOWNLOAD_FAILED, | |
| 73 INVALID_JOB_DATA, | |
| 74 PRINT_FAILED, | |
| 75 }; | |
| 76 struct JobDetails { | |
| 77 JobDetails(); | |
| 78 ~JobDetails(); | |
| 79 void Clear(); | |
| 80 | |
| 81 std::string job_id_; | |
| 82 std::string job_title_; | |
| 83 std::string print_ticket_; | |
| 84 FilePath print_data_file_path_; | |
| 85 std::string print_data_mime_type_; | |
| 86 std::vector<std::string> tags_; | |
| 87 }; | |
| 88 | |
| 89 public: | 70 public: |
| 90 class Delegate { | 71 class Delegate { |
| 91 public: | 72 public: |
| 92 // Notify delegate about authentication error. | 73 // Notify delegate about authentication error. |
| 93 virtual void OnAuthError() = 0; | 74 virtual void OnAuthError() = 0; |
| 94 // Notify delegate that printer has been deleted. | 75 // Notify delegate that printer has been deleted. |
| 95 virtual void OnPrinterDeleted(const std::string& printer_name) = 0; | 76 virtual void OnPrinterDeleted(const std::string& printer_name) = 0; |
| 96 | 77 |
| 97 protected: | 78 protected: |
| 98 virtual ~Delegate() {} | 79 virtual ~Delegate() {} |
| 99 }; | 80 }; |
| 100 | 81 |
| 101 struct PrinterInfoFromCloud { | 82 struct PrinterInfoFromCloud { |
| 102 std::string printer_id; | 83 std::string printer_id; |
| 103 std::string caps_hash; | 84 std::string caps_hash; |
| 104 std::string tags_hash; | 85 std::string tags_hash; |
| 105 }; | 86 }; |
| 106 | 87 |
| 107 // Begin public interface | 88 // Begin public interface |
| 108 PrinterJobHandler(const printing::PrinterBasicInfo& printer_info, | 89 PrinterJobHandler(const printing::PrinterBasicInfo& printer_info, |
| 109 const PrinterInfoFromCloud& printer_info_from_server, | 90 const PrinterInfoFromCloud& printer_info_from_server, |
| 110 const GURL& cloud_print_server_url, | 91 const GURL& cloud_print_server_url, |
| 111 cloud_print::PrintSystem* print_system, | 92 cloud_print::PrintSystem* print_system, |
| 112 Delegate* delegate); | 93 Delegate* delegate); |
| 113 virtual ~PrinterJobHandler(); | 94 |
| 114 bool Initialize(); | 95 bool Initialize(); |
| 96 |
| 115 std::string GetPrinterName() const; | 97 std::string GetPrinterName() const; |
| 98 |
| 116 // Requests a job check. |reason| is the reason for fetching the job. Used | 99 // Requests a job check. |reason| is the reason for fetching the job. Used |
| 117 // for logging and diagnostc purposes. | 100 // for logging and diagnostc purposes. |
| 118 void CheckForJobs(const std::string& reason); | 101 void CheckForJobs(const std::string& reason); |
| 102 |
| 119 // Shutdown everything (the process is exiting). | 103 // Shutdown everything (the process is exiting). |
| 120 void Shutdown(); | 104 void Shutdown(); |
| 105 |
| 121 base::TimeTicks last_job_fetch_time() const { return last_job_fetch_time_; } | 106 base::TimeTicks last_job_fetch_time() const { return last_job_fetch_time_; } |
| 122 // End public interface | 107 // End public interface |
| 123 | 108 |
| 124 // Begin Delegate implementations | 109 // Begin Delegate implementations |
| 125 | 110 |
| 126 // CloudPrintURLFetcher::Delegate implementation. | 111 // CloudPrintURLFetcher::Delegate implementation. |
| 127 virtual CloudPrintURLFetcher::ResponseAction HandleRawResponse( | 112 virtual CloudPrintURLFetcher::ResponseAction HandleRawResponse( |
| 128 const content::URLFetcher* source, | 113 const content::URLFetcher* source, |
| 129 const GURL& url, | 114 const GURL& url, |
| 130 const net::URLRequestStatus& status, | 115 const net::URLRequestStatus& status, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 155 | 140 |
| 156 // cloud_print::JobSpoolerDelegate implementation. | 141 // cloud_print::JobSpoolerDelegate implementation. |
| 157 // Called on print_thread_. | 142 // Called on print_thread_. |
| 158 virtual void OnJobSpoolSucceeded( | 143 virtual void OnJobSpoolSucceeded( |
| 159 const cloud_print::PlatformJobId& job_id) OVERRIDE; | 144 const cloud_print::PlatformJobId& job_id) OVERRIDE; |
| 160 virtual void OnJobSpoolFailed() OVERRIDE; | 145 virtual void OnJobSpoolFailed() OVERRIDE; |
| 161 | 146 |
| 162 // End Delegate implementations | 147 // End Delegate implementations |
| 163 | 148 |
| 164 private: | 149 private: |
| 150 friend class base::RefCountedThreadSafe<PrinterJobHandler>; |
| 151 |
| 152 enum PrintJobError { |
| 153 SUCCESS, |
| 154 JOB_DOWNLOAD_FAILED, |
| 155 INVALID_JOB_DATA, |
| 156 PRINT_FAILED, |
| 157 }; |
| 158 |
| 165 // Prototype for a JSON data handler. | 159 // Prototype for a JSON data handler. |
| 166 typedef CloudPrintURLFetcher::ResponseAction | 160 typedef CloudPrintURLFetcher::ResponseAction |
| 167 (PrinterJobHandler::*JSONDataHandler)(const content::URLFetcher* source, | 161 (PrinterJobHandler::*JSONDataHandler)(const content::URLFetcher* source, |
| 168 const GURL& url, | 162 const GURL& url, |
| 169 base::DictionaryValue* json_data, | 163 base::DictionaryValue* json_data, |
| 170 bool succeeded); | 164 bool succeeded); |
| 171 // Prototype for a data handler. | 165 // Prototype for a data handler. |
| 172 typedef CloudPrintURLFetcher::ResponseAction | 166 typedef CloudPrintURLFetcher::ResponseAction |
| 173 (PrinterJobHandler::*DataHandler)(const content::URLFetcher* source, | 167 (PrinterJobHandler::*DataHandler)(const content::URLFetcher* source, |
| 174 const GURL& url, | 168 const GURL& url, |
| 175 const std::string& data); | 169 const std::string& data); |
| 170 |
| 171 struct JobDetails { |
| 172 JobDetails(); |
| 173 ~JobDetails(); |
| 174 void Clear(); |
| 175 |
| 176 std::string job_id_; |
| 177 std::string job_title_; |
| 178 std::string print_ticket_; |
| 179 FilePath print_data_file_path_; |
| 180 std::string print_data_mime_type_; |
| 181 std::vector<std::string> tags_; |
| 182 }; |
| 183 |
| 184 virtual ~PrinterJobHandler(); |
| 185 |
| 176 // Begin request handlers for each state in the state machine | 186 // Begin request handlers for each state in the state machine |
| 177 CloudPrintURLFetcher::ResponseAction HandlePrinterUpdateResponse( | 187 CloudPrintURLFetcher::ResponseAction HandlePrinterUpdateResponse( |
| 178 const content::URLFetcher* source, | 188 const content::URLFetcher* source, |
| 179 const GURL& url, | 189 const GURL& url, |
| 180 base::DictionaryValue* json_data, | 190 base::DictionaryValue* json_data, |
| 181 bool succeeded); | 191 bool succeeded); |
| 182 | 192 |
| 183 CloudPrintURLFetcher::ResponseAction HandleJobMetadataResponse( | 193 CloudPrintURLFetcher::ResponseAction HandleJobMetadataResponse( |
| 184 const content::URLFetcher* source, | 194 const content::URLFetcher* source, |
| 185 const GURL& url, | 195 const GURL& url, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 212 // Start the state machine. Based on the flags set this could mean updating | 222 // Start the state machine. Based on the flags set this could mean updating |
| 213 // printer information, deleting the printer from the server or looking for | 223 // printer information, deleting the printer from the server or looking for |
| 214 // new print jobs | 224 // new print jobs |
| 215 void Start(); | 225 void Start(); |
| 216 | 226 |
| 217 // End the state machine. If there are pending tasks, we will post a Start | 227 // End the state machine. If there are pending tasks, we will post a Start |
| 218 // again. | 228 // again. |
| 219 void Stop(); | 229 void Stop(); |
| 220 | 230 |
| 221 void StartPrinting(); | 231 void StartPrinting(); |
| 222 void HandleServerError(const GURL& url); | |
| 223 void Reset(); | 232 void Reset(); |
| 224 void UpdateJobStatus(cloud_print::PrintJobStatus status, PrintJobError error); | 233 void UpdateJobStatus(cloud_print::PrintJobStatus status, PrintJobError error); |
| 225 | 234 |
| 226 // Sets the next response handler to the specifed JSON data handler. | 235 // Sets the next response handler to the specifed JSON data handler. |
| 227 void SetNextJSONHandler(JSONDataHandler handler); | 236 void SetNextJSONHandler(JSONDataHandler handler); |
| 228 // Sets the next response handler to the specifed data handler. | 237 // Sets the next response handler to the specifed data handler. |
| 229 void SetNextDataHandler(DataHandler handler); | 238 void SetNextDataHandler(DataHandler handler); |
| 230 | 239 |
| 231 void JobFailed(PrintJobError error); | 240 void JobFailed(PrintJobError error); |
| 232 void JobSpooled(cloud_print::PlatformJobId local_job_id); | 241 void JobSpooled(cloud_print::PlatformJobId local_job_id); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 DISALLOW_COPY_AND_ASSIGN(PrinterJobHandler); | 304 DISALLOW_COPY_AND_ASSIGN(PrinterJobHandler); |
| 296 }; | 305 }; |
| 297 | 306 |
| 298 // This typedef is to workaround the issue with certain versions of | 307 // This typedef is to workaround the issue with certain versions of |
| 299 // Visual Studio where it gets confused between multiple Delegate | 308 // Visual Studio where it gets confused between multiple Delegate |
| 300 // classes and gives a C2500 error. (I saw this error on the try bots - | 309 // classes and gives a C2500 error. (I saw this error on the try bots - |
| 301 // the workaround was not needed for my machine). | 310 // the workaround was not needed for my machine). |
| 302 typedef PrinterJobHandler::Delegate PrinterJobHandlerDelegate; | 311 typedef PrinterJobHandler::Delegate PrinterJobHandlerDelegate; |
| 303 | 312 |
| 304 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ | 313 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ |
| OLD | NEW |