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

Side by Side Diff: chrome/browser/android/offline_pages/background_scheduler_bridge.cc

Issue 2697493002: [Offline pages] Implementation of OfflineBackgroundTask using background_task_scheduler (Closed)
Patch Set: Fixing compilation issues, addressing feedback Created 3 years, 9 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "chrome/browser/android/offline_pages/background_scheduler_bridge.h"
5 #include "base/android/callback_android.h" 6 #include "base/android/callback_android.h"
6 #include "base/android/scoped_java_ref.h" 7 #include "base/android/scoped_java_ref.h"
7 #include "chrome/browser/android/offline_pages/background_scheduler_bridge.h"
8 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 8 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
9 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" 9 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "components/offline_pages/core/background/device_conditions.h" 12 #include "components/offline_pages/core/background/device_conditions.h"
13 #include "components/offline_pages/core/background/offliner.h"
13 #include "components/offline_pages/core/background/request_coordinator.h" 14 #include "components/offline_pages/core/background/request_coordinator.h"
14 #include "jni/BackgroundSchedulerBridge_jni.h" 15 #include "jni/BackgroundSchedulerBridge_jni.h"
15 16
16 using base::android::JavaParamRef; 17 using base::android::JavaParamRef;
17 using base::android::ScopedJavaGlobalRef; 18 using base::android::ScopedJavaGlobalRef;
18 using base::android::ScopedJavaLocalRef; 19 using base::android::ScopedJavaLocalRef;
19 20
20 namespace offline_pages { 21 namespace offline_pages {
21 namespace android { 22 namespace android {
22 23
(...skipping 26 matching lines...) Expand all
49 GetForBrowserContext(profile); 50 GetForBrowserContext(profile);
50 DVLOG(2) << "resource_coordinator: " << coordinator; 51 DVLOG(2) << "resource_coordinator: " << coordinator;
51 DeviceConditions device_conditions( 52 DeviceConditions device_conditions(
52 j_power_connected, j_battery_percentage, 53 j_power_connected, j_battery_percentage,
53 static_cast<net::NetworkChangeNotifier::ConnectionType>( 54 static_cast<net::NetworkChangeNotifier::ConnectionType>(
54 j_net_connection_type)); 55 j_net_connection_type));
55 return coordinator->StartScheduledProcessing( 56 return coordinator->StartScheduledProcessing(
56 device_conditions, base::Bind(&ProcessingDoneCallback, j_callback_ref)); 57 device_conditions, base::Bind(&ProcessingDoneCallback, j_callback_ref));
57 } 58 }
58 59
60 // JNI call to stop request processing in scheduled mode.
61 static void StopScheduledProcessing(JNIEnv* env,
62 const JavaParamRef<jclass>& jcaller) {
63 Profile* profile = ProfileManager::GetLastUsedProfile();
64 RequestCoordinator* coordinator =
65 RequestCoordinatorFactory::GetInstance()->GetForBrowserContext(profile);
66 DVLOG(2) << "resource_coordinator: " << coordinator;
67 if (!coordinator)
68 return;
69 coordinator->StopProcessing(
70 Offliner::RequestStatus::BACKGROUND_SCHEDULER_CANCELED);
Pete Williamson 2017/02/28 20:17:49 After thinking about it and looking at the current
fgorski 2017/02/28 21:24:09 Done.
71 }
72
59 BackgroundSchedulerBridge::BackgroundSchedulerBridge() = default; 73 BackgroundSchedulerBridge::BackgroundSchedulerBridge() = default;
60 74
61 BackgroundSchedulerBridge::~BackgroundSchedulerBridge() = default; 75 BackgroundSchedulerBridge::~BackgroundSchedulerBridge() = default;
62 76
63 void BackgroundSchedulerBridge::Schedule( 77 void BackgroundSchedulerBridge::Schedule(
64 const TriggerConditions& trigger_conditions) { 78 const TriggerConditions& trigger_conditions) {
65 JNIEnv* env = base::android::AttachCurrentThread(); 79 JNIEnv* env = base::android::AttachCurrentThread();
66 ScopedJavaLocalRef<jobject> j_conditions = 80 ScopedJavaLocalRef<jobject> j_conditions =
67 CreateTriggerConditions(env, trigger_conditions.require_power_connected, 81 CreateTriggerConditions(env, trigger_conditions.require_power_connected,
68 trigger_conditions.minimum_battery_percentage, 82 trigger_conditions.minimum_battery_percentage,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 power, battery, network_connection_type); 130 power, battery, network_connection_type);
117 return *device_conditions_; 131 return *device_conditions_;
118 } 132 }
119 133
120 bool RegisterBackgroundSchedulerBridge(JNIEnv* env) { 134 bool RegisterBackgroundSchedulerBridge(JNIEnv* env) {
121 return RegisterNativesImpl(env); 135 return RegisterNativesImpl(env);
122 } 136 }
123 137
124 } // namespace android 138 } // namespace android
125 } // namespace offline_pages 139 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698