| 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 "blimp/client/app/android/blimp_client_session_android.h" | 5 #include "blimp/client/app/android/blimp_client_session_android.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 base::android::ConvertJavaStringToUTF8(env, jclient_auth_token); | 80 base::android::ConvertJavaStringToUTF8(env, jclient_auth_token); |
| 81 } | 81 } |
| 82 | 82 |
| 83 BlimpClientSession::Connect(client_auth_token); | 83 BlimpClientSession::Connect(client_auth_token); |
| 84 } | 84 } |
| 85 | 85 |
| 86 BlimpClientSessionAndroid::~BlimpClientSessionAndroid() {} | 86 BlimpClientSessionAndroid::~BlimpClientSessionAndroid() {} |
| 87 | 87 |
| 88 void BlimpClientSessionAndroid::OnConnected() { | 88 void BlimpClientSessionAndroid::OnConnected() { |
| 89 JNIEnv* env = base::android::AttachCurrentThread(); | 89 JNIEnv* env = base::android::AttachCurrentThread(); |
| 90 Java_BlimpClientSession_onConnected(env, java_obj_.obj()); | 90 Java_BlimpClientSession_onConnected(env, java_obj_); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void BlimpClientSessionAndroid::OnDisconnected(int result) { | 93 void BlimpClientSessionAndroid::OnDisconnected(int result) { |
| 94 JNIEnv* env = base::android::AttachCurrentThread(); | 94 JNIEnv* env = base::android::AttachCurrentThread(); |
| 95 Java_BlimpClientSession_onDisconnected( | 95 Java_BlimpClientSession_onDisconnected( |
| 96 env, java_obj_.obj(), base::android::ConvertUTF8ToJavaString( | 96 env, java_obj_, base::android::ConvertUTF8ToJavaString( |
| 97 env, net::ErrorToShortString(result)).obj()); | 97 env, net::ErrorToShortString(result))); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void BlimpClientSessionAndroid::Destroy(JNIEnv* env, | 100 void BlimpClientSessionAndroid::Destroy(JNIEnv* env, |
| 101 const JavaParamRef<jobject>& jobj) { | 101 const JavaParamRef<jobject>& jobj) { |
| 102 delete this; | 102 delete this; |
| 103 } | 103 } |
| 104 | 104 |
| 105 void BlimpClientSessionAndroid::OnAssignmentConnectionAttempted( | 105 void BlimpClientSessionAndroid::OnAssignmentConnectionAttempted( |
| 106 AssignmentRequestResult result, | 106 AssignmentRequestResult result, |
| 107 const Assignment& assignment) { | 107 const Assignment& assignment) { |
| 108 // Notify the front end of the assignment result. | 108 // Notify the front end of the assignment result. |
| 109 std::string engine_ip = IPAddressToStringWithPort( | 109 std::string engine_ip = IPAddressToStringWithPort( |
| 110 assignment.engine_endpoint.address(), assignment.engine_endpoint.port()); | 110 assignment.engine_endpoint.address(), assignment.engine_endpoint.port()); |
| 111 JNIEnv* env = base::android::AttachCurrentThread(); | 111 JNIEnv* env = base::android::AttachCurrentThread(); |
| 112 Java_BlimpClientSession_onAssignmentReceived( | 112 Java_BlimpClientSession_onAssignmentReceived( |
| 113 env, java_obj_.obj(), static_cast<jint>(result), | 113 env, java_obj_, static_cast<jint>(result), |
| 114 base::android::ConvertUTF8ToJavaString(env, engine_ip).obj(), | 114 base::android::ConvertUTF8ToJavaString(env, engine_ip), |
| 115 base::android::ConvertUTF8ToJavaString(env, | 115 base::android::ConvertUTF8ToJavaString(env, |
| 116 version_info::GetVersionNumber()) | 116 version_info::GetVersionNumber())); |
| 117 .obj()); | |
| 118 | 117 |
| 119 BlimpClientSession::OnAssignmentConnectionAttempted(result, assignment); | 118 BlimpClientSession::OnAssignmentConnectionAttempted(result, assignment); |
| 120 } | 119 } |
| 121 | 120 |
| 122 base::android::ScopedJavaLocalRef<jintArray> | 121 base::android::ScopedJavaLocalRef<jintArray> |
| 123 BlimpClientSessionAndroid::GetDebugInfo( | 122 BlimpClientSessionAndroid::GetDebugInfo( |
| 124 JNIEnv* env, | 123 JNIEnv* env, |
| 125 const base::android::JavaParamRef<jobject>& jobj) { | 124 const base::android::JavaParamRef<jobject>& jobj) { |
| 126 BlimpStats* stats = BlimpStats::GetInstance(); | 125 BlimpStats* stats = BlimpStats::GetInstance(); |
| 127 int metrics[] = {stats->Get(BlimpStats::BYTES_RECEIVED), | 126 int metrics[] = {stats->Get(BlimpStats::BYTES_RECEIVED), |
| 128 stats->Get(BlimpStats::BYTES_SENT), | 127 stats->Get(BlimpStats::BYTES_SENT), |
| 129 stats->Get(BlimpStats::COMMIT)}; | 128 stats->Get(BlimpStats::COMMIT)}; |
| 130 return base::android::ToJavaIntArray(env, metrics, arraysize(metrics)); | 129 return base::android::ToJavaIntArray(env, metrics, arraysize(metrics)); |
| 131 } | 130 } |
| 132 | 131 |
| 133 } // namespace client | 132 } // namespace client |
| 134 } // namespace blimp | 133 } // namespace blimp |
| OLD | NEW |