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

Side by Side 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, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TASK_H _
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TASK_H _
7
8 #include "base/android/jni_android.h"
9 #include "components/offline_pages/core/prefetch/prefetch_service.h"
10
11 namespace offline_pages {
12
13 // A task with a counterpart in Java for managing the background activity of the
14 // offline page prefetcher. Schedules and listens for events about prefetching
15 // tasks.
16 class PrefetchBackgroundTask : public PrefetchService::ScopedBackgroundTask {
17 public:
18 PrefetchBackgroundTask(
19 JNIEnv* env,
20 const base::android::JavaParamRef<jobject>& j_prefetch_background_task,
21 PrefetchService* service);
22 ~PrefetchBackgroundTask() override;
23
24 // API for interacting with BackgroundTaskScheduler from native.
25 // Schedules the default 'NWake' prefetching task.
26 static void Schedule();
27
28 // Cancels the default 'NWake' prefetching task.
29 static void Cancel();
30
31 // Java hooks.
32 bool OnStopTask(JNIEnv* env,
33 const base::android::JavaParamRef<jobject>& jcaller);
34
35 // When this task completes, we tell the system whether the task should be
36 // rescheduled with the same parameters as last time.
37 void SetNeedsReschedule(bool reschedule) override;
38 bool needs_reschedule() { return needs_reschedule_; }
39
40 private:
41 bool needs_reschedule_ = true;
42
43 // A pointer to the controlling |PrefetchBackgroundTask|.
44 base::android::ScopedJavaGlobalRef<jobject> java_prefetch_background_task_;
45
46 // The PrefetchService owns |this|, so a raw pointer is OK.
47 PrefetchService* service_;
48 };
49
50 bool RegisterPrefetchBackgroundTask(JNIEnv* env);
51
52 } // namespace offline_pages
53
54 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_PREFETCH_PREFETCH_BACKGROUND_TAS K_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698