OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/doodle/doodle_service.h" | 5 #include "components/doodle/doodle_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "components/data_use_measurement/core/data_use_user_data.h" | 13 #include "components/data_use_measurement/core/data_use_user_data.h" |
14 #include "components/doodle/pref_names.h" | 14 #include "components/doodle/pref_names.h" |
15 #include "components/image_fetcher/core/image_fetcher.h" | 15 #include "components/image_fetcher/core/image_fetcher.h" |
16 #include "components/image_fetcher/core/request_metadata.h" | 16 #include "components/image_fetcher/core/request_metadata.h" |
17 #include "components/prefs/pref_registry.h" | 17 #include "components/prefs/pref_registry.h" |
18 #include "components/prefs/pref_registry_simple.h" | 18 #include "components/prefs/pref_registry_simple.h" |
19 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
20 #include "net/traffic_annotation/network_traffic_annotation.h" | |
20 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
21 | 22 |
22 namespace doodle { | 23 namespace doodle { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 // The maximum time-to-live we'll accept; any larger values will be clamped to | 27 // The maximum time-to-live we'll accept; any larger values will be clamped to |
27 // this one. This is a last resort in case the server sends bad data. | 28 // this one. This is a last resort in case the server sends bad data. |
28 const int64_t kMaxTimeToLiveSecs = 30 * 24 * 60 * 60; // 30 days | 29 const int64_t kMaxTimeToLiveSecs = 30 * 24 * 60 * 60; // 30 days |
29 | 30 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 callback.Run(gfx::Image()); | 100 callback.Run(gfx::Image()); |
100 return; | 101 return; |
101 } | 102 } |
102 | 103 |
103 // If there is a CTA image, that means the main image is animated. Show the | 104 // If there is a CTA image, that means the main image is animated. Show the |
104 // non-animated CTA image first, and load the animated one only when the | 105 // non-animated CTA image first, and load the animated one only when the |
105 // user requests it. | 106 // user requests it. |
106 bool has_cta = cached_config_->large_cta_image.has_value(); | 107 bool has_cta = cached_config_->large_cta_image.has_value(); |
107 const GURL& image_url = has_cta ? cached_config_->large_cta_image->url | 108 const GURL& image_url = has_cta ? cached_config_->large_cta_image->url |
108 : cached_config_->large_image.url; | 109 : cached_config_->large_image.url; |
110 net::NetworkTrafficAnnotationTag traffic_annotation = | |
111 net::DefineNetworkTrafficAnnotation("doodle_service", R"( | |
112 semantics { | |
113 sender: "Doodle Service" | |
114 description: | |
115 "Downloads the Doodle image if Google is the configured search " | |
116 "provider." | |
117 trigger: "Displaying the new tab page on Android." | |
118 data: "None." | |
119 destination: GOOGLE_OWNED_SERVICE | |
120 } | |
121 policy { | |
122 cookies_allowed: false | |
123 setting: | |
124 "Choosing a non-Google search engine in Chromium settings under " | |
125 "'Search Engine' disables this feature." | |
126 policy_exception_justification: | |
127 "Not implemented, considered not useful as it does not upload any " | |
msramek
2017/05/19 08:47:38
Wouldn't this be https://www.chromium.org/administ
Ramin Halavati
2017/05/19 09:03:37
Sorry, missed again.
Marc Treib
2017/05/19 09:19:24
Yep, sounds like this policy would do the trick (i
| |
128 "data and just downloads a logo image." | |
129 })"); | |
109 image_fetcher_->StartOrQueueNetworkRequest( | 130 image_fetcher_->StartOrQueueNetworkRequest( |
110 image_url.spec(), image_url, | 131 image_url.spec(), image_url, |
111 base::Bind(&DoodleService::ImageFetched, base::Unretained(this), | 132 base::Bind(&DoodleService::ImageFetched, base::Unretained(this), |
112 callback)); | 133 callback), |
134 traffic_annotation); | |
113 } | 135 } |
114 | 136 |
115 void DoodleService::AddObserver(Observer* observer) { | 137 void DoodleService::AddObserver(Observer* observer) { |
116 observers_.AddObserver(observer); | 138 observers_.AddObserver(observer); |
117 } | 139 } |
118 | 140 |
119 void DoodleService::RemoveObserver(Observer* observer) { | 141 void DoodleService::RemoveObserver(Observer* observer) { |
120 observers_.RemoveObserver(observer); | 142 observers_.RemoveObserver(observer); |
121 } | 143 } |
122 | 144 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 // TODO(treib): Rename this to "Doodle.*" after we've decided what to do | 325 // TODO(treib): Rename this to "Doodle.*" after we've decided what to do |
304 // about crbug.com/719513. | 326 // about crbug.com/719513. |
305 UMA_HISTOGRAM_BOOLEAN("NewTabPage.LogoImageDownloaded", | 327 UMA_HISTOGRAM_BOOLEAN("NewTabPage.LogoImageDownloaded", |
306 metadata.from_http_cache); | 328 metadata.from_http_cache); |
307 } | 329 } |
308 | 330 |
309 callback.Run(image); | 331 callback.Run(image); |
310 } | 332 } |
311 | 333 |
312 } // namespace doodle | 334 } // namespace doodle |
OLD | NEW |