Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/browser/autofill/personal_data_manager.h

Issue 545175: Add the ability to save and remove AutoFill profiles from the AutoFillDialog.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_PERSONAL_DATA_MANAGER_H_ 5 #ifndef CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_
6 #define CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ 6 #define CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_
7 7
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "base/scoped_vector.h" 12 #include "base/scoped_vector.h"
13 #include "base/string16.h" 13 #include "base/string16.h"
14 #include "chrome/browser/autofill/autofill_profile.h" 14 #include "chrome/browser/autofill/autofill_profile.h"
15 #include "chrome/browser/autofill/credit_card.h" 15 #include "chrome/browser/autofill/credit_card.h"
16 #include "chrome/browser/autofill/field_types.h" 16 #include "chrome/browser/autofill/field_types.h"
17 #include "chrome/browser/webdata/web_data_service.h"
17 18
18 class AutoFillManager; 19 class AutoFillManager;
19 class FormStructure; 20 class FormStructure;
21 class Profile;
20 22
21 // Handles loading and saving AutoFill profile information to the web database. 23 // Handles loading and saving AutoFill profile information to the web database.
22 // This class also stores the profiles loaded from the database for use during 24 // This class also stores the profiles loaded from the database for use during
23 // AutoFill. 25 // AutoFill.
24 class PersonalDataManager { 26 class PersonalDataManager : public WebDataServiceConsumer {
25 public: 27 public:
28 // An interface observers implement to receive notifications from the
29 // PersonalDataManager. Register the observer via
30 // PersonalDataManager::SetObserver.
31 class Observer {
32 public:
33 // Notifies the observer that the PersonalDataManager has finished loading.
34 virtual void OnPersonalDataLoaded() = 0;
35
36 protected:
37 virtual ~Observer() {}
38 };
39
26 virtual ~PersonalDataManager(); 40 virtual ~PersonalDataManager();
27 41
42 // WebDataServiceConsumer implementation:
43 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
44 const WDTypedResult* result);
45
46 // Sets the listener to be notified of PersonalDataManager events.
47 void SetObserver(PersonalDataManager::Observer* observer);
48
49 // Removes |observer| as the observer of this PersonalDataManager.
50 void RemoveObserver(PersonalDataManager::Observer* observer);
51
28 // If AutoFill is able to determine the field types of a significant number 52 // If AutoFill is able to determine the field types of a significant number
29 // of field types that contain information in the FormStructures and the user 53 // of field types that contain information in the FormStructures and the user
30 // has not previously been prompted, the user will be asked if he would like 54 // has not previously been prompted, the user will be asked if he would like
31 // to import the data. If the user selects yes, a profile will be created 55 // to import the data. If the user selects yes, a profile will be created
32 // with all of the information from recognized fields. 56 // with all of the information from recognized fields.
33 bool ImportFormData(const std::vector<FormStructure*>& form_structures, 57 bool ImportFormData(const std::vector<FormStructure*>& form_structures,
34 AutoFillManager* autofill_manager); 58 AutoFillManager* autofill_manager);
35 59
60 // Sets |profiles_| to the contents of |profiles| and updates the web database
61 // by adding, updating and removing profiles.
62 void SetProfiles(std::vector<AutoFillProfile>* profiles);
63
36 // Gets the possible field types for the given text, determined by matching 64 // Gets the possible field types for the given text, determined by matching
37 // the text with all known personal information and returning matching types. 65 // the text with all known personal information and returning matching types.
38 void GetPossibleFieldTypes(const string16& text, 66 void GetPossibleFieldTypes(const string16& text,
39 FieldTypeSet* possible_types); 67 FieldTypeSet* possible_types);
40 68
41 // Returns true if the credit card information is stored with a password. 69 // Returns true if the credit card information is stored with a password.
42 bool HasPassword(); 70 bool HasPassword();
43 71
72 // Returns whether the personal data has been loaded from the web database.
73 bool IsDataLoaded() const { return is_data_loaded_; }
74
75 // This PersonalDataManager owns these profiles. Their lifetime is until the
76 // web database is updated with new profile information.
77 const std::vector<AutoFillProfile*>& profiles() { return profiles_.get(); }
78
44 private: 79 private:
45 // Make sure that only Profile can create an instance of PersonalDataManager. 80 // Make sure that only Profile and the PersonalDataManager tests can create an
81 // instance of PersonalDataManager.
46 friend class ProfileImpl; 82 friend class ProfileImpl;
83 friend class PersonalDataManagerTest;
47 84
48 PersonalDataManager(); 85 explicit PersonalDataManager(Profile* profile);
86
87 // Returns the profile of the tab contents.
88 Profile* profile();
49 89
50 // Initializes the object if needed. This should be called at the beginning 90 // Initializes the object if needed. This should be called at the beginning
51 // of all the public functions to make sure that the object has been properly 91 // of all the public functions to make sure that the object has been properly
52 // initialized before use. 92 // initialized before use.
53 void InitializeIfNeeded(); 93 void InitializeIfNeeded();
54 94
55 // This will create and reserve a new unique id for a profile. 95 // This will create and reserve a new unique ID for a profile.
56 int CreateNextUniqueId(); 96 int CreateNextUniqueID();
57 97
58 // Parses value to extract the components of a phone number and adds them to 98 // Parses value to extract the components of a phone number and adds them to
59 // profile. 99 // profile.
60 // 100 //
61 // TODO(jhawkins): Investigate if this can be moved to PhoneField. 101 // TODO(jhawkins): Investigate if this can be moved to PhoneField.
62 void ParsePhoneNumber(AutoFillProfile* profile, 102 void ParsePhoneNumber(AutoFillProfile* profile,
63 string16* value, 103 string16* value,
64 AutoFillFieldType number, 104 AutoFillFieldType number,
65 AutoFillFieldType city_code, 105 AutoFillFieldType city_code,
66 AutoFillFieldType country_code) const; 106 AutoFillFieldType country_code) const;
67 107
108 // Loads the saved profiles from the web database.
109 void LoadProfiles();
110
111 // Cancels a pending query to the web database.
112 void CancelPendingQuery();
113
114 // The profile hosting this PersonalDataManager.
115 Profile* profile_;
116
68 // True if PersonalDataManager is initialized. 117 // True if PersonalDataManager is initialized.
69 bool is_initialized_; 118 bool is_initialized_;
70 119
120 // True if personal data has been loaded from the web database.
121 bool is_data_loaded_;
122
71 // The set of already created unique IDs, used to create a new unique ID. 123 // The set of already created unique IDs, used to create a new unique ID.
72 std::set<int> unique_ids_; 124 std::set<int> unique_ids_;
73 125
74 // The loaded profiles. 126 // The loaded profiles.
75 ScopedVector<FormGroup> profiles_; 127 ScopedVector<AutoFillProfile> profiles_;
76 128
77 // The loaded credit cards. 129 // The loaded credit cards.
78 ScopedVector<FormGroup> credit_cards_; 130 ScopedVector<FormGroup> credit_cards_;
79 131
80 // The profile that is imported from a web form by ImportFormData. 132 // The profile that is imported from a web form by ImportFormData.
81 scoped_ptr<AutoFillProfile> imported_profile_; 133 scoped_ptr<AutoFillProfile> imported_profile_;
82 134
83 // The credit card that is imported from a web form by ImportFormData. 135 // The credit card that is imported from a web form by ImportFormData.
84 scoped_ptr<CreditCard> imported_credit_card_; 136 scoped_ptr<CreditCard> imported_credit_card_;
85 137
86 // The hash of the password used to store the credit card. This is empty if 138 // The hash of the password used to store the credit card. This is empty if
87 // no password exists. 139 // no password exists.
88 string16 password_hash_; 140 string16 password_hash_;
141
142 // When the manager makes a request from WebDataService, the database
143 // is queried on another thread, we record the query handle until we
144 // get called back.
145 WebDataService::Handle pending_query_handle_;
146
147 // The observer. This can be NULL.
148 Observer* observer_;
149
150 DISALLOW_COPY_AND_ASSIGN(PersonalDataManager);
89 }; 151 };
90 152
91 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_ 153 #endif // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_profile.cc ('k') | chrome/browser/autofill/personal_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698