| OLD | NEW |
| 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 "base/android/callback_android.h" | 5 #include "base/android/callback_android.h" |
| 6 #include "base/android/scoped_java_ref.h" | 6 #include "base/android/scoped_java_ref.h" |
| 7 #include "chrome/browser/android/offline_pages/background_scheduler_bridge.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" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 DVLOG(2) << "resource_coordinator: " << coordinator; | 47 DVLOG(2) << "resource_coordinator: " << coordinator; |
| 48 DeviceConditions device_conditions( | 48 DeviceConditions device_conditions( |
| 49 j_power_connected, j_battery_percentage, | 49 j_power_connected, j_battery_percentage, |
| 50 static_cast<net::NetworkChangeNotifier::ConnectionType>( | 50 static_cast<net::NetworkChangeNotifier::ConnectionType>( |
| 51 j_net_connection_type)); | 51 j_net_connection_type)); |
| 52 return coordinator->StartProcessing( | 52 return coordinator->StartProcessing( |
| 53 device_conditions, base::Bind(&ProcessingDoneCallback, j_callback_ref)); | 53 device_conditions, base::Bind(&ProcessingDoneCallback, j_callback_ref)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void BackgroundSchedulerBridge::Schedule( | 56 void BackgroundSchedulerBridge::Schedule( |
| 57 const TriggerCondition& trigger_condition) { | 57 const TriggerConditions& trigger_conditions) { |
| 58 JNIEnv* env = base::android::AttachCurrentThread(); | 58 JNIEnv* env = base::android::AttachCurrentThread(); |
| 59 // TODO(dougarnett): pass trigger_condition. | 59 ScopedJavaLocalRef<jobject> j_conditions = |
| 60 Java_BackgroundSchedulerBridge_schedule(env); | 60 CreateTriggerConditions(env, trigger_conditions.require_power_connected, |
| 61 trigger_conditions.minimum_battery_percentage, |
| 62 trigger_conditions.require_unmetered_network); |
| 63 Java_BackgroundSchedulerBridge_schedule(env, j_conditions.obj()); |
| 61 } | 64 } |
| 62 | 65 |
| 63 void BackgroundSchedulerBridge::Unschedule() { | 66 void BackgroundSchedulerBridge::Unschedule() { |
| 64 JNIEnv* env = base::android::AttachCurrentThread(); | 67 JNIEnv* env = base::android::AttachCurrentThread(); |
| 65 Java_BackgroundSchedulerBridge_unschedule(env); | 68 Java_BackgroundSchedulerBridge_unschedule(env); |
| 66 } | 69 } |
| 67 | 70 |
| 71 ScopedJavaLocalRef<jobject> BackgroundSchedulerBridge::CreateTriggerConditions( |
| 72 JNIEnv* env, |
| 73 bool require_power_connected, |
| 74 int minimum_battery_percentage, |
| 75 bool require_unmetered_network) const { |
| 76 return Java_BackgroundSchedulerBridge_createTriggerConditions( |
| 77 env, require_power_connected, minimum_battery_percentage, |
| 78 require_unmetered_network); |
| 79 } |
| 80 |
| 68 bool RegisterBackgroundSchedulerBridge(JNIEnv* env) { | 81 bool RegisterBackgroundSchedulerBridge(JNIEnv* env) { |
| 69 return RegisterNativesImpl(env); | 82 return RegisterNativesImpl(env); |
| 70 } | 83 } |
| 71 | 84 |
| 72 } // namespace android | 85 } // namespace android |
| 73 } // namespace offline_pages | 86 } // namespace offline_pages |
| OLD | NEW |