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> | |
msw
2012/11/09 23:18:17
This looks unused here, please remove.
Chen Yu
2012/11/13 14:02:15
Done.
| |
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; | |
msw
2012/11/09 23:18:17
This looks unused here, please remove.
Chen Yu
2012/11/13 14:02:15
Done.
| |
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 |
44 // Prepares one value as part of a multi-part upload request. | 64 // Prepares one value as part of a multi-part upload request. |
45 void AddMultipartValueForUpload(const std::string& value_name, | 65 void AddMultipartValueForUpload(const std::string& value_name, |
46 const std::string& value, | 66 const std::string& value, |
47 const std::string& mime_boundary, | 67 const std::string& mime_boundary, |
48 const std::string& content_type, | 68 const std::string& content_type, |
49 std::string* post_data); | 69 std::string* post_data); |
50 | 70 |
71 // Returns the mime type of multipart with |mime_boundary|. | |
72 std::string GetMultipartMimeType(const std::string& mime_boundary); | |
73 | |
51 // Create a MIME boundary marker (27 '-' characters followed by 16 hex digits). | 74 // Create a MIME boundary marker (27 '-' characters followed by 16 hex digits). |
52 void CreateMimeBoundaryForUpload(std::string *out); | 75 void CreateMimeBoundaryForUpload(std::string *out); |
53 | 76 |
77 // Returns an MD5 hash for printer tags from |printer_tags| and the default tags | |
78 // required by cloud print server. | |
79 std::string GetHashOfPrinterTags(const PrinterTags& printer_tags); | |
80 | |
81 // Returns an post data for printer tags from |printer_tags| and the default | |
82 // tags required by cloud print server. | |
83 std::string GetPostDataForPrinterTags( | |
84 const PrinterTags& printer_tags, | |
85 const std::string& mime_boundary, | |
86 const std::string& proxy_tag_prefix, | |
87 const std::string& tags_hash_tag_name); | |
88 | |
54 } // namespace cloud_print | 89 } // namespace cloud_print |
55 | 90 |
56 #endif // CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ | 91 #endif // CHROME_COMMON_CLOUD_PRINT_CLOUD_PRINT_HELPERS_H_ |
OLD | NEW |