personal_data_manager_android.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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. 4 5#ifndef CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ 6#define CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ 7 8#include "base/android/jni_helper.h" 9#include "base/android/scoped_java_ref.h" 10#include "components/autofill/browser/personal_data_manager.h" 11#include "components/autofill/browser/personal_data_manager_observer.h" 12 13// Android wrapper of the PersonalDataManager which provides access from the 14// Java layer. Note that on Android, there's only a single profile, and 15// therefore a single instance of this wrapper. 16class PersonalDataManagerAndroid : public PersonalDataManagerObserver { 17 public: 18 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); 19 20 // Regular Autofill Profiles 21 // ------------------------- 22 23 // Returns the number of web and auxiliary profiles. 24 jint GetProfileCount(JNIEnv* unused_env, jobject unused_obj); 25 26 // Returns the profile as indexed by |index| in the PersonalDataManager's 27 // |GetProfiles()| collection. 28 base::android::ScopedJavaLocalRef<jobject> GetProfileByIndex( 29 JNIEnv* env, 30 jobject unused_obj, 31 jint index); 32 33 // Returns the profile with the specified |jguid|, or NULL if there is no 34 // profile with the specified |jguid|. Both web and auxiliary profiles may 35 // be returned. 36 base::android::ScopedJavaLocalRef<jobject> GetProfileByGUID( 37 JNIEnv* env, 38 jobject unused_obj, 39 jstring jguid); 40 41 // Adds or modifies a profile. If |jguid| is an empty string, we are creating 42 // a new profile. Else we are updating an existing profile. Always returns 43 // the GUID for this profile; the GUID it may have just been created. 44 base::android::ScopedJavaLocalRef<jstring> SetProfile(JNIEnv* env, 45 jobject unused_obj, 46 jobject jprofile); 47 48 // Credit Card Profiles 49 // -------------------- 50 51 // Returns the number of credit cards. 52 jint GetCreditCardCount(JNIEnv* unused_env, jobject unused_obj); 53 54 // Returns the credit card as indexed by |index| in the PersonalDataManager's 55 // |credit_cards()| collection. 56 base::android::ScopedJavaLocalRef<jobject> GetCreditCardByIndex( 57 JNIEnv* env, 58 jobject unused_obj, 59 jint index); 60 61 // Returns the credit card with the specified |jguid|, or NULL if there is 62 // no credit card with the specified |jguid|. 63 base::android::ScopedJavaLocalRef<jobject> GetCreditCardByGUID( 64 JNIEnv* env, 65 jobject unused_obj, 66 jstring jguid); 67 68 // Adds or modifies a credit card. If |jguid| is an empty string, we are 69 // creating a new profile. Else we are updating an existing profile. Always 70 // returns the GUID for this profile; the GUID it may have just been created. 71 base::android::ScopedJavaLocalRef<jstring> SetCreditCard( 72 JNIEnv* env, 73 jobject unused_obj, 74 jobject jcard); 75 76 // Removes the profile or credit card represented by |jguid|. 77 void RemoveByGUID(JNIEnv* env, jobject unused_obj, jstring jguid); 78 79 // PersonalDataManagerObserver: 80 virtual void OnPersonalDataChanged() OVERRIDE; 81 82 // Registers the JNI bindings for this class. 83 static bool Register(JNIEnv* env); 84 85 private: 86 virtual ~PersonalDataManagerAndroid(); 87 88 // Pointer to the java counterpart. 89 JavaObjectWeakGlobalRef weak_java_obj_; 90 91 // Pointer to the PersonalDataManager for the main profile. 92 PersonalDataManager* personal_data_manager_; 93 94 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); 95}; 96 97#endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ 98