| 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" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 std::string encoded_image_base64; | 87 std::string encoded_image_base64; |
| 88 if (logo_dict->GetString("data", &encoded_image_base64)) { | 88 if (logo_dict->GetString("data", &encoded_image_base64)) { |
| 89 // Data is optional, since we may be revalidating a cached logo. | 89 // Data is optional, since we may be revalidating a cached logo. |
| 90 base::RefCountedString* encoded_image_string = new base::RefCountedString(); | 90 base::RefCountedString* encoded_image_string = new base::RefCountedString(); |
| 91 if (!base::Base64Decode(encoded_image_base64, | 91 if (!base::Base64Decode(encoded_image_base64, |
| 92 &encoded_image_string->data())) | 92 &encoded_image_string->data())) |
| 93 return scoped_ptr<EncodedLogo>(); | 93 return scoped_ptr<EncodedLogo>(); |
| 94 logo->encoded_image = encoded_image_string; | 94 logo->encoded_image = encoded_image_string; |
| 95 if (!logo_dict->GetString("mime_type", &logo->metadata.mime_type)) | 95 if (!logo_dict->GetString("mime_type", &logo->metadata.mime_type)) |
| 96 return scoped_ptr<EncodedLogo>(); | 96 return scoped_ptr<EncodedLogo>(); |
| 97 | |
| 98 // Existance of url indicates |data| is a call to action image for an | |
| 99 // animated doodle. |url| points to that animated doodle. | |
| 100 logo_dict->GetString("url", &logo->metadata.animated_url); | |
| 101 } | 97 } |
| 102 | 98 |
| 103 // Don't check return values since these fields are optional. | 99 // Don't check return values since these fields are optional. |
| 104 logo_dict->GetString("target", &logo->metadata.on_click_url); | 100 logo_dict->GetString("target", &logo->metadata.on_click_url); |
| 105 logo_dict->GetString("fingerprint", &logo->metadata.fingerprint); | 101 logo_dict->GetString("fingerprint", &logo->metadata.fingerprint); |
| 106 logo_dict->GetString("alt", &logo->metadata.alt_text); | 102 logo_dict->GetString("alt", &logo->metadata.alt_text); |
| 107 | 103 |
| 104 // Existance of url indicates |data| is a call to action image for an |
| 105 // animated doodle. |url| points to that animated doodle. |
| 106 logo_dict->GetString("url", &logo->metadata.animated_url); |
| 107 |
| 108 base::TimeDelta time_to_live; | 108 base::TimeDelta time_to_live; |
| 109 int time_to_live_ms; | 109 int time_to_live_ms; |
| 110 if (logo_dict->GetInteger("time_to_live", &time_to_live_ms)) { | 110 if (logo_dict->GetInteger("time_to_live", &time_to_live_ms)) { |
| 111 time_to_live = base::TimeDelta::FromMilliseconds( | 111 time_to_live = base::TimeDelta::FromMilliseconds( |
| 112 std::min(static_cast<int64>(time_to_live_ms), kMaxTimeToLiveMS)); | 112 std::min(static_cast<int64>(time_to_live_ms), kMaxTimeToLiveMS)); |
| 113 logo->metadata.can_show_after_expiration = false; | 113 logo->metadata.can_show_after_expiration = false; |
| 114 } else { | 114 } else { |
| 115 time_to_live = base::TimeDelta::FromMilliseconds(kMaxTimeToLiveMS); | 115 time_to_live = base::TimeDelta::FromMilliseconds(kMaxTimeToLiveMS); |
| 116 logo->metadata.can_show_after_expiration = true; | 116 logo->metadata.can_show_after_expiration = true; |
| 117 } | 117 } |
| 118 logo->metadata.expiration_time = response_time + time_to_live; | 118 logo->metadata.expiration_time = response_time + time_to_live; |
| 119 | 119 |
| 120 return logo.Pass(); | 120 return logo.Pass(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 } // namespace search_provider_logos | 123 } // namespace search_provider_logos |
| OLD | NEW |