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 #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 "base/android/jni_string.h" | |
| 7 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 8 #include "blimp/client/feature/tab_control_feature.h" | 9 #include "blimp/client/feature/tab_control_feature.h" |
| 9 #include "blimp/client/session/assignment_source.h" | 10 #include "blimp/client/session/assignment_source.h" |
| 10 #include "jni/BlimpClientSession_jni.h" | 11 #include "jni/BlimpClientSession_jni.h" |
| 11 | 12 |
| 12 namespace blimp { | 13 namespace blimp { |
| 13 namespace client { | 14 namespace client { |
| 14 namespace { | 15 namespace { |
| 15 const int kDummyTabId = 0; | 16 const int kDummyTabId = 0; |
| 16 } // namespace | 17 } // namespace |
| 17 | 18 |
| 18 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { | 19 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { |
| 19 scoped_ptr<AssignmentSource> assignment_source = make_scoped_ptr( | 20 return reinterpret_cast<intptr_t>(new BlimpClientSessionAndroid(env, jobj)); |
| 20 new AssignmentSource(base::ThreadTaskRunnerHandle::Get())); | |
| 21 return reinterpret_cast<intptr_t>( | |
| 22 new BlimpClientSessionAndroid(env, jobj, std::move(assignment_source))); | |
| 23 } | 21 } |
| 24 | 22 |
| 25 // static | 23 // static |
| 26 bool BlimpClientSessionAndroid::RegisterJni(JNIEnv* env) { | 24 bool BlimpClientSessionAndroid::RegisterJni(JNIEnv* env) { |
| 27 return RegisterNativesImpl(env); | 25 return RegisterNativesImpl(env); |
| 28 } | 26 } |
| 29 | 27 |
| 30 // static | 28 // static |
| 31 BlimpClientSessionAndroid* BlimpClientSessionAndroid::FromJavaObject( | 29 BlimpClientSessionAndroid* BlimpClientSessionAndroid::FromJavaObject( |
| 32 JNIEnv* env, | 30 JNIEnv* env, |
| 33 jobject jobj) { | 31 jobject jobj) { |
| 34 return reinterpret_cast<BlimpClientSessionAndroid*>( | 32 return reinterpret_cast<BlimpClientSessionAndroid*>( |
| 35 Java_BlimpClientSession_getNativePtr(env, jobj)); | 33 Java_BlimpClientSession_getNativePtr(env, jobj)); |
| 36 } | 34 } |
| 37 | 35 |
| 38 BlimpClientSessionAndroid::BlimpClientSessionAndroid( | 36 BlimpClientSessionAndroid::BlimpClientSessionAndroid( |
| 39 JNIEnv* env, | 37 JNIEnv* env, |
| 40 const base::android::JavaParamRef<jobject>& jobj, | 38 const base::android::JavaParamRef<jobject>& jobj) { |
| 41 scoped_ptr<AssignmentSource> assignment_source) | |
| 42 : BlimpClientSession(std::move(assignment_source)) { | |
| 43 java_obj_.Reset(env, jobj); | 39 java_obj_.Reset(env, jobj); |
| 44 | 40 |
| 45 // Create a single tab's WebContents. | 41 // Create a single tab's WebContents. |
| 46 // TODO(kmarshall): Remove this once we add tab-literacy to Blimp. | 42 // TODO(kmarshall): Remove this once we add tab-literacy to Blimp. |
| 47 GetTabControlFeature()->CreateTab(kDummyTabId); | 43 GetTabControlFeature()->CreateTab(kDummyTabId); |
| 48 } | 44 } |
| 49 | 45 |
| 50 void BlimpClientSessionAndroid::Connect( | 46 void BlimpClientSessionAndroid::Connect( |
| 51 JNIEnv* env, | 47 JNIEnv* env, |
| 52 const base::android::JavaParamRef<jobject>& jobj) { | 48 const base::android::JavaParamRef<jobject>& jobj, |
|
nyquist
2016/02/18 01:58:39
Nit: Should we include base/android/scoped_java_re
David Trainor- moved to gerrit
2016/02/18 16:01:54
Done.
| |
| 53 BlimpClientSession::Connect(); | 49 const base::android::JavaParamRef<jstring>& jclient_auth_token) { |
| 50 std::string client_auth_token; | |
| 51 if (jclient_auth_token.obj()) { | |
| 52 client_auth_token = | |
| 53 base::android::ConvertJavaStringToUTF8(env, jclient_auth_token); | |
| 54 } | |
| 55 | |
| 56 BlimpClientSession::Connect(client_auth_token); | |
| 54 } | 57 } |
| 55 | 58 |
| 56 BlimpClientSessionAndroid::~BlimpClientSessionAndroid() {} | 59 BlimpClientSessionAndroid::~BlimpClientSessionAndroid() {} |
| 57 | 60 |
| 58 void BlimpClientSessionAndroid::Destroy(JNIEnv* env, | 61 void BlimpClientSessionAndroid::Destroy(JNIEnv* env, |
| 59 const JavaParamRef<jobject>& jobj) { | 62 const JavaParamRef<jobject>& jobj) { |
| 60 delete this; | 63 delete this; |
| 61 } | 64 } |
| 62 | 65 |
| 66 void BlimpClientSessionAndroid::OnAssignmentConnectionAttempted( | |
| 67 AssignmentSource::Result result) { | |
| 68 // Notify the front end of the assignment result. | |
| 69 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 70 Java_BlimpClientSession_onAssignmentReceived(env, java_obj_.obj(), | |
| 71 static_cast<jint>(result)); | |
| 72 | |
| 73 BlimpClientSession::OnAssignmentConnectionAttempted(result); | |
| 74 } | |
| 75 | |
| 63 } // namespace client | 76 } // namespace client |
| 64 } // namespace blimp | 77 } // namespace blimp |
| OLD | NEW |