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_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ | 5 #ifndef CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ |
6 #define CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ | 6 #define CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ |
7 | 7 |
| 8 #include <map> |
| 9 #include <set> |
8 #include <string> | 10 #include <string> |
9 | 11 |
10 class GURL; | 12 class GURL; |
11 | 13 |
12 namespace base { | 14 namespace base { |
13 class DictionaryValue; | 15 class DictionaryValue; |
| 16 class ListValue; |
14 } | 17 } |
15 | 18 |
16 // Helper consts and methods for both cloud print and chrome browser. | 19 // Helper consts and methods for both cloud print and chrome browser. |
17 namespace cloud_print { | 20 namespace cloud_print { |
18 | 21 |
19 // Values in the respone JSON from the cloud print server | 22 typedef std::map<std::string, std::string> PrinterTags; |
20 extern const char kPrinterListValue[]; | |
21 extern const char kSuccessValue[]; | |
22 | |
23 extern const char kChromeCloudPrintProxyHeader[]; | |
24 | 23 |
25 // Appends a relative path to the url making sure to append a '/' if the | 24 // Appends a relative path to the url making sure to append a '/' if the |
26 // URL's path does not end with a slash. It is assumed that |path| does not | 25 // URL's path does not end with a slash. It is assumed that |path| does not |
27 // begin with a '/'. | 26 // begin with a '/'. |
28 // NOTE: Since we ALWAYS want to append here, we simply append the path string | 27 // NOTE: Since we ALWAYS want to append here, we simply append the path string |
29 // instead of calling url_utils::ResolveRelative. The input |url| may or may not | 28 // instead of calling url_utils::ResolveRelative. The input |url| may or may not |
30 // contain a '/' at the end. | 29 // contain a '/' at the end. |
31 std::string AppendPathToUrl(const GURL& url, const std::string& path); | 30 std::string AppendPathToUrl(const GURL& url, const std::string& path); |
32 | 31 |
33 GURL GetUrlForSearch(const GURL& cloud_print_server_url); | 32 GURL GetUrlForSearch(const GURL& cloud_print_server_url); |
34 GURL GetUrlForSubmit(const GURL& cloud_print_server_url); | 33 GURL GetUrlForSubmit(const GURL& cloud_print_server_url); |
| 34 GURL GetUrlForPrinterList(const GURL& cloud_print_server_url, |
| 35 const std::string& proxy_id); |
| 36 GURL GetUrlForPrinterRegistration(const GURL& cloud_print_server_url); |
| 37 GURL GetUrlForPrinterUpdate(const GURL& cloud_print_server_url, |
| 38 const std::string& printer_id); |
| 39 GURL GetUrlForPrinterDelete(const GURL& cloud_print_server_url, |
| 40 const std::string& printer_id, |
| 41 const std::string& reason); |
| 42 GURL GetUrlForJobFetch(const GURL& cloud_print_server_url, |
| 43 const std::string& printer_id, |
| 44 const std::string& reason); |
| 45 GURL GetUrlForJobDelete(const GURL& cloud_print_server_url, |
| 46 const std::string& job_id); |
| 47 GURL GetUrlForJobStatusUpdate(const GURL& cloud_print_server_url, |
| 48 const std::string& job_id, |
| 49 const std::string& status_string); |
| 50 GURL GetUrlForUserMessage(const GURL& cloud_print_server_url, |
| 51 const std::string& message_id); |
| 52 GURL GetUrlForGetAuthCode(const GURL& cloud_print_server_url, |
| 53 const std::string& oauth_client_id, |
| 54 const std::string& proxy_id); |
35 | 55 |
36 // Parses the response data for any cloud print server request. The method | 56 // Parses the response data for any cloud print server request. The method |
37 // returns false if there was an error in parsing the JSON. The succeeded | 57 // returns false if there was an error in parsing the JSON. The succeeded |
38 // value returns the value of the "success" value in the response JSON. | 58 // value returns the value of the "success" value in the response JSON. |
39 // Returns the response as a dictionary value. | 59 // Returns the response as a dictionary value. |
40 bool ParseResponseJSON(const std::string& response_data, | 60 bool ParseResponseJSON(const std::string& response_data, |
41 bool* succeeded, | 61 bool* succeeded, |
42 base::DictionaryValue** response_dict); | 62 base::DictionaryValue** response_dict); |
43 | 63 |
| 64 // Parses the list of printer ids from cloud print list |response_data|; the |
| 65 // parsed results are returned in pointer parameters |succeeded| and |
| 66 // |printer_ids|, which should not be NULL. The |succeeded| value returns the |
| 67 // value of the "success" value in the respnse JSON. |printer_ids| is cleared |
| 68 // if !|succeeded| or fails to parse data. |
| 69 void ParsePrinterIdsFromListResponse(const std::string& response_data, |
| 70 bool* succeeded, |
| 71 std::set<std::string>* printer_ids); |
| 72 |
| 73 // Parses the registered pinter id from cloud print register |response_data|; |
| 74 // the parsed results are returned in pointer parameters |succeeded| and |
| 75 // |printer_id|, which should not be NULL. The |succeeded| value returns the |
| 76 // value of the "success" value in the respnse JSON. |printer_id| is cleared |
| 77 // if !|succeeded| or fails to parse data. |
| 78 void ParsePrinterIdFromRegisterResponse(const std::string& response_data, |
| 79 bool* succeeded, |
| 80 std::string* printer_id); |
| 81 |
44 // Prepares one value as part of a multi-part upload request. | 82 // Prepares one value as part of a multi-part upload request. |
45 void AddMultipartValueForUpload(const std::string& value_name, | 83 void AddMultipartValueForUpload(const std::string& value_name, |
46 const std::string& value, | 84 const std::string& value, |
47 const std::string& mime_boundary, | 85 const std::string& mime_boundary, |
48 const std::string& content_type, | 86 const std::string& content_type, |
49 std::string* post_data); | 87 std::string* post_data); |
50 | 88 |
| 89 // Returns the mime type of multipart with |mime_boundary|. |
| 90 std::string GetMultipartMimeType(const std::string& mime_boundary); |
| 91 |
51 // Create a MIME boundary marker (27 '-' characters followed by 16 hex digits). | 92 // Create a MIME boundary marker (27 '-' characters followed by 16 hex digits). |
52 void CreateMimeBoundaryForUpload(std::string *out); | 93 void CreateMimeBoundaryForUpload(std::string *out); |
53 | 94 |
| 95 // Returns an MD5 hash for printer tags from |printer_tags| and the default tags |
| 96 // required by cloud print server. |
| 97 std::string GetHashOfPrinterTags(const PrinterTags& printer_tags); |
| 98 |
| 99 // Returns an post data for printer tags from |printer_tags| and the default |
| 100 // tags required by cloud print server. |
| 101 std::string GetPostDataForPrinterTags( |
| 102 const PrinterTags& printer_tags, |
| 103 const std::string& mime_boundary, |
| 104 const std::string& proxy_tag_prefix, |
| 105 const std::string& tags_hash_tag_name); |
| 106 |
54 } // namespace cloud_print | 107 } // namespace cloud_print |
55 | 108 |
56 #endif // CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ | 109 #endif // CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ |
OLD | NEW |