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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java

Issue 2064323004: Defines initial DeviceConditions and and plumbs down through StartProcessing() call. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 package org.chromium.chrome.browser.offlinepages; 5 package org.chromium.chrome.browser.offlinepages;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.Intent; 8 import android.content.Intent;
9 import android.content.IntentFilter; 9 import android.content.IntentFilter;
10 import android.os.BatteryManager; 10 import android.os.BatteryManager;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 foundTab.loadUrl(params); 194 foundTab.loadUrl(params);
195 } 195 }
196 196
197 @Override 197 @Override
198 public void onDismissNoAction(Object actionData) { 198 public void onDismissNoAction(Object actionData) {
199 RecordUserAction.record("OfflinePages.ReloadButtonNotClicked"); 199 RecordUserAction.record("OfflinePages.ReloadButtonNotClicked");
200 } 200 }
201 }; 201 };
202 } 202 }
203 203
204 public static DeviceConditions getDeviceConditions(Context context) {
205 IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
206 // Note this is a sticky intent, so we aren't really registering a recei ver, just getting
207 // the sticky intent. That means that we don't need to unregister the f ilter later.
208 Intent batteryStatus = context.registerReceiver(null, filter);
209 if (batteryStatus == null) return null;
210
211 return new DeviceConditions(isPowerConnected(batteryStatus),
212 batteryPercentage(batteryStatus),
213 NetworkChangeNotifier.getInstance().getCurrentConnectionType());
Pete Williamson 2016/06/16 17:46:26 So what Does the NetworkChangeNotifier return if w
dougarnett 2016/06/16 21:03:07 It returns the default connection type - eg, the o
Pete Williamson 2016/06/16 22:43:57 Acknowledged.
214 }
215
204 /** 216 /**
205 * Records UMA data when the Offline Pages Background Load service awakens. 217 * Records UMA data when the Offline Pages Background Load service awakens.
206 * @param context android context 218 * @param context android context
207 */ 219 */
208 public static void recordWakeupUMA(Context context, long taskScheduledTimeMi llis) { 220 public static void recordWakeupUMA(Context context, long taskScheduledTimeMi llis) {
209 IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); 221 DeviceConditions deviceConditions = getDeviceConditions(context);
210 // Note this is a sticky intent, so we aren't really registering a recei ver, just getting 222 if (deviceConditions == null) return;
211 // the sticky intent. That means that we don't need to unregister the f ilter later.
212 Intent batteryStatus = context.registerReceiver(null, filter);
213 if (batteryStatus == null) return;
214 223
215 // Report charging state. 224 // Report charging state.
216 RecordHistogram.recordBooleanHistogram( 225 RecordHistogram.recordBooleanHistogram(
217 "OfflinePages.Wakeup.ConnectedToPower", isPowerConnected(battery Status)); 226 "OfflinePages.Wakeup.ConnectedToPower", deviceConditions.isPower Connected());
218 227
219 // Report battery percentage. 228 // Report battery percentage.
220 RecordHistogram.recordPercentageHistogram( 229 RecordHistogram.recordPercentageHistogram(
221 "OfflinePages.Wakeup.BatteryPercentage", batteryPercentage(batte ryStatus)); 230 "OfflinePages.Wakeup.BatteryPercentage", deviceConditions.getBat teryPercentage());
222 231
223 // Report the default network found (or none, if we aren't connected). 232 // Report the default network found (or none, if we aren't connected).
224 int connectionType = NetworkChangeNotifier.getInstance().getCurrentConne ctionType(); 233 int connectionType = deviceConditions.getNetConnectionType();
225 Log.d(TAG, "Found single network of type " + connectionType); 234 Log.d(TAG, "Found default network of type " + connectionType);
226 RecordHistogram.recordEnumeratedHistogram("OfflinePages.Wakeup.NetworkAv ailable", 235 RecordHistogram.recordEnumeratedHistogram("OfflinePages.Wakeup.NetworkAv ailable",
227 connectionType, ConnectionType.CONNECTION_LAST + 1); 236 connectionType, ConnectionType.CONNECTION_LAST + 1);
228 237
229 // Collect UMA on the time since the request started. 238 // Collect UMA on the time since the request started.
230 long nowMillis = System.currentTimeMillis(); 239 long nowMillis = System.currentTimeMillis();
231 long delayInMilliseconds = nowMillis - taskScheduledTimeMillis; 240 long delayInMilliseconds = nowMillis - taskScheduledTimeMillis;
232 if (delayInMilliseconds <= 0) { 241 if (delayInMilliseconds <= 0) {
233 return; 242 return;
234 } 243 }
235 RecordHistogram.recordLongTimesHistogram( 244 RecordHistogram.recordLongTimesHistogram(
(...skipping 13 matching lines...) Expand all
249 private static int batteryPercentage(Intent batteryStatus) { 258 private static int batteryPercentage(Intent batteryStatus) {
250 int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); 259 int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
251 int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1); 260 int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
252 if (scale == 0) return 0; 261 if (scale == 0) return 0;
253 262
254 int percentage = Math.round(100 * level / (float) scale); 263 int percentage = Math.round(100 * level / (float) scale);
255 Log.d(TAG, "Battery Percentage is " + percentage); 264 Log.d(TAG, "Battery Percentage is " + percentage);
256 return percentage; 265 return percentage;
257 } 266 }
258 } 267 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698