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 "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "net/base/url_util.h" | |
13 | 12 |
14 namespace search_provider_logos { | 13 namespace search_provider_logos { |
15 | 14 |
16 namespace { | 15 namespace { |
17 const char kResponsePreamble[] = ")]}'"; | 16 const char kResponsePreamble[] = ")]}'"; |
18 } | 17 } |
19 | 18 |
20 GURL GoogleAppendFingerprintToLogoURL(const GURL& logo_url, | 19 GURL GoogleAppendFingerprintToLogoURL(const GURL& logo_url, |
21 const std::string& fingerprint) { | 20 const std::string& fingerprint) { |
22 return net::AppendQueryParameter(logo_url, "async", "es_dfp:" + fingerprint); | 21 // Note: we can't just use net::AppendQueryParameter() because it escapes |
| 22 // ":" to "%3A", but the server requires the colon not to be escaped. |
| 23 // See: http://crbug.com/413845 |
| 24 |
| 25 // TODO(newt): Switch to using net::AppendQueryParameter once it no longer |
| 26 // escapes ":" |
| 27 |
| 28 std::string query(logo_url.query()); |
| 29 if (!query.empty()) |
| 30 query += "&"; |
| 31 |
| 32 query += "async=es_dfp:"; |
| 33 query += fingerprint; |
| 34 GURL::Replacements replacements; |
| 35 replacements.SetQueryStr(query); |
| 36 return logo_url.ReplaceComponents(replacements); |
23 } | 37 } |
24 | 38 |
25 scoped_ptr<EncodedLogo> GoogleParseLogoResponse( | 39 scoped_ptr<EncodedLogo> GoogleParseLogoResponse( |
26 const scoped_ptr<std::string>& response, | 40 const scoped_ptr<std::string>& response, |
27 base::Time response_time) { | 41 base::Time response_time) { |
28 // Google doodles are sent as JSON with a prefix. Example: | 42 // Google doodles are sent as JSON with a prefix. Example: |
29 // )]}' {"update":{"logo":{ | 43 // )]}' {"update":{"logo":{ |
30 // "data": "/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/...", | 44 // "data": "/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/...", |
31 // "mime_type": "image/png", | 45 // "mime_type": "image/png", |
32 // "fingerprint": "db063e32", | 46 // "fingerprint": "db063e32", |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } else { | 98 } else { |
85 time_to_live = base::TimeDelta::FromMilliseconds(kMaxTimeToLiveMS); | 99 time_to_live = base::TimeDelta::FromMilliseconds(kMaxTimeToLiveMS); |
86 logo->metadata.can_show_after_expiration = true; | 100 logo->metadata.can_show_after_expiration = true; |
87 } | 101 } |
88 logo->metadata.expiration_time = response_time + time_to_live; | 102 logo->metadata.expiration_time = response_time + time_to_live; |
89 | 103 |
90 return logo.Pass(); | 104 return logo.Pass(); |
91 } | 105 } |
92 | 106 |
93 } // namespace search_provider_logos | 107 } // namespace search_provider_logos |
OLD | NEW |