Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1323)

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_provider.cc

Issue 2569663004: [NTPSnippets] Switch from TickClock to Clock for storing the last background fetched time. (Closed)
Patch Set: Add a DCHECK to check that the num or args passed to the new method is 0 Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_snippets/remote/remote_suggestions_provider.h" 5 #include "components/ntp_snippets/remote/remote_suggestions_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/feature_list.h" 12 #include "base/feature_list.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/metrics/sparse_histogram.h" 16 #include "base/metrics/sparse_histogram.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/task_runner_util.h" 21 #include "base/task_runner_util.h"
22 #include "base/time/default_clock.h"
22 #include "base/time/default_tick_clock.h" 23 #include "base/time/default_tick_clock.h"
23 #include "base/time/time.h" 24 #include "base/time/time.h"
24 #include "base/values.h" 25 #include "base/values.h"
25 #include "components/data_use_measurement/core/data_use_user_data.h" 26 #include "components/data_use_measurement/core/data_use_user_data.h"
26 #include "components/history/core/browser/history_service.h" 27 #include "components/history/core/browser/history_service.h"
27 #include "components/image_fetcher/image_decoder.h" 28 #include "components/image_fetcher/image_decoder.h"
28 #include "components/image_fetcher/image_fetcher.h" 29 #include "components/image_fetcher/image_fetcher.h"
29 #include "components/ntp_snippets/features.h" 30 #include "components/ntp_snippets/features.h"
30 #include "components/ntp_snippets/pref_names.h" 31 #include "components/ntp_snippets/pref_names.h"
31 #include "components/ntp_snippets/remote/remote_suggestions_database.h" 32 #include "components/ntp_snippets/remote/remote_suggestions_database.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 snippets_fetcher_(std::move(snippets_fetcher)), 245 snippets_fetcher_(std::move(snippets_fetcher)),
245 image_fetcher_(std::move(image_fetcher)), 246 image_fetcher_(std::move(image_fetcher)),
246 image_decoder_(std::move(image_decoder)), 247 image_decoder_(std::move(image_decoder)),
247 database_(std::move(database)), 248 database_(std::move(database)),
248 status_service_(std::move(status_service)), 249 status_service_(std::move(status_service)),
249 fetch_when_ready_(false), 250 fetch_when_ready_(false),
250 nuke_when_initialized_(false), 251 nuke_when_initialized_(false),
251 thumbnail_requests_throttler_( 252 thumbnail_requests_throttler_(
252 pref_service, 253 pref_service,
253 RequestThrottler::RequestType::CONTENT_SUGGESTION_THUMBNAIL), 254 RequestThrottler::RequestType::CONTENT_SUGGESTION_THUMBNAIL),
254 tick_clock_(base::MakeUnique<base::DefaultTickClock>()) { 255 clock_(base::MakeUnique<base::DefaultClock>()) {
255 pref_service_->ClearPref(kDeprecatedSnippetHostsPref); 256 pref_service_->ClearPref(kDeprecatedSnippetHostsPref);
256 257
257 RestoreCategoriesFromPrefs(); 258 RestoreCategoriesFromPrefs();
258 // The articles category always exists. Add it if we didn't get it from prefs. 259 // The articles category always exists. Add it if we didn't get it from prefs.
259 // TODO(treib): Rethink this. 260 // TODO(treib): Rethink this.
260 category_contents_.insert( 261 category_contents_.insert(
261 std::make_pair(articles_category_, 262 std::make_pair(articles_category_,
262 CategoryContent(BuildArticleCategoryInfo(base::nullopt)))); 263 CategoryContent(BuildArticleCategoryInfo(base::nullopt))));
263 // Tell the observer about all the categories. 264 // Tell the observer about all the categories.
264 for (const auto& entry : category_contents_) { 265 for (const auto& entry : category_contents_) {
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 if (!ready()) { 713 if (!ready()) {
713 // TODO(tschumann): What happens if this was a user-triggered, interactive 714 // TODO(tschumann): What happens if this was a user-triggered, interactive
714 // request? Is the UI waiting indefinitely now? 715 // request? Is the UI waiting indefinitely now?
715 return; 716 return;
716 } 717 }
717 718
718 // Record the fetch time of a successfull background fetch. 719 // Record the fetch time of a successfull background fetch.
719 if (!interactive_request && 720 if (!interactive_request &&
720 fetch_result == NTPSnippetsFetcher::FetchResult::SUCCESS) { 721 fetch_result == NTPSnippetsFetcher::FetchResult::SUCCESS) {
721 pref_service_->SetInt64(prefs::kLastSuccessfulBackgroundFetchTime, 722 pref_service_->SetInt64(prefs::kLastSuccessfulBackgroundFetchTime,
722 tick_clock_->NowTicks().ToInternalValue()); 723 clock_->Now().ToInternalValue());
723 } 724 }
724 725
725 // Mark all categories as not provided by the server in the latest fetch. The 726 // Mark all categories as not provided by the server in the latest fetch. The
726 // ones we got will be marked again below. 727 // ones we got will be marked again below.
727 for (auto& item : category_contents_) { 728 for (auto& item : category_contents_) {
728 CategoryContent* content = &item.second; 729 CategoryContent* content = &item.second;
729 content->included_in_last_server_response = false; 730 content->included_in_last_server_response = false;
730 } 731 }
731 732
732 // Clear up expired dismissed snippets before we use them to filter new ones. 733 // Clear up expired dismissed snippets before we use them to filter new ones.
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 RemoteSuggestionsProvider::CategoryContent::CategoryContent(CategoryContent&&) = 1346 RemoteSuggestionsProvider::CategoryContent::CategoryContent(CategoryContent&&) =
1346 default; 1347 default;
1347 1348
1348 RemoteSuggestionsProvider::CategoryContent::~CategoryContent() = default; 1349 RemoteSuggestionsProvider::CategoryContent::~CategoryContent() = default;
1349 1350
1350 RemoteSuggestionsProvider::CategoryContent& 1351 RemoteSuggestionsProvider::CategoryContent&
1351 RemoteSuggestionsProvider::CategoryContent::operator=(CategoryContent&&) = 1352 RemoteSuggestionsProvider::CategoryContent::operator=(CategoryContent&&) =
1352 default; 1353 default;
1353 1354
1354 } // namespace ntp_snippets 1355 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698