OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ |
6 #define CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ | 6 #define CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // The class used to combine home phone parts into a whole number. | 49 // The class used to combine home phone parts into a whole number. |
50 class PhoneCombineHelper { | 50 class PhoneCombineHelper { |
51 public: | 51 public: |
52 PhoneCombineHelper(); | 52 PhoneCombineHelper(); |
53 ~PhoneCombineHelper(); | 53 ~PhoneCombineHelper(); |
54 | 54 |
55 // If |type| is a phone field type, saves the |value| accordingly and | 55 // If |type| is a phone field type, saves the |value| accordingly and |
56 // returns true. For all other field types returs false. | 56 // returns true. For all other field types returs false. |
57 bool SetInfo(AutofillFieldType type, const string16& value); | 57 bool SetInfo(AutofillFieldType type, const string16& value); |
58 | 58 |
59 // Returns true if parsing was successful, false otherwise. | 59 // Parses the number built up from pieces stored via SetInfo() according to |
60 bool ParseNumber(const std::string& region, string16* value); | 60 // the specified |profile|'s country code, falling back to the given |
| 61 // |app_locale| if the |profile| has no associated country code. Returns |
| 62 // true if parsing was successful, false otherwise. |
| 63 bool ParseNumber(const AutofillProfile& profile, |
| 64 const std::string& app_locale, |
| 65 string16* value); |
61 | 66 |
62 // Returns true if both |phone_| and |whole_number_| are empty. | 67 // Returns true if both |phone_| and |whole_number_| are empty. |
63 bool IsEmpty() const; | 68 bool IsEmpty() const; |
64 | 69 |
65 private: | 70 private: |
66 string16 country_; | 71 string16 country_; |
67 string16 city_; | 72 string16 city_; |
68 string16 phone_; | 73 string16 phone_; |
69 string16 whole_number_; | 74 string16 whole_number_; |
70 }; | 75 }; |
71 | 76 |
72 private: | 77 private: |
73 // FormGroup: | 78 // FormGroup: |
74 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE; | 79 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE; |
75 | 80 |
76 // Returns the region code for this phone number, which is an ISO 3166 | |
77 // 2-letter country code. The name "region" is chosen since "country code" | |
78 // already refers to part of a phone number. The returned value is based on | |
79 // the |profile_|; if the |profile_| does not have a country code associated | |
80 // with it, falls back to the country code corresponding to the |app_locale|. | |
81 std::string GetRegion(const std::string& app_locale) const; | |
82 | |
83 // Updates the cached parsed number if the profile's region has changed | 81 // Updates the cached parsed number if the profile's region has changed |
84 // since the last time the cache was updated. | 82 // since the last time the cache was updated. |
85 void UpdateCacheIfNeeded(const std::string& app_locale) const; | 83 void UpdateCacheIfNeeded(const std::string& app_locale) const; |
86 | 84 |
87 // The phone number. | 85 // The phone number. |
88 string16 number_; | 86 string16 number_; |
89 // Profile which stores the region used as hint when normalizing the number. | 87 // Profile which stores the region used as hint when normalizing the number. |
90 const AutofillProfile* profile_; // WEAK | 88 const AutofillProfile* profile_; // WEAK |
91 | 89 |
92 // Cached number. | 90 // Cached number. |
93 mutable autofill_i18n::PhoneObject cached_parsed_phone_; | 91 mutable autofill_i18n::PhoneObject cached_parsed_phone_; |
94 }; | 92 }; |
95 | 93 |
96 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ | 94 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ |
OLD | NEW |