1dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be
3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file.
4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_
6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_
73345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once
8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <set>
10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <vector>
11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
12a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian Monsen#ifdef ANDROID
13a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian Monsen#include "base/base_api.h"
14a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian Monsen#endif
15ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/memory/ref_counted.h"
16ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/memory/scoped_ptr.h"
17ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "base/memory/scoped_vector.h"
18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/observer_list.h"
19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/string16.h"
20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/autofill/autofill_profile.h"
21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/autofill/credit_card.h"
22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/autofill/field_types.h"
23ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen#include "chrome/browser/sync/profile_sync_service_observer.h"
24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/webdata/web_data_service.h"
25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
26dc0f95d653279beabeb9817299e2902918ba123eKristian Monsenclass AutofillManager;
27dc0f95d653279beabeb9817299e2902918ba123eKristian Monsenclass AutofillMetrics;
28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass FormStructure;
29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass Profile;
30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
31ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// Handles loading and saving Autofill profile information to the web database.
32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This class also stores the profiles loaded from the database for use during
33ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// Autofill.
34a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian Monsenclass
35a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian Monsen#ifdef ANDROID
36a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian MonsenBASE_API
37a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian Monsen#endif
38a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian MonsenPersonalDataManager
39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    : public WebDataServiceConsumer,
40ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen      public ProfileSyncServiceObserver,
41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch      public base::RefCountedThreadSafe<PersonalDataManager> {
42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public:
43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // An interface the PersonalDataManager uses to notify its clients (observers)
44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // when it has finished loading personal data from the web database.  Register
45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // the observer via PersonalDataManager::SetObserver.
46a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian Monsen  class
47a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian Monsen#ifdef ANDROID
48a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian MonsenBASE_API
49a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian Monsen#endif
50a1fe9c0450e6d56112949b33ef2f7491e0cf0f60Kristian Monsen  Observer {
51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch   public:
52c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Notifies the observer that the PersonalDataManager has finished loading.
53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // TODO: OnPersonalDataLoaded should be nuked in favor of only
54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // OnPersonalDataChanged.
55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnPersonalDataLoaded() = 0;
56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    // Notifies the observer that the PersonalDataManager changed in some way.
58c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual void OnPersonalDataChanged() {}
59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch   protected:
61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch    virtual ~Observer() {}
62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  };
63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // WebDataServiceConsumer implementation:
65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                           const WDTypedResult* result);
67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Sets the listener to be notified of PersonalDataManager events.
69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void SetObserver(PersonalDataManager::Observer* observer);
70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Removes |observer| as the observer of this PersonalDataManager.
72c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void RemoveObserver(PersonalDataManager::Observer* observer);
73c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
74ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // ProfileSyncServiceObserver:
75ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void OnStateChanged();
76ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
7772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen        // TODO(isherman): Update this comment
78ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // If Autofill is able to determine the field types of a significant number of
79c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // field types that contain information in the FormStructures a profile will
80c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // be created with all of the information from recognized fields. Returns
81c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // whether a profile was created.
8272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  bool ImportFormData(const std::vector<const FormStructure*>& form_structures,
8372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen                      const CreditCard** credit_card);
84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Saves a credit card value detected in |ImportedFormData|.
86ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void SaveImportedCreditCard(const CreditCard& imported_credit_card);
87c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
88c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Sets |web_profiles_| to the contents of |profiles| and updates the web
89513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  // database by adding, updating and removing profiles.
90c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  //
91c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The relationship between this and Refresh is subtle.
92731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // A call to |SetProfiles| could include out-of-date data that may conflict
93ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // if we didn't refresh-to-latest before an Autofill window was opened for
94731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick  // editing. |SetProfiles| is implemented to make a "best effort" to apply the
95c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // changes, but in extremely rare edge cases it is possible not all of the
96c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // updates in |profiles| make it to the DB.  This is why SetProfiles will
97c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // invoke Refresh after finishing, to ensure we get into a
98c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // consistent state.  See Refresh for details.
99ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void SetProfiles(std::vector<AutofillProfile>* profiles);
100c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
101c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Sets |credit_cards_| to the contents of |credit_cards| and updates the web
102513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  // database by adding, updating and removing credit cards.
103c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void SetCreditCards(std::vector<CreditCard>* credit_cards);
104c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
1053345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Adds |profile| to the web database.
106ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void AddProfile(const AutofillProfile& profile);
1073345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
1083345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Updates |profile| which already exists in the web database.
109ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void UpdateProfile(const AutofillProfile& profile);
1103345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
111513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  // Removes the profile represented by |guid|.
112513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  void RemoveProfile(const std::string& guid);
1133345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
114513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  // Returns the profile with the specified |guid|, or NULL if there is no
115513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  // profile with the specified |guid|.
116ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  AutofillProfile* GetProfileByGUID(const std::string& guid);
117731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick
1183345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Adds |credit_card| to the web database.
1193345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void AddCreditCard(const CreditCard& credit_card);
1203345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
1213345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  // Updates |credit_card| which already exists in the web database.
1223345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick  void UpdateCreditCard(const CreditCard& credit_card);
1233345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
124513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  // Removes the credit card represented by |guid|.
125513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  void RemoveCreditCard(const std::string& guid);
126513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch
127513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  // Returns the credit card with the specified |guid|, or NULL if there is
128513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  // no credit card with the specified |guid|.
129513209b27ff55e2841eac0e4120199c23acce758Ben Murdoch  CreditCard* GetCreditCardByGUID(const std::string& guid);
1303345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick
131c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Gets the possible field types for the given text, determined by matching
132c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // the text with all known personal information and returning matching types.
133c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void GetPossibleFieldTypes(const string16& text,
134c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                             FieldTypeSet* possible_types);
135c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
136c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns true if the credit card information is stored with a password.
137c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool HasPassword();
138c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
139c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Returns whether the personal data has been loaded from the web database.
14021d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual bool IsDataLoaded() const;
141c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
142c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // This PersonalDataManager owns these profiles and credit cards.  Their
143c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // lifetime is until the web database is updated with new profile and credit
144c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // card information, respectively.  |profiles()| returns both web and
145c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // auxiliary profiles.  |web_profiles()| returns only web profiles.
146ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  const std::vector<AutofillProfile*>& profiles();
147ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual const std::vector<AutofillProfile*>& web_profiles();
14821d179b334e59e9a3bfcaed4c4430bef1bc5759dKristian Monsen  virtual const std::vector<CreditCard*>& credit_cards();
149c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
150c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Re-loads profiles and credit cards from the WebDatabase asynchronously.
151c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // In the general case, this is a no-op and will re-create the same
152c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // in-memory model as existed prior to the call.  If any change occurred to
153c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // profiles in the WebDatabase directly, as is the case if the browser sync
154c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // engine processed a change from the cloud, we will learn of these as a
155c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // result of this call.
156c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  //
157c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Also see SetProfile for more details.
158c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void Refresh();
159c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
160c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Kicks off asynchronous loading of profiles and credit cards.
161c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void Init(Profile* profile);
162c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
163ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Checks suitability of |profile| for adding to the user's set of profiles.
164ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  static bool IsValidLearnableProfile(const AutofillProfile& profile);
165ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
166ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Merges |profile| into one of the |existing_profiles| if possible; otherwise
167ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // appends |profile| to the end of that list. Fills |merged_profiles| with the
168ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // result.
169ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  static bool MergeProfile(
170ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen      const AutofillProfile& profile,
171ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen      const std::vector<AutofillProfile*>& existing_profiles,
172ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen      std::vector<AutofillProfile>* merged_profiles);
173ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
174c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch protected:
175c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Make sure that only Profile and certain tests can create an instance of
176c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // PersonalDataManager.
177c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  friend class base::RefCountedThreadSafe<PersonalDataManager>;
178ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  friend class AutofillMergeTest;
179c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  friend class PersonalDataManagerTest;
180c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  friend class ProfileImpl;
181c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  friend class ProfileSyncServiceAutofillTest;
1827d214dfa174224b459660971e5b5cce2e06be02aBen Murdoch#ifdef ANDROID
1837d214dfa174224b459660971e5b5cce2e06be02aBen Murdoch  friend class ProfileImplAndroid;
1847d214dfa174224b459660971e5b5cce2e06be02aBen Murdoch#endif
185c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
186c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  PersonalDataManager();
18772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  virtual ~PersonalDataManager();
188c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
189c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Loads the saved profiles from the web database.
190c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void LoadProfiles();
191c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
192c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Loads the auxiliary profiles.  Currently Mac only.
193c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void LoadAuxiliaryProfiles();
194c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
195c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Loads the saved credit cards from the web database.
196c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  virtual void LoadCreditCards();
197c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
198c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Receives the loaded profiles from the web data service and stores them in
199c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // |credit_cards_|.
200c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void ReceiveLoadedProfiles(WebDataService::Handle h,
201c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                             const WDTypedResult* result);
202c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
203c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Receives the loaded credit cards from the web data service and stores them
204c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // in |credit_cards_|.
205c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void ReceiveLoadedCreditCards(WebDataService::Handle h,
206c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch                                const WDTypedResult* result);
207c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
208c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Cancels a pending query to the web database.  |handle| is a pointer to the
209c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // query handle.
210c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  void CancelPendingQuery(WebDataService::Handle* handle);
211c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
21272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Saves |imported_profile| to the WebDB if it exists.
213ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual void SaveImportedProfile(const AutofillProfile& imported_profile);
21472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
215ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Notifies Sync about data migration if necessary.
216ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  void EmptyMigrationTrash();
217c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
218dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // The first time this is called, logs an UMA metrics for the number of
219dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // profiles the user has. On subsequent calls, does nothing.
220dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  void LogProfileCount() const;
221dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
222ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Returns the value of the AutofillEnabled pref.
223ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  virtual bool IsAutofillEnabled() const;
224ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
225dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // For tests.
226dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  const AutofillMetrics* metric_logger() const;
227dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  void set_metric_logger(const AutofillMetrics* metric_logger);
228dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
229c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The profile hosting this PersonalDataManager.
230c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  Profile* profile_;
231c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
232c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // True if personal data has been loaded from the web database.
233c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  bool is_data_loaded_;
234c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
235c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The loaded web profiles.
236ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  ScopedVector<AutofillProfile> web_profiles_;
237c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
238c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Auxiliary profiles.
239ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  ScopedVector<AutofillProfile> auxiliary_profiles_;
240c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
241c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // Storage for combined web and auxiliary profiles.  Contents are weak
242c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // references.  Lifetime managed by |web_profiles_| and |auxiliary_profiles_|.
243ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  std::vector<AutofillProfile*> profiles_;
244c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
245c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The loaded credit cards.
246c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  ScopedVector<CreditCard> credit_cards_;
247c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
248c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The hash of the password used to store the credit card.  This is empty if
249c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // no password exists.
250c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  string16 password_hash_;
251c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
252c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // When the manager makes a request from WebDataService, the database
253c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // is queried on another thread, we record the query handle until we
254c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // get called back.  We store handles for both profile and credit card queries
255c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // so they can be loaded at the same time.
256c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  WebDataService::Handle pending_profiles_query_;
257c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  WebDataService::Handle pending_creditcards_query_;
258c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
259c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  // The observers.
260c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  ObserverList<Observer> observers_;
261c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
262dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen private:
263dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  // For logging UMA metrics. Overridden by metrics tests.
264dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen  scoped_ptr<const AutofillMetrics> metric_logger_;
265dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen
266ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  // Whether we have already logged the number of profiles this session.
267ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen  mutable bool has_logged_profile_count_;
268ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen
269c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch  DISALLOW_COPY_AND_ASSIGN(PersonalDataManager);
270c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch};
271c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch
272c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif  // CHROME_BROWSER_AUTOFILL_PERSONAL_DATA_MANAGER_H_
273