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

Unified Diff: chrome/browser/android/offline_pages/background_scheduler_bridge.cc

Issue 2662103003: Always get device conditions from Java for every attempt. (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/offline_pages/background_scheduler_bridge.cc
diff --git a/chrome/browser/android/offline_pages/background_scheduler_bridge.cc b/chrome/browser/android/offline_pages/background_scheduler_bridge.cc
index 9c59ebb6180918612532f3ed7eb8948f81d7268f..41810ac56ae9c7dbeaec465750b350f34e209bbb 100644
--- a/chrome/browser/android/offline_pages/background_scheduler_bridge.cc
+++ b/chrome/browser/android/offline_pages/background_scheduler_bridge.cc
@@ -56,6 +56,10 @@ static jboolean StartScheduledProcessing(
device_conditions, base::Bind(&ProcessingDoneCallback, j_callback_ref));
}
+BackgroundSchedulerBridge::BackgroundSchedulerBridge() = default;
+
+BackgroundSchedulerBridge::~BackgroundSchedulerBridge() = default;
+
void BackgroundSchedulerBridge::Schedule(
const TriggerConditions& trigger_conditions) {
JNIEnv* env = base::android::AttachCurrentThread();
@@ -92,6 +96,27 @@ ScopedJavaLocalRef<jobject> BackgroundSchedulerBridge::CreateTriggerConditions(
require_unmetered_network);
}
+const DeviceConditions&
+BackgroundSchedulerBridge::GetCurrentDeviceConditions() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ // Call the JNI methods to get the device conditions we need.
+ jboolean jpower = Java_BackgroundSchedulerBridge_getPowerConditions(env);
+ jint jbattery = Java_BackgroundSchedulerBridge_getBatteryConditions(env);
+ jint jnetwork = Java_BackgroundSchedulerBridge_getNetworkConditions(env);
+
+ // Cast the java types back to the types we use.
+ bool power = static_cast<bool>(jpower);
+ int battery = static_cast<int>(jbattery);
+
+ net::NetworkChangeNotifier::ConnectionType network_connection_type =
+ static_cast<net::NetworkChangeNotifier::ConnectionType>(jnetwork);
+
+ // Now return the current conditions to the caller.
+ device_conditions_ = base::MakeUnique<DeviceConditions>(
+ power, battery, network_connection_type);
+ return *device_conditions_;
+}
+
bool RegisterBackgroundSchedulerBridge(JNIEnv* env) {
return RegisterNativesImpl(env);
}

Powered by Google App Engine
This is Rietveld 408576698