OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ |
| 6 #define CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "chrome/browser/printing/cloud_print/printer_info.h" |
| 11 #include "googleurl/src/gurl.h" |
| 12 |
| 13 class DictionaryValue; |
| 14 class Task; |
| 15 class URLFetcher; |
| 16 |
| 17 // Helper methods for the cloud print proxy code. |
| 18 class CloudPrintHelpers { |
| 19 public: |
| 20 static GURL GetUrlForPrinterRegistration(); |
| 21 static GURL GetUrlForPrinterUpdate(const std::string& printer_id); |
| 22 static GURL GetUrlForPrinterDelete(const std::string& printer_id); |
| 23 static GURL GetUrlForPrinterList(const std::string& proxy_id); |
| 24 static GURL GetUrlForJobFetch(const std::string& printer_id); |
| 25 static GURL GetUrlForJobStatusUpdate(const std::string& job_id, |
| 26 cloud_print::PrintJobStatus status); |
| 27 static GURL GetUrlForJobStatusUpdate( |
| 28 const std::string& job_id, const cloud_print::PrintJobDetails& details); |
| 29 // Parses the response data for any cloud print server request. The method |
| 30 // returns false if there was an error in parsing the JSON. The succeeded |
| 31 // value returns the value of the "success" value in the response JSON. |
| 32 // Returns the response as a dictionary value. |
| 33 static bool ParseResponseJSON(const std::string& response_data, |
| 34 bool* succeeded, DictionaryValue** response_dict); |
| 35 // Sets up common parameters for a cloud print request |
| 36 // (such as the GAIA auth token in the request headers, the request context |
| 37 // etc). |
| 38 static void PrepCloudPrintRequest(URLFetcher* request, |
| 39 const std::string& auth_token); |
| 40 // Strictly speaking, this helper method is not specific to cloud printing. |
| 41 // It handles the logic to retry tasks when the server returns an error. |
| 42 // The parameters are as below: |
| 43 // |error_count| Contains the current number of consecutive failed attempts. |
| 44 // This method increments it (in/out) |
| 45 // |max_retry_count| Number of retries before giving up. -1 implies no limit. |
| 46 // |max_retry_interval| Maximum amount of time (in ms) we are willing to |
| 47 // wait between retries. -1 implies no limit. |
| 48 // |base_retry_interval| Starting value of the retry interval. This |
| 49 // method progressively increases the interval on each retry. |
| 50 // |task_to_retry| The task to be retried. |
| 51 // |task_on_give_up| Task to be performed when we give up. This is only |
| 52 // valid when max_retry_count is not -1. It can be NULL. |
| 53 static void HandleServerError(int* error_count, int max_retry_count, |
| 54 int64 max_retry_interval, |
| 55 int64 base_retry_interval, |
| 56 Task* task_to_retry, Task* task_on_give_up); |
| 57 // Prepares one value as part of a multi-part upload request. |
| 58 static void AddMultipartValueForUpload( |
| 59 const std::string& value_name, const std::string& value, |
| 60 const std::string& mime_boundary, const std::string& content_type, |
| 61 std::string* post_data); |
| 62 // Create a MIME boundary marker (27 '-' characters followed by 16 hex digits). |
| 63 static void CreateMimeBoundaryForUpload(std::string *out); |
| 64 |
| 65 private: |
| 66 CloudPrintHelpers() { |
| 67 } |
| 68 }; |
| 69 |
| 70 #endif // CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ |
| 71 |
OLD | NEW |