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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/precache/PrecacheController.java

Issue 2333063002: Record UMA for battery level when precache starts and ends (Closed)
Patch Set: Addressed nits Created 4 years, 3 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
« no previous file with comments | « no previous file | components/precache/android/java/src/org/chromium/components/precache/DeviceState.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.precache; 5 package org.chromium.chrome.browser.precache;
6 6
7 import android.content.BroadcastReceiver; 7 import android.content.BroadcastReceiver;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.content.IntentFilter; 10 import android.content.IntentFilter;
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 cancelPeriodicPrecacheTask(mAppContext); 362 cancelPeriodicPrecacheTask(mAppContext);
363 cancelPrecacheCompletionTask(mAppContext); 363 cancelPrecacheCompletionTask(mAppContext);
364 PrecacheUMA.record(PrecacheUMA.Event.DISABLED_IN_PRECACHE_PREF); 364 PrecacheUMA.record(PrecacheUMA.Event.DISABLED_IN_PRECACHE_PREF);
365 return GcmNetworkManager.RESULT_SUCCESS; 365 return GcmNetworkManager.RESULT_SUCCESS;
366 } 366 }
367 if (setIsPrecaching(true)) { 367 if (setIsPrecaching(true)) {
368 if (PERIODIC_TASK_TAG.equals(tag)) { 368 if (PERIODIC_TASK_TAG.equals(tag)) {
369 recordPeriodicTaskIntervalHistogram(); 369 recordPeriodicTaskIntervalHistogram();
370 cancelPrecacheCompletionTask(mAppContext); 370 cancelPrecacheCompletionTask(mAppContext);
371 } 371 }
372 recordBatteryLevelAtStart();
372 registerDeviceStateReceiver(); 373 registerDeviceStateReceiver();
373 acquirePrecachingWakeLock(); 374 acquirePrecachingWakeLock();
374 startPrecachingAfterSyncInit(); 375 startPrecachingAfterSyncInit();
375 return GcmNetworkManager.RESULT_SUCCESS; 376 return GcmNetworkManager.RESULT_SUCCESS;
376 } 377 }
377 Log.v(TAG, "precache session was already running"); 378 Log.v(TAG, "precache session was already running");
378 PrecacheUMA.record(PrecacheUMA.Event.PRECACHE_TASK_STARTED_DUPLICATE); 379 PrecacheUMA.record(PrecacheUMA.Event.PRECACHE_TASK_STARTED_DUPLICATE);
379 return GcmNetworkManager.RESULT_FAILURE; 380 return GcmNetworkManager.RESULT_FAILURE;
380 } 381 }
381 382
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 433
433 /** 434 /**
434 * Updates state to indicate that the precache session is no longer in 435 * Updates state to indicate that the precache session is no longer in
435 * progress, and stops the service. 436 * progress, and stops the service.
436 */ 437 */
437 private void shutdownPrecaching(boolean precachingIncomplete) { 438 private void shutdownPrecaching(boolean precachingIncomplete) {
438 Log.v(TAG, "shutting down precache session"); 439 Log.v(TAG, "shutting down precache session");
439 if (precachingIncomplete) { 440 if (precachingIncomplete) {
440 schedulePrecacheCompletionTask(mAppContext); 441 schedulePrecacheCompletionTask(mAppContext);
441 } 442 }
443 recordBatteryLevelAtEnd();
442 mHandler.removeCallbacks(mTimeoutRunnable); 444 mHandler.removeCallbacks(mTimeoutRunnable);
443 mAppContext.unregisterReceiver(mDeviceStateReceiver); 445 mAppContext.unregisterReceiver(mDeviceStateReceiver);
444 releasePrecachingWakeLock(); 446 releasePrecachingWakeLock();
445 } 447 }
446 448
447 /** 449 /**
448 * Registers a BroadcastReceiver to detect when conditions become wrong 450 * Registers a BroadcastReceiver to detect when conditions become wrong
449 * for precaching. 451 * for precaching.
450 */ 452 */
451 private void registerDeviceStateReceiver() { 453 private void registerDeviceStateReceiver() {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 if (previous_start_time_ms > 0 && current_start_time_ms > previous_start _time_ms) { 538 if (previous_start_time_ms > 0 && current_start_time_ms > previous_start _time_ms) {
537 int interval_mins = 539 int interval_mins =
538 (int) ((current_start_time_ms - previous_start_time_ms) / (1 000 * 60)); 540 (int) ((current_start_time_ms - previous_start_time_ms) / (1 000 * 60));
539 RecordHistogram.recordCustomCountHistogram( 541 RecordHistogram.recordCustomCountHistogram(
540 "Precache.PeriodicTaskInterval", interval_mins, 1, 10000, 50 ); 542 "Precache.PeriodicTaskInterval", interval_mins, 1, 10000, 50 );
541 } 543 }
542 prefs.edit() 544 prefs.edit()
543 .putLong(PREF_PRECACHE_PERIODIC_TASK_START_TIME_MS, current_star t_time_ms) 545 .putLong(PREF_PRECACHE_PERIODIC_TASK_START_TIME_MS, current_star t_time_ms)
544 .apply(); 546 .apply();
545 } 547 }
548
549 private void recordBatteryLevelAtStart() {
550 mDeviceState.saveCurrentBatteryPercentage(mAppContext);
551
552 // Report battery percentage.
553 RecordHistogram.recordPercentageHistogram(
554 "Precache.BatteryPercentage.Start", mDeviceState.getSavedBattery Percentage());
555 }
556
557 private void recordBatteryLevelAtEnd() {
558 int delta_percentage = mDeviceState.getCurrentBatteryPercentage(mAppCont ext)
559 - mDeviceState.getSavedBatteryPercentage();
560 if (delta_percentage >= 0) {
561 RecordHistogram.recordPercentageHistogram(
562 "Precache.BatteryPercentageDiff.End", delta_percentage);
563 }
564 }
546 } 565 }
OLDNEW
« no previous file with comments | « no previous file | components/precache/android/java/src/org/chromium/components/precache/DeviceState.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698