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

Unified Diff: chrome/browser/android/offline_pages/prefetch/prefetch_background_task.h

Issue 2820263002: [Offline Prefetch] Create a new JobScheduler task to wake up for net activity. (Closed)
Patch Set: tommycli@ comments. Created 3 years, 8 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: chrome/browser/android/offline_pages/prefetch/prefetch_background_task.h
diff --git a/chrome/browser/android/offline_pages/prefetch/prefetch_background_task.h b/chrome/browser/android/offline_pages/prefetch/prefetch_background_task.h
new file mode 100644
index 0000000000000000000000000000000000000000..699b1ddcc7bc4d9d9b738de06970d2de386245b8
--- /dev/null
+++ b/chrome/browser/android/offline_pages/prefetch/prefetch_background_task.h
@@ -0,0 +1,54 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TASK_H_
+#define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TASK_H_
+
+#include "base/android/jni_android.h"
+#include "components/offline_pages/core/prefetch/prefetch_service.h"
+
+namespace offline_pages {
+
+// A task with a counterpart in Java for managing the background activity of the
+// offline page prefetcher. Schedules and listens for events about prefetching
+// tasks.
+class PrefetchBackgroundTask : public PrefetchService::ScopedBackgroundTask {
+ public:
+ PrefetchBackgroundTask(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& j_prefetch_background_task,
+ PrefetchService* service);
+ ~PrefetchBackgroundTask() override;
+
+ // API for interacting with BackgroundTaskScheduler from native.
+ // Schedules the default 'NWake' prefetching task.
+ static void Schedule();
+
+ // Cancels the default 'NWake' prefetching task.
+ static void Cancel();
+
+ // Java hooks.
+ bool OnStopTask(JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& jcaller);
+
+ // When this task completes, we tell the system whether the task should be
+ // rescheduled with the same parameters as last time.
+ void SetNeedsReschedule(bool reschedule) override;
+ bool needs_reschedule() { return needs_reschedule_; }
+
+ private:
+ bool needs_reschedule_ = true;
+
+ // A pointer to the controlling |PrefetchBackgroundTask|.
+ base::android::ScopedJavaGlobalRef<jobject> java_prefetch_background_task_;
+
+ // The PrefetchService owns |this|, so a raw pointer is OK.
+ PrefetchService* service_;
+};
+
+bool RegisterPrefetchBackgroundTask(JNIEnv* env);
+
+} // namespace offline_pages
+
+#endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TASK_H_

Powered by Google App Engine
This is Rietveld 408576698