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 chrome_policy { |
| 127 DefaultSearchProviderEnabled { |
| 128 policy_options {mode: MANDATORY} |
| 129 DefaultSearchProviderEnabled: false |
| 130 } |
| 131 } |
| 132 })"); |
109 image_fetcher_->StartOrQueueNetworkRequest( | 133 image_fetcher_->StartOrQueueNetworkRequest( |
110 image_url.spec(), image_url, | 134 image_url.spec(), image_url, |
111 base::Bind(&DoodleService::ImageFetched, base::Unretained(this), | 135 base::Bind(&DoodleService::ImageFetched, base::Unretained(this), |
112 callback)); | 136 callback), |
| 137 traffic_annotation); |
113 } | 138 } |
114 | 139 |
115 void DoodleService::AddObserver(Observer* observer) { | 140 void DoodleService::AddObserver(Observer* observer) { |
116 observers_.AddObserver(observer); | 141 observers_.AddObserver(observer); |
117 } | 142 } |
118 | 143 |
119 void DoodleService::RemoveObserver(Observer* observer) { | 144 void DoodleService::RemoveObserver(Observer* observer) { |
120 observers_.RemoveObserver(observer); | 145 observers_.RemoveObserver(observer); |
121 } | 146 } |
122 | 147 |
(...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 | 328 // TODO(treib): Rename this to "Doodle.*" after we've decided what to do |
304 // about crbug.com/719513. | 329 // about crbug.com/719513. |
305 UMA_HISTOGRAM_BOOLEAN("NewTabPage.LogoImageDownloaded", | 330 UMA_HISTOGRAM_BOOLEAN("NewTabPage.LogoImageDownloaded", |
306 metadata.from_http_cache); | 331 metadata.from_http_cache); |
307 } | 332 } |
308 | 333 |
309 callback.Run(image); | 334 callback.Run(image); |
310 } | 335 } |
311 | 336 |
312 } // namespace doodle | 337 } // namespace doodle |
OLD | NEW |