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..4ff354f6b697750382057030828db4b3d856afab 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_(base::MakeUnique<base::DefaultTickClock>()) { |
| 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::kLastSuccessfulBackgroundFetchTime, 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,6 +644,7 @@ void RemoteSuggestionsProvider::OnDatabaseError() { |
| void RemoteSuggestionsProvider::OnFetchMoreFinished( |
| const FetchDoneCallback& fetching_callback, |
| + NTPSnippetsFetcher::FetchResult fetch_result, |
| NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories) { |
| if (!fetched_categories) { |
| // TODO(fhorschig): Disambiguate the kind of error that led here. |
| @@ -702,6 +706,8 @@ void RemoteSuggestionsProvider::OnFetchMoreFinished( |
| } |
| void RemoteSuggestionsProvider::OnFetchFinished( |
| + bool interactive_request, |
| + NTPSnippetsFetcher::FetchResult fetch_result, |
| NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories) { |
| if (!ready()) { |
| // TODO(tschumann): What happens if this was a user-triggered, interactive |
| @@ -709,6 +715,13 @@ void RemoteSuggestionsProvider::OnFetchFinished( |
| return; |
| } |
| + // Record the fetch time of a successfull background fetch. |
| + if (!interactive_request && |
| + fetch_result == NTPSnippetsFetcher::FetchResult::SUCCESS) { |
| + pref_service_->SetInt64(prefs::kLastSuccessfulBackgroundFetchTime, |
|
tschumann
2016/12/08 18:18:51
just a comment -- no need to action: I guess that
|
| + 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_) { |