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/logo_tracker.h" | 5 #include "components/search_provider_logos/logo_tracker.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/task_runner_util.h" | 13 #include "base/task_runner_util.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
15 #include "base/time/default_clock.h" | 15 #include "base/time/default_clock.h" |
16 #include "components/data_use_measurement/core/data_use_user_data.h" | 16 #include "components/data_use_measurement/core/data_use_user_data.h" |
17 #include "components/search_provider_logos/switches.h" | 17 #include "components/search_provider_logos/switches.h" |
18 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
19 #include "net/http/http_status_code.h" | 19 #include "net/http/http_status_code.h" |
| 20 #include "net/traffic_annotation/network_traffic_annotation.h" |
20 #include "net/url_request/url_fetcher.h" | 21 #include "net/url_request/url_fetcher.h" |
21 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
22 #include "net/url_request/url_request_status.h" | 23 #include "net/url_request/url_request_status.h" |
23 | 24 |
24 namespace search_provider_logos { | 25 namespace search_provider_logos { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 const int64_t kMaxDownloadBytes = 1024 * 1024; | 29 const int64_t kMaxDownloadBytes = 1024 * 1024; |
29 | 30 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 } | 220 } |
220 GURL url; | 221 GURL url; |
221 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 222 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
222 if (command_line->HasSwitch(switches::kGoogleDoodleUrl)) { | 223 if (command_line->HasSwitch(switches::kGoogleDoodleUrl)) { |
223 url = GURL(command_line->GetSwitchValueASCII(switches::kGoogleDoodleUrl)); | 224 url = GURL(command_line->GetSwitchValueASCII(switches::kGoogleDoodleUrl)); |
224 } else { | 225 } else { |
225 url = append_queryparams_func_.Run( | 226 url = append_queryparams_func_.Run( |
226 logo_url_, fingerprint, wants_cta_, transparent_); | 227 logo_url_, fingerprint, wants_cta_, transparent_); |
227 } | 228 } |
228 | 229 |
229 fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this); | 230 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 231 net::DefineNetworkTrafficAnnotation("logo_tracker", R"( |
| 232 semantics { |
| 233 sender: "Logo Tracker" |
| 234 description: |
| 235 "Provides the logo image (aka Doodle) if Google is your configured " |
| 236 "search provider." |
| 237 trigger: "Displaying the new tab page on iOS or Android." |
| 238 data: |
| 239 "Logo ID, and the user's Google cookies to show for example " |
| 240 "birthday doodles at appropriate times." |
| 241 destination: OTHER |
| 242 } |
| 243 policy { |
| 244 cookies_allowed: true |
| 245 cookies_store: "user" |
| 246 setting: |
| 247 "Choosing a non-Google search engine in Chromium settings under " |
| 248 "'Search Engine' will disable this feature." |
| 249 policy_exception_justification: |
| 250 "Not implemented, considered not useful as it does not upload any" |
| 251 "data and just downloads a logo image." |
| 252 })"); |
| 253 fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this, |
| 254 traffic_annotation); |
230 fetcher_->SetRequestContext(request_context_getter_.get()); | 255 fetcher_->SetRequestContext(request_context_getter_.get()); |
231 data_use_measurement::DataUseUserData::AttachToFetcher( | 256 data_use_measurement::DataUseUserData::AttachToFetcher( |
232 fetcher_.get(), | 257 fetcher_.get(), |
233 data_use_measurement::DataUseUserData::SEARCH_PROVIDER_LOGOS); | 258 data_use_measurement::DataUseUserData::SEARCH_PROVIDER_LOGOS); |
234 fetcher_->Start(); | 259 fetcher_->Start(); |
235 logo_download_start_time_ = base::TimeTicks::Now(); | 260 logo_download_start_time_ = base::TimeTicks::Now(); |
236 } | 261 } |
237 | 262 |
238 void LogoTracker::OnFreshLogoParsed(bool* parsing_failed, | 263 void LogoTracker::OnFreshLogoParsed(bool* parsing_failed, |
239 std::unique_ptr<EncodedLogo> logo) { | 264 std::unique_ptr<EncodedLogo> logo) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 int64_t current, | 373 int64_t current, |
349 int64_t total, | 374 int64_t total, |
350 int64_t current_network_bytes) { | 375 int64_t current_network_bytes) { |
351 if (total > kMaxDownloadBytes || current > kMaxDownloadBytes) { | 376 if (total > kMaxDownloadBytes || current > kMaxDownloadBytes) { |
352 LOG(WARNING) << "Search provider logo exceeded download size limit"; | 377 LOG(WARNING) << "Search provider logo exceeded download size limit"; |
353 ReturnToIdle(DOWNLOAD_OUTCOME_DOWNLOAD_FAILED); | 378 ReturnToIdle(DOWNLOAD_OUTCOME_DOWNLOAD_FAILED); |
354 } | 379 } |
355 } | 380 } |
356 | 381 |
357 } // namespace search_provider_logos | 382 } // namespace search_provider_logos |
OLD | NEW |