[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / android / password_ui_view_android.cc
blobe26c552d594945a790c6b0bdb2bbf435b680a246
1 // Copyright 2013 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.
5 #include "chrome/browser/android/password_ui_view_android.h"
7 #include "base/android/jni_string.h"
8 #include "base/android/jni_weak_ref.h"
9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "components/autofill/core/common/password_form.h"
11 #include "jni/PasswordUIView_jni.h"
13 using base::android::ConvertUTF16ToJavaString;
14 using base::android::ConvertUTF8ToJavaString;
15 using base::android::ScopedJavaLocalRef;
17 PasswordUIViewAndroid::PasswordUIViewAndroid(JNIEnv* env, jobject obj)
18 : password_manager_presenter_(this), weak_java_ui_controller_(env, obj) {}
20 PasswordUIViewAndroid::~PasswordUIViewAndroid() {}
22 void PasswordUIViewAndroid::Destroy(JNIEnv*, jobject) { delete this; }
24 Profile* PasswordUIViewAndroid::GetProfile() {
25 return ProfileManager::GetLastUsedProfile();
28 void PasswordUIViewAndroid::ShowPassword(
29 size_t index, const base::string16& password_value) {
30 NOTIMPLEMENTED();
33 void PasswordUIViewAndroid::SetPasswordList(
34 const ScopedVector<autofill::PasswordForm>& password_list,
35 bool show_passwords) {
36 // Android just ignores the |show_passwords| argument.
37 JNIEnv* env = base::android::AttachCurrentThread();
38 ScopedJavaLocalRef<jobject> ui_controller = weak_java_ui_controller_.get(env);
39 if (!ui_controller.is_null()) {
40 Java_PasswordUIView_passwordListAvailable(
41 env, ui_controller.obj(), static_cast<int>(password_list.size()));
45 void PasswordUIViewAndroid::SetPasswordExceptionList(
46 const ScopedVector<autofill::PasswordForm>& password_exception_list) {
47 JNIEnv* env = base::android::AttachCurrentThread();
48 ScopedJavaLocalRef<jobject> ui_controller = weak_java_ui_controller_.get(env);
49 if (!ui_controller.is_null()) {
50 Java_PasswordUIView_passwordExceptionListAvailable(
51 env,
52 ui_controller.obj(),
53 static_cast<int>(password_exception_list.size()));
57 void PasswordUIViewAndroid::UpdatePasswordLists(JNIEnv* env, jobject) {
58 password_manager_presenter_.UpdatePasswordLists();
61 ScopedJavaLocalRef<jobject>
62 PasswordUIViewAndroid::GetSavedPasswordEntry(JNIEnv* env, jobject, int index) {
63 const autofill::PasswordForm* form =
64 password_manager_presenter_.GetPassword(index);
65 if (!form) {
66 return Java_PasswordUIView_createSavedPasswordEntry(
67 env,
68 ConvertUTF8ToJavaString(env, std::string()).obj(),
69 ConvertUTF16ToJavaString(env, base::string16()).obj());
71 return Java_PasswordUIView_createSavedPasswordEntry(
72 env,
73 ConvertUTF8ToJavaString(env, form->origin.spec()).obj(),
74 ConvertUTF16ToJavaString(env, form->username_value).obj());
77 ScopedJavaLocalRef<jstring> PasswordUIViewAndroid::GetSavedPasswordException(
78 JNIEnv* env, jobject, int index) {
79 const autofill::PasswordForm* form =
80 password_manager_presenter_.GetPasswordException(index);
81 if (!form)
82 return ConvertUTF8ToJavaString(env, std::string());
83 return ConvertUTF8ToJavaString(env, form->origin.spec());
86 void PasswordUIViewAndroid::HandleRemoveSavedPasswordEntry(
87 JNIEnv* env, jobject, int index) {
88 password_manager_presenter_.RemoveSavedPassword(index);
91 void PasswordUIViewAndroid::HandleRemoveSavedPasswordException(
92 JNIEnv* env, jobject, int index) {
93 password_manager_presenter_.RemovePasswordException(index);
96 // static
97 static jlong Init(JNIEnv* env, jobject obj) {
98 PasswordUIViewAndroid* controller = new PasswordUIViewAndroid(env, obj);
99 return reinterpret_cast<intptr_t>(controller);
102 bool PasswordUIViewAndroid::RegisterPasswordUIViewAndroid(JNIEnv* env) {
103 return RegisterNativesImpl(env);