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.h" | 5 #include "components/ntp_tiles/popular_sites.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/files/important_file_writer.h" | 13 #include "base/files/important_file_writer.h" |
14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/task_runner_util.h" | 19 #include "base/task_runner_util.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "components/data_use_measurement/core/data_use_user_data.h" |
22 #include "components/google/core/browser/google_util.h" | 23 #include "components/google/core/browser/google_util.h" |
23 #include "components/ntp_tiles/constants.h" | 24 #include "components/ntp_tiles/constants.h" |
24 #include "components/ntp_tiles/pref_names.h" | 25 #include "components/ntp_tiles/pref_names.h" |
25 #include "components/ntp_tiles/switches.h" | 26 #include "components/ntp_tiles/switches.h" |
26 #include "components/pref_registry/pref_registry_syncable.h" | 27 #include "components/pref_registry/pref_registry_syncable.h" |
27 #include "components/prefs/pref_service.h" | 28 #include "components/prefs/pref_service.h" |
28 #include "components/search_engines/search_engine_type.h" | 29 #include "components/search_engines/search_engine_type.h" |
29 #include "components/search_engines/template_url_service.h" | 30 #include "components/search_engines/template_url_service.h" |
30 #include "components/variations/service/variations_service.h" | 31 #include "components/variations/service/variations_service.h" |
31 #include "components/variations/variations_associated_data.h" | 32 #include "components/variations/variations_associated_data.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 OnJsonParseFailed("previously-fetched JSON was no longer parseable"); | 272 OnJsonParseFailed("previously-fetched JSON was no longer parseable"); |
272 } | 273 } |
273 } else { | 274 } else { |
274 // File didn't exist, or couldn't be read for some other reason. | 275 // File didn't exist, or couldn't be read for some other reason. |
275 FetchPopularSites(); | 276 FetchPopularSites(); |
276 } | 277 } |
277 } | 278 } |
278 | 279 |
279 void PopularSites::FetchPopularSites() { | 280 void PopularSites::FetchPopularSites() { |
280 fetcher_ = URLFetcher::Create(pending_url_, URLFetcher::GET, this); | 281 fetcher_ = URLFetcher::Create(pending_url_, URLFetcher::GET, this); |
| 282 // TODO(sfiera): Count the downloaded bytes of icons fetched by popular sites. |
| 283 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 284 fetcher_.get(), data_use_measurement::DataUseUserData::NTP_TILES); |
281 fetcher_->SetRequestContext(download_context_); | 285 fetcher_->SetRequestContext(download_context_); |
282 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 286 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
283 net::LOAD_DO_NOT_SAVE_COOKIES); | 287 net::LOAD_DO_NOT_SAVE_COOKIES); |
284 fetcher_->SetAutomaticallyRetryOnNetworkChanges(1); | 288 fetcher_->SetAutomaticallyRetryOnNetworkChanges(1); |
285 fetcher_->Start(); | 289 fetcher_->Start(); |
286 } | 290 } |
287 | 291 |
288 void PopularSites::OnURLFetchComplete(const net::URLFetcher* source) { | 292 void PopularSites::OnURLFetchComplete(const net::URLFetcher* source) { |
289 DCHECK_EQ(fetcher_.get(), source); | 293 DCHECK_EQ(fetcher_.get(), source); |
290 std::unique_ptr<net::URLFetcher> free_fetcher = std::move(fetcher_); | 294 std::unique_ptr<net::URLFetcher> free_fetcher = std::move(fetcher_); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, | 377 pending_url_ = GetPopularSitesURL(kPopularSitesDefaultCountryCode, |
374 kPopularSitesDefaultVersion); | 378 kPopularSitesDefaultVersion); |
375 FetchPopularSites(); | 379 FetchPopularSites(); |
376 } else { | 380 } else { |
377 DLOG(WARNING) << "Download fallback site list failed"; | 381 DLOG(WARNING) << "Download fallback site list failed"; |
378 callback_.Run(false); | 382 callback_.Run(false); |
379 } | 383 } |
380 } | 384 } |
381 | 385 |
382 } // namespace ntp_tiles | 386 } // namespace ntp_tiles |
OLD | NEW |