Commit 6220ec58 authored by Tiger Oakes's avatar Tiger Oakes Committed by Commit Bot

Removed context#getApplicationContext calls from...

Removed context#getApplicationContext calls from /chrome/android/java/src/org/chromium/chrome/browser/services/gcm

Continuation of work in bug 646094.

This CL was uploaded by git cl split.

R=peter@chromium.org

Bug: 846456
Change-Id: If4634124016982063b17725552585ef08d333a94
Reviewed-on: https://chromium-review.googlesource.com/1095914
Commit-Queue: Peter Beverloo <peter@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568805}
parent 119bc604
...@@ -12,6 +12,7 @@ import android.text.TextUtils; ...@@ -12,6 +12,7 @@ import android.text.TextUtils;
import com.google.android.gms.gcm.GcmListenerService; import com.google.android.gms.gcm.GcmListenerService;
import com.google.ipc.invalidation.ticl.android2.channel.AndroidGcmController; import com.google.ipc.invalidation.ticl.android2.channel.AndroidGcmController;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.ProcessInitException; import org.chromium.base.library_loader.ProcessInitException;
...@@ -38,7 +39,7 @@ public class ChromeGcmListenerService extends GcmListenerService { ...@@ -38,7 +39,7 @@ public class ChromeGcmListenerService extends GcmListenerService {
@Override @Override
public void onMessageReceived(final String from, final Bundle data) { public void onMessageReceived(final String from, final Bundle data) {
boolean hasCollapseKey = !TextUtils.isEmpty(data.getString("collapse_key")); boolean hasCollapseKey = !TextUtils.isEmpty(data.getString("collapse_key"));
GcmUma.recordDataMessageReceived(getApplicationContext(), hasCollapseKey); GcmUma.recordDataMessageReceived(ContextUtils.getApplicationContext(), hasCollapseKey);
String invalidationSenderId = AndroidGcmController.get(this).getSenderId(); String invalidationSenderId = AndroidGcmController.get(this).getSenderId();
if (from.equals(invalidationSenderId)) { if (from.equals(invalidationSenderId)) {
...@@ -46,8 +47,6 @@ public class ChromeGcmListenerService extends GcmListenerService { ...@@ -46,8 +47,6 @@ public class ChromeGcmListenerService extends GcmListenerService {
return; return;
} }
final Context applicationContext = getApplicationContext();
// Dispatch the message to the GCM Driver for native features. // Dispatch the message to the GCM Driver for native features.
ThreadUtils.runOnUiThread(new Runnable() { ThreadUtils.runOnUiThread(new Runnable() {
@Override @Override
...@@ -60,7 +59,7 @@ public class ChromeGcmListenerService extends GcmListenerService { ...@@ -60,7 +59,7 @@ public class ChromeGcmListenerService extends GcmListenerService {
return; return;
} }
scheduleOrDispatchMessageToDriver(applicationContext, message); scheduleOrDispatchMessageToDriver(message);
} }
}); });
} }
...@@ -68,13 +67,15 @@ public class ChromeGcmListenerService extends GcmListenerService { ...@@ -68,13 +67,15 @@ public class ChromeGcmListenerService extends GcmListenerService {
@Override @Override
public void onMessageSent(String msgId) { public void onMessageSent(String msgId) {
Log.d(TAG, "Message sent successfully. Message id: " + msgId); Log.d(TAG, "Message sent successfully. Message id: " + msgId);
GcmUma.recordGcmUpstreamHistogram(getApplicationContext(), GcmUma.UMA_UPSTREAM_SUCCESS); GcmUma.recordGcmUpstreamHistogram(
ContextUtils.getApplicationContext(), GcmUma.UMA_UPSTREAM_SUCCESS);
} }
@Override @Override
public void onSendError(String msgId, String error) { public void onSendError(String msgId, String error) {
Log.w(TAG, "Error in sending message. Message id: " + msgId + " Error: " + error); Log.w(TAG, "Error in sending message. Message id: " + msgId + " Error: " + error);
GcmUma.recordGcmUpstreamHistogram(getApplicationContext(), GcmUma.UMA_UPSTREAM_SEND_FAILED); GcmUma.recordGcmUpstreamHistogram(
ContextUtils.getApplicationContext(), GcmUma.UMA_UPSTREAM_SEND_FAILED);
} }
@Override @Override
...@@ -82,7 +83,7 @@ public class ChromeGcmListenerService extends GcmListenerService { ...@@ -82,7 +83,7 @@ public class ChromeGcmListenerService extends GcmListenerService {
// TODO(johnme): Ask GCM to include the subtype in this event. // TODO(johnme): Ask GCM to include the subtype in this event.
Log.w(TAG, "Push messages were deleted, but we can't tell the Service Worker as we don't" Log.w(TAG, "Push messages were deleted, but we can't tell the Service Worker as we don't"
+ "know what subtype (app ID) it occurred for."); + "know what subtype (app ID) it occurred for.");
GcmUma.recordDeletedMessages(getApplicationContext()); GcmUma.recordDeletedMessages(ContextUtils.getApplicationContext());
} }
/** /**
...@@ -91,7 +92,7 @@ public class ChromeGcmListenerService extends GcmListenerService { ...@@ -91,7 +92,7 @@ public class ChromeGcmListenerService extends GcmListenerService {
* Must be called on the UI thread both for the BackgroundTaskScheduler and for dispatching * Must be called on the UI thread both for the BackgroundTaskScheduler and for dispatching
* the |message| to the GCMDriver. * the |message| to the GCMDriver.
*/ */
static void scheduleOrDispatchMessageToDriver(Context context, GCMMessage message) { static void scheduleOrDispatchMessageToDriver(GCMMessage message) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
...@@ -103,10 +104,11 @@ public class ChromeGcmListenerService extends GcmListenerService { ...@@ -103,10 +104,11 @@ public class ChromeGcmListenerService extends GcmListenerService {
.setExtras(extras) .setExtras(extras)
.build(); .build();
BackgroundTaskSchedulerFactory.getScheduler().schedule(context, backgroundTask); BackgroundTaskSchedulerFactory.getScheduler().schedule(
ContextUtils.getApplicationContext(), backgroundTask);
} else { } else {
dispatchMessageToDriver(context, message); dispatchMessageToDriver(ContextUtils.getApplicationContext(), message);
} }
} }
......
...@@ -16,6 +16,7 @@ import android.util.Log; ...@@ -16,6 +16,7 @@ import android.util.Log;
import com.google.android.gms.gcm.GoogleCloudMessaging; import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.ipc.invalidation.ticl.android2.channel.GcmUpstreamSenderService; import com.google.ipc.invalidation.ticl.android2.channel.GcmUpstreamSenderService;
import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.init.ProcessInitializationHandler; import org.chromium.chrome.browser.init.ProcessInitializationHandler;
import org.chromium.chrome.browser.signin.OAuth2TokenService; import org.chromium.chrome.browser.signin.OAuth2TokenService;
...@@ -40,12 +41,11 @@ public class InvalidationGcmUpstreamSender extends GcmUpstreamSenderService { ...@@ -40,12 +41,11 @@ public class InvalidationGcmUpstreamSender extends GcmUpstreamSenderService {
@Override @Override
public void deliverMessage(final String to, final Bundle data) { public void deliverMessage(final String to, final Bundle data) {
final Bundle dataToSend = createDeepCopy(data); final Bundle dataToSend = createDeepCopy(data);
final Context applicationContext = getApplicationContext();
ThreadUtils.postOnUiThread(new Runnable() { ThreadUtils.postOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
doDeliverMessage(applicationContext, to, dataToSend); doDeliverMessage(ContextUtils.getApplicationContext(), to, dataToSend);
} }
}); });
} }
...@@ -82,8 +82,8 @@ public class InvalidationGcmUpstreamSender extends GcmUpstreamSenderService { ...@@ -82,8 +82,8 @@ public class InvalidationGcmUpstreamSender extends GcmUpstreamSenderService {
@Override @Override
public void tokenUnavailable(boolean isTransientError) { public void tokenUnavailable(boolean isTransientError) {
GcmUma.recordGcmUpstreamHistogram( GcmUma.recordGcmUpstreamHistogram(ContextUtils.getApplicationContext(),
getApplicationContext(), GcmUma.UMA_UPSTREAM_TOKEN_REQUEST_FAILED); GcmUma.UMA_UPSTREAM_TOKEN_REQUEST_FAILED);
} }
}); });
} }
...@@ -100,7 +100,8 @@ public class InvalidationGcmUpstreamSender extends GcmUpstreamSenderService { ...@@ -100,7 +100,8 @@ public class InvalidationGcmUpstreamSender extends GcmUpstreamSenderService {
} }
String msgId = UUID.randomUUID().toString(); String msgId = UUID.randomUUID().toString();
try { try {
GoogleCloudMessaging.getInstance(getApplicationContext()).send(to, msgId, 1, data); GoogleCloudMessaging.getInstance(ContextUtils.getApplicationContext())
.send(to, msgId, 1, data);
} catch (IOException | IllegalArgumentException exception) { } catch (IOException | IllegalArgumentException exception) {
Log.w(TAG, "Send message failed"); Log.w(TAG, "Send message failed");
GcmUma.recordGcmUpstreamHistogram(context, GcmUma.UMA_UPSTREAM_SEND_FAILED); GcmUma.recordGcmUpstreamHistogram(context, GcmUma.UMA_UPSTREAM_SEND_FAILED);
......
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