| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_AUTOFILL_CORE_BROWSER_PHONE_NUMBER_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_PHONE_NUMBER_H_ |
| 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_PHONE_NUMBER_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_PHONE_NUMBER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "components/autofill/core/browser/autofill_type.h" | |
| 14 #include "components/autofill/core/browser/form_group.h" | 13 #include "components/autofill/core/browser/form_group.h" |
| 15 #include "components/autofill/core/browser/phone_number_i18n.h" | 14 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 16 | 15 |
| 17 namespace autofill { | 16 namespace autofill { |
| 18 | 17 |
| 19 class AutofillProfile; | 18 class AutofillProfile; |
| 20 | 19 |
| 21 // A form group that stores phone number information. | 20 // A form group that stores phone number information. |
| 22 class PhoneNumber : public FormGroup { | 21 class PhoneNumber : public FormGroup { |
| 23 public: | 22 public: |
| 24 explicit PhoneNumber(AutofillProfile* profile); | 23 explicit PhoneNumber(AutofillProfile* profile); |
| 25 PhoneNumber(const PhoneNumber& number); | 24 PhoneNumber(const PhoneNumber& number); |
| 26 virtual ~PhoneNumber(); | 25 virtual ~PhoneNumber(); |
| 27 | 26 |
| 28 PhoneNumber& operator=(const PhoneNumber& number); | 27 PhoneNumber& operator=(const PhoneNumber& number); |
| 29 | 28 |
| 30 void set_profile(AutofillProfile* profile) { profile_ = profile; } | 29 void set_profile(AutofillProfile* profile) { profile_ = profile; } |
| 31 | 30 |
| 32 // FormGroup implementation: | 31 // FormGroup implementation: |
| 33 virtual void GetMatchingTypes(const base::string16& text, | 32 virtual void GetMatchingTypes( |
| 34 const std::string& app_locale, | 33 const base::string16& text, |
| 35 FieldTypeSet* matching_types) const OVERRIDE; | 34 const std::string& app_locale, |
| 36 virtual base::string16 GetRawInfo(AutofillFieldType type) const OVERRIDE; | 35 ServerFieldTypeSet* matching_types) const OVERRIDE; |
| 37 virtual void SetRawInfo(AutofillFieldType type, | 36 virtual base::string16 GetRawInfo(ServerFieldType type) const OVERRIDE; |
| 37 virtual void SetRawInfo(ServerFieldType type, |
| 38 const base::string16& value) OVERRIDE; | 38 const base::string16& value) OVERRIDE; |
| 39 virtual base::string16 GetInfo(AutofillFieldType type, | 39 virtual base::string16 GetInfo(const AutofillType& type, |
| 40 const std::string& app_locale) const OVERRIDE; | 40 const std::string& app_locale) const OVERRIDE; |
| 41 virtual bool SetInfo(AutofillFieldType type, | 41 virtual bool SetInfo(const AutofillType& type, |
| 42 const base::string16& value, | 42 const base::string16& value, |
| 43 const std::string& app_locale) OVERRIDE; | 43 const std::string& app_locale) OVERRIDE; |
| 44 | 44 |
| 45 // Size and offset of the prefix and suffix portions of phone numbers. | 45 // Size and offset of the prefix and suffix portions of phone numbers. |
| 46 static const size_t kPrefixOffset = 0; | 46 static const size_t kPrefixOffset = 0; |
| 47 static const size_t kPrefixLength = 3; | 47 static const size_t kPrefixLength = 3; |
| 48 static const size_t kSuffixOffset = 3; | 48 static const size_t kSuffixOffset = 3; |
| 49 static const size_t kSuffixLength = 4; | 49 static const size_t kSuffixLength = 4; |
| 50 | 50 |
| 51 // The class used to combine home phone parts into a whole number. | 51 // The class used to combine home phone parts into a whole number. |
| 52 class PhoneCombineHelper { | 52 class PhoneCombineHelper { |
| 53 public: | 53 public: |
| 54 PhoneCombineHelper(); | 54 PhoneCombineHelper(); |
| 55 ~PhoneCombineHelper(); | 55 ~PhoneCombineHelper(); |
| 56 | 56 |
| 57 // If |type| is a phone field type, saves the |value| accordingly and | 57 // If |type| is a phone field type, saves the |value| accordingly and |
| 58 // returns true. For all other field types returs false. | 58 // returns true. For all other field types returs false. |
| 59 bool SetInfo(AutofillFieldType type, const base::string16& value); | 59 bool SetInfo(const AutofillType& type, const base::string16& value); |
| 60 | 60 |
| 61 // Parses the number built up from pieces stored via SetInfo() according to | 61 // Parses the number built up from pieces stored via SetInfo() according to |
| 62 // the specified |profile|'s country code, falling back to the given | 62 // the specified |profile|'s country code, falling back to the given |
| 63 // |app_locale| if the |profile| has no associated country code. Returns | 63 // |app_locale| if the |profile| has no associated country code. Returns |
| 64 // true if parsing was successful, false otherwise. | 64 // true if parsing was successful, false otherwise. |
| 65 bool ParseNumber(const AutofillProfile& profile, | 65 bool ParseNumber(const AutofillProfile& profile, |
| 66 const std::string& app_locale, | 66 const std::string& app_locale, |
| 67 base::string16* value); | 67 base::string16* value); |
| 68 | 68 |
| 69 // Returns true if both |phone_| and |whole_number_| are empty. | 69 // Returns true if both |phone_| and |whole_number_| are empty. |
| 70 bool IsEmpty() const; | 70 bool IsEmpty() const; |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 base::string16 country_; | 73 base::string16 country_; |
| 74 base::string16 city_; | 74 base::string16 city_; |
| 75 base::string16 phone_; | 75 base::string16 phone_; |
| 76 base::string16 whole_number_; | 76 base::string16 whole_number_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 // FormGroup: | 80 // FormGroup: |
| 81 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE; | 81 virtual void GetSupportedTypes( |
| 82 ServerFieldTypeSet* supported_types) const OVERRIDE; |
| 82 | 83 |
| 83 // Updates the cached parsed number if the profile's region has changed | 84 // Updates the cached parsed number if the profile's region has changed |
| 84 // since the last time the cache was updated. | 85 // since the last time the cache was updated. |
| 85 void UpdateCacheIfNeeded(const std::string& app_locale) const; | 86 void UpdateCacheIfNeeded(const std::string& app_locale) const; |
| 86 | 87 |
| 87 // The phone number. | 88 // The phone number. |
| 88 base::string16 number_; | 89 base::string16 number_; |
| 89 // Profile which stores the region used as hint when normalizing the number. | 90 // Profile which stores the region used as hint when normalizing the number. |
| 90 const AutofillProfile* profile_; // WEAK | 91 const AutofillProfile* profile_; // WEAK |
| 91 | 92 |
| 92 // Cached number. | 93 // Cached number. |
| 93 mutable i18n::PhoneObject cached_parsed_phone_; | 94 mutable i18n::PhoneObject cached_parsed_phone_; |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 } // namespace autofill | 97 } // namespace autofill |
| 97 | 98 |
| 98 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PHONE_NUMBER_H_ | 99 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PHONE_NUMBER_H_ |
| OLD | NEW |