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

Unified Diff: components/ntp_snippets/ntp_snippets_service.cc

Issue 1699143002: [NTP Snippets] Schedule periodic fetching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippets_feature
Patch Set: rebase Created 4 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/ntp_snippets_service.cc
diff --git a/components/ntp_snippets/ntp_snippets_service.cc b/components/ntp_snippets/ntp_snippets_service.cc
index 66a923fe1e367cdc84df1e3f5a7338e637c392e3..db962648a7ac5bd1522e97dbd0ec5aa1da7bfa0d 100644
--- a/components/ntp_snippets/ntp_snippets_service.cc
+++ b/components/ntp_snippets/ntp_snippets_service.cc
@@ -14,6 +14,12 @@
namespace ntp_snippets {
noyau (Ping after 24h) 2016/02/22 11:58:49 nit: I would avoid nesting the namespaces, this li
Marc Treib 2016/02/22 12:44:32 Done. Nesting is a somewhat common pattern though.
+namespace {
+
+// TODO(treib): This is an extremely small value, for ease of development.
noyau (Ping after 24h) 2016/02/22 11:58:49 Please use the format TODO(crbug/XXXX): and add a
Bernhard Bauer 2016/02/22 12:05:12 Nit: `TODO(crbug.com/1234)`, to make it clickable
Marc Treib 2016/02/22 12:44:31 Done.
+// Replace it by something sensible and add a command line param to control it.
+const int kDefaultFetchingIntervalSeconds = 60;
+
std::string ReadFileToString(const base::FilePath& path) {
std::string data;
bool success = base::ReadFileToString(path, &data);
@@ -22,13 +28,17 @@ std::string ReadFileToString(const base::FilePath& path) {
return data;
}
+} // namespace
+
NTPSnippetsService::NTPSnippetsService(
scoped_refptr<base::SequencedTaskRunner> file_task_runner,
const std::string& application_language_code,
+ NTPSnippetsScheduler* scheduler,
scoped_ptr<NTPSnippetsFetcher> snippets_fetcher)
: loaded_(false),
file_task_runner_(file_task_runner),
application_language_code_(application_language_code),
+ scheduler_(scheduler),
snippets_fetcher_(std::move(snippets_fetcher)),
weak_ptr_factory_(this) {
snippets_fetcher_callback_ = snippets_fetcher_->AddCallback(
@@ -38,6 +48,17 @@ NTPSnippetsService::NTPSnippetsService(
NTPSnippetsService::~NTPSnippetsService() {}
+void NTPSnippetsService::Init(bool enabled) {
+ // The scheduler only exists on Android so far, it's null on other platforms.
+ if (!scheduler_)
+ return;
+
+ if (enabled)
+ scheduler_->Schedule(kDefaultFetchingIntervalSeconds);
+ else
+ scheduler_->Unschedule();
+}
+
void NTPSnippetsService::Shutdown() {
FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_,
NTPSnippetsServiceShutdown(this));

Powered by Google App Engine
This is Rietveld 408576698