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. |
25 class InstanceIDAndroid : public InstanceID { | 25 class InstanceIDAndroid : public InstanceID { |
26 public: | 26 public: |
| 27 // 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 // block the UI thread. |
| 30 class ScopedBlockOnAsyncTasksForTesting { |
| 31 public: |
| 32 ScopedBlockOnAsyncTasksForTesting(); |
| 33 ~ScopedBlockOnAsyncTasksForTesting(); |
| 34 |
| 35 private: |
| 36 bool previous_value_; |
| 37 DISALLOW_COPY_AND_ASSIGN(ScopedBlockOnAsyncTasksForTesting); |
| 38 }; |
| 39 |
27 // Register JNI methods. | 40 // Register JNI methods. |
28 static bool RegisterJni(JNIEnv* env); | 41 static bool RegisterJni(JNIEnv* env); |
29 | 42 |
30 InstanceIDAndroid(const std::string& app_id); | 43 InstanceIDAndroid(const std::string& app_id); |
31 ~InstanceIDAndroid() override; | 44 ~InstanceIDAndroid() override; |
32 | 45 |
33 // InstanceID implementation: | 46 // InstanceID implementation: |
34 void GetID(const GetIDCallback& callback) override; | 47 void GetID(const GetIDCallback& callback) override; |
35 void GetCreationTime(const GetCreationTimeCallback& callback) override; | 48 void GetCreationTime(const GetCreationTimeCallback& callback) override; |
36 void GetToken(const std::string& audience, | 49 void GetToken(const std::string& audience, |
(...skipping 27 matching lines...) Expand all Loading... |
64 IDMap<DeleteIDCallback, IDMapOwnPointer> delete_id_callbacks_; | 77 IDMap<DeleteIDCallback, IDMapOwnPointer> delete_id_callbacks_; |
65 | 78 |
66 base::ThreadChecker thread_checker_; | 79 base::ThreadChecker thread_checker_; |
67 | 80 |
68 DISALLOW_COPY_AND_ASSIGN(InstanceIDAndroid); | 81 DISALLOW_COPY_AND_ASSIGN(InstanceIDAndroid); |
69 }; | 82 }; |
70 | 83 |
71 } // namespace instance_id | 84 } // namespace instance_id |
72 | 85 |
73 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_ANDROID_H_ | 86 #endif // COMPONENTS_GCM_DRIVER_INSTANCE_ID_INSTANCE_ID_ANDROID_H_ |
OLD | NEW |