| 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 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 5 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/md5.h" | 13 #include "base/md5.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/rand_util.h" | |
| 16 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 17 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 18 #include "base/values.h" | 17 #include "base/values.h" |
| 19 #include "chrome/common/channel_info.h" | 18 #include "chrome/common/channel_info.h" |
| 20 #include "chrome/common/cloud_print/cloud_print_constants.h" | 19 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 21 #include "net/base/mime_util.h" | 20 #include "net/base/mime_util.h" |
| 22 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 23 | 22 |
| 24 namespace cloud_print { | 23 namespace cloud_print { |
| 25 | 24 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 if (succeeded && | 199 if (succeeded && |
| 201 !response_dict->GetBoolean(kSuccessValue, succeeded)) | 200 !response_dict->GetBoolean(kSuccessValue, succeeded)) |
| 202 *succeeded = false; | 201 *succeeded = false; |
| 203 return response_dict; | 202 return response_dict; |
| 204 } | 203 } |
| 205 | 204 |
| 206 std::string GetMultipartMimeType(const std::string& mime_boundary) { | 205 std::string GetMultipartMimeType(const std::string& mime_boundary) { |
| 207 return std::string("multipart/form-data; boundary=") + mime_boundary; | 206 return std::string("multipart/form-data; boundary=") + mime_boundary; |
| 208 } | 207 } |
| 209 | 208 |
| 210 // Create a MIME boundary marker (27 '-' characters followed by 16 hex digits). | |
| 211 void CreateMimeBoundaryForUpload(std::string* out) { | |
| 212 int r1 = base::RandInt(0, std::numeric_limits<int32_t>::max()); | |
| 213 int r2 = base::RandInt(0, std::numeric_limits<int32_t>::max()); | |
| 214 base::SStringPrintf(out, "---------------------------%08X%08X", r1, r2); | |
| 215 } | |
| 216 | |
| 217 std::string GetHashOfPrinterTags(const PrinterTags& printer_tags) { | 209 std::string GetHashOfPrinterTags(const PrinterTags& printer_tags) { |
| 218 return HashPrinterTags(PreparePrinterTags(printer_tags)); | 210 return HashPrinterTags(PreparePrinterTags(printer_tags)); |
| 219 } | 211 } |
| 220 | 212 |
| 221 std::string GetPostDataForPrinterTags( | 213 std::string GetPostDataForPrinterTags( |
| 222 const PrinterTags& printer_tags, | 214 const PrinterTags& printer_tags, |
| 223 const std::string& mime_boundary, | 215 const std::string& mime_boundary, |
| 224 const std::string& proxy_tag_prefix, | 216 const std::string& proxy_tag_prefix, |
| 225 const std::string& tags_hash_tag_name) { | 217 const std::string& tags_hash_tag_name) { |
| 226 PrinterTags printer_tags_prepared = PreparePrinterTags(printer_tags); | 218 PrinterTags printer_tags_prepared = PreparePrinterTags(printer_tags); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 245 net::AddMultipartValueForUpload(kPrinterTagValue, tags_hash_msg, | 237 net::AddMultipartValueForUpload(kPrinterTagValue, tags_hash_msg, |
| 246 mime_boundary, std::string(), &post_data); | 238 mime_boundary, std::string(), &post_data); |
| 247 return post_data; | 239 return post_data; |
| 248 } | 240 } |
| 249 | 241 |
| 250 std::string GetCloudPrintAuthHeader(const std::string& auth_token) { | 242 std::string GetCloudPrintAuthHeader(const std::string& auth_token) { |
| 251 return base::StringPrintf("Authorization: OAuth %s", auth_token.c_str()); | 243 return base::StringPrintf("Authorization: OAuth %s", auth_token.c_str()); |
| 252 } | 244 } |
| 253 | 245 |
| 254 } // namespace cloud_print | 246 } // namespace cloud_print |
| OLD | NEW |