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

Side by Side 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, 10 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 "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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 GetForBrowserContext(profile); 49 GetForBrowserContext(profile);
50 DVLOG(2) << "resource_coordinator: " << coordinator; 50 DVLOG(2) << "resource_coordinator: " << coordinator;
51 DeviceConditions device_conditions( 51 DeviceConditions device_conditions(
52 j_power_connected, j_battery_percentage, 52 j_power_connected, j_battery_percentage,
53 static_cast<net::NetworkChangeNotifier::ConnectionType>( 53 static_cast<net::NetworkChangeNotifier::ConnectionType>(
54 j_net_connection_type)); 54 j_net_connection_type));
55 return coordinator->StartScheduledProcessing( 55 return coordinator->StartScheduledProcessing(
56 device_conditions, base::Bind(&ProcessingDoneCallback, j_callback_ref)); 56 device_conditions, base::Bind(&ProcessingDoneCallback, j_callback_ref));
57 } 57 }
58 58
59 BackgroundSchedulerBridge::BackgroundSchedulerBridge() = default;
60
61 BackgroundSchedulerBridge::~BackgroundSchedulerBridge() = default;
62
59 void BackgroundSchedulerBridge::Schedule( 63 void BackgroundSchedulerBridge::Schedule(
60 const TriggerConditions& trigger_conditions) { 64 const TriggerConditions& trigger_conditions) {
61 JNIEnv* env = base::android::AttachCurrentThread(); 65 JNIEnv* env = base::android::AttachCurrentThread();
62 ScopedJavaLocalRef<jobject> j_conditions = 66 ScopedJavaLocalRef<jobject> j_conditions =
63 CreateTriggerConditions(env, trigger_conditions.require_power_connected, 67 CreateTriggerConditions(env, trigger_conditions.require_power_connected,
64 trigger_conditions.minimum_battery_percentage, 68 trigger_conditions.minimum_battery_percentage,
65 trigger_conditions.require_unmetered_network); 69 trigger_conditions.require_unmetered_network);
66 Java_BackgroundSchedulerBridge_schedule(env, j_conditions); 70 Java_BackgroundSchedulerBridge_schedule(env, j_conditions);
67 } 71 }
68 72
(...skipping 16 matching lines...) Expand all
85 ScopedJavaLocalRef<jobject> BackgroundSchedulerBridge::CreateTriggerConditions( 89 ScopedJavaLocalRef<jobject> BackgroundSchedulerBridge::CreateTriggerConditions(
86 JNIEnv* env, 90 JNIEnv* env,
87 bool require_power_connected, 91 bool require_power_connected,
88 int minimum_battery_percentage, 92 int minimum_battery_percentage,
89 bool require_unmetered_network) const { 93 bool require_unmetered_network) const {
90 return Java_BackgroundSchedulerBridge_createTriggerConditions( 94 return Java_BackgroundSchedulerBridge_createTriggerConditions(
91 env, require_power_connected, minimum_battery_percentage, 95 env, require_power_connected, minimum_battery_percentage,
92 require_unmetered_network); 96 require_unmetered_network);
93 } 97 }
94 98
99 const DeviceConditions&
100 BackgroundSchedulerBridge::GetCurrentDeviceConditions() {
101 JNIEnv* env = base::android::AttachCurrentThread();
102 // Call the JNI methods to get the device conditions we need.
103 jboolean jpower = Java_BackgroundSchedulerBridge_getPowerConditions(env);
104 jint jbattery = Java_BackgroundSchedulerBridge_getBatteryConditions(env);
105 jint jnetwork = Java_BackgroundSchedulerBridge_getNetworkConditions(env);
106
107 // Cast the java types back to the types we use.
108 bool power = static_cast<bool>(jpower);
109 int battery = static_cast<int>(jbattery);
110
111 net::NetworkChangeNotifier::ConnectionType network_connection_type =
112 static_cast<net::NetworkChangeNotifier::ConnectionType>(jnetwork);
113
114 // Now return the current conditions to the caller.
115 device_conditions_ = base::MakeUnique<DeviceConditions>(
116 power, battery, network_connection_type);
117 return *device_conditions_;
118 }
119
95 bool RegisterBackgroundSchedulerBridge(JNIEnv* env) { 120 bool RegisterBackgroundSchedulerBridge(JNIEnv* env) {
96 return RegisterNativesImpl(env); 121 return RegisterNativesImpl(env);
97 } 122 }
98 123
99 } // namespace android 124 } // namespace android
100 } // namespace offline_pages 125 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698