| OLD | NEW |
| 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 #include "components/invalidation/impl/invalidation_service_android.h" | 5 #include "components/invalidation/impl/invalidation_service_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // the object ids into object source and object name arrays. | 57 // the object ids into object source and object name arrays. |
| 58 std::vector<int> sources; | 58 std::vector<int> sources; |
| 59 std::vector<std::string> names; | 59 std::vector<std::string> names; |
| 60 syncer::ObjectIdSet::const_iterator id; | 60 syncer::ObjectIdSet::const_iterator id; |
| 61 for (id = registered_ids.begin(); id != registered_ids.end(); ++id) { | 61 for (id = registered_ids.begin(); id != registered_ids.end(); ++id) { |
| 62 sources.push_back(id->source()); | 62 sources.push_back(id->source()); |
| 63 names.push_back(id->name()); | 63 names.push_back(id->name()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 Java_InvalidationService_setRegisteredObjectIds( | 66 Java_InvalidationService_setRegisteredObjectIds( |
| 67 env, | 67 env, java_ref_, base::android::ToJavaIntArray(env, sources), |
| 68 java_ref_.obj(), | 68 base::android::ToJavaArrayOfStrings(env, names)); |
| 69 base::android::ToJavaIntArray(env, sources).obj(), | |
| 70 base::android::ToJavaArrayOfStrings(env, names).obj()); | |
| 71 | 69 |
| 72 logger_.OnUpdateIds(invalidator_registrar_.GetSanitizedHandlersIdsMap()); | 70 logger_.OnUpdateIds(invalidator_registrar_.GetSanitizedHandlersIdsMap()); |
| 73 return true; | 71 return true; |
| 74 } | 72 } |
| 75 | 73 |
| 76 void InvalidationServiceAndroid::UnregisterInvalidationHandler( | 74 void InvalidationServiceAndroid::UnregisterInvalidationHandler( |
| 77 syncer::InvalidationHandler* handler) { | 75 syncer::InvalidationHandler* handler) { |
| 78 DCHECK(CalledOnValidThread()); | 76 DCHECK(CalledOnValidThread()); |
| 79 invalidator_registrar_.UnregisterHandler(handler); | 77 invalidator_registrar_.UnregisterHandler(handler); |
| 80 logger_.OnUnregistration(handler->GetOwnerName()); | 78 logger_.OnUnregistration(handler->GetOwnerName()); |
| 81 } | 79 } |
| 82 | 80 |
| 83 syncer::InvalidatorState | 81 syncer::InvalidatorState |
| 84 InvalidationServiceAndroid::GetInvalidatorState() const { | 82 InvalidationServiceAndroid::GetInvalidatorState() const { |
| 85 DCHECK(CalledOnValidThread()); | 83 DCHECK(CalledOnValidThread()); |
| 86 return invalidator_state_; | 84 return invalidator_state_; |
| 87 } | 85 } |
| 88 | 86 |
| 89 std::string InvalidationServiceAndroid::GetInvalidatorClientId() const { | 87 std::string InvalidationServiceAndroid::GetInvalidatorClientId() const { |
| 90 DCHECK(CalledOnValidThread()); | 88 DCHECK(CalledOnValidThread()); |
| 91 JNIEnv* env = base::android::AttachCurrentThread(); | 89 JNIEnv* env = base::android::AttachCurrentThread(); |
| 92 DCHECK(env); | 90 DCHECK(env); |
| 93 | 91 |
| 94 // Ask the Java code to for the invalidator ID it's currently using. | 92 // Ask the Java code to for the invalidator ID it's currently using. |
| 95 base::android::ScopedJavaLocalRef<_jbyteArray*> id_bytes_java = | 93 base::android::ScopedJavaLocalRef<_jbyteArray*> id_bytes_java = |
| 96 Java_InvalidationService_getInvalidatorClientId(env, java_ref_.obj()); | 94 Java_InvalidationService_getInvalidatorClientId(env, java_ref_); |
| 97 | 95 |
| 98 // Convert it into a more convenient format for C++. | 96 // Convert it into a more convenient format for C++. |
| 99 std::vector<uint8_t> id_bytes; | 97 std::vector<uint8_t> id_bytes; |
| 100 base::android::JavaByteArrayToByteVector(env, id_bytes_java.obj(), &id_bytes); | 98 base::android::JavaByteArrayToByteVector(env, id_bytes_java.obj(), &id_bytes); |
| 101 std::string id(id_bytes.begin(), id_bytes.end()); | 99 std::string id(id_bytes.begin(), id_bytes.end()); |
| 102 | 100 |
| 103 return id; | 101 return id; |
| 104 } | 102 } |
| 105 | 103 |
| 106 InvalidationLogger* InvalidationServiceAndroid::GetInvalidationLogger() { | 104 InvalidationLogger* InvalidationServiceAndroid::GetInvalidationLogger() { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 object_invalidation_map); | 168 object_invalidation_map); |
| 171 logger_.OnInvalidation(object_invalidation_map); | 169 logger_.OnInvalidation(object_invalidation_map); |
| 172 } | 170 } |
| 173 | 171 |
| 174 // static | 172 // static |
| 175 bool InvalidationServiceAndroid::RegisterJni(JNIEnv* env) { | 173 bool InvalidationServiceAndroid::RegisterJni(JNIEnv* env) { |
| 176 return RegisterNativesImpl(env); | 174 return RegisterNativesImpl(env); |
| 177 } | 175 } |
| 178 | 176 |
| 179 } // namespace invalidation | 177 } // namespace invalidation |
| OLD | NEW |