| 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 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 std::string printer_id; | 87 std::string printer_id; |
| 88 std::string caps_hash; | 88 std::string caps_hash; |
| 89 std::string tags_hash; | 89 std::string tags_hash; |
| 90 int current_xmpp_timeout; | 90 int current_xmpp_timeout; |
| 91 int pending_xmpp_timeout; | 91 int pending_xmpp_timeout; |
| 92 | 92 |
| 93 PrinterInfoFromCloud(); | 93 PrinterInfoFromCloud(); |
| 94 PrinterInfoFromCloud(const PrinterInfoFromCloud& other); | 94 PrinterInfoFromCloud(const PrinterInfoFromCloud& other); |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 // Begin public interface | 97 static void ReportsStats(); |
| 98 |
| 98 PrinterJobHandler(const printing::PrinterBasicInfo& printer_info, | 99 PrinterJobHandler(const printing::PrinterBasicInfo& printer_info, |
| 99 const PrinterInfoFromCloud& printer_info_from_server, | 100 const PrinterInfoFromCloud& printer_info_from_server, |
| 100 const GURL& cloud_print_server_url, | 101 const GURL& cloud_print_server_url, |
| 101 PrintSystem* print_system, | 102 PrintSystem* print_system, |
| 102 Delegate* delegate); | 103 Delegate* delegate); |
| 103 | 104 |
| 104 bool Initialize(); | 105 bool Initialize(); |
| 105 | 106 |
| 106 std::string GetPrinterName() const; | 107 std::string GetPrinterName() const; |
| 107 | 108 |
| 108 // Requests a job check. |reason| is the reason for fetching the job. Used | 109 // Requests a job check. |reason| is the reason for fetching the job. Used |
| 109 // for logging and diagnostc purposes. | 110 // for logging and diagnostc purposes. |
| 110 void CheckForJobs(const std::string& reason); | 111 void CheckForJobs(const std::string& reason); |
| 111 | 112 |
| 112 // Shutdown everything (the process is exiting). | 113 // Shutdown everything (the process is exiting). |
| 113 void Shutdown(); | 114 void Shutdown(); |
| 114 | 115 |
| 115 base::TimeTicks last_job_fetch_time() const { return last_job_fetch_time_; } | 116 base::TimeTicks last_job_fetch_time() const { return last_job_fetch_time_; } |
| 116 // End public interface | |
| 117 | |
| 118 // Begin Delegate implementations | |
| 119 | 117 |
| 120 // CloudPrintURLFetcher::Delegate implementation. | 118 // CloudPrintURLFetcher::Delegate implementation. |
| 121 CloudPrintURLFetcher::ResponseAction HandleRawResponse( | 119 CloudPrintURLFetcher::ResponseAction HandleRawResponse( |
| 122 const net::URLFetcher* source, | 120 const net::URLFetcher* source, |
| 123 const GURL& url, | 121 const GURL& url, |
| 124 const net::URLRequestStatus& status, | 122 const net::URLRequestStatus& status, |
| 125 int response_code, | 123 int response_code, |
| 126 const net::ResponseCookies& cookies, | 124 const net::ResponseCookies& cookies, |
| 127 const std::string& data) override; | 125 const std::string& data) override; |
| 128 CloudPrintURLFetcher::ResponseAction HandleRawData( | 126 CloudPrintURLFetcher::ResponseAction HandleRawData( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 141 // JobStatusUpdater::Delegate implementation | 139 // JobStatusUpdater::Delegate implementation |
| 142 bool OnJobCompleted(JobStatusUpdater* updater) override; | 140 bool OnJobCompleted(JobStatusUpdater* updater) override; |
| 143 void OnAuthError() override; | 141 void OnAuthError() override; |
| 144 | 142 |
| 145 // PrinterWatcherDelegate implementation | 143 // PrinterWatcherDelegate implementation |
| 146 void OnPrinterDeleted() override; | 144 void OnPrinterDeleted() override; |
| 147 void OnPrinterChanged() override; | 145 void OnPrinterChanged() override; |
| 148 void OnJobChanged() override; | 146 void OnJobChanged() override; |
| 149 | 147 |
| 150 // JobSpoolerDelegate implementation. | 148 // JobSpoolerDelegate implementation. |
| 151 // Called on print_thread_. | 149 // Called on |print_thread_|. |
| 152 void OnJobSpoolSucceeded(const PlatformJobId& job_id) override; | 150 void OnJobSpoolSucceeded(const PlatformJobId& job_id) override; |
| 153 void OnJobSpoolFailed() override; | 151 void OnJobSpoolFailed() override; |
| 154 | 152 |
| 155 // End Delegate implementations | |
| 156 | |
| 157 static void ReportsStats(); | |
| 158 | |
| 159 private: | 153 private: |
| 160 friend class base::RefCountedThreadSafe<PrinterJobHandler>; | 154 friend class base::RefCountedThreadSafe<PrinterJobHandler>; |
| 161 | 155 |
| 162 enum PrintJobError { | 156 enum PrintJobError { |
| 163 JOB_SUCCESS, | 157 JOB_SUCCESS, |
| 164 JOB_DOWNLOAD_FAILED, | 158 JOB_DOWNLOAD_FAILED, |
| 165 JOB_VALIDATE_TICKET_FAILED, | 159 JOB_VALIDATE_TICKET_FAILED, |
| 166 JOB_FAILED, | 160 JOB_FAILED, |
| 167 JOB_MAX, | 161 JOB_MAX, |
| 168 }; | 162 }; |
| 169 | 163 |
| 170 // Prototype for a JSON data handler. | 164 // Prototype for a JSON data handler. |
| 171 typedef CloudPrintURLFetcher::ResponseAction ( | 165 typedef CloudPrintURLFetcher::ResponseAction ( |
| 172 PrinterJobHandler::*JSONDataHandler)( | 166 PrinterJobHandler::*JSONDataHandler)( |
| 173 const net::URLFetcher* source, | 167 const net::URLFetcher* source, |
| 174 const GURL& url, | 168 const GURL& url, |
| 175 const base::DictionaryValue* json_data, | 169 const base::DictionaryValue* json_data, |
| 176 bool succeeded); | 170 bool succeeded); |
| 177 // Prototype for a data handler. | 171 // Prototype for a data handler. |
| 178 typedef CloudPrintURLFetcher::ResponseAction | 172 typedef CloudPrintURLFetcher::ResponseAction ( |
| 179 (PrinterJobHandler::*DataHandler)(const net::URLFetcher* source, | 173 PrinterJobHandler::*DataHandler)(const net::URLFetcher* source, |
| 180 const GURL& url, | 174 const GURL& url, |
| 181 const std::string& data); | 175 const std::string& data); |
| 182 | 176 |
| 183 ~PrinterJobHandler() override; | 177 ~PrinterJobHandler() override; |
| 184 | 178 |
| 185 // Begin request handlers for each state in the state machine | 179 // Begin request handlers for each state in the state machine |
| 186 CloudPrintURLFetcher::ResponseAction HandlePrinterUpdateResponse( | 180 CloudPrintURLFetcher::ResponseAction HandlePrinterUpdateResponse( |
| 187 const net::URLFetcher* source, | 181 const net::URLFetcher* source, |
| 188 const GURL& url, | 182 const GURL& url, |
| 189 const base::DictionaryValue* json_data, | 183 const base::DictionaryValue* json_data, |
| 190 bool succeeded); | 184 bool succeeded); |
| 191 | 185 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 235 |
| 242 void JobFailed(PrintJobError error); | 236 void JobFailed(PrintJobError error); |
| 243 void JobSpooled(PlatformJobId local_job_id); | 237 void JobSpooled(PlatformJobId local_job_id); |
| 244 // Returns false if printer info is up to date and no updating is needed. | 238 // Returns false if printer info is up to date and no updating is needed. |
| 245 bool UpdatePrinterInfo(); | 239 bool UpdatePrinterInfo(); |
| 246 bool HavePendingTasks(); | 240 bool HavePendingTasks(); |
| 247 void ValidatePrintTicketFailed(); | 241 void ValidatePrintTicketFailed(); |
| 248 | 242 |
| 249 // Callback that asynchronously receives printer caps and defaults. | 243 // Callback that asynchronously receives printer caps and defaults. |
| 250 void OnReceivePrinterCaps( | 244 void OnReceivePrinterCaps( |
| 251 bool succeeded, | 245 bool succeeded, |
| 252 const std::string& printer_name, | 246 const std::string& printer_name, |
| 253 const printing::PrinterCapsAndDefaults& caps_and_defaults); | 247 const printing::PrinterCapsAndDefaults& caps_and_defaults); |
| 254 | 248 |
| 255 // Called on print_thread_. | 249 // Called on |print_thread_|. It is not safe to access any members other than |
| 250 // |job_handler_task_runner_|, |job_spooler_| and |print_system_|. |
| 256 void DoPrint(const JobDetails& job_details, | 251 void DoPrint(const JobDetails& job_details, |
| 257 const std::string& printer_name); | 252 const std::string& printer_name); |
| 258 | 253 |
| 254 bool CurrentlyOnPrintThread() const; |
| 255 |
| 259 scoped_refptr<CloudPrintURLFetcher> request_; | 256 scoped_refptr<CloudPrintURLFetcher> request_; |
| 260 scoped_refptr<PrintSystem> print_system_; | 257 scoped_refptr<PrintSystem> print_system_; |
| 261 printing::PrinterBasicInfo printer_info_; | 258 printing::PrinterBasicInfo printer_info_; |
| 262 PrinterInfoFromCloud printer_info_cloud_; | 259 PrinterInfoFromCloud printer_info_cloud_; |
| 263 GURL cloud_print_server_url_; | 260 GURL cloud_print_server_url_; |
| 264 std::string print_data_url_; | 261 std::string print_data_url_; |
| 265 JobDetails job_details_; | 262 JobDetails job_details_; |
| 266 Delegate* delegate_; | 263 Delegate* const delegate_; |
| 264 |
| 267 // Once the job has been spooled to the local spooler, this specifies the | 265 // Once the job has been spooled to the local spooler, this specifies the |
| 268 // job id of the job on the local spooler. | 266 // job id of the job on the local spooler. |
| 269 PlatformJobId local_job_id_; | 267 PlatformJobId local_job_id_; |
| 270 | 268 |
| 271 // The next response handler can either be a JSONDataHandler or a | 269 // The next response handler can either be a JSONDataHandler or a |
| 272 // DataHandler (depending on the current request being made). | 270 // DataHandler (depending on the current request being made). |
| 273 JSONDataHandler next_json_data_handler_; | 271 JSONDataHandler next_json_data_handler_; |
| 274 DataHandler next_data_handler_; | 272 DataHandler next_data_handler_; |
| 275 // The thread on which the actual print operation happens | 273 // The thread on which the actual print operation happens |
| 276 base::Thread print_thread_; | 274 base::Thread print_thread_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 base::Time last_caps_update_time_; | 307 base::Time last_caps_update_time_; |
| 310 | 308 |
| 311 base::WeakPtrFactory<PrinterJobHandler> weak_ptr_factory_; | 309 base::WeakPtrFactory<PrinterJobHandler> weak_ptr_factory_; |
| 312 | 310 |
| 313 DISALLOW_COPY_AND_ASSIGN(PrinterJobHandler); | 311 DISALLOW_COPY_AND_ASSIGN(PrinterJobHandler); |
| 314 }; | 312 }; |
| 315 | 313 |
| 316 } // namespace cloud_print | 314 } // namespace cloud_print |
| 317 | 315 |
| 318 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ | 316 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ |
| OLD | NEW |