Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_provider_logos/google_logo_api.h" | 5 #include "components/search_provider_logos/google_logo_api.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 | 16 |
| 17 namespace search_provider_logos { | 17 namespace search_provider_logos { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 const char kResponsePreamble[] = ")]}'"; | 20 const char kResponsePreamble[] = ")]}'"; |
| 21 } | 21 } |
| 22 | 22 |
| 23 GURL GoogleAppendQueryparamsToLogoURL(const GURL& logo_url, | 23 GURL GoogleAppendQueryparamsToLogoURL(const GURL& logo_url, |
| 24 const std::string& fingerprint, | 24 const std::string& fingerprint, |
| 25 bool wants_cta) { | 25 bool wants_cta, |
| 26 bool transparent) { | |
| 26 // Note: we can't just use net::AppendQueryParameter() because it escapes | 27 // Note: we can't just use net::AppendQueryParameter() because it escapes |
| 27 // ":" to "%3A", but the server requires the colon not to be escaped. | 28 // ":" to "%3A", but the server requires the colon not to be escaped. |
| 28 // See: http://crbug.com/413845 | 29 // See: http://crbug.com/413845 |
| 29 | 30 |
| 30 // TODO(newt): Switch to using net::AppendQueryParameter once it no longer | 31 // TODO(newt): Switch to using net::AppendQueryParameter once it no longer |
| 31 // escapes ":" | 32 // escapes ":" |
| 32 if (!fingerprint.empty() || wants_cta) { | 33 if (!fingerprint.empty() || wants_cta) { |
| 33 std::string query(logo_url.query()); | 34 std::string query(logo_url.query()); |
| 34 if (!query.empty()) | 35 if (!query.empty()) |
| 35 query += "&"; | 36 query += "&"; |
| 36 | 37 |
| 37 query += "async="; | 38 query += "async="; |
| 38 if (!fingerprint.empty()) { | 39 std::vector<std::string> params; |
| 39 query += "es_dfp:" + fingerprint; | 40 if (!fingerprint.empty()) |
| 40 if (wants_cta) | 41 params.push_back("es_dfp:" + fingerprint); |
| 41 query += ","; | 42 |
| 42 } | 43 if (wants_cta) |
| 43 if (wants_cta) { | 44 params.push_back("cta:1"); |
| 44 query += "cta:1"; | 45 |
| 45 } | 46 if (transparent) |
| 47 params.push_back("transp:1"); | |
|
Bernhard Bauer
2016/05/10 09:15:24
Nit: empty line afterwards.
atanasova
2016/05/10 13:51:25
Done.
| |
| 48 query += base::JoinString(params, ","); | |
| 46 GURL::Replacements replacements; | 49 GURL::Replacements replacements; |
| 47 replacements.SetQueryStr(query); | 50 replacements.SetQueryStr(query); |
| 48 return logo_url.ReplaceComponents(replacements); | 51 return logo_url.ReplaceComponents(replacements); |
| 49 } | 52 } |
| 50 | 53 |
| 51 return logo_url; | 54 return logo_url; |
| 52 } | 55 } |
| 53 | 56 |
| 54 std::unique_ptr<EncodedLogo> GoogleParseLogoResponse( | 57 std::unique_ptr<EncodedLogo> GoogleParseLogoResponse( |
| 55 const std::unique_ptr<std::string>& response, | 58 const std::unique_ptr<std::string>& response, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 logo->metadata.can_show_after_expiration = true; | 132 logo->metadata.can_show_after_expiration = true; |
| 130 } | 133 } |
| 131 logo->metadata.expiration_time = response_time + time_to_live; | 134 logo->metadata.expiration_time = response_time + time_to_live; |
| 132 | 135 |
| 133 // If this point is reached, parsing has succeeded. | 136 // If this point is reached, parsing has succeeded. |
| 134 *parsing_failed = false; | 137 *parsing_failed = false; |
| 135 return logo; | 138 return logo; |
| 136 } | 139 } |
| 137 | 140 |
| 138 } // namespace search_provider_logos | 141 } // namespace search_provider_logos |
| OLD | NEW |