| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ntp_tiles/popular_sites_impl.h" | 5 #include "components/ntp_tiles/popular_sites_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "components/ntp_tiles/pref_names.h" | 24 #include "components/ntp_tiles/pref_names.h" |
| 25 #include "components/ntp_tiles/switches.h" | 25 #include "components/ntp_tiles/switches.h" |
| 26 #include "components/pref_registry/pref_registry_syncable.h" | 26 #include "components/pref_registry/pref_registry_syncable.h" |
| 27 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
| 28 #include "components/search_engines/search_engine_type.h" | 28 #include "components/search_engines/search_engine_type.h" |
| 29 #include "components/search_engines/template_url_service.h" | 29 #include "components/search_engines/template_url_service.h" |
| 30 #include "components/variations/service/variations_service.h" | 30 #include "components/variations/service/variations_service.h" |
| 31 #include "components/variations/variations_associated_data.h" | 31 #include "components/variations/variations_associated_data.h" |
| 32 #include "net/base/load_flags.h" | 32 #include "net/base/load_flags.h" |
| 33 #include "net/http/http_status_code.h" | 33 #include "net/http/http_status_code.h" |
| 34 #include "net/traffic_annotation/network_traffic_annotation.h" |
| 34 | 35 |
| 35 #if defined(OS_ANDROID) || defined(OS_IOS) | 36 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 36 #include "base/json/json_reader.h" | 37 #include "base/json/json_reader.h" |
| 37 #include "components/grit/components_resources.h" | 38 #include "components/grit/components_resources.h" |
| 38 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
| 39 #endif | 40 #endif |
| 40 | 41 |
| 41 #if defined(OS_IOS) | 42 #if defined(OS_IOS) |
| 42 #include "components/ntp_tiles/country_code_ios.h" | 43 #include "components/ntp_tiles/country_code_ios.h" |
| 43 #endif | 44 #endif |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 user_prefs->RegisterStringPref(ntp_tiles::prefs::kPopularSitesOverrideVersion, | 300 user_prefs->RegisterStringPref(ntp_tiles::prefs::kPopularSitesOverrideVersion, |
| 300 std::string()); | 301 std::string()); |
| 301 | 302 |
| 302 user_prefs->RegisterInt64Pref(kPopularSitesLastDownloadPref, 0); | 303 user_prefs->RegisterInt64Pref(kPopularSitesLastDownloadPref, 0); |
| 303 user_prefs->RegisterStringPref(kPopularSitesURLPref, std::string()); | 304 user_prefs->RegisterStringPref(kPopularSitesURLPref, std::string()); |
| 304 user_prefs->RegisterListPref(kPopularSitesJsonPref, | 305 user_prefs->RegisterListPref(kPopularSitesJsonPref, |
| 305 DefaultPopularSites().release()); | 306 DefaultPopularSites().release()); |
| 306 } | 307 } |
| 307 | 308 |
| 308 void PopularSitesImpl::FetchPopularSites() { | 309 void PopularSitesImpl::FetchPopularSites() { |
| 309 fetcher_ = URLFetcher::Create(pending_url_, URLFetcher::GET, this); | 310 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 311 net::DefineNetworkTrafficAnnotation("popular_sites_fetch", R"( |
| 312 semantics { |
| 313 sender: "Popular Sites New Tab Fetch" |
| 314 description: |
| 315 "Google Chrome may display a list of regionally-popular web sites " |
| 316 "on the New Tab Page. This service fetches the list of these sites." |
| 317 trigger: |
| 318 "Once per day, unless no popular web sites are required because " |
| 319 "the New Tab Page is filled with suggestions based on the user's " |
| 320 "browsing history." |
| 321 data: "A two letter country code based on the user's location." |
| 322 destination: GOOGLE_OWNED_SERVICE |
| 323 } |
| 324 policy { |
| 325 cookies_allowed: false |
| 326 setting: "This feature cannot be disabled in settings." |
| 327 policy_exception_justification: |
| 328 "Not implemented, considered not useful." |
| 329 })"); |
| 330 fetcher_ = URLFetcher::Create(pending_url_, URLFetcher::GET, this, |
| 331 traffic_annotation); |
| 310 data_use_measurement::DataUseUserData::AttachToFetcher( | 332 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 311 fetcher_.get(), data_use_measurement::DataUseUserData::NTP_TILES); | 333 fetcher_.get(), data_use_measurement::DataUseUserData::NTP_TILES); |
| 312 fetcher_->SetRequestContext(download_context_); | 334 fetcher_->SetRequestContext(download_context_); |
| 313 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 335 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 314 net::LOAD_DO_NOT_SAVE_COOKIES); | 336 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 315 fetcher_->SetAutomaticallyRetryOnNetworkChanges(1); | 337 fetcher_->SetAutomaticallyRetryOnNetworkChanges(1); |
| 316 fetcher_->Start(); | 338 fetcher_->Start(); |
| 317 } | 339 } |
| 318 | 340 |
| 319 void PopularSitesImpl::OnURLFetchComplete(const net::URLFetcher* source) { | 341 void PopularSitesImpl::OnURLFetchComplete(const net::URLFetcher* source) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, | 386 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, |
| 365 kPopularSitesDefaultVersion); | 387 kPopularSitesDefaultVersion); |
| 366 FetchPopularSites(); | 388 FetchPopularSites(); |
| 367 } else { | 389 } else { |
| 368 DLOG(WARNING) << "Download fallback site list failed"; | 390 DLOG(WARNING) << "Download fallback site list failed"; |
| 369 callback_.Run(false); | 391 callback_.Run(false); |
| 370 } | 392 } |
| 371 } | 393 } |
| 372 | 394 |
| 373 } // namespace ntp_tiles | 395 } // namespace ntp_tiles |
| OLD | NEW |