| 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 #include <memory> |
| 10 | 11 |
| 11 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/md5.h" | 14 #include "base/md5.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/common/channel_info.h" | 18 #include "chrome/common/channel_info.h" |
| 19 #include "chrome/common/cloud_print/cloud_print_constants.h" | 19 #include "chrome/common/cloud_print/cloud_print_constants.h" |
| 20 #include "net/base/mime_util.h" | 20 #include "net/base/mime_util.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 22 | 22 |
| 23 namespace cloud_print { | 23 namespace cloud_print { |
| 24 | 24 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 std::string path(AppendPathToUrl(cloud_print_server_url, "createrobot")); | 177 std::string path(AppendPathToUrl(cloud_print_server_url, "createrobot")); |
| 178 GURL::Replacements replacements; | 178 GURL::Replacements replacements; |
| 179 replacements.SetPathStr(path); | 179 replacements.SetPathStr(path); |
| 180 std::string query = base::StringPrintf("oauth_client_id=%s&proxy=%s", | 180 std::string query = base::StringPrintf("oauth_client_id=%s&proxy=%s", |
| 181 oauth_client_id.c_str(), | 181 oauth_client_id.c_str(), |
| 182 proxy_id.c_str()); | 182 proxy_id.c_str()); |
| 183 replacements.SetQueryStr(query); | 183 replacements.SetQueryStr(query); |
| 184 return cloud_print_server_url.ReplaceComponents(replacements); | 184 return cloud_print_server_url.ReplaceComponents(replacements); |
| 185 } | 185 } |
| 186 | 186 |
| 187 scoped_ptr<base::DictionaryValue> ParseResponseJSON( | 187 std::unique_ptr<base::DictionaryValue> ParseResponseJSON( |
| 188 const std::string& response_data, | 188 const std::string& response_data, |
| 189 bool* succeeded) { | 189 bool* succeeded) { |
| 190 scoped_ptr<base::Value> message_value(base::JSONReader::Read(response_data)); | 190 std::unique_ptr<base::Value> message_value( |
| 191 base::JSONReader::Read(response_data)); |
| 191 if (!message_value.get()) | 192 if (!message_value.get()) |
| 192 return scoped_ptr<base::DictionaryValue>(); | 193 return std::unique_ptr<base::DictionaryValue>(); |
| 193 | 194 |
| 194 if (!message_value->IsType(base::Value::TYPE_DICTIONARY)) | 195 if (!message_value->IsType(base::Value::TYPE_DICTIONARY)) |
| 195 return scoped_ptr<base::DictionaryValue>(); | 196 return std::unique_ptr<base::DictionaryValue>(); |
| 196 | 197 |
| 197 scoped_ptr<base::DictionaryValue> response_dict( | 198 std::unique_ptr<base::DictionaryValue> response_dict( |
| 198 static_cast<base::DictionaryValue*>(message_value.release())); | 199 static_cast<base::DictionaryValue*>(message_value.release())); |
| 199 if (succeeded && | 200 if (succeeded && |
| 200 !response_dict->GetBoolean(kSuccessValue, succeeded)) | 201 !response_dict->GetBoolean(kSuccessValue, succeeded)) |
| 201 *succeeded = false; | 202 *succeeded = false; |
| 202 return response_dict; | 203 return response_dict; |
| 203 } | 204 } |
| 204 | 205 |
| 205 std::string GetMultipartMimeType(const std::string& mime_boundary) { | 206 std::string GetMultipartMimeType(const std::string& mime_boundary) { |
| 206 return std::string("multipart/form-data; boundary=") + mime_boundary; | 207 return std::string("multipart/form-data; boundary=") + mime_boundary; |
| 207 } | 208 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 237 net::AddMultipartValueForUpload(kPrinterTagValue, tags_hash_msg, | 238 net::AddMultipartValueForUpload(kPrinterTagValue, tags_hash_msg, |
| 238 mime_boundary, std::string(), &post_data); | 239 mime_boundary, std::string(), &post_data); |
| 239 return post_data; | 240 return post_data; |
| 240 } | 241 } |
| 241 | 242 |
| 242 std::string GetCloudPrintAuthHeader(const std::string& auth_token) { | 243 std::string GetCloudPrintAuthHeader(const std::string& auth_token) { |
| 243 return base::StringPrintf("Authorization: OAuth %s", auth_token.c_str()); | 244 return base::StringPrintf("Authorization: OAuth %s", auth_token.c_str()); |
| 244 } | 245 } |
| 245 | 246 |
| 246 } // namespace cloud_print | 247 } // namespace cloud_print |
| OLD | NEW |