| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
| 6 #define CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 6 #define CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
| 7 | 7 |
| 8 #include "base/android/jni_weak_ref.h" | 8 #include "base/android/jni_weak_ref.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "components/autofill/core/browser/personal_data_manager.h" | 11 #include "components/autofill/core/browser/personal_data_manager.h" |
| 12 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 12 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 13 | 13 |
| 14 namespace autofill { | 14 namespace autofill { |
| 15 | 15 |
| 16 // Android wrapper of the PersonalDataManager which provides access from the | 16 // Android wrapper of the PersonalDataManager which provides access from the |
| 17 // Java layer. Note that on Android, there's only a single profile, and | 17 // Java layer. Note that on Android, there's only a single profile, and |
| 18 // therefore a single instance of this wrapper. | 18 // therefore a single instance of this wrapper. |
| 19 class PersonalDataManagerAndroid : public PersonalDataManagerObserver { | 19 class PersonalDataManagerAndroid : public PersonalDataManagerObserver { |
| 20 public: | 20 public: |
| 21 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); | 21 PersonalDataManagerAndroid(JNIEnv* env, jobject obj); |
| 22 | 22 |
| 23 // These functions act on "web profiles" aka "LOCAL_PROFILE" profiles. | 23 // These functions act on "web profiles" aka "LOCAL_PROFILE" profiles. |
| 24 // ------------------------- | 24 // ------------------------- |
| 25 | 25 |
| 26 // Returns the number of web and auxiliary profiles. | 26 // Returns the GUIDs of all profiles. |
| 27 jint GetProfileCount(JNIEnv* unused_env, | 27 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDsForSettings( |
| 28 const base::android::JavaParamRef<jobject>& unused_obj); | 28 JNIEnv* env, |
| 29 const base::android::JavaParamRef<jobject>& unused_obj); |
| 29 | 30 |
| 30 // Returns the profile as indexed by |index| in the PersonalDataManager's | 31 // Returns the GUIDs of the profiles to suggest to the user. See |
| 31 // |GetProfiles()| collection. | 32 // PersonalDataManager::GetProfilesToSuggest for more details. |
| 32 base::android::ScopedJavaLocalRef<jobject> GetProfileByIndex( | 33 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDsToSuggest( |
| 33 JNIEnv* env, | 34 JNIEnv* env, |
| 34 const base::android::JavaParamRef<jobject>& unused_obj, | 35 const base::android::JavaParamRef<jobject>& unused_obj); |
| 35 jint index); | |
| 36 | 36 |
| 37 // Returns the profile with the specified |jguid|, or NULL if there is no | 37 // Returns the profile with the specified |jguid|, or NULL if there is no |
| 38 // profile with the specified |jguid|. Both web and auxiliary profiles may | 38 // profile with the specified |jguid|. Both web and auxiliary profiles may |
| 39 // be returned. | 39 // be returned. |
| 40 base::android::ScopedJavaLocalRef<jobject> GetProfileByGUID( | 40 base::android::ScopedJavaLocalRef<jobject> GetProfileByGUID( |
| 41 JNIEnv* env, | 41 JNIEnv* env, |
| 42 const base::android::JavaParamRef<jobject>& unused_obj, | 42 const base::android::JavaParamRef<jobject>& unused_obj, |
| 43 const base::android::JavaParamRef<jstring>& jguid); | 43 const base::android::JavaParamRef<jstring>& jguid); |
| 44 | 44 |
| 45 // Adds or modifies a profile. If |jguid| is an empty string, we are creating | 45 // Adds or modifies a profile. If |jguid| is an empty string, we are creating |
| 46 // a new profile. Else we are updating an existing profile. Always returns | 46 // a new profile. Else we are updating an existing profile. Always returns |
| 47 // the GUID for this profile; the GUID it may have just been created. | 47 // the GUID for this profile; the GUID it may have just been created. |
| 48 base::android::ScopedJavaLocalRef<jstring> SetProfile( | 48 base::android::ScopedJavaLocalRef<jstring> SetProfile( |
| 49 JNIEnv* env, | 49 JNIEnv* env, |
| 50 const base::android::JavaParamRef<jobject>& unused_obj, | 50 const base::android::JavaParamRef<jobject>& unused_obj, |
| 51 const base::android::JavaParamRef<jobject>& jprofile); | 51 const base::android::JavaParamRef<jobject>& jprofile); |
| 52 | 52 |
| 53 // Gets the labels for all known profiles. These labels are useful for | 53 // Gets the labels for all known profiles. These labels are useful for |
| 54 // distinguishing the profiles from one another. | 54 // distinguishing the profiles from one another. |
| 55 // | 55 // |
| 56 // The labels never contain the full name and include at least 2 fields. | 56 // The labels never contain the full name and include at least 2 fields. |
| 57 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabelsForSettings( |
| 58 JNIEnv* env, |
| 59 const base::android::JavaParamRef<jobject>& unused_obj); |
| 60 |
| 61 // Gets the labels for the profiles to suggest to the user. These labels are |
| 62 // useful for distinguishing the profiles from one another. |
| 57 // | 63 // |
| 58 // If |address_only| is true, then such fields as phone number and email | 64 // The labels never contain the full name. Fields such as phone number and |
| 59 // address are also omitted, but all fields are included in the label. | 65 // email address are also omitted, but all other fields are included in the |
| 60 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels( | 66 // label. |
| 67 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabelsToSuggest( |
| 61 JNIEnv* env, | 68 JNIEnv* env, |
| 62 const base::android::JavaParamRef<jobject>& unused_obj, | 69 const base::android::JavaParamRef<jobject>& unused_obj); |
| 63 bool address_only); | |
| 64 | 70 |
| 65 // These functions act on local credit cards. | 71 // These functions act on local credit cards. |
| 66 // -------------------- | 72 // -------------------- |
| 67 | 73 |
| 68 // Returns the number of credit cards. | 74 // Returns the GUIDs of all the credit cards. |
| 69 jint GetCreditCardCount( | 75 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDsForSettings( |
| 70 JNIEnv* unused_env, | 76 JNIEnv* env, |
| 71 const base::android::JavaParamRef<jobject>& unused_obj); | 77 const base::android::JavaParamRef<jobject>& unused_obj); |
| 72 | 78 |
| 73 // Returns the credit card as indexed by |index| in the PersonalDataManager's | 79 // Returns the GUIDs of the credit cards to suggest to the user. See |
| 74 // |GetCreditCards()| collection. | 80 // PersonalDataManager::GetCreditCardsToSuggest for more details. |
| 75 base::android::ScopedJavaLocalRef<jobject> GetCreditCardByIndex( | 81 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDsToSuggest( |
| 76 JNIEnv* env, | 82 JNIEnv* env, |
| 77 const base::android::JavaParamRef<jobject>& unused_obj, | 83 const base::android::JavaParamRef<jobject>& unused_obj); |
| 78 jint index); | |
| 79 | 84 |
| 80 // Returns the credit card with the specified |jguid|, or NULL if there is | 85 // Returns the credit card with the specified |jguid|, or NULL if there is |
| 81 // no credit card with the specified |jguid|. | 86 // no credit card with the specified |jguid|. |
| 82 base::android::ScopedJavaLocalRef<jobject> GetCreditCardByGUID( | 87 base::android::ScopedJavaLocalRef<jobject> GetCreditCardByGUID( |
| 83 JNIEnv* env, | 88 JNIEnv* env, |
| 84 const base::android::JavaParamRef<jobject>& unused_obj, | 89 const base::android::JavaParamRef<jobject>& unused_obj, |
| 85 const base::android::JavaParamRef<jstring>& jguid); | 90 const base::android::JavaParamRef<jstring>& jguid); |
| 86 | 91 |
| 87 // Adds or modifies a local credit card. If |jguid| is an empty string, we | 92 // Adds or modifies a local credit card. If |jguid| is an empty string, we |
| 88 // are creating a new card. Else we are updating an existing profile. Always | 93 // are creating a new card. Else we are updating an existing profile. Always |
| (...skipping 27 matching lines...) Expand all Loading... |
| 116 const base::android::JavaParamRef<jobject>& jweb_contents, | 121 const base::android::JavaParamRef<jobject>& jweb_contents, |
| 117 const base::android::JavaParamRef<jstring>& jguid, | 122 const base::android::JavaParamRef<jstring>& jguid, |
| 118 const base::android::JavaParamRef<jobject>& jdelegate); | 123 const base::android::JavaParamRef<jobject>& jdelegate); |
| 119 | 124 |
| 120 // PersonalDataManagerObserver: | 125 // PersonalDataManagerObserver: |
| 121 void OnPersonalDataChanged() override; | 126 void OnPersonalDataChanged() override; |
| 122 | 127 |
| 123 // Registers the JNI bindings for this class. | 128 // Registers the JNI bindings for this class. |
| 124 static bool Register(JNIEnv* env); | 129 static bool Register(JNIEnv* env); |
| 125 | 130 |
| 131 // Sets the use count and use date of the profile associated to the |jguid|. |
| 132 // Both |count| and |date| should be non-negative. |date| represents an |
| 133 // absolute point in coordinated universal time (UTC) represented as |
| 134 // microseconds since the Windows epoch. For more details see the comment |
| 135 // header in time.h. |
| 136 void SetProfileUseStatsForTesting( |
| 137 JNIEnv* env, |
| 138 const base::android::JavaParamRef<jobject>& unused_obj, |
| 139 const base::android::JavaParamRef<jstring>& jguid, |
| 140 jint count, |
| 141 jint date); |
| 142 |
| 143 // Sets the use count and use date of the credit card associated to the |
| 144 // |jguid|. Both |count| and |date| should be non-negative. |date| represents |
| 145 // an absolute point in coordinated universal time (UTC) represented as |
| 146 // microseconds since the Windows epoch. For more details see the comment |
| 147 // header in time.h. |
| 148 void SetCreditCardUseStatsForTesting( |
| 149 JNIEnv* env, |
| 150 const base::android::JavaParamRef<jobject>& unused_obj, |
| 151 const base::android::JavaParamRef<jstring>& jguid, |
| 152 jint count, |
| 153 jint date); |
| 154 |
| 126 private: | 155 private: |
| 127 ~PersonalDataManagerAndroid() override; | 156 ~PersonalDataManagerAndroid() override; |
| 128 | 157 |
| 158 // Returns the GUIDs of the |profiles| passed as parameter. |
| 159 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileGUIDs( |
| 160 JNIEnv* env, |
| 161 const std::vector<AutofillProfile*>& profiles); |
| 162 |
| 163 // Returns the GUIDs of the |credit_cards| passed as parameter. |
| 164 base::android::ScopedJavaLocalRef<jobjectArray> GetCreditCardGUIDs( |
| 165 JNIEnv* env, |
| 166 const std::vector<CreditCard*>& credit_cards); |
| 167 |
| 168 // Gets the labels for the |profiles| passed as parameters. These labels are |
| 169 // useful for distinguishing the profiles from one another. |
| 170 // |
| 171 // The labels never contain the full name and include at least 2 fields. |
| 172 // |
| 173 // If |address_only| is true, then such fields as phone number and email |
| 174 // address are also omitted, but all fields are included in the label. |
| 175 base::android::ScopedJavaLocalRef<jobjectArray> GetProfileLabels( |
| 176 JNIEnv* env, |
| 177 bool address_only, |
| 178 std::vector<AutofillProfile*> profiles); |
| 179 |
| 129 // Pointer to the java counterpart. | 180 // Pointer to the java counterpart. |
| 130 JavaObjectWeakGlobalRef weak_java_obj_; | 181 JavaObjectWeakGlobalRef weak_java_obj_; |
| 131 | 182 |
| 132 // Pointer to the PersonalDataManager for the main profile. | 183 // Pointer to the PersonalDataManager for the main profile. |
| 133 PersonalDataManager* personal_data_manager_; | 184 PersonalDataManager* personal_data_manager_; |
| 134 | 185 |
| 135 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); | 186 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerAndroid); |
| 136 }; | 187 }; |
| 137 | 188 |
| 138 } // namespace autofill | 189 } // namespace autofill |
| 139 | 190 |
| 140 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ | 191 #endif // CHROME_BROWSER_AUTOFILL_ANDROID_PERSONAL_DATA_MANAGER_ANDROID_H_ |
| OLD | NEW |