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