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