| 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 #include "chrome/browser/autofill/personal_data_manager.h" | 5 #include "chrome/browser/autofill/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/api/prefs/pref_service_base.h" |
| 14 #include "chrome/browser/api/sync/profile_sync_service_base.h" |
| 15 #include "chrome/browser/api/webdata/autofill_web_data_service.h" |
| 13 #include "chrome/browser/autofill/autofill-inl.h" | 16 #include "chrome/browser/autofill/autofill-inl.h" |
| 14 #include "chrome/browser/autofill/autofill_field.h" | 17 #include "chrome/browser/autofill/autofill_field.h" |
| 15 #include "chrome/browser/autofill/autofill_metrics.h" | 18 #include "chrome/browser/autofill/autofill_metrics.h" |
| 16 #include "chrome/browser/autofill/autofill_regexes.h" | 19 #include "chrome/browser/autofill/autofill_regexes.h" |
| 17 #include "chrome/browser/autofill/form_structure.h" | 20 #include "chrome/browser/autofill/form_structure.h" |
| 18 #include "chrome/browser/autofill/personal_data_manager_observer.h" | 21 #include "chrome/browser/autofill/personal_data_manager_observer.h" |
| 19 #include "chrome/browser/autofill/phone_number.h" | 22 #include "chrome/browser/autofill/phone_number.h" |
| 20 #include "chrome/browser/autofill/phone_number_i18n.h" | 23 #include "chrome/browser/autofill/phone_number_i18n.h" |
| 21 #include "chrome/browser/autofill/select_control_handler.h" | 24 #include "chrome/browser/autofill/select_control_handler.h" |
| 22 #include "chrome/browser/api/prefs/pref_service_base.h" | |
| 23 #include "chrome/browser/profiles/profile.h" | |
| 24 #include "chrome/browser/sync/profile_sync_service.h" | |
| 25 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 26 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "content/public/browser/browser_context.h" |
| 28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
| 30 | 30 |
| 31 using content::BrowserContext; | 31 using content::BrowserContext; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 template<typename T> | 35 template<typename T> |
| 36 class FormGroupMatchesByGUIDFunctor { | 36 class FormGroupMatchesByGUIDFunctor { |
| 37 public: | 37 public: |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 std::vector<AutofillProfile*> profile_pointers(web_profiles_.size()); | 159 std::vector<AutofillProfile*> profile_pointers(web_profiles_.size()); |
| 160 std::copy(web_profiles_.begin(), web_profiles_.end(), | 160 std::copy(web_profiles_.begin(), web_profiles_.end(), |
| 161 profile_pointers.begin()); | 161 profile_pointers.begin()); |
| 162 AutofillProfile::AdjustInferredLabels(&profile_pointers); | 162 AutofillProfile::AdjustInferredLabels(&profile_pointers); |
| 163 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_, | 163 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_, |
| 164 OnPersonalDataChanged()); | 164 OnPersonalDataChanged()); |
| 165 | 165 |
| 166 // As all Autofill data is ready, the Autocomplete data is ready as well. | 166 // As all Autofill data is ready, the Autocomplete data is ready as well. |
| 167 // If sync is not set, cull older entries of the autocomplete. Otherwise, | 167 // If sync is not set, cull older entries of the autocomplete. Otherwise, |
| 168 // the entries will be culled when sync is connected. | 168 // the entries will be culled when sync is connected. |
| 169 ProfileSyncService* sync_service = | 169 ProfileSyncServiceBase* sync_service = |
| 170 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 170 ProfileSyncServiceBase::ForContext(browser_context_); |
| 171 static_cast<Profile*>(browser_context_)); | |
| 172 if (sync_service && (!sync_service->HasSyncSetupCompleted() || | 171 if (sync_service && (!sync_service->HasSyncSetupCompleted() || |
| 173 !PrefServiceBase::ForContext( | 172 !PrefServiceBase::ForContext( |
| 174 browser_context_)->GetBoolean( | 173 browser_context_)->GetBoolean( |
| 175 prefs::kSyncAutofill))) { | 174 prefs::kSyncAutofill))) { |
| 176 scoped_ptr<AutofillWebDataService> service( | 175 scoped_ptr<AutofillWebDataService> service( |
| 177 AutofillWebDataService::ForContext(browser_context_)); | 176 AutofillWebDataService::ForContext(browser_context_)); |
| 178 if (service.get()) | 177 if (service.get()) |
| 179 service->RemoveExpiredFormElements(); | 178 service->RemoveExpiredFormElements(); |
| 180 } | 179 } |
| 181 } | 180 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 201 if (!browser_context_ || browser_context_->IsOffTheRecord()) | 200 if (!browser_context_ || browser_context_->IsOffTheRecord()) |
| 202 return; | 201 return; |
| 203 | 202 |
| 204 scoped_ptr<AutofillWebDataService> autofill_data( | 203 scoped_ptr<AutofillWebDataService> autofill_data( |
| 205 AutofillWebDataService::ForContext(browser_context_)); | 204 AutofillWebDataService::ForContext(browser_context_)); |
| 206 if (!autofill_data.get()) { | 205 if (!autofill_data.get()) { |
| 207 NOTREACHED(); | 206 NOTREACHED(); |
| 208 return; | 207 return; |
| 209 } | 208 } |
| 210 | 209 |
| 211 ProfileSyncService* sync_service = | 210 ProfileSyncServiceBase* sync_service = |
| 212 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 211 ProfileSyncServiceBase::ForContext(browser_context_); |
| 213 static_cast<Profile*>(browser_context_)); | |
| 214 if (!sync_service) | 212 if (!sync_service) |
| 215 return; | 213 return; |
| 216 | 214 |
| 217 if (sync_service->ShouldPushChanges()) { | 215 if (sync_service->ShouldPushChanges()) { |
| 218 autofill_data->EmptyMigrationTrash(true); | 216 autofill_data->EmptyMigrationTrash(true); |
| 219 sync_service->RemoveObserver(this); | 217 sync_service->RemoveObserver(this); |
| 220 } | 218 } |
| 221 } | 219 } |
| 222 | 220 |
| 223 void PersonalDataManager::Shutdown() { | 221 void PersonalDataManager::Shutdown() { |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 if (!browser_context_ || browser_context_->IsOffTheRecord()) | 915 if (!browser_context_ || browser_context_->IsOffTheRecord()) |
| 918 return; | 916 return; |
| 919 | 917 |
| 920 scoped_ptr<AutofillWebDataService> autofill_data( | 918 scoped_ptr<AutofillWebDataService> autofill_data( |
| 921 AutofillWebDataService::ForContext(browser_context_)); | 919 AutofillWebDataService::ForContext(browser_context_)); |
| 922 if (!autofill_data.get()) { | 920 if (!autofill_data.get()) { |
| 923 NOTREACHED(); | 921 NOTREACHED(); |
| 924 return; | 922 return; |
| 925 } | 923 } |
| 926 | 924 |
| 927 ProfileSyncService* sync_service = | 925 ProfileSyncServiceBase* sync_service = |
| 928 ProfileSyncServiceFactory::GetInstance()->GetForProfile( | 926 ProfileSyncServiceBase::ForContext(browser_context_); |
| 929 static_cast<Profile*>(browser_context_)); | |
| 930 if (!sync_service) | 927 if (!sync_service) |
| 931 return; | 928 return; |
| 932 | 929 |
| 933 if (!sync_service->HasSyncSetupCompleted()) { | 930 if (!sync_service->HasSyncSetupCompleted()) { |
| 934 autofill_data->EmptyMigrationTrash(false); | 931 autofill_data->EmptyMigrationTrash(false); |
| 935 } else if (sync_service->ShouldPushChanges()) { | 932 } else if (sync_service->ShouldPushChanges()) { |
| 936 autofill_data->EmptyMigrationTrash(true); | 933 autofill_data->EmptyMigrationTrash(true); |
| 937 } else { | 934 } else { |
| 938 // Install ourself as a listener so we can empty the trash once the | 935 // Install ourself as a listener so we can empty the trash once the |
| 939 // sync service becomes available. | 936 // sync service becomes available. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 950 } | 947 } |
| 951 | 948 |
| 952 const AutofillMetrics* PersonalDataManager::metric_logger() const { | 949 const AutofillMetrics* PersonalDataManager::metric_logger() const { |
| 953 return metric_logger_.get(); | 950 return metric_logger_.get(); |
| 954 } | 951 } |
| 955 | 952 |
| 956 void PersonalDataManager::set_metric_logger( | 953 void PersonalDataManager::set_metric_logger( |
| 957 const AutofillMetrics* metric_logger) { | 954 const AutofillMetrics* metric_logger) { |
| 958 metric_logger_.reset(metric_logger); | 955 metric_logger_.reset(metric_logger); |
| 959 } | 956 } |
| OLD | NEW |