Chromium Code Reviews| Index: components/ntp_snippets/remote/remote_suggestions_provider.cc |
| diff --git a/components/ntp_snippets/remote/remote_suggestions_provider.cc b/components/ntp_snippets/remote/remote_suggestions_provider.cc |
| index 653c82b401289a641bde225d90324a52c4239aa9..806b090ef3b071125d6cae619a05d44403a46d65 100644 |
| --- a/components/ntp_snippets/remote/remote_suggestions_provider.cc |
| +++ b/components/ntp_snippets/remote/remote_suggestions_provider.cc |
| @@ -19,6 +19,7 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/task_runner_util.h" |
| +#include "base/time/default_tick_clock.h" |
| #include "base/time/time.h" |
| #include "base/values.h" |
| #include "components/data_use_measurement/core/data_use_user_data.h" |
| @@ -249,7 +250,8 @@ RemoteSuggestionsProvider::RemoteSuggestionsProvider( |
| nuke_when_initialized_(false), |
| thumbnail_requests_throttler_( |
| pref_service, |
| - RequestThrottler::RequestType::CONTENT_SUGGESTION_THUMBNAIL) { |
| + RequestThrottler::RequestType::CONTENT_SUGGESTION_THUMBNAIL), |
| + tick_clock_(new base::DefaultTickClock()) { |
|
Marc Treib
2016/12/07 14:42:13
nit: base::MakeUnique<base::DefaultTickClock>()
(t
markusheintz_
2016/12/08 09:47:41
Done.
|
| pref_service_->ClearPref(kDeprecatedSnippetHostsPref); |
| RestoreCategoriesFromPrefs(); |
| @@ -290,6 +292,7 @@ void RemoteSuggestionsProvider::RegisterProfilePrefs( |
| registry->RegisterInt64Pref(prefs::kSnippetBackgroundFetchingIntervalWifi, 0); |
| registry->RegisterInt64Pref(prefs::kSnippetBackgroundFetchingIntervalFallback, |
| 0); |
| + registry->RegisterInt64Pref(prefs::kLastSuccessfullBackgroundFetchTime, 0); |
| RemoteSuggestionsStatusService::RegisterProfilePrefs(registry); |
| } |
| @@ -331,7 +334,7 @@ void RemoteSuggestionsProvider::FetchSnippetsFromHosts( |
| params.interactive_request = interactive_request; |
| snippets_fetcher_->FetchSnippets( |
| params, base::BindOnce(&RemoteSuggestionsProvider::OnFetchFinished, |
| - base::Unretained(this))); |
| + base::Unretained(this), interactive_request)); |
| } |
| void RemoteSuggestionsProvider::Fetch( |
| @@ -641,7 +644,8 @@ void RemoteSuggestionsProvider::OnDatabaseError() { |
| void RemoteSuggestionsProvider::OnFetchMoreFinished( |
| const FetchDoneCallback& fetching_callback, |
| - NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories) { |
| + NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories, |
| + NTPSnippetsFetcher::FetchResult fetch_result) { |
| if (!fetched_categories) { |
| // TODO(fhorschig): Disambiguate the kind of error that led here. |
| CallWithEmptyResults(fetching_callback, |
| @@ -702,13 +706,22 @@ void RemoteSuggestionsProvider::OnFetchMoreFinished( |
| } |
| void RemoteSuggestionsProvider::OnFetchFinished( |
| - NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories) { |
| + bool interactive_request, |
| + NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories, |
| + NTPSnippetsFetcher::FetchResult fetch_result) { |
| if (!ready()) { |
| // TODO(tschumann): What happens if this was a user-triggered, interactive |
| // request? Is the UI waiting indefinitely now? |
| return; |
| } |
| + // Record the fetch time of a successfull background fetch. |
| + if (!interactive_request && |
| + fetch_result == NTPSnippetsFetcher::FetchResult::SUCCESS) { |
| + pref_service_->SetInt64(prefs::kLastSuccessfullBackgroundFetchTime, |
| + tick_clock_->NowTicks().ToInternalValue()); |
| + } |
| + |
| // Mark all categories as not provided by the server in the latest fetch. The |
| // ones we got will be marked again below. |
| for (auto& item : category_contents_) { |