OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "blimp/client/core/settings/android/blimp_settings_android.h" |
| 6 |
| 7 #include "blimp/client/public/blimp_client_context.h" |
| 8 #include "jni/AboutBlimpPreferences_jni.h" |
| 9 |
| 10 namespace blimp { |
| 11 namespace client { |
| 12 |
| 13 // static |
| 14 bool BlimpSettingsAndroid::RegisterJni(JNIEnv* env) { |
| 15 return RegisterNativesImpl(env); |
| 16 } |
| 17 |
| 18 // static |
| 19 BlimpSettingsAndroid* BlimpSettingsAndroid::FromJavaObject(JNIEnv* env, |
| 20 jobject jobj) { |
| 21 return reinterpret_cast<BlimpSettingsAndroid*>( |
| 22 Java_AboutBlimpPreferences_getNativePtr(env, jobj)); |
| 23 } |
| 24 |
| 25 static jlong Init(JNIEnv* env, |
| 26 const base::android::JavaParamRef<jobject>& jobj) { |
| 27 return reinterpret_cast<intptr_t>(new BlimpSettingsAndroid(env, jobj)); |
| 28 } |
| 29 |
| 30 BlimpSettingsAndroid::BlimpSettingsAndroid(JNIEnv* env, jobject jobj) |
| 31 : identity_source_(nullptr) { |
| 32 java_obj_.Reset(env, jobj); |
| 33 } |
| 34 |
| 35 BlimpSettingsAndroid::~BlimpSettingsAndroid() { |
| 36 Java_AboutBlimpPreferences_clearNativePtr( |
| 37 base::android::AttachCurrentThread(), java_obj_); |
| 38 } |
| 39 |
| 40 void BlimpSettingsAndroid::Destroy( |
| 41 JNIEnv* env, |
| 42 const base::android::JavaParamRef<jobject>& jobj) { |
| 43 DCHECK(identity_source_); |
| 44 identity_source_->RemoveObserver(this); |
| 45 delete this; |
| 46 } |
| 47 |
| 48 void BlimpSettingsAndroid::SetIdentitySource(IdentitySource* identity_source) { |
| 49 if (identity_source_) { |
| 50 identity_source_->RemoveObserver(this); |
| 51 } |
| 52 |
| 53 identity_source_ = identity_source; |
| 54 DCHECK(identity_source_); |
| 55 |
| 56 // Listen to sign in state change. |
| 57 identity_source->AddObserver(this); |
| 58 } |
| 59 |
| 60 void BlimpSettingsAndroid::OnSignedOut() { |
| 61 Java_AboutBlimpPreferences_onSignedOut(base::android::AttachCurrentThread(), |
| 62 java_obj_); |
| 63 } |
| 64 |
| 65 void BlimpSettingsAndroid::OnSignedIn() { |
| 66 Java_AboutBlimpPreferences_onSignedIn(base::android::AttachCurrentThread(), |
| 67 java_obj_); |
| 68 } |
| 69 |
| 70 void BlimpSettingsAndroid::OnActiveAccountLogout() { |
| 71 OnSignedOut(); |
| 72 } |
| 73 |
| 74 void BlimpSettingsAndroid::OnActiveAccountLogin() { |
| 75 OnSignedIn(); |
| 76 } |
| 77 |
| 78 } // namespace client |
| 79 } // namespace blimp |
OLD | NEW |