| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TASK_H
_ | 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TASK_H
_ |
| 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TASK_H
_ | 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TASK_H
_ |
| 7 | 7 |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "components/offline_pages/core/prefetch/prefetch_dispatcher.h" | 9 #include "components/offline_pages/core/prefetch/prefetch_dispatcher.h" |
| 10 #include "components/offline_pages/core/prefetch/prefetch_service.h" |
| 11 #include "net/base/backoff_entry.h" |
| 12 |
| 13 class PrefRegistrySimple; |
| 14 class Profile; |
| 10 | 15 |
| 11 namespace offline_pages { | 16 namespace offline_pages { |
| 12 class PrefetchService; | 17 class PrefetchService; |
| 13 | 18 |
| 14 // A task with a counterpart in Java for managing the background activity of the | 19 // A task with a counterpart in Java for managing the background activity of the |
| 15 // offline page prefetcher. Schedules and listens for events about prefetching | 20 // offline page prefetcher. Schedules and listens for events about prefetching |
| 16 // tasks. | 21 // tasks. |
| 17 class PrefetchBackgroundTask : public PrefetchDispatcher::ScopedBackgroundTask { | 22 class PrefetchBackgroundTask : public PrefetchDispatcher::ScopedBackgroundTask { |
| 18 public: | 23 public: |
| 19 PrefetchBackgroundTask( | 24 PrefetchBackgroundTask( |
| 20 JNIEnv* env, | 25 JNIEnv* env, |
| 21 const base::android::JavaParamRef<jobject>& j_prefetch_background_task, | 26 const base::android::JavaParamRef<jobject>& j_prefetch_background_task, |
| 22 PrefetchService* service); | 27 PrefetchService* service, |
| 28 Profile* profile); |
| 23 ~PrefetchBackgroundTask() override; | 29 ~PrefetchBackgroundTask() override; |
| 24 | 30 |
| 25 // API for interacting with BackgroundTaskScheduler from native. | 31 // API for interacting with BackgroundTaskScheduler from native. |
| 26 // Schedules the default 'NWake' prefetching task. | 32 // Schedules the default 'NWake' prefetching task. |
| 27 static void Schedule(); | 33 static void Schedule(int additional_delay_seconds); |
| 28 | 34 |
| 29 // Cancels the default 'NWake' prefetching task. | 35 // Cancels the default 'NWake' prefetching task. |
| 30 static void Cancel(); | 36 static void Cancel(); |
| 31 | 37 |
| 32 // Java hooks. | 38 // Java hooks. |
| 33 bool OnStopTask(JNIEnv* env, | 39 bool OnStopTask(JNIEnv* env, |
| 34 const base::android::JavaParamRef<jobject>& jcaller); | 40 const base::android::JavaParamRef<jobject>& jcaller); |
| 41 void SetTaskReschedulingForTesting( |
| 42 JNIEnv* env, |
| 43 const base::android::JavaParamRef<jobject>& jcaller, |
| 44 jboolean reschedule, |
| 45 jboolean backoff); |
| 46 void SignalTaskFinishedForTesting( |
| 47 JNIEnv* env, |
| 48 const base::android::JavaParamRef<jobject>& jcaller); |
| 35 | 49 |
| 36 // When this task completes, we tell the system whether the task should be | 50 // When this task completes, we tell the system whether the task should be |
| 37 // rescheduled with the same parameters as last time. | 51 // rescheduled with or without backoff. |
| 38 void SetNeedsReschedule(bool reschedule) override; | 52 void SetNeedsReschedule(bool reschedule, bool backoff) override; |
| 39 bool needs_reschedule() { return needs_reschedule_; } | 53 bool needs_reschedule() { return needs_reschedule_; } |
| 40 | 54 |
| 41 private: | 55 private: |
| 42 bool needs_reschedule_ = true; | 56 void SetupBackOff(); |
| 57 int GetAdditionalBackoffSeconds() const; |
| 58 |
| 59 bool task_killed_by_system_ = false; |
| 60 bool needs_reschedule_ = false; |
| 43 | 61 |
| 44 // A pointer to the controlling |PrefetchBackgroundTask|. | 62 // A pointer to the controlling |PrefetchBackgroundTask|. |
| 45 base::android::ScopedJavaGlobalRef<jobject> java_prefetch_background_task_; | 63 base::android::ScopedJavaGlobalRef<jobject> java_prefetch_background_task_; |
| 46 | 64 |
| 47 // The PrefetchService owns |this|, so a raw pointer is OK. | 65 // The PrefetchService owns |this|, so a raw pointer is OK. |
| 48 PrefetchService* service_; | 66 PrefetchService* service_; |
| 67 |
| 68 Profile* profile_; |
| 69 |
| 70 std::unique_ptr<net::BackoffEntry> backoff_; |
| 49 }; | 71 }; |
| 50 | 72 |
| 51 bool RegisterPrefetchBackgroundTask(JNIEnv* env); | 73 bool RegisterPrefetchBackgroundTask(JNIEnv* env); |
| 52 | 74 |
| 75 void RegisterPrefetchBackgroundTaskPrefs(PrefRegistrySimple* registry); |
| 76 |
| 53 } // namespace offline_pages | 77 } // namespace offline_pages |
| 54 | 78 |
| 55 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TAS
K_H_ | 79 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TAS
K_H_ |
| OLD | NEW |