Commit d6674cc2 authored by maxbogue's avatar maxbogue Committed by Commit bot

Start moving ownership of SyncNotificationController to SyncController, take 2.

Original: http://crrev.com/889723002
Reverted: http://crrev.com/895373002

This version restores a missing @VisibleForTests annotation
to GoogleServicesNotificationController.getInstance(). Its
removal caused the method to be pruned on build, breaking
downstream tests that depended on it.

GoogleServicesNotificationController is modified to work
the way most other singleton classes work, so that it is
not necessary to pass into the SyncNotificationController
constructor (and thus, into SyncController in the future).

SyncController gets a temporary setter method so that SNC
can be constructed downstream and passed in until all its
dependencies are upstream.

BUG=428882

Review URL: https://codereview.chromium.org/895283003

Cr-Commit-Position: refs/heads/master@{#315367}
parent 3ca3cf20
......@@ -10,7 +10,6 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
......@@ -27,28 +26,31 @@ public class GoogleServicesNotificationController {
private static final Object LOCK = new Object();
private static GoogleServicesNotificationController sInstance;
private static NotificationManagerProxy sNotificationManagerProxyOverride;
private final Context mApplicationContext;
private final NotificationManagerProxy mNotificationManager;
private NotificationManagerProxy mNotificationManager;
@VisibleForTesting
public static void overrideNotificationManagerForTests(NotificationManagerProxy managerProxy) {
sNotificationManagerProxyOverride = managerProxy;
}
public static GoogleServicesNotificationController createNewInstance(Context context) {
/**
* Retrieve the singleton instance of this class.
*
* @param context the current context.
* @return the singleton instance.
*/
public static GoogleServicesNotificationController get(Context context) {
synchronized (LOCK) {
if (sInstance == null) {
sInstance = new GoogleServicesNotificationController(context);
} else {
Log.e(TAG, "GoogleServicesNotificationController already created. "
+ "Currently on thread: " + Thread.currentThread());
}
return sInstance;
}
}
@Deprecated
public static GoogleServicesNotificationController createNewInstance(Context context) {
return get(context);
}
@Deprecated
@VisibleForTesting
public static GoogleServicesNotificationController getInstance() {
synchronized (LOCK) {
......@@ -63,13 +65,9 @@ public class GoogleServicesNotificationController {
private GoogleServicesNotificationController(Context context) {
mApplicationContext = context.getApplicationContext();
if (sNotificationManagerProxyOverride == null) {
mNotificationManager = new NotificationManagerProxyImpl(
(NotificationManager) mApplicationContext.getSystemService(
Context.NOTIFICATION_SERVICE));
} else {
mNotificationManager = sNotificationManagerProxyOverride;
}
mNotificationManager = new NotificationManagerProxyImpl(
(NotificationManager) mApplicationContext.getSystemService(
Context.NOTIFICATION_SERVICE));
}
public void updateSingleNotification(int id, String message, Intent intent) {
......@@ -107,4 +105,9 @@ public class GoogleServicesNotificationController {
public void cancelNotification(int id) {
mNotificationManager.cancel(id);
}
@VisibleForTesting
public void overrideNotificationManagerForTests(NotificationManagerProxy managerProxy) {
mNotificationManager = managerProxy;
}
}
......@@ -42,6 +42,8 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
private final ChromeSigninController mChromeSigninController;
private final AndroidSyncSettings mAndroidSyncSettings;
private final ProfileSyncService mProfileSyncService;
// TODO(maxbogue): Make final once it's constructed in this class.
private SyncNotificationController mSyncNotificationController = null;
private SyncController(Context context) {
mContext = context;
......@@ -186,4 +188,24 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
}
});
}
/**
* Sets the SyncNotificationController.
*
* This is a temporary method for transferring ownership of SyncNotificationController
* upstream. Once all of SNC's dependencies are upstreamed, it will be created in the
* SyncController constructor and this method won't exist.
*/
public void setSyncNotificationController(SyncNotificationController snc) {
assert mSyncNotificationController == null;
mSyncNotificationController = snc;
mProfileSyncService.addSyncStateChangedListener(mSyncNotificationController);
}
/**
* Returns the SyncNotificationController.
*/
public SyncNotificationController getSyncNotificationController() {
return mSyncNotificationController;
}
}
......@@ -32,6 +32,21 @@ public class SyncNotificationController implements ProfileSyncService.SyncStateC
private final Class<? extends Fragment> mAccountManagementFragment;
private final ProfileSyncService mProfileSyncService;
public SyncNotificationController(Context context,
Class<? extends Activity> passphraseRequestActivity,
Class<? extends Fragment> accountManagementFragment) {
mApplicationContext = context.getApplicationContext();
mNotificationController = GoogleServicesNotificationController.get(context);
mProfileSyncService = ProfileSyncService.get(context);
mAndroidSyncSettings = AndroidSyncSettings.get(context);
mPassphraseRequestActivity = passphraseRequestActivity;
mAccountManagementFragment = accountManagementFragment;
}
/**
* Deprecated for having unnecessary args; use the first constructor.
*/
@Deprecated
public SyncNotificationController(Context context,
GoogleServicesNotificationController controller,
Class<? extends Activity> passphraseRequestActivity,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment