Chromium Code Reviews| 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..a101d3119bdbd0772afeb7b23bc4455c31e197a0 |
| --- /dev/null |
| +++ b/chrome/browser/android/offline_pages/prefetch/prefetch_background_task.h |
| @@ -0,0 +1,56 @@ |
| +// 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 { |
|
carlosk
2017/04/19 23:01:38
Why is this out of the offline_pages::prefetch nam
dewittj
2017/04/20 21:41:45
I invented the offline_pages::prefetch namespace o
|
| + public: |
| + PrefetchBackgroundTask( |
| + JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& j_prefetch_background_task, |
| + PrefetchService* service); |
| + ~PrefetchBackgroundTask() override; |
| + |
| + // API for interacting with JobScheduler from native. |
| + // Schedules the default 'NWake' prefetching task. Does nothing if |
| + // JobScheduler is not supported. |
| + static void Schedule(); |
| + |
| + // Cancels the default 'NWake' prefetching task. Does nothing if |
| + // JobScheduler is not supported. |
| + 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_ |