| 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 "sync/test/fake_server/android/fake_server_helper_android.h" | 5 #include "sync/test/fake_server/android/fake_server_helper_android.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 testing::AssertionResult result = | 73 testing::AssertionResult result = |
| 74 fake_server_verifier.VerifyEntityCountByTypeAndName( | 74 fake_server_verifier.VerifyEntityCountByTypeAndName( |
| 75 count, model_type, base::android::ConvertJavaStringToUTF8(env, name)); | 75 count, model_type, base::android::ConvertJavaStringToUTF8(env, name)); |
| 76 | 76 |
| 77 if (!result) | 77 if (!result) |
| 78 LOG(WARNING) << result.message(); | 78 LOG(WARNING) << result.message(); |
| 79 | 79 |
| 80 return result; | 80 return result; |
| 81 } | 81 } |
| 82 | 82 |
| 83 void FakeServerHelperAndroid::InjectTypedUrl(JNIEnv* env, | 83 void FakeServerHelperAndroid::InjectUniqueClientEntity( |
| 84 jobject obj, | 84 JNIEnv* env, |
| 85 jlong fake_server, | 85 jobject obj, |
| 86 jstring url) { | 86 jlong fake_server, |
| 87 jstring name, |
| 88 jbyteArray serialized_entity_specifics) { |
| 87 fake_server::FakeServer* fake_server_ptr = | 89 fake_server::FakeServer* fake_server_ptr = |
| 88 reinterpret_cast<fake_server::FakeServer*>(fake_server); | 90 reinterpret_cast<fake_server::FakeServer*>(fake_server); |
| 89 | 91 |
| 90 // TODO(pvalenzuela): Move this proto creation and serialization to the Java | 92 int specifics_bytes_length = env->GetArrayLength(serialized_entity_specifics); |
| 91 // code once the appropriate Java objects are generated. | 93 jbyte* specifics_bytes = |
| 92 std::string native_url = base::android::ConvertJavaStringToUTF8(env, url); | 94 env->GetByteArrayElements(serialized_entity_specifics, NULL); |
| 95 std::string specifics_string(reinterpret_cast<char *>(specifics_bytes), |
| 96 specifics_bytes_length); |
| 97 |
| 93 sync_pb::EntitySpecifics entity_specifics; | 98 sync_pb::EntitySpecifics entity_specifics; |
| 94 sync_pb::TypedUrlSpecifics* typed_url_specifics = | 99 if (!entity_specifics.ParseFromString(specifics_string)) |
| 95 entity_specifics.mutable_typed_url(); | 100 NOTREACHED() << "Could not deserialize EntitySpecifics"; |
| 96 typed_url_specifics->set_url(native_url); | |
| 97 typed_url_specifics->set_title(native_url); | |
| 98 typed_url_specifics->add_visits(1L); | |
| 99 typed_url_specifics->add_visit_transitions( | |
| 100 sync_pb::SyncEnums_PageTransition_TYPED); | |
| 101 | 101 |
| 102 fake_server_ptr->InjectEntity( | 102 fake_server_ptr->InjectEntity( |
| 103 fake_server::UniqueClientEntity::CreateForInjection( | 103 fake_server::UniqueClientEntity::CreateForInjection( |
| 104 syncer::ModelType::TYPED_URLS, | 104 base::android::ConvertJavaStringToUTF8(env, name), |
| 105 native_url, | |
| 106 entity_specifics)); | 105 entity_specifics)); |
| 107 } | 106 } |
| 108 | 107 |
| 109 // static | 108 // static |
| 110 bool FakeServerHelperAndroid::Register(JNIEnv* env) { | 109 bool FakeServerHelperAndroid::Register(JNIEnv* env) { |
| 111 return RegisterNativesImpl(env); | 110 return RegisterNativesImpl(env); |
| 112 } | 111 } |
| OLD | NEW |