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

Side by Side Diff: components/gcm_driver/android/java/src/org/chromium/components/gcm_driver/GCMDriver.java

Issue 2810863003: Android: Remove GetApplicationContext: components/ (Closed)
Patch Set: Fix tests Created 3 years, 8 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/gcm_driver/android/java/src/org/chromium/components/gcm_driver/GoogleCloudMessagingV2.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.components.gcm_driver; 5 package org.chromium.components.gcm_driver;
6 6
7 import android.content.Context;
8 import android.os.AsyncTask; 7 import android.os.AsyncTask;
9 8
10 import org.chromium.base.Log; 9 import org.chromium.base.Log;
11 import org.chromium.base.ThreadUtils; 10 import org.chromium.base.ThreadUtils;
12 import org.chromium.base.VisibleForTesting; 11 import org.chromium.base.VisibleForTesting;
13 import org.chromium.base.annotations.CalledByNative; 12 import org.chromium.base.annotations.CalledByNative;
14 import org.chromium.base.annotations.JNINamespace; 13 import org.chromium.base.annotations.JNINamespace;
15 14
16 import java.io.IOException; 15 import java.io.IOException;
17 16
18 /** 17 /**
19 * This class is the Java counterpart to the C++ GCMDriverAndroid class. 18 * This class is the Java counterpart to the C++ GCMDriverAndroid class.
20 * It uses Android's Java GCM APIs to implement GCM registration etc, and 19 * It uses Android's Java GCM APIs to implement GCM registration etc, and
21 * sends back GCM messages over JNI. 20 * sends back GCM messages over JNI.
22 * 21 *
23 * Threading model: all calls to/from C++ happen on the UI thread. 22 * Threading model: all calls to/from C++ happen on the UI thread.
24 */ 23 */
25 @JNINamespace("gcm") 24 @JNINamespace("gcm")
26 public class GCMDriver { 25 public class GCMDriver {
27 private static final String TAG = "GCMDriver"; 26 private static final String TAG = "GCMDriver";
28 27
29 // The instance of GCMDriver currently owned by a C++ GCMDriverAndroid, if a ny. 28 // The instance of GCMDriver currently owned by a C++ GCMDriverAndroid, if a ny.
30 private static GCMDriver sInstance; 29 private static GCMDriver sInstance;
31 30
32 private long mNativeGCMDriverAndroid; 31 private long mNativeGCMDriverAndroid;
33 private final Context mContext;
34 private GoogleCloudMessagingSubscriber mSubscriber; 32 private GoogleCloudMessagingSubscriber mSubscriber;
35 33
36 private GCMDriver(long nativeGCMDriverAndroid, Context context) { 34 private GCMDriver(long nativeGCMDriverAndroid) {
37 mNativeGCMDriverAndroid = nativeGCMDriverAndroid; 35 mNativeGCMDriverAndroid = nativeGCMDriverAndroid;
38 mContext = context; 36 mSubscriber = new GoogleCloudMessagingV2();
39 mSubscriber = new GoogleCloudMessagingV2(context);
40 } 37 }
41 38
42 /** 39 /**
43 * Create a GCMDriver object, which is owned by GCMDriverAndroid 40 * Create a GCMDriver object, which is owned by GCMDriverAndroid
44 * on the C++ side. 41 * on the C++ side.
42 * @param nativeGCMDriverAndroid The C++ object that owns us.
45 * 43 *
46 * @param nativeGCMDriverAndroid The C++ object that owns us.
47 * @param context The app context.
48 */ 44 */
49 @CalledByNative 45 @CalledByNative
50 private static GCMDriver create(long nativeGCMDriverAndroid, 46 private static GCMDriver create(long nativeGCMDriverAndroid) {
51 Context context) {
52 if (sInstance != null) { 47 if (sInstance != null) {
53 throw new IllegalStateException("Already instantiated"); 48 throw new IllegalStateException("Already instantiated");
54 } 49 }
55 sInstance = new GCMDriver(nativeGCMDriverAndroid, context); 50 sInstance = new GCMDriver(nativeGCMDriverAndroid);
56 return sInstance; 51 return sInstance;
57 } 52 }
58 53
59 /** 54 /**
60 * Called when our C++ counterpart is deleted. Clear the handle to our 55 * Called when our C++ counterpart is deleted. Clear the handle to our
61 * native C++ object, ensuring it's never called. 56 * native C++ object, ensuring it's never called.
62 */ 57 */
63 @CalledByNative 58 @CalledByNative
64 private void destroy() { 59 private void destroy() {
65 assert sInstance == this; 60 assert sInstance == this;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 sInstance.mSubscriber = subscriber; 126 sInstance.mSubscriber = subscriber;
132 } 127 }
133 128
134 private native void nativeOnRegisterFinished(long nativeGCMDriverAndroid, St ring appId, 129 private native void nativeOnRegisterFinished(long nativeGCMDriverAndroid, St ring appId,
135 String registrationId, boolean success); 130 String registrationId, boolean success);
136 private native void nativeOnUnregisterFinished(long nativeGCMDriverAndroid, String appId, 131 private native void nativeOnUnregisterFinished(long nativeGCMDriverAndroid, String appId,
137 boolean success); 132 boolean success);
138 private native void nativeOnMessageReceived(long nativeGCMDriverAndroid, Str ing appId, 133 private native void nativeOnMessageReceived(long nativeGCMDriverAndroid, Str ing appId,
139 String senderId, String collapseKey, byte[] rawData, String[] dataKe ysAndValues); 134 String senderId, String collapseKey, byte[] rawData, String[] dataKe ysAndValues);
140 } 135 }
OLDNEW
« no previous file with comments | « no previous file | components/gcm_driver/android/java/src/org/chromium/components/gcm_driver/GoogleCloudMessagingV2.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698