Commit 0d4fcfbc authored by perezju's avatar perezju Committed by Commit bot

Revert of Start moving ownership of SyncNotificationController to...

Revert of Start moving ownership of SyncNotificationController to SyncController. (patchset #3 id:40001 of https://codereview.chromium.org/889723002/)

Reason for revert:
Broke downstream builds

Original issue's description:
> Start moving ownership of SyncNotificationController to SyncController.
>
> 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
>
> Committed: https://crrev.com/deaa0fe6ca3e0428a85fc22b019819437d84120b
> Cr-Commit-Position: refs/heads/master@{#314515}

TBR=nyquist@chromium.org,maxbogue@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=428882

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

Cr-Commit-Position: refs/heads/master@{#314537}
parent d5eeecc5
...@@ -10,6 +10,7 @@ import android.app.PendingIntent; ...@@ -10,6 +10,7 @@ import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.util.Log;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -26,31 +27,29 @@ public class GoogleServicesNotificationController { ...@@ -26,31 +27,29 @@ public class GoogleServicesNotificationController {
private static final Object LOCK = new Object(); private static final Object LOCK = new Object();
private static GoogleServicesNotificationController sInstance; private static GoogleServicesNotificationController sInstance;
private static NotificationManagerProxy sNotificationManagerProxyOverride;
private final Context mApplicationContext; private final Context mApplicationContext;
private NotificationManagerProxy mNotificationManager; private final NotificationManagerProxy mNotificationManager;
/** @VisibleForTesting
* Retrieve the singleton instance of this class. public static void overrideNotificationManagerForTests(NotificationManagerProxy managerProxy) {
* sNotificationManagerProxyOverride = managerProxy;
* @param context the current context. }
* @return the singleton instance.
*/ public static GoogleServicesNotificationController createNewInstance(Context context) {
public static GoogleServicesNotificationController get(Context context) {
synchronized (LOCK) { synchronized (LOCK) {
if (sInstance == null) { if (sInstance == null) {
sInstance = new GoogleServicesNotificationController(context); sInstance = new GoogleServicesNotificationController(context);
} else {
Log.e(TAG, "GoogleServicesNotificationController already created. "
+ "Currently on thread: " + Thread.currentThread());
} }
return sInstance; return sInstance;
} }
} }
@Deprecated @VisibleForTesting
public static GoogleServicesNotificationController createNewInstance(Context context) {
return get(context);
}
@Deprecated
public static GoogleServicesNotificationController getInstance() { public static GoogleServicesNotificationController getInstance() {
synchronized (LOCK) { synchronized (LOCK) {
return sInstance; return sInstance;
...@@ -64,9 +63,13 @@ public class GoogleServicesNotificationController { ...@@ -64,9 +63,13 @@ public class GoogleServicesNotificationController {
private GoogleServicesNotificationController(Context context) { private GoogleServicesNotificationController(Context context) {
mApplicationContext = context.getApplicationContext(); mApplicationContext = context.getApplicationContext();
mNotificationManager = new NotificationManagerProxyImpl( if (sNotificationManagerProxyOverride == null) {
(NotificationManager) mApplicationContext.getSystemService( mNotificationManager = new NotificationManagerProxyImpl(
Context.NOTIFICATION_SERVICE)); (NotificationManager) mApplicationContext.getSystemService(
Context.NOTIFICATION_SERVICE));
} else {
mNotificationManager = sNotificationManagerProxyOverride;
}
} }
public void updateSingleNotification(int id, String message, Intent intent) { public void updateSingleNotification(int id, String message, Intent intent) {
...@@ -104,9 +107,4 @@ public class GoogleServicesNotificationController { ...@@ -104,9 +107,4 @@ public class GoogleServicesNotificationController {
public void cancelNotification(int id) { public void cancelNotification(int id) {
mNotificationManager.cancel(id); mNotificationManager.cancel(id);
} }
@VisibleForTesting
public void overrideNotificationManagerForTests(NotificationManagerProxy managerProxy) {
mNotificationManager = managerProxy;
}
} }
...@@ -42,8 +42,6 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen ...@@ -42,8 +42,6 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen
private final ChromeSigninController mChromeSigninController; private final ChromeSigninController mChromeSigninController;
private final AndroidSyncSettings mAndroidSyncSettings; private final AndroidSyncSettings mAndroidSyncSettings;
private final ProfileSyncService mProfileSyncService; private final ProfileSyncService mProfileSyncService;
// TODO(maxbogue): Make final once it's constructed in this class.
private SyncNotificationController mSyncNotificationController = null;
private SyncController(Context context) { private SyncController(Context context) {
mContext = context; mContext = context;
...@@ -188,24 +186,4 @@ public class SyncController implements ProfileSyncService.SyncStateChangedListen ...@@ -188,24 +186,4 @@ 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,21 +32,6 @@ public class SyncNotificationController implements ProfileSyncService.SyncStateC ...@@ -32,21 +32,6 @@ public class SyncNotificationController implements ProfileSyncService.SyncStateC
private final Class<? extends Fragment> mAccountManagementFragment; private final Class<? extends Fragment> mAccountManagementFragment;
private final ProfileSyncService mProfileSyncService; 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, public SyncNotificationController(Context context,
GoogleServicesNotificationController controller, GoogleServicesNotificationController controller,
Class<? extends Activity> passphraseRequestActivity, 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