| 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/autofill_manager.h" | 5 #include "chrome/browser/autofill/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/guid.h" | 16 #include "base/guid.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/string16.h" | 18 #include "base/string16.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "chrome/browser/api/infobars/infobar_service.h" | 22 #include "chrome/browser/api/infobars/infobar_service.h" |
| 23 #include "chrome/browser/api/prefs/pref_service_base.h" |
| 24 #include "chrome/browser/api/sync/profile_sync_service_base.h" |
| 23 #include "chrome/browser/autofill/autocomplete_history_manager.h" | 25 #include "chrome/browser/autofill/autocomplete_history_manager.h" |
| 24 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 26 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
| 25 #include "chrome/browser/autofill/autofill_external_delegate.h" | 27 #include "chrome/browser/autofill/autofill_external_delegate.h" |
| 26 #include "chrome/browser/autofill/autofill_field.h" | 28 #include "chrome/browser/autofill/autofill_field.h" |
| 27 #include "chrome/browser/autofill/autofill_manager_delegate.h" | 29 #include "chrome/browser/autofill/autofill_manager_delegate.h" |
| 28 #include "chrome/browser/autofill/autofill_metrics.h" | 30 #include "chrome/browser/autofill/autofill_metrics.h" |
| 29 #include "chrome/browser/autofill/autofill_profile.h" | 31 #include "chrome/browser/autofill/autofill_profile.h" |
| 30 #include "chrome/browser/autofill/autofill_type.h" | 32 #include "chrome/browser/autofill/autofill_type.h" |
| 31 #include "chrome/browser/autofill/credit_card.h" | 33 #include "chrome/browser/autofill/credit_card.h" |
| 32 #include "chrome/browser/autofill/form_structure.h" | 34 #include "chrome/browser/autofill/form_structure.h" |
| 33 #include "chrome/browser/autofill/password_generator.h" | 35 #include "chrome/browser/autofill/password_generator.h" |
| 34 #include "chrome/browser/autofill/personal_data_manager.h" | 36 #include "chrome/browser/autofill/personal_data_manager.h" |
| 35 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 37 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 36 #include "chrome/browser/autofill/phone_number.h" | 38 #include "chrome/browser/autofill/phone_number.h" |
| 37 #include "chrome/browser/autofill/phone_number_i18n.h" | 39 #include "chrome/browser/autofill/phone_number_i18n.h" |
| 38 #include "chrome/browser/autofill/select_control_handler.h" | 40 #include "chrome/browser/autofill/select_control_handler.h" |
| 39 #include "chrome/browser/api/prefs/pref_service_base.h" | |
| 40 #include "chrome/browser/profiles/profile.h" | |
| 41 #include "chrome/browser/sync/profile_sync_service.h" | |
| 42 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 43 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 41 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 44 #include "chrome/common/autofill_messages.h" | 42 #include "chrome/common/autofill_messages.h" |
| 45 #include "chrome/common/chrome_notification_types.h" | 43 #include "chrome/common/chrome_notification_types.h" |
| 46 #include "chrome/common/chrome_switches.h" | 44 #include "chrome/common/chrome_switches.h" |
| 47 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
| 48 #include "chrome/common/url_constants.h" | 46 #include "chrome/common/url_constants.h" |
| 49 #include "content/public/browser/browser_context.h" | 47 #include "content/public/browser/browser_context.h" |
| 50 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
| 51 #include "content/public/browser/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
| 52 #include "content/public/browser/notification_source.h" | 50 #include "content/public/browser/notification_source.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 has_logged_autofill_enabled_(false), | 184 has_logged_autofill_enabled_(false), |
| 187 has_logged_address_suggestions_count_(false), | 185 has_logged_address_suggestions_count_(false), |
| 188 did_show_suggestions_(false), | 186 did_show_suggestions_(false), |
| 189 user_did_type_(false), | 187 user_did_type_(false), |
| 190 user_did_autofill_(false), | 188 user_did_autofill_(false), |
| 191 user_did_edit_autofilled_field_(false), | 189 user_did_edit_autofilled_field_(false), |
| 192 password_generation_enabled_(false), | 190 password_generation_enabled_(false), |
| 193 external_delegate_(NULL) { | 191 external_delegate_(NULL) { |
| 194 // |personal_data_| is NULL when using test-enabled WebContents. | 192 // |personal_data_| is NULL when using test-enabled WebContents. |
| 195 personal_data_ = PersonalDataManagerFactory::GetForProfile( | 193 personal_data_ = PersonalDataManagerFactory::GetForProfile( |
| 196 tab_contents_->profile()->GetOriginalProfile()); | 194 delegate->GetOriginalProfile()); |
| 197 RegisterWithSyncService(); | 195 RegisterWithSyncService(); |
| 198 registrar_.Init(manager_delegate_->GetPrefs()); | 196 registrar_.Init(manager_delegate_->GetPrefs()); |
| 199 registrar_.Add(prefs::kPasswordGenerationEnabled, this); | 197 registrar_.Add(prefs::kPasswordGenerationEnabled, this); |
| 200 notification_registrar_.Add(this, | 198 notification_registrar_.Add(this, |
| 201 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 199 chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
| 202 content::Source<TabContents>(tab_contents)); | 200 content::Source<TabContents>(tab_contents)); |
| 203 } | 201 } |
| 204 | 202 |
| 205 AutofillManager::~AutofillManager() { | 203 AutofillManager::~AutofillManager() { |
| 206 } | 204 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 224 #endif | 222 #endif |
| 225 prefs->RegisterDoublePref(prefs::kAutofillPositiveUploadRate, | 223 prefs->RegisterDoublePref(prefs::kAutofillPositiveUploadRate, |
| 226 kAutofillPositiveUploadRateDefaultValue, | 224 kAutofillPositiveUploadRateDefaultValue, |
| 227 PrefServiceBase::UNSYNCABLE_PREF); | 225 PrefServiceBase::UNSYNCABLE_PREF); |
| 228 prefs->RegisterDoublePref(prefs::kAutofillNegativeUploadRate, | 226 prefs->RegisterDoublePref(prefs::kAutofillNegativeUploadRate, |
| 229 kAutofillNegativeUploadRateDefaultValue, | 227 kAutofillNegativeUploadRateDefaultValue, |
| 230 PrefServiceBase::UNSYNCABLE_PREF); | 228 PrefServiceBase::UNSYNCABLE_PREF); |
| 231 } | 229 } |
| 232 | 230 |
| 233 void AutofillManager::RegisterWithSyncService() { | 231 void AutofillManager::RegisterWithSyncService() { |
| 234 ProfileSyncService* temp_sync_service = | 232 ProfileSyncServiceBase* service = manager_delegate_->GetProfileSyncService(); |
| 235 ProfileSyncServiceFactory::GetForProfile(tab_contents_->profile()); | 233 if (service) |
| 236 if (temp_sync_service) | 234 service->AddObserver(this); |
| 237 temp_sync_service->AddObserver(this); | |
| 238 } | 235 } |
| 239 | 236 |
| 240 void AutofillManager::SendPasswordGenerationStateToRenderer( | 237 void AutofillManager::SendPasswordGenerationStateToRenderer( |
| 241 content::RenderViewHost* host, bool enabled) { | 238 content::RenderViewHost* host, bool enabled) { |
| 242 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), | 239 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(), |
| 243 enabled)); | 240 enabled)); |
| 244 } | 241 } |
| 245 | 242 |
| 246 // In order for password generation to be enabled, we need to make sure: | 243 // In order for password generation to be enabled, we need to make sure: |
| 247 // (1) Password sync is enabled, | 244 // (1) Password sync is enabled, |
| 248 // (2) Password manager is enabled, and | 245 // (2) Password manager is enabled, and |
| 249 // (3) Password generation preference check box is checked. | 246 // (3) Password generation preference check box is checked. |
| 250 void AutofillManager::UpdatePasswordGenerationState( | 247 void AutofillManager::UpdatePasswordGenerationState( |
| 251 content::RenderViewHost* host, | 248 content::RenderViewHost* host, |
| 252 bool new_renderer) { | 249 bool new_renderer) { |
| 253 ProfileSyncService* service = ProfileSyncServiceFactory::GetForProfile( | 250 ProfileSyncServiceBase* service = manager_delegate_->GetProfileSyncService(); |
| 254 tab_contents_->profile()); | |
| 255 | 251 |
| 256 bool password_sync_enabled = false; | 252 bool password_sync_enabled = false; |
| 257 if (service) { | 253 if (service) { |
| 258 syncer::ModelTypeSet sync_set = service->GetPreferredDataTypes(); | 254 syncer::ModelTypeSet sync_set = service->GetPreferredDataTypes(); |
| 259 password_sync_enabled = | 255 password_sync_enabled = |
| 260 service->HasSyncSetupCompleted() && sync_set.Has(syncer::PASSWORDS); | 256 service->HasSyncSetupCompleted() && sync_set.Has(syncer::PASSWORDS); |
| 261 } | 257 } |
| 262 | 258 |
| 263 bool saving_passwords_enabled = manager_delegate_->IsSavingPasswordsEnabled(); | 259 bool saving_passwords_enabled = manager_delegate_->IsSavingPasswordsEnabled(); |
| 264 bool preference_checked = manager_delegate_->GetPrefs()->GetBoolean( | 260 bool preference_checked = manager_delegate_->GetPrefs()->GetBoolean( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 283 void AutofillManager::Observe( | 279 void AutofillManager::Observe( |
| 284 int type, | 280 int type, |
| 285 const content::NotificationSource& source, | 281 const content::NotificationSource& source, |
| 286 const content::NotificationDetails& details) { | 282 const content::NotificationDetails& details) { |
| 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 288 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 284 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 289 std::string* pref = content::Details<std::string>(details).ptr(); | 285 std::string* pref = content::Details<std::string>(details).ptr(); |
| 290 DCHECK(prefs::kPasswordGenerationEnabled == *pref); | 286 DCHECK(prefs::kPasswordGenerationEnabled == *pref); |
| 291 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), false); | 287 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), false); |
| 292 } else if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { | 288 } else if (type == chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED) { |
| 293 if (ProfileSyncServiceFactory::HasProfileSyncService( | 289 ProfileSyncServiceBase* service = |
| 294 tab_contents_->profile())) { | 290 manager_delegate_->GetProfileSyncService(); |
| 295 ProfileSyncService* service = ProfileSyncServiceFactory::GetForProfile( | 291 if (service != NULL && service->HasObserver(this)) |
| 296 tab_contents_->profile()); | 292 service->RemoveObserver(this); |
| 297 if (service->HasObserver(this)) | |
| 298 service->RemoveObserver(this); | |
| 299 } | |
| 300 } else { | 293 } else { |
| 301 NOTREACHED(); | 294 NOTREACHED(); |
| 302 } | 295 } |
| 303 } | 296 } |
| 304 | 297 |
| 305 void AutofillManager::OnStateChanged() { | 298 void AutofillManager::OnStateChanged() { |
| 306 // It is possible for sync state to change during tab contents destruction. | 299 // It is possible for sync state to change during tab contents destruction. |
| 307 // In this case, we don't need to update the renderer since it's going away. | 300 // In this case, we don't need to update the renderer since it's going away. |
| 308 if (web_contents() && web_contents()->GetRenderViewHost()) { | 301 if (web_contents() && web_contents()->GetRenderViewHost()) { |
| 309 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), | 302 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(), |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 external_delegate_->Reset(); | 882 external_delegate_->Reset(); |
| 890 } | 883 } |
| 891 | 884 |
| 892 AutofillManager::AutofillManager(autofill::AutofillManagerDelegate* delegate, | 885 AutofillManager::AutofillManager(autofill::AutofillManagerDelegate* delegate, |
| 893 TabContents* tab_contents, | 886 TabContents* tab_contents, |
| 894 PersonalDataManager* personal_data) | 887 PersonalDataManager* personal_data) |
| 895 : content::WebContentsObserver(tab_contents->web_contents()), | 888 : content::WebContentsObserver(tab_contents->web_contents()), |
| 896 manager_delegate_(delegate), | 889 manager_delegate_(delegate), |
| 897 tab_contents_(tab_contents), | 890 tab_contents_(tab_contents), |
| 898 personal_data_(personal_data), | 891 personal_data_(personal_data), |
| 899 download_manager_(tab_contents->profile(), this), | 892 download_manager_(delegate->GetBrowserContext(), this), |
| 900 disable_download_manager_requests_(true), | 893 disable_download_manager_requests_(true), |
| 901 metric_logger_(new AutofillMetrics), | 894 metric_logger_(new AutofillMetrics), |
| 902 has_logged_autofill_enabled_(false), | 895 has_logged_autofill_enabled_(false), |
| 903 has_logged_address_suggestions_count_(false), | 896 has_logged_address_suggestions_count_(false), |
| 904 did_show_suggestions_(false), | 897 did_show_suggestions_(false), |
| 905 user_did_type_(false), | 898 user_did_type_(false), |
| 906 user_did_autofill_(false), | 899 user_did_autofill_(false), |
| 907 user_did_edit_autofilled_field_(false), | 900 user_did_edit_autofilled_field_(false), |
| 908 password_generation_enabled_(false), | 901 password_generation_enabled_(false), |
| 909 external_delegate_(NULL) { | 902 external_delegate_(NULL) { |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 *profile_guid = IDToGUID(profile_id); | 1388 *profile_guid = IDToGUID(profile_id); |
| 1396 } | 1389 } |
| 1397 | 1390 |
| 1398 void AutofillManager::UpdateInitialInteractionTimestamp( | 1391 void AutofillManager::UpdateInitialInteractionTimestamp( |
| 1399 const TimeTicks& interaction_timestamp) { | 1392 const TimeTicks& interaction_timestamp) { |
| 1400 if (initial_interaction_timestamp_.is_null() || | 1393 if (initial_interaction_timestamp_.is_null() || |
| 1401 interaction_timestamp < initial_interaction_timestamp_) { | 1394 interaction_timestamp < initial_interaction_timestamp_) { |
| 1402 initial_interaction_timestamp_ = interaction_timestamp; | 1395 initial_interaction_timestamp_ = interaction_timestamp; |
| 1403 } | 1396 } |
| 1404 } | 1397 } |
| OLD | NEW |