Chromium Code Reviews| 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 SetTaskRescheduling(JNIEnv* env, | |
| 42 const base::android::JavaParamRef<jobject>& jcaller, | |
| 43 jboolean reschedule, | |
| 44 jboolean backoff); | |
| 45 void SignalTaskFinished(JNIEnv* env, | |
|
dewittj
2017/05/31 21:33:33
Please rename to SignalTaskFinishedForTesting, sin
jianli
2017/06/01 00:09:59
Done.
| |
| 46 const base::android::JavaParamRef<jobject>& jcaller); | |
| 35 | 47 |
| 36 // When this task completes, we tell the system whether the task should be | 48 // When this task completes, we tell the system whether the task should be |
| 37 // rescheduled with the same parameters as last time. | 49 // rescheduled with or without backoff. |
| 38 void SetNeedsReschedule(bool reschedule) override; | 50 void SetNeedsReschedule(bool reschedule, bool backoff) override; |
| 39 bool needs_reschedule() { return needs_reschedule_; } | 51 bool needs_reschedule() { return needs_reschedule_; } |
| 40 | 52 |
| 41 private: | 53 private: |
| 42 bool needs_reschedule_ = true; | 54 void SetupBackOff(); |
| 55 int GetAdditionalBackoffSeconds() const; | |
| 56 | |
| 57 bool task_killed_by_system_ = false; | |
| 58 bool needs_reschedule_ = false; | |
| 43 | 59 |
| 44 // A pointer to the controlling |PrefetchBackgroundTask|. | 60 // A pointer to the controlling |PrefetchBackgroundTask|. |
| 45 base::android::ScopedJavaGlobalRef<jobject> java_prefetch_background_task_; | 61 base::android::ScopedJavaGlobalRef<jobject> java_prefetch_background_task_; |
| 46 | 62 |
| 47 // The PrefetchService owns |this|, so a raw pointer is OK. | 63 // The PrefetchService owns |this|, so a raw pointer is OK. |
| 48 PrefetchService* service_; | 64 PrefetchService* service_; |
| 65 | |
| 66 Profile* profile_; | |
| 67 | |
| 68 std::unique_ptr<net::BackoffEntry> backoff_; | |
| 49 }; | 69 }; |
| 50 | 70 |
| 51 bool RegisterPrefetchBackgroundTask(JNIEnv* env); | 71 bool RegisterPrefetchBackgroundTask(JNIEnv* env); |
| 52 | 72 |
| 73 void RegisterPrefetchBackgroundTaskPrefs(PrefRegistrySimple* registry); | |
| 74 | |
| 53 } // namespace offline_pages | 75 } // namespace offline_pages |
| 54 | 76 |
| 55 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TAS K_H_ | 77 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TAS K_H_ |
| OLD | NEW |