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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/crash/MinidumpUploadRetry.java

Issue 2599063002: [minidump uploader] Retries: only initiate uploads when on WiFi/Ethernet (Closed)
Patch Set: s/mPermManager/mPermissionManager/ and remove lock mechanism in test. Created 3 years, 11 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.crash; 5 package org.chromium.chrome.browser.crash;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.os.Handler; 8 import android.os.Handler;
9 9
10 import org.chromium.base.NonThreadSafe; 10 import org.chromium.base.NonThreadSafe;
11 import org.chromium.base.annotations.SuppressFBWarnings; 11 import org.chromium.base.annotations.SuppressFBWarnings;
12 import org.chromium.net.ConnectionType; 12 import org.chromium.components.minidump_uploader.util.CrashReportingPermissionMa nager;
13 import org.chromium.net.NetworkChangeNotifier; 13 import org.chromium.net.NetworkChangeNotifier;
14 14
15 /** 15 /**
16 * This class listens to network changes and determine when it would good to 16 * This class listens to network changes and determine when it would good to
17 * retry uploading minidumps. 17 * retry uploading minidumps.
18 */ 18 */
19 class MinidumpUploadRetry implements NetworkChangeNotifier.ConnectionTypeObserve r { 19 class MinidumpUploadRetry implements NetworkChangeNotifier.ConnectionTypeObserve r {
20 private final Context mContext; 20 private final Context mContext;
21 private final CrashReportingPermissionManager mPermissionManager;
21 private static MinidumpUploadRetry sSingleton; 22 private static MinidumpUploadRetry sSingleton;
22 23
23 private static class Scheduler implements Runnable { 24 private static class Scheduler implements Runnable {
24 private static NonThreadSafe sThreadCheck; 25 private static NonThreadSafe sThreadCheck;
25 private final Context mContext; 26 private final Context mContext;
27 private final CrashReportingPermissionManager mPermissionManager;
26 28
27 private Scheduler(Context context) { 29 private Scheduler(Context context, CrashReportingPermissionManager permi ssionManager) {
28 this.mContext = context; 30 this.mContext = context;
31 mPermissionManager = permissionManager;
29 } 32 }
30 33
31 @Override 34 @Override
32 public void run() { 35 public void run() {
33 if (sThreadCheck == null) { 36 if (sThreadCheck == null) {
34 sThreadCheck = new NonThreadSafe(); 37 sThreadCheck = new NonThreadSafe();
35 } 38 }
36 // Make sure this is called on the same thread all the time. 39 // Make sure this is called on the same thread all the time.
37 assert sThreadCheck.calledOnValidThread(); 40 assert sThreadCheck.calledOnValidThread();
38 if (!NetworkChangeNotifier.isInitialized()) { 41 if (!NetworkChangeNotifier.isInitialized()) {
39 return; 42 return;
40 } 43 }
41 if (sSingleton == null) { 44 if (sSingleton == null) {
42 sSingleton = new MinidumpUploadRetry(mContext); 45 sSingleton = new MinidumpUploadRetry(mContext, mPermissionManage r);
43 } 46 }
44 } 47 }
45 } 48 }
46 49
47 /** 50 /**
48 * Schedule a retry. If there is already one schedule, this is NO-OP. 51 * Schedule a retry. If there is already one schedule, this is NO-OP.
49 */ 52 */
50 static void scheduleRetry(Context context) { 53 static void scheduleRetry(Context context, CrashReportingPermissionManager p ermissionManager) {
51 // NetworkChangeNotifier is not thread safe. We will post to UI thread 54 // NetworkChangeNotifier is not thread safe. We will post to UI thread
52 // instead since that's where it fires off notification changes. 55 // instead since that's where it fires off notification changes.
53 new Handler(context.getMainLooper()).post(new Scheduler(context)); 56 new Handler(context.getMainLooper()).post(new Scheduler(context, permiss ionManager));
54 } 57 }
55 58
56 private MinidumpUploadRetry(Context context) { 59 private MinidumpUploadRetry(
60 Context context, CrashReportingPermissionManager permissionManager) {
57 this.mContext = context; 61 this.mContext = context;
62 this.mPermissionManager = permissionManager;
58 NetworkChangeNotifier.addConnectionTypeObserver(this); 63 NetworkChangeNotifier.addConnectionTypeObserver(this);
59 } 64 }
60 65
61 @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") 66 @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
62 @Override 67 @Override
63 public void onConnectionTypeChanged(int connectionType) { 68 public void onConnectionTypeChanged(int connectionType) {
64 // Look for "favorable" connections. Note that we never 69 if (!mPermissionManager.isNetworkAvailableForCrashUploads()) {
Maria 2017/01/03 19:28:41 As a small optimization I would keep the check for
gsennton 2017/01/03 20:00:35 Done.
65 // know what the user's crash upload preference is until
66 // the time when we are actually uploading.
67 if (connectionType == ConnectionType.CONNECTION_NONE) {
68 return; 70 return;
69 } 71 }
70 MinidumpUploadService.tryUploadAllCrashDumps(mContext); 72 MinidumpUploadService.tryUploadAllCrashDumps(mContext);
71 NetworkChangeNotifier.removeConnectionTypeObserver(this); 73 NetworkChangeNotifier.removeConnectionTypeObserver(this);
72 sSingleton = null; 74 sSingleton = null;
73 } 75 }
74 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698