| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 : tab_contents_(tab_contents), | 100 : tab_contents_(tab_contents), |
| 101 personal_data_(NULL), | 101 personal_data_(NULL), |
| 102 download_manager_(tab_contents_->profile()), | 102 download_manager_(tab_contents_->profile()), |
| 103 disable_download_manager_requests_(false) { | 103 disable_download_manager_requests_(false) { |
| 104 DCHECK(tab_contents); | 104 DCHECK(tab_contents); |
| 105 | 105 |
| 106 // |personal_data_| is NULL when using TestTabContents. | 106 // |personal_data_| is NULL when using TestTabContents. |
| 107 personal_data_ = | 107 personal_data_ = |
| 108 tab_contents_->profile()->GetOriginalProfile()->GetPersonalDataManager(); | 108 tab_contents_->profile()->GetOriginalProfile()->GetPersonalDataManager(); |
| 109 download_manager_.SetObserver(this); | 109 download_manager_.SetObserver(this); |
| 110 if (personal_data_) |
| 111 personal_data_->SetObserver(this); |
| 110 } | 112 } |
| 111 | 113 |
| 112 AutoFillManager::~AutoFillManager() { | 114 AutoFillManager::~AutoFillManager() { |
| 113 download_manager_.SetObserver(NULL); | 115 download_manager_.SetObserver(NULL); |
| 116 if (personal_data_) |
| 117 personal_data_->RemoveObserver(this); |
| 114 } | 118 } |
| 115 | 119 |
| 116 // static | 120 // static |
| 117 void AutoFillManager::RegisterBrowserPrefs(PrefService* prefs) { | 121 void AutoFillManager::RegisterBrowserPrefs(PrefService* prefs) { |
| 118 prefs->RegisterDictionaryPref(prefs::kAutoFillDialogPlacement); | 122 prefs->RegisterDictionaryPref(prefs::kAutoFillDialogPlacement); |
| 119 } | 123 } |
| 120 | 124 |
| 121 // static | 125 // static |
| 122 void AutoFillManager::RegisterUserPrefs(PrefService* prefs) { | 126 void AutoFillManager::RegisterUserPrefs(PrefService* prefs) { |
| 123 prefs->RegisterBooleanPref(prefs::kAutoFillEnabled, true); | 127 prefs->RegisterBooleanPref(prefs::kAutoFillEnabled, true); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 152 // Determine the possible field types and upload the form structure to the | 156 // Determine the possible field types and upload the form structure to the |
| 153 // PersonalDataManager. | 157 // PersonalDataManager. |
| 154 DeterminePossibleFieldTypes(upload_form_structure_.get()); | 158 DeterminePossibleFieldTypes(upload_form_structure_.get()); |
| 155 HandleSubmit(); | 159 HandleSubmit(); |
| 156 } | 160 } |
| 157 | 161 |
| 158 void AutoFillManager::FormsSeen(const std::vector<FormData>& forms) { | 162 void AutoFillManager::FormsSeen(const std::vector<FormData>& forms) { |
| 159 if (!IsAutoFillEnabled()) | 163 if (!IsAutoFillEnabled()) |
| 160 return; | 164 return; |
| 161 | 165 |
| 166 if (!personal_data_->IsDataLoaded()) { |
| 167 // Profile data is in the process of loading: delay parsing of the forms. |
| 168 delayed_forms_.push_back(forms); |
| 169 return; |
| 170 } |
| 171 |
| 162 // No profiles or credit cards, no need to parse the forms. | 172 // No profiles or credit cards, no need to parse the forms. |
| 163 if (personal_data_->profiles().empty() && | 173 if (personal_data_->profiles().empty() && |
| 164 personal_data_->credit_cards().empty()) | 174 personal_data_->credit_cards().empty()) |
| 165 return; | 175 return; |
| 166 | 176 |
| 167 ParseForms(forms); | 177 ParseForms(forms); |
| 168 } | 178 } |
| 169 | 179 |
| 170 bool AutoFillManager::GetAutoFillSuggestions(int query_id, | 180 bool AutoFillManager::GetAutoFillSuggestions(int query_id, |
| 171 bool form_autofilled, | 181 bool form_autofilled, |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 void AutoFillManager::OnUploadedAutoFillHeuristics( | 406 void AutoFillManager::OnUploadedAutoFillHeuristics( |
| 397 const std::string& form_signature) { | 407 const std::string& form_signature) { |
| 398 } | 408 } |
| 399 | 409 |
| 400 void AutoFillManager::OnHeuristicsRequestError( | 410 void AutoFillManager::OnHeuristicsRequestError( |
| 401 const std::string& form_signature, | 411 const std::string& form_signature, |
| 402 AutoFillDownloadManager::AutoFillRequestType request_type, | 412 AutoFillDownloadManager::AutoFillRequestType request_type, |
| 403 int http_error) { | 413 int http_error) { |
| 404 } | 414 } |
| 405 | 415 |
| 416 void AutoFillManager::OnPersonalDataLoaded() { |
| 417 DCHECK(personal_data_->IsDataLoaded()); |
| 418 while (!delayed_forms_.empty()) { |
| 419 FormsSeen(delayed_forms_.front()); |
| 420 delayed_forms_.pop_front(); |
| 421 } |
| 422 } |
| 423 |
| 406 bool AutoFillManager::IsAutoFillEnabled() const { | 424 bool AutoFillManager::IsAutoFillEnabled() const { |
| 407 PrefService* prefs = tab_contents_->profile()->GetPrefs(); | 425 PrefService* prefs = tab_contents_->profile()->GetPrefs(); |
| 408 | 426 |
| 409 // Migrate obsolete AutoFill pref. | 427 // Migrate obsolete AutoFill pref. |
| 410 if (prefs->FindPreference(prefs::kFormAutofillEnabled)) { | 428 if (prefs->FindPreference(prefs::kFormAutofillEnabled)) { |
| 411 bool enabled = prefs->GetBoolean(prefs::kFormAutofillEnabled); | 429 bool enabled = prefs->GetBoolean(prefs::kFormAutofillEnabled); |
| 412 prefs->ClearPref(prefs::kFormAutofillEnabled); | 430 prefs->ClearPref(prefs::kFormAutofillEnabled); |
| 413 prefs->SetBoolean(prefs::kAutoFillEnabled, enabled); | 431 prefs->SetBoolean(prefs::kAutoFillEnabled, enabled); |
| 414 return enabled; | 432 return enabled; |
| 415 } | 433 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 disable_download_manager_requests_(false) { | 488 disable_download_manager_requests_(false) { |
| 471 } | 489 } |
| 472 | 490 |
| 473 AutoFillManager::AutoFillManager(TabContents* tab_contents, | 491 AutoFillManager::AutoFillManager(TabContents* tab_contents, |
| 474 PersonalDataManager* personal_data) | 492 PersonalDataManager* personal_data) |
| 475 : tab_contents_(tab_contents), | 493 : tab_contents_(tab_contents), |
| 476 personal_data_(personal_data), | 494 personal_data_(personal_data), |
| 477 download_manager_(NULL), | 495 download_manager_(NULL), |
| 478 disable_download_manager_requests_(false) { | 496 disable_download_manager_requests_(false) { |
| 479 DCHECK(tab_contents); | 497 DCHECK(tab_contents); |
| 498 if (personal_data_) |
| 499 personal_data_->SetObserver(this); |
| 480 } | 500 } |
| 481 | 501 |
| 482 void AutoFillManager::GetProfileSuggestions(FormStructure* form, | 502 void AutoFillManager::GetProfileSuggestions(FormStructure* form, |
| 483 const FormField& field, | 503 const FormField& field, |
| 484 AutoFillType type, | 504 AutoFillType type, |
| 485 bool include_cc_labels, | 505 bool include_cc_labels, |
| 486 std::vector<string16>* values, | 506 std::vector<string16>* values, |
| 487 std::vector<string16>* labels, | 507 std::vector<string16>* labels, |
| 488 std::vector<string16>* icons, | 508 std::vector<string16>* icons, |
| 489 std::vector<int>* unique_ids) { | 509 std::vector<int>* unique_ids) { |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 | 813 |
| 794 // When receiving IDs (across processes) from the renderer we unpack credit card | 814 // When receiving IDs (across processes) from the renderer we unpack credit card |
| 795 // and profile IDs from a single integer. Credit card IDs are stored in the | 815 // and profile IDs from a single integer. Credit card IDs are stored in the |
| 796 // high word and profile IDs are stored in the low word. | 816 // high word and profile IDs are stored in the low word. |
| 797 // static | 817 // static |
| 798 void AutoFillManager::UnpackIDs(int id, int* cc_id, int* profile_id) { | 818 void AutoFillManager::UnpackIDs(int id, int* cc_id, int* profile_id) { |
| 799 *cc_id = id >> std::numeric_limits<unsigned short>::digits & | 819 *cc_id = id >> std::numeric_limits<unsigned short>::digits & |
| 800 std::numeric_limits<unsigned short>::max(); | 820 std::numeric_limits<unsigned short>::max(); |
| 801 *profile_id = id & std::numeric_limits<unsigned short>::max(); | 821 *profile_id = id & std::numeric_limits<unsigned short>::max(); |
| 802 } | 822 } |
| OLD | NEW |