OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/core/settings/android/blimp_settings_android.h" | 5 #include "blimp/client/core/settings/android/blimp_settings_android.h" |
6 | 6 |
7 #include "base/android/jni_string.h" | |
8 #include "base/bind.h" | |
9 #include "blimp/client/core/session/connection_status.h" | |
10 #include "blimp/client/core/settings/blimp_settings_delegate.h" | |
7 #include "blimp/client/public/blimp_client_context.h" | 11 #include "blimp/client/public/blimp_client_context.h" |
8 #include "jni/AboutBlimpPreferences_jni.h" | 12 #include "jni/AboutBlimpPreferences_jni.h" |
9 | 13 |
10 namespace blimp { | 14 namespace blimp { |
11 namespace client { | 15 namespace client { |
12 | 16 |
13 // static | 17 // static |
14 bool BlimpSettingsAndroid::RegisterJni(JNIEnv* env) { | 18 bool BlimpSettingsAndroid::RegisterJni(JNIEnv* env) { |
15 return RegisterNativesImpl(env); | 19 return RegisterNativesImpl(env); |
16 } | 20 } |
17 | 21 |
18 // static | 22 // static |
19 BlimpSettingsAndroid* BlimpSettingsAndroid::FromJavaObject(JNIEnv* env, | 23 BlimpSettingsAndroid* BlimpSettingsAndroid::FromJavaObject(JNIEnv* env, |
20 jobject jobj) { | 24 jobject jobj) { |
21 return reinterpret_cast<BlimpSettingsAndroid*>( | 25 return reinterpret_cast<BlimpSettingsAndroid*>( |
22 Java_AboutBlimpPreferences_getNativePtr(env, jobj)); | 26 Java_AboutBlimpPreferences_getNativePtr(env, jobj)); |
23 } | 27 } |
24 | 28 |
25 static jlong Init(JNIEnv* env, | 29 static jlong Init(JNIEnv* env, |
26 const base::android::JavaParamRef<jobject>& jobj) { | 30 const base::android::JavaParamRef<jobject>& jobj) { |
27 return reinterpret_cast<intptr_t>(new BlimpSettingsAndroid(env, jobj)); | 31 return reinterpret_cast<intptr_t>(new BlimpSettingsAndroid(env, jobj)); |
28 } | 32 } |
29 | 33 |
30 BlimpSettingsAndroid::BlimpSettingsAndroid(JNIEnv* env, jobject jobj) | 34 BlimpSettingsAndroid::BlimpSettingsAndroid(JNIEnv* env, jobject jobj) { |
David Trainor- moved to gerrit
2016/09/13 05:54:51
delegate_(nullptr)?
xingliu
2016/09/13 18:36:15
Done. Did it in the header, but put it here seems
| |
31 : identity_source_(nullptr) { | |
32 java_obj_.Reset(env, jobj); | 35 java_obj_.Reset(env, jobj); |
33 } | 36 } |
34 | 37 |
35 BlimpSettingsAndroid::~BlimpSettingsAndroid() { | 38 BlimpSettingsAndroid::~BlimpSettingsAndroid() { |
36 Java_AboutBlimpPreferences_clearNativePtr( | 39 Java_AboutBlimpPreferences_clearNativePtr( |
37 base::android::AttachCurrentThread(), java_obj_); | 40 base::android::AttachCurrentThread(), java_obj_); |
38 } | 41 } |
39 | 42 |
40 void BlimpSettingsAndroid::Destroy( | 43 void BlimpSettingsAndroid::Destroy( |
41 JNIEnv* env, | 44 JNIEnv* env, |
42 const base::android::JavaParamRef<jobject>& jobj) { | 45 const base::android::JavaParamRef<jobject>& jobj) { |
43 DCHECK(identity_source_); | 46 if (delegate_) { |
44 identity_source_->RemoveObserver(this); | 47 delegate_->GetIdentitySource()->RemoveObserver(this); |
David Trainor- moved to gerrit
2016/09/13 05:54:51
Put this in the destructor. Sorry for not catchin
xingliu
2016/09/13 18:36:15
Done.
| |
48 delegate_->GetConnectionStatus()->RemoveObserver(this); | |
49 } | |
50 | |
45 delete this; | 51 delete this; |
46 } | 52 } |
47 | 53 |
48 void BlimpSettingsAndroid::SetIdentitySource(IdentitySource* identity_source) { | 54 void BlimpSettingsAndroid::SetDelegate(BlimpSettingsDelegate* delegate) { |
49 if (identity_source_) { | 55 // Set the Delegate, it can only get called for once. |
David Trainor- moved to gerrit
2016/09/13 05:54:51
get -> be. Remove for. Put this comment in the h
xingliu
2016/09/13 18:36:15
Done.
| |
50 identity_source_->RemoveObserver(this); | 56 DCHECK(!delegate_ && delegate); |
51 } | 57 delegate_ = delegate; |
52 | |
53 identity_source_ = identity_source; | |
54 DCHECK(identity_source_); | |
55 | 58 |
56 // Listen to sign in state change. | 59 // Listen to sign in state change. |
57 identity_source->AddObserver(this); | 60 delegate_->GetIdentitySource()->AddObserver(this); |
61 | |
62 // Listen to connection state change. | |
63 ConnectionStatus* conn_status = delegate_->GetConnectionStatus(); | |
64 DCHECK(conn_status); | |
65 conn_status->AddObserver(this); | |
66 | |
67 // Propagate connection info if the client is connected to the engine. | |
68 if (conn_status->IsConnected()) { | |
69 OnConnected(); | |
70 } | |
58 } | 71 } |
59 | 72 |
60 void BlimpSettingsAndroid::OnSignedOut() { | 73 void BlimpSettingsAndroid::OnSignedOut() { |
61 Java_AboutBlimpPreferences_onSignedOut(base::android::AttachCurrentThread(), | 74 Java_AboutBlimpPreferences_onSignedOut(base::android::AttachCurrentThread(), |
62 java_obj_); | 75 java_obj_); |
63 } | 76 } |
64 | 77 |
65 void BlimpSettingsAndroid::OnSignedIn() { | 78 void BlimpSettingsAndroid::OnSignedIn() { |
66 Java_AboutBlimpPreferences_onSignedIn(base::android::AttachCurrentThread(), | 79 Java_AboutBlimpPreferences_onSignedIn(base::android::AttachCurrentThread(), |
67 java_obj_); | 80 java_obj_); |
68 } | 81 } |
69 | 82 |
70 void BlimpSettingsAndroid::OnActiveAccountLogout() { | 83 void BlimpSettingsAndroid::OnActiveAccountLogout() { |
71 OnSignedOut(); | 84 OnSignedOut(); |
72 } | 85 } |
73 | 86 |
74 void BlimpSettingsAndroid::OnActiveAccountLogin() { | 87 void BlimpSettingsAndroid::OnActiveAccountLogin() { |
75 OnSignedIn(); | 88 OnSignedIn(); |
76 } | 89 } |
77 | 90 |
91 void BlimpSettingsAndroid::OnConnected() { | |
92 DCHECK(delegate_); | |
93 | |
94 JNIEnv* env = base::android::AttachCurrentThread(); | |
95 std::string ip = | |
96 delegate_->GetConnectionStatus()->GetIpEndPoint().address().ToString(); | |
97 base::android::ScopedJavaLocalRef<jstring> jengine_ip( | |
98 base::android::ConvertUTF8ToJavaString(env, ip)); | |
99 | |
100 Java_AboutBlimpPreferences_onConnected(env, java_obj_, jengine_ip); | |
David Trainor- moved to gerrit
2016/09/13 05:54:51
If it's not connected can we expose the error reas
xingliu
2016/09/13 18:36:15
Done, removed Java onConnect, onDisconnect, call U
| |
101 } | |
102 | |
103 void BlimpSettingsAndroid::OnDisconnected(int result) { | |
104 JNIEnv* env = base::android::AttachCurrentThread(); | |
105 Java_AboutBlimpPreferences_onDisconnected(env, java_obj_); | |
David Trainor- moved to gerrit
2016/09/13 05:54:51
Is this the same as onConnected() but with an empt
xingliu
2016/09/13 18:36:15
Renamed it to UpdateEngineInfo..
| |
106 } | |
107 | |
78 } // namespace client | 108 } // namespace client |
79 } // namespace blimp | 109 } // namespace blimp |
OLD | NEW |