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

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

Issue 2659813006: Always get device conditions from Java for every attempt. (Closed)
Patch Set: Change JNI interface to use 3 small methods instead of an object. 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() {}
dewittj 2017/01/30 19:18:02 could use = default instead of {}
Pete Williamson 2017/01/30 21:35:23 Done.
60
61 BackgroundSchedulerBridge::~BackgroundSchedulerBridge() {}
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 DeviceConditions& BackgroundSchedulerBridge::GetCurrentDeviceConditions() {
dewittj 2017/01/30 19:18:02 const
Pete Williamson 2017/01/30 21:35:23 Done.
100 JNIEnv* env = base::android::AttachCurrentThread();
101 // Call the JNI methods to get the device conditions we need.
102 jboolean jpower = Java_BackgroundSchedulerBridge_getPowerConditions(env);
103 jint jbattery = Java_BackgroundSchedulerBridge_getBatteryConditions(env);
104 jint jnetwork = Java_BackgroundSchedulerBridge_getNetworkConditions(env);
105
106 // Cast the java types back to the types we use.
107 bool power = static_cast<bool>(jpower);
108 int battery = static_cast<int>(jbattery);;
109 net::NetworkChangeNotifier::ConnectionType network_connection_type =
110 static_cast<net::NetworkChangeNotifier::ConnectionType>(jnetwork);
111
112 // Now return the current conditions to the caller.
113 device_conditions_ = base::MakeUnique<DeviceConditions>(
114 power, battery, network_connection_type);
115 return *(device_conditions_.get());
dewittj 2017/01/30 19:18:02 I think you can just say *device_conditions_
Pete Williamson 2017/01/30 21:35:23 Done.
116 }
117
95 bool RegisterBackgroundSchedulerBridge(JNIEnv* env) { 118 bool RegisterBackgroundSchedulerBridge(JNIEnv* env) {
96 return RegisterNativesImpl(env); 119 return RegisterNativesImpl(env);
97 } 120 }
98 121
99 } // namespace android 122 } // namespace android
100 } // namespace offline_pages 123 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698