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, |
53 BlimpClientSession::Connect(); | 49 const base::android::JavaParamRef<jstring>& jtoken) { |
50 std::string token; | |
51 if (jtoken.obj()) | |
52 token = base::android::ConvertJavaStringToUTF8(env, jtoken); | |
53 | |
54 BlimpClientSession::Connect(token); | |
54 } | 55 } |
55 | 56 |
56 BlimpClientSessionAndroid::~BlimpClientSessionAndroid() {} | 57 BlimpClientSessionAndroid::~BlimpClientSessionAndroid() {} |
57 | 58 |
58 void BlimpClientSessionAndroid::Destroy(JNIEnv* env, | 59 void BlimpClientSessionAndroid::Destroy(JNIEnv* env, |
59 const JavaParamRef<jobject>& jobj) { | 60 const JavaParamRef<jobject>& jobj) { |
60 delete this; | 61 delete this; |
61 } | 62 } |
62 | 63 |
64 void BlimpClientSessionAndroid::ConnectWithAssignment( | |
Kevin M
2016/02/12 19:45:26
I think that subclassing this method obfuscates th
David Trainor- moved to gerrit
2016/02/17 21:09:47
Good point. Done :).
| |
65 AssignmentSourceResult result, | |
66 const Assignment& assignment) { | |
67 // Notify the front end of the assignment result. | |
68 JNIEnv* env = base::android::AttachCurrentThread(); | |
69 Java_BlimpClientSession_onAssignmentReceived(env, java_obj_.obj(), | |
70 static_cast<jint>(result)); | |
71 | |
72 BlimpClientSession::ConnectWithAssignment(result, assignment); | |
73 } | |
74 | |
63 } // namespace client | 75 } // namespace client |
64 } // namespace blimp | 76 } // namespace blimp |
OLD | NEW |