Chromium Code Reviews| 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 #ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_ANDROID_H_ | 5 #ifndef COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_ANDROID_H_ |
| 6 #define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_ANDROID_H_ | 6 #define COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_ANDROID_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/android/scoped_java_ref.h" | 13 #include "base/android/scoped_java_ref.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/id_map.h" | 16 #include "base/id_map.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "components/gcm_driver/instance_id/instance_id.h" | 20 #include "components/gcm_driver/instance_id/instance_id.h" |
| 21 | 21 |
| 22 namespace instance_id { | 22 namespace instance_id { |
| 23 | 23 |
| 24 // InstanceID implementation for Android. | 24 // InstanceID implementation for Android. Callbacks other than DeleteIDCallback |
| 25 // mustn't synchronously delete this (using InstanceIDDriver::RemoveInstanceID). | |
|
jianli
2016/04/26 20:50:55
I don't think we want to allow synchronous deletin
johnme
2016/04/27 09:41:56
Ok, done. DeleteID no longer supports synchronous
| |
| 25 class InstanceIDAndroid : public InstanceID { | 26 class InstanceIDAndroid : public InstanceID { |
| 26 public: | 27 public: |
| 27 // Tests depending on InstanceID that run without a nested Java message loop | 28 // Tests depending on InstanceID that run without a nested Java message loop |
| 28 // must use this. Operations that would normally be asynchronous will instead | 29 // must use this. Operations that would normally be asynchronous will instead |
| 29 // block the UI thread. | 30 // block the UI thread. |
| 30 class ScopedBlockOnAsyncTasksForTesting { | 31 class ScopedBlockOnAsyncTasksForTesting { |
| 31 public: | 32 public: |
| 32 ScopedBlockOnAsyncTasksForTesting(); | 33 ScopedBlockOnAsyncTasksForTesting(); |
| 33 ~ScopedBlockOnAsyncTasksForTesting(); | 34 ~ScopedBlockOnAsyncTasksForTesting(); |
| 34 | 35 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 49 void GetToken(const std::string& audience, | 50 void GetToken(const std::string& audience, |
| 50 const std::string& scope, | 51 const std::string& scope, |
| 51 const std::map<std::string, std::string>& options, | 52 const std::map<std::string, std::string>& options, |
| 52 const GetTokenCallback& callback) override; | 53 const GetTokenCallback& callback) override; |
| 53 void DeleteToken(const std::string& audience, | 54 void DeleteToken(const std::string& audience, |
| 54 const std::string& scope, | 55 const std::string& scope, |
| 55 const DeleteTokenCallback& callback) override; | 56 const DeleteTokenCallback& callback) override; |
| 56 void DeleteID(const DeleteIDCallback& callback) override; | 57 void DeleteID(const DeleteIDCallback& callback) override; |
| 57 | 58 |
| 58 // Methods called from Java via JNI: | 59 // Methods called from Java via JNI: |
| 60 void DidGetID(JNIEnv* env, | |
| 61 const base::android::JavaParamRef<jobject>& obj, | |
| 62 jint request_id, | |
| 63 const base::android::JavaParamRef<jstring>& jid); | |
| 64 void DidGetCreationTime(JNIEnv* env, | |
| 65 const base::android::JavaParamRef<jobject>& obj, | |
| 66 jint request_id, | |
| 67 jlong creation_time_unix_ms); | |
| 59 void DidGetToken(JNIEnv* env, | 68 void DidGetToken(JNIEnv* env, |
| 60 const base::android::JavaParamRef<jobject>& obj, | 69 const base::android::JavaParamRef<jobject>& obj, |
| 61 jint request_id, | 70 jint request_id, |
| 62 const base::android::JavaParamRef<jstring>& jtoken); | 71 const base::android::JavaParamRef<jstring>& jtoken); |
| 63 void DidDeleteToken(JNIEnv* env, | 72 void DidDeleteToken(JNIEnv* env, |
| 64 const base::android::JavaParamRef<jobject>& obj, | 73 const base::android::JavaParamRef<jobject>& obj, |
| 65 jint request_id, | 74 jint request_id, |
| 66 jboolean success); | 75 jboolean success); |
| 67 void DidDeleteID(JNIEnv* env, | 76 void DidDeleteID(JNIEnv* env, |
| 68 const base::android::JavaParamRef<jobject>& obj, | 77 const base::android::JavaParamRef<jobject>& obj, |
| 69 jint request_id, | 78 jint request_id, |
| 70 jboolean success); | 79 jboolean success); |
| 71 | 80 |
| 72 private: | 81 private: |
| 73 base::android::ScopedJavaGlobalRef<jobject> java_ref_; | 82 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 74 | 83 |
| 84 IDMap<GetIDCallback, IDMapOwnPointer> get_id_callbacks_; | |
| 85 IDMap<GetCreationTimeCallback, IDMapOwnPointer> get_creation_time_callbacks_; | |
| 75 IDMap<GetTokenCallback, IDMapOwnPointer> get_token_callbacks_; | 86 IDMap<GetTokenCallback, IDMapOwnPointer> get_token_callbacks_; |
| 76 IDMap<DeleteTokenCallback, IDMapOwnPointer> delete_token_callbacks_; | 87 IDMap<DeleteTokenCallback, IDMapOwnPointer> delete_token_callbacks_; |
| 77 IDMap<DeleteIDCallback, IDMapOwnPointer> delete_id_callbacks_; | 88 IDMap<DeleteIDCallback, IDMapOwnPointer> delete_id_callbacks_; |
| 78 | 89 |
| 79 base::ThreadChecker thread_checker_; | 90 base::ThreadChecker thread_checker_; |
| 80 | 91 |
| 81 DISALLOW_COPY_AND_ASSIGN(InstanceIDAndroid); | 92 DISALLOW_COPY_AND_ASSIGN(InstanceIDAndroid); |
| 82 }; | 93 }; |
| 83 | 94 |
| 84 } // namespace instance_id | 95 } // namespace instance_id |
| 85 | 96 |
| 86 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_ANDROID_H_ | 97 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_ANDROID_H_ |
| OLD | NEW |