| OLD | NEW | 
|    1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2012 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 COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ |    5 #ifndef COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ | 
|    6 #define COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ |    6 #define COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ | 
|    7  |    7  | 
|    8 #include <set> |    8 #include <set> | 
|    9 #include <vector> |    9 #include <vector> | 
|   10  |   10  | 
|   11 #include "base/basictypes.h" |   11 #include "base/basictypes.h" | 
|   12 #include "base/memory/scoped_ptr.h" |   12 #include "base/memory/scoped_ptr.h" | 
|   13 #include "base/memory/scoped_vector.h" |   13 #include "base/memory/scoped_vector.h" | 
|   14 #include "base/observer_list.h" |   14 #include "base/observer_list.h" | 
|   15 #include "base/string16.h" |   15 #include "base/string16.h" | 
|   16 #include "chrome/browser/api/webdata/web_data_service_consumer.h" |   16 #include "chrome/browser/api/webdata/web_data_service_consumer.h" | 
 |   17 #include "chrome/browser/webdata/autofill_web_data_service_observer.h" | 
|   17 #include "components/autofill/browser/autofill_profile.h" |   18 #include "components/autofill/browser/autofill_profile.h" | 
|   18 #include "components/autofill/browser/credit_card.h" |   19 #include "components/autofill/browser/credit_card.h" | 
|   19 #include "components/autofill/browser/field_types.h" |   20 #include "components/autofill/browser/field_types.h" | 
|   20 #include "content/public/browser/notification_observer.h" |  | 
|   21 #include "content/public/browser/notification_registrar.h" |  | 
|   22  |   21  | 
|   23 class AutofillMetrics; |   22 class AutofillMetrics; | 
|   24 class FormStructure; |   23 class FormStructure; | 
|   25 class PersonalDataManagerObserver; |   24 class PersonalDataManagerObserver; | 
|   26  |   25  | 
|   27 namespace autofill_helper { |   26 namespace autofill_helper { | 
|   28 void SetProfiles(int, std::vector<AutofillProfile>*); |   27 void SetProfiles(int, std::vector<AutofillProfile>*); | 
|   29 void SetCreditCards(int, std::vector<CreditCard>*); |   28 void SetCreditCards(int, std::vector<CreditCard>*); | 
|   30 } |   29 } | 
|   31  |   30  | 
|   32 namespace content { |   31 namespace content { | 
|   33 class BrowserContext; |   32 class BrowserContext; | 
|   34 } |   33 } | 
|   35  |   34  | 
|   36 // Handles loading and saving Autofill profile information to the web database. |   35 // Handles loading and saving Autofill profile information to the web database. | 
|   37 // This class also stores the profiles loaded from the database for use during |   36 // This class also stores the profiles loaded from the database for use during | 
|   38 // Autofill. |   37 // Autofill. | 
|   39 class PersonalDataManager : public WebDataServiceConsumer, |   38 class PersonalDataManager : public WebDataServiceConsumer, | 
|   40                             public content::NotificationObserver { |   39                             public AutofillWebDataServiceObserverOnUIThread { | 
|   41  public: |   40  public: | 
|   42   // A pair of GUID and variant index. Represents a single FormGroup and a |   41   // A pair of GUID and variant index. Represents a single FormGroup and a | 
|   43   // specific data variant. |   42   // specific data variant. | 
|   44   typedef std::pair<std::string, size_t> GUIDPair; |   43   typedef std::pair<std::string, size_t> GUIDPair; | 
|   45  |   44  | 
|   46   PersonalDataManager(); |   45   PersonalDataManager(); | 
|   47   virtual ~PersonalDataManager(); |   46   virtual ~PersonalDataManager(); | 
|   48  |   47  | 
|   49   // Kicks off asynchronous loading of profiles and credit cards. |   48   // Kicks off asynchronous loading of profiles and credit cards. | 
|   50   void Init(content::BrowserContext* context); |   49   void Init(content::BrowserContext* context); | 
|   51  |   50  | 
|   52   // WebDataServiceConsumer: |   51   // WebDataServiceConsumer: | 
|   53   virtual void OnWebDataServiceRequestDone( |   52   virtual void OnWebDataServiceRequestDone( | 
|   54       WebDataServiceBase::Handle h, |   53       WebDataServiceBase::Handle h, | 
|   55       const WDTypedResult* result) OVERRIDE; |   54       const WDTypedResult* result) OVERRIDE; | 
|   56  |   55  | 
 |   56   // AutofillWebDataServiceObserverOnUIThread: | 
 |   57   virtual void AutofillMultipleChanged() OVERRIDE; | 
 |   58  | 
|   57   // Adds a listener to be notified of PersonalDataManager events. |   59   // Adds a listener to be notified of PersonalDataManager events. | 
|   58   virtual void AddObserver(PersonalDataManagerObserver* observer); |   60   virtual void AddObserver(PersonalDataManagerObserver* observer); | 
|   59  |   61  | 
|   60   // Removes |observer| as an observer of this PersonalDataManager. |   62   // Removes |observer| as an observer of this PersonalDataManager. | 
|   61   virtual void RemoveObserver(PersonalDataManagerObserver* observer); |   63   virtual void RemoveObserver(PersonalDataManagerObserver* observer); | 
|   62  |   64  | 
|   63   // content::NotificationObserver: |  | 
|   64   // Observes "batch" changes made by Sync and refreshes data from the |  | 
|   65   // WebDataServiceBase in response. |  | 
|   66   virtual void Observe(int type, |  | 
|   67                        const content::NotificationSource& source, |  | 
|   68                        const content::NotificationDetails& details) OVERRIDE; |  | 
|   69  |  | 
|   70   // Scans the given |form| for importable Autofill data. If the form includes |   65   // Scans the given |form| for importable Autofill data. If the form includes | 
|   71   // sufficient address data, it is immediately imported. If the form includes |   66   // sufficient address data, it is immediately imported. If the form includes | 
|   72   // sufficient credit card data, it is stored into |credit_card|, so that we |   67   // sufficient credit card data, it is stored into |credit_card|, so that we | 
|   73   // can prompt the user whether to save this data. |   68   // can prompt the user whether to save this data. | 
|   74   // Returns |true| if sufficient address or credit card data was found. |   69   // Returns |true| if sufficient address or credit card data was found. | 
|   75   bool ImportFormData(const FormStructure& form, |   70   bool ImportFormData(const FormStructure& form, | 
|   76                       const CreditCard** credit_card); |   71                       const CreditCard** credit_card); | 
|   77  |   72  | 
|   78   // Saves |imported_profile| to the WebDB if it exists. |   73   // Saves |imported_profile| to the WebDB if it exists. | 
|   79   virtual void SaveImportedProfile(const AutofillProfile& imported_profile); |   74   virtual void SaveImportedProfile(const AutofillProfile& imported_profile); | 
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  266   ObserverList<PersonalDataManagerObserver> observers_; |  261   ObserverList<PersonalDataManagerObserver> observers_; | 
|  267  |  262  | 
|  268  private: |  263  private: | 
|  269  |  264  | 
|  270   // For logging UMA metrics. Overridden by metrics tests. |  265   // For logging UMA metrics. Overridden by metrics tests. | 
|  271   scoped_ptr<const AutofillMetrics> metric_logger_; |  266   scoped_ptr<const AutofillMetrics> metric_logger_; | 
|  272  |  267  | 
|  273   // Whether we have already logged the number of profiles this session. |  268   // Whether we have already logged the number of profiles this session. | 
|  274   mutable bool has_logged_profile_count_; |  269   mutable bool has_logged_profile_count_; | 
|  275  |  270  | 
|  276   // Manages registration lifetime for NotificationObserver implementation. |  | 
|  277   content::NotificationRegistrar notification_registrar_; |  | 
|  278  |  | 
|  279   DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); |  271   DISALLOW_COPY_AND_ASSIGN(PersonalDataManager); | 
|  280 }; |  272 }; | 
|  281  |  273  | 
|  282 #endif  // COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ |  274 #endif  // COMPONENTS_AUTOFILL_BROWSER_PERSONAL_DATA_MANAGER_H_ | 
| OLD | NEW |