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