OLD | NEW |
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 #include "components/gcm_driver/instance_id/instance_id_android.h" | 5 #include "components/gcm_driver/instance_id/instance_id_android.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 Java_InstanceIDBridge_setBlockOnAsyncTasksForTesting(env, previous_value_); | 39 Java_InstanceIDBridge_setBlockOnAsyncTasksForTesting(env, previous_value_); |
40 } | 40 } |
41 | 41 |
42 // static | 42 // static |
43 bool InstanceIDAndroid::RegisterJni(JNIEnv* env) { | 43 bool InstanceIDAndroid::RegisterJni(JNIEnv* env) { |
44 return RegisterNativesImpl(env); | 44 return RegisterNativesImpl(env); |
45 } | 45 } |
46 | 46 |
47 // static | 47 // static |
48 std::unique_ptr<InstanceID> InstanceID::Create(const std::string& app_id, | 48 std::unique_ptr<InstanceID> InstanceID::Create(const std::string& app_id, |
49 gcm::InstanceIDHandler* unused) { | 49 gcm::GCMDriver* gcm_driver) { |
50 return base::WrapUnique(new InstanceIDAndroid(app_id)); | 50 return base::WrapUnique(new InstanceIDAndroid(app_id, gcm_driver)); |
51 } | 51 } |
52 | 52 |
53 InstanceIDAndroid::InstanceIDAndroid(const std::string& app_id) | 53 InstanceIDAndroid::InstanceIDAndroid(const std::string& app_id, |
54 : InstanceID(app_id) { | 54 gcm::GCMDriver* gcm_driver) |
| 55 : InstanceID(app_id, gcm_driver) { |
55 DCHECK(thread_checker_.CalledOnValidThread()); | 56 DCHECK(thread_checker_.CalledOnValidThread()); |
56 | 57 |
57 DCHECK(!app_id.empty()) << "Empty app_id is not supported"; | 58 DCHECK(!app_id.empty()) << "Empty app_id is not supported"; |
58 // The |app_id| is stored in GCM's category field by the desktop InstanceID | 59 // The |app_id| is stored in GCM's category field by the desktop InstanceID |
59 // implementation, but because the category is reserved for the app's package | 60 // implementation, but because the category is reserved for the app's package |
60 // name on Android the subtype field is used instead. | 61 // name on Android the subtype field is used instead. |
61 std::string subtype = app_id; | 62 std::string subtype = app_id; |
62 | 63 |
63 JNIEnv* env = AttachCurrentThread(); | 64 JNIEnv* env = AttachCurrentThread(); |
64 java_ref_.Reset(Java_InstanceIDBridge_create( | 65 java_ref_.Reset(Java_InstanceIDBridge_create( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 111 } |
111 | 112 |
112 JNIEnv* env = AttachCurrentThread(); | 113 JNIEnv* env = AttachCurrentThread(); |
113 Java_InstanceIDBridge_getToken( | 114 Java_InstanceIDBridge_getToken( |
114 env, java_ref_.obj(), request_id, | 115 env, java_ref_.obj(), request_id, |
115 ConvertUTF8ToJavaString(env, authorized_entity).obj(), | 116 ConvertUTF8ToJavaString(env, authorized_entity).obj(), |
116 ConvertUTF8ToJavaString(env, scope).obj(), | 117 ConvertUTF8ToJavaString(env, scope).obj(), |
117 base::android::ToJavaArrayOfStrings(env, options_strings).obj()); | 118 base::android::ToJavaArrayOfStrings(env, options_strings).obj()); |
118 } | 119 } |
119 | 120 |
120 void InstanceIDAndroid::DeleteToken(const std::string& authorized_entity, | 121 void InstanceIDAndroid::DeleteTokenImpl(const std::string& authorized_entity, |
121 const std::string& scope, | 122 const std::string& scope, |
122 const DeleteTokenCallback& callback) { | 123 const DeleteTokenCallback& callback) { |
123 DCHECK(thread_checker_.CalledOnValidThread()); | 124 DCHECK(thread_checker_.CalledOnValidThread()); |
124 | 125 |
125 int32_t request_id = | 126 int32_t request_id = |
126 delete_token_callbacks_.Add(new DeleteTokenCallback(callback)); | 127 delete_token_callbacks_.Add(new DeleteTokenCallback(callback)); |
127 | 128 |
128 JNIEnv* env = AttachCurrentThread(); | 129 JNIEnv* env = AttachCurrentThread(); |
129 Java_InstanceIDBridge_deleteToken( | 130 Java_InstanceIDBridge_deleteToken( |
130 env, java_ref_.obj(), request_id, | 131 env, java_ref_.obj(), request_id, |
131 ConvertUTF8ToJavaString(env, authorized_entity).obj(), | 132 ConvertUTF8ToJavaString(env, authorized_entity).obj(), |
132 ConvertUTF8ToJavaString(env, scope).obj()); | 133 ConvertUTF8ToJavaString(env, scope).obj()); |
133 } | 134 } |
134 | 135 |
135 void InstanceIDAndroid::DeleteID(const DeleteIDCallback& callback) { | 136 void InstanceIDAndroid::DeleteIDImpl(const DeleteIDCallback& callback) { |
136 DCHECK(thread_checker_.CalledOnValidThread()); | 137 DCHECK(thread_checker_.CalledOnValidThread()); |
137 | 138 |
138 int32_t request_id = delete_id_callbacks_.Add(new DeleteIDCallback(callback)); | 139 int32_t request_id = delete_id_callbacks_.Add(new DeleteIDCallback(callback)); |
139 | 140 |
140 JNIEnv* env = AttachCurrentThread(); | 141 JNIEnv* env = AttachCurrentThread(); |
141 Java_InstanceIDBridge_deleteInstanceID(env, java_ref_.obj(), request_id); | 142 Java_InstanceIDBridge_deleteInstanceID(env, java_ref_.obj(), request_id); |
142 } | 143 } |
143 | 144 |
144 void InstanceIDAndroid::DidGetID( | 145 void InstanceIDAndroid::DidGetID( |
145 JNIEnv* env, | 146 JNIEnv* env, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 jboolean success) { | 212 jboolean success) { |
212 DCHECK(thread_checker_.CalledOnValidThread()); | 213 DCHECK(thread_checker_.CalledOnValidThread()); |
213 | 214 |
214 DeleteIDCallback* callback = delete_id_callbacks_.Lookup(request_id); | 215 DeleteIDCallback* callback = delete_id_callbacks_.Lookup(request_id); |
215 DCHECK(callback); | 216 DCHECK(callback); |
216 callback->Run(success ? InstanceID::SUCCESS : InstanceID::UNKNOWN_ERROR); | 217 callback->Run(success ? InstanceID::SUCCESS : InstanceID::UNKNOWN_ERROR); |
217 delete_id_callbacks_.Remove(request_id); | 218 delete_id_callbacks_.Remove(request_id); |
218 } | 219 } |
219 | 220 |
220 } // namespace instance_id | 221 } // namespace instance_id |
OLD | NEW |