Chromium Code Reviews| Index: blimp/client/core/settings/android/blimp_settings_android.cc |
| diff --git a/blimp/client/core/settings/android/blimp_settings_android.cc b/blimp/client/core/settings/android/blimp_settings_android.cc |
| index 993b15503d8ba574bc887c48821d7261338fa800..00663290c668f2e3090f3e0107b6f48666f8e531 100644 |
| --- a/blimp/client/core/settings/android/blimp_settings_android.cc |
| +++ b/blimp/client/core/settings/android/blimp_settings_android.cc |
| @@ -4,6 +4,10 @@ |
| #include "blimp/client/core/settings/android/blimp_settings_android.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/bind.h" |
| +#include "blimp/client/core/session/connection_status.h" |
| +#include "blimp/client/core/settings/blimp_settings_delegate.h" |
| #include "blimp/client/public/blimp_client_context.h" |
| #include "jni/AboutBlimpPreferences_jni.h" |
| @@ -27,8 +31,7 @@ static jlong Init(JNIEnv* env, |
| return reinterpret_cast<intptr_t>(new BlimpSettingsAndroid(env, jobj)); |
| } |
| -BlimpSettingsAndroid::BlimpSettingsAndroid(JNIEnv* env, jobject jobj) |
| - : identity_source_(nullptr) { |
| +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
|
| java_obj_.Reset(env, jobj); |
| } |
| @@ -40,21 +43,31 @@ BlimpSettingsAndroid::~BlimpSettingsAndroid() { |
| void BlimpSettingsAndroid::Destroy( |
| JNIEnv* env, |
| const base::android::JavaParamRef<jobject>& jobj) { |
| - DCHECK(identity_source_); |
| - identity_source_->RemoveObserver(this); |
| + if (delegate_) { |
| + 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.
|
| + delegate_->GetConnectionStatus()->RemoveObserver(this); |
| + } |
| + |
| delete this; |
| } |
| -void BlimpSettingsAndroid::SetIdentitySource(IdentitySource* identity_source) { |
| - if (identity_source_) { |
| - identity_source_->RemoveObserver(this); |
| - } |
| - |
| - identity_source_ = identity_source; |
| - DCHECK(identity_source_); |
| +void BlimpSettingsAndroid::SetDelegate(BlimpSettingsDelegate* delegate) { |
| + // 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.
|
| + DCHECK(!delegate_ && delegate); |
| + delegate_ = delegate; |
| // Listen to sign in state change. |
| - identity_source->AddObserver(this); |
| + delegate_->GetIdentitySource()->AddObserver(this); |
| + |
| + // Listen to connection state change. |
| + ConnectionStatus* conn_status = delegate_->GetConnectionStatus(); |
| + DCHECK(conn_status); |
| + conn_status->AddObserver(this); |
| + |
| + // Propagate connection info if the client is connected to the engine. |
| + if (conn_status->IsConnected()) { |
| + OnConnected(); |
| + } |
| } |
| void BlimpSettingsAndroid::OnSignedOut() { |
| @@ -75,5 +88,22 @@ void BlimpSettingsAndroid::OnActiveAccountLogin() { |
| OnSignedIn(); |
| } |
| +void BlimpSettingsAndroid::OnConnected() { |
| + DCHECK(delegate_); |
| + |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + std::string ip = |
| + delegate_->GetConnectionStatus()->GetIpEndPoint().address().ToString(); |
| + base::android::ScopedJavaLocalRef<jstring> jengine_ip( |
| + base::android::ConvertUTF8ToJavaString(env, ip)); |
| + |
| + 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
|
| +} |
| + |
| +void BlimpSettingsAndroid::OnDisconnected(int result) { |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + 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..
|
| +} |
| + |
| } // namespace client |
| } // namespace blimp |