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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/guid.h" |
12 #include "base/string16.h" | 13 #include "base/string16.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 15 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
15 #include "chrome/browser/autofill/autofill_dialog.h" | 16 #include "chrome/browser/autofill/autofill_dialog.h" |
16 #include "chrome/browser/autofill/form_structure.h" | 17 #include "chrome/browser/autofill/form_structure.h" |
17 #include "chrome/browser/autofill/phone_number.h" | 18 #include "chrome/browser/autofill/phone_number.h" |
18 #include "chrome/browser/autofill/select_control_handler.h" | 19 #include "chrome/browser/autofill/select_control_handler.h" |
19 #include "chrome/browser/guid.h" | |
20 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/renderer_host/render_view_host.h" | 22 #include "chrome/browser/renderer_host/render_view_host.h" |
23 #include "chrome/browser/tab_contents/tab_contents.h" | 23 #include "chrome/browser/tab_contents/tab_contents.h" |
24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
28 #include "webkit/glue/form_data.h" | 28 #include "webkit/glue/form_data.h" |
29 #include "webkit/glue/form_field.h" | 29 #include "webkit/glue/form_field.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 return false; | 277 return false; |
278 | 278 |
279 DCHECK(host); | 279 DCHECK(host); |
280 DCHECK(form_structure); | 280 DCHECK(form_structure); |
281 DCHECK(autofill_field); | 281 DCHECK(autofill_field); |
282 | 282 |
283 // Unpack the |unique_id| into component parts. | 283 // Unpack the |unique_id| into component parts. |
284 std::string cc_guid; | 284 std::string cc_guid; |
285 std::string profile_guid; | 285 std::string profile_guid; |
286 UnpackGUIDs(unique_id, &cc_guid, &profile_guid); | 286 UnpackGUIDs(unique_id, &cc_guid, &profile_guid); |
287 DCHECK(!guid::IsValidGUID(cc_guid) || !guid::IsValidGUID(profile_guid)); | 287 DCHECK(!base::IsValidGUID(cc_guid) || !base::IsValidGUID(profile_guid)); |
288 | 288 |
289 // Find the profile that matches the |profile_id|, if one is specified. | 289 // Find the profile that matches the |profile_id|, if one is specified. |
290 const AutoFillProfile* profile = NULL; | 290 const AutoFillProfile* profile = NULL; |
291 if (guid::IsValidGUID(profile_guid)) { | 291 if (base::IsValidGUID(profile_guid)) { |
292 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); | 292 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); |
293 iter != profiles.end(); ++iter) { | 293 iter != profiles.end(); ++iter) { |
294 if ((*iter)->guid() == profile_guid) { | 294 if ((*iter)->guid() == profile_guid) { |
295 profile = *iter; | 295 profile = *iter; |
296 break; | 296 break; |
297 } | 297 } |
298 } | 298 } |
299 DCHECK(profile); | 299 DCHECK(profile); |
300 } | 300 } |
301 | 301 |
302 // Find the credit card that matches the |cc_id|, if one is specified. | 302 // Find the credit card that matches the |cc_id|, if one is specified. |
303 const CreditCard* credit_card = NULL; | 303 const CreditCard* credit_card = NULL; |
304 if (guid::IsValidGUID(cc_guid)) { | 304 if (base::IsValidGUID(cc_guid)) { |
305 for (std::vector<CreditCard*>::const_iterator iter = credit_cards.begin(); | 305 for (std::vector<CreditCard*>::const_iterator iter = credit_cards.begin(); |
306 iter != credit_cards.end(); ++iter) { | 306 iter != credit_cards.end(); ++iter) { |
307 if ((*iter)->guid() == cc_guid) { | 307 if ((*iter)->guid() == cc_guid) { |
308 credit_card = *iter; | 308 credit_card = *iter; |
309 break; | 309 break; |
310 } | 310 } |
311 } | 311 } |
312 DCHECK(credit_card); | 312 DCHECK(credit_card); |
313 } | 313 } |
314 | 314 |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 std::numeric_limits<unsigned short>::max(); | 743 std::numeric_limits<unsigned short>::max(); |
744 int profile_id = id & std::numeric_limits<unsigned short>::max(); | 744 int profile_id = id & std::numeric_limits<unsigned short>::max(); |
745 | 745 |
746 *cc_guid = IDToGUID(cc_id); | 746 *cc_guid = IDToGUID(cc_id); |
747 *profile_guid = IDToGUID(profile_id); | 747 *profile_guid = IDToGUID(profile_id); |
748 } | 748 } |
749 | 749 |
750 int AutoFillManager::GUIDToID(const std::string& guid) { | 750 int AutoFillManager::GUIDToID(const std::string& guid) { |
751 static int last_id = 1; | 751 static int last_id = 1; |
752 | 752 |
753 if (!guid::IsValidGUID(guid)) | 753 if (!base::IsValidGUID(guid)) |
754 return 0; | 754 return 0; |
755 | 755 |
756 std::map<std::string, int>::const_iterator iter = guid_id_map_.find(guid); | 756 std::map<std::string, int>::const_iterator iter = guid_id_map_.find(guid); |
757 if (iter == guid_id_map_.end()) { | 757 if (iter == guid_id_map_.end()) { |
758 guid_id_map_[guid] = last_id; | 758 guid_id_map_[guid] = last_id; |
759 id_guid_map_[last_id] = guid; | 759 id_guid_map_[last_id] = guid; |
760 return last_id++; | 760 return last_id++; |
761 } else { | 761 } else { |
762 return iter->second; | 762 return iter->second; |
763 } | 763 } |
764 } | 764 } |
765 | 765 |
766 const std::string AutoFillManager::IDToGUID(int id) { | 766 const std::string AutoFillManager::IDToGUID(int id) { |
767 if (id == 0) | 767 if (id == 0) |
768 return std::string(); | 768 return std::string(); |
769 | 769 |
770 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); | 770 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); |
771 if (iter == id_guid_map_.end()) { | 771 if (iter == id_guid_map_.end()) { |
772 NOTREACHED(); | 772 NOTREACHED(); |
773 return std::string(); | 773 return std::string(); |
774 } | 774 } |
775 | 775 |
776 return iter->second; | 776 return iter->second; |
777 } | 777 } |
OLD | NEW |