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" |
12 | 13 |
13 namespace search_provider_logos { | 14 namespace search_provider_logos { |
14 | 15 |
15 namespace { | 16 namespace { |
16 const char kResponsePreamble[] = ")]}'"; | 17 const char kResponsePreamble[] = ")]}'"; |
17 } | 18 } |
18 | 19 |
19 GURL GoogleAppendFingerprintToLogoURL(const GURL& logo_url, | 20 GURL GoogleAppendFingerprintToLogoURL(const GURL& logo_url, |
20 const std::string& fingerprint) { | 21 const std::string& fingerprint) { |
21 // Note: we can't just use net::AppendQueryParameter() because it escapes | 22 return net::AppendQueryParameter(logo_url, "async", "es_dfp:" + fingerprint); |
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); | |
37 } | 23 } |
38 | 24 |
39 scoped_ptr<EncodedLogo> GoogleParseLogoResponse( | 25 scoped_ptr<EncodedLogo> GoogleParseLogoResponse( |
40 const scoped_ptr<std::string>& response, | 26 const scoped_ptr<std::string>& response, |
41 base::Time response_time) { | 27 base::Time response_time) { |
42 // Google doodles are sent as JSON with a prefix. Example: | 28 // Google doodles are sent as JSON with a prefix. Example: |
43 // )]}' {"update":{"logo":{ | 29 // )]}' {"update":{"logo":{ |
44 // "data": "/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/...", | 30 // "data": "/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/...", |
45 // "mime_type": "image/png", | 31 // "mime_type": "image/png", |
46 // "fingerprint": "db063e32", | 32 // "fingerprint": "db063e32", |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } else { | 84 } else { |
99 time_to_live = base::TimeDelta::FromMilliseconds(kMaxTimeToLiveMS); | 85 time_to_live = base::TimeDelta::FromMilliseconds(kMaxTimeToLiveMS); |
100 logo->metadata.can_show_after_expiration = true; | 86 logo->metadata.can_show_after_expiration = true; |
101 } | 87 } |
102 logo->metadata.expiration_time = response_time + time_to_live; | 88 logo->metadata.expiration_time = response_time + time_to_live; |
103 | 89 |
104 return logo.Pass(); | 90 return logo.Pass(); |
105 } | 91 } |
106 | 92 |
107 } // namespace search_provider_logos | 93 } // namespace search_provider_logos |
OLD | NEW |