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

Side by Side Diff: chrome/browser/android/offline_pages/prefetch/prefetch_background_task.h

Issue 2914703002: [Offline Prefetch] Backoff support for PrefetchBackgroundTask (Closed)
Patch Set: Address feedback Created 3 years, 6 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 unified diff | Download patch
OLDNEW
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,
dewittj 2017/06/01 00:22:27 also ForTesting
jianli 2017/06/02 00:48:37 Done.
42 const base::android::JavaParamRef<jobject>& jcaller,
43 jboolean reschedule,
44 jboolean backoff);
45 void SignalTaskFinishedForTesting(
46 JNIEnv* env,
47 const base::android::JavaParamRef<jobject>& jcaller);
35 48
36 // When this task completes, we tell the system whether the task should be 49 // When this task completes, we tell the system whether the task should be
37 // rescheduled with the same parameters as last time. 50 // rescheduled with or without backoff.
38 void SetNeedsReschedule(bool reschedule) override; 51 void SetNeedsReschedule(bool reschedule, bool backoff) override;
39 bool needs_reschedule() { return needs_reschedule_; } 52 bool needs_reschedule() { return needs_reschedule_; }
40 53
41 private: 54 private:
42 bool needs_reschedule_ = true; 55 void SetupBackOff();
56 int GetAdditionalBackoffSeconds() const;
57
58 bool task_killed_by_system_ = false;
59 bool needs_reschedule_ = false;
43 60
44 // A pointer to the controlling |PrefetchBackgroundTask|. 61 // A pointer to the controlling |PrefetchBackgroundTask|.
45 base::android::ScopedJavaGlobalRef<jobject> java_prefetch_background_task_; 62 base::android::ScopedJavaGlobalRef<jobject> java_prefetch_background_task_;
46 63
47 // The PrefetchService owns |this|, so a raw pointer is OK. 64 // The PrefetchService owns |this|, so a raw pointer is OK.
48 PrefetchService* service_; 65 PrefetchService* service_;
66
67 Profile* profile_;
68
69 std::unique_ptr<net::BackoffEntry> backoff_;
49 }; 70 };
50 71
51 bool RegisterPrefetchBackgroundTask(JNIEnv* env); 72 bool RegisterPrefetchBackgroundTask(JNIEnv* env);
52 73
74 void RegisterPrefetchBackgroundTaskPrefs(PrefRegistrySimple* registry);
75
53 } // namespace offline_pages 76 } // namespace offline_pages
54 77
55 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TAS K_H_ 78 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TAS K_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698