| 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_AUTOFILL_XML_PARSER_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_XML_PARSER_H_ |
| 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_XML_PARSER_H_ | 6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_XML_PARSER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 public: | 21 public: |
| 22 AutofillXmlParser(); | 22 AutofillXmlParser(); |
| 23 | 23 |
| 24 // Returns true if no parsing errors were encountered. | 24 // Returns true if no parsing errors were encountered. |
| 25 bool succeeded() const { return succeeded_; } | 25 bool succeeded() const { return succeeded_; } |
| 26 | 26 |
| 27 private: | 27 private: |
| 28 // A callback for the end of an </element>, called by Expat. | 28 // A callback for the end of an </element>, called by Expat. |
| 29 // |context| is a parsing context used to resolve element/attribute names. | 29 // |context| is a parsing context used to resolve element/attribute names. |
| 30 // |name| is the name of the element. | 30 // |name| is the name of the element. |
| 31 virtual void EndElement(buzz::XmlParseContext* context, const char* name); | 31 virtual void EndElement(buzz::XmlParseContext* context, |
| 32 const char* name) OVERRIDE; |
| 32 | 33 |
| 33 // The callback for character data between tags (<element>text...</element>). | 34 // The callback for character data between tags (<element>text...</element>). |
| 34 // |context| is a parsing context used to resolve element/attribute names. | 35 // |context| is a parsing context used to resolve element/attribute names. |
| 35 // |text| is a pointer to the beginning of character data (not null | 36 // |text| is a pointer to the beginning of character data (not null |
| 36 // terminated). | 37 // terminated). |
| 37 // |len| is the length of the string pointed to by text. | 38 // |len| is the length of the string pointed to by text. |
| 38 virtual void CharacterData(buzz::XmlParseContext* context, const char* text, | 39 virtual void CharacterData(buzz::XmlParseContext* context, |
| 39 int len); | 40 const char* text, |
| 41 int len) OVERRIDE; |
| 40 | 42 |
| 41 // The callback for parsing errors. | 43 // The callback for parsing errors. |
| 42 // |context| is a parsing context used to resolve names. | 44 // |context| is a parsing context used to resolve names. |
| 43 // |error_code| is a code representing the parsing error. | 45 // |error_code| is a code representing the parsing error. |
| 44 virtual void Error(buzz::XmlParseContext* context, XML_Error error_code); | 46 virtual void Error(buzz::XmlParseContext* context, |
| 47 XML_Error error_code) OVERRIDE; |
| 45 | 48 |
| 46 // True if parsing succeeded. | 49 // True if parsing succeeded. |
| 47 bool succeeded_; | 50 bool succeeded_; |
| 48 | 51 |
| 49 DISALLOW_COPY_AND_ASSIGN(AutofillXmlParser); | 52 DISALLOW_COPY_AND_ASSIGN(AutofillXmlParser); |
| 50 }; | 53 }; |
| 51 | 54 |
| 52 // The XML parse handler for parsing Autofill query responses. A typical | 55 // The XML parse handler for parsing Autofill query responses. A typical |
| 53 // response looks like: | 56 // response looks like: |
| 54 // | 57 // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 66 public: | 69 public: |
| 67 AutofillQueryXmlParser(std::vector<AutofillFieldType>* field_types, | 70 AutofillQueryXmlParser(std::vector<AutofillFieldType>* field_types, |
| 68 UploadRequired* upload_required, | 71 UploadRequired* upload_required, |
| 69 std::string* experiment_id); | 72 std::string* experiment_id); |
| 70 | 73 |
| 71 private: | 74 private: |
| 72 // A callback for the beginning of a new <element>, called by Expat. | 75 // A callback for the beginning of a new <element>, called by Expat. |
| 73 // |context| is a parsing context used to resolve element/attribute names. | 76 // |context| is a parsing context used to resolve element/attribute names. |
| 74 // |name| is the name of the element. | 77 // |name| is the name of the element. |
| 75 // |attrs| is the list of attributes (names and values) for the element. | 78 // |attrs| is the list of attributes (names and values) for the element. |
| 76 virtual void StartElement(buzz::XmlParseContext* context, const char* name, | 79 virtual void StartElement(buzz::XmlParseContext* context, |
| 77 const char** attrs); | 80 const char* name, |
| 81 const char** attrs) OVERRIDE; |
| 78 | 82 |
| 79 // A helper function to retrieve integer values from strings. Raises an | 83 // A helper function to retrieve integer values from strings. Raises an |
| 80 // XML parse error if it fails. | 84 // XML parse error if it fails. |
| 81 // |context| is the current parsing context. | 85 // |context| is the current parsing context. |
| 82 // |value| is the string to convert. | 86 // |value| is the string to convert. |
| 83 int GetIntValue(buzz::XmlParseContext* context, const char* attribute); | 87 int GetIntValue(buzz::XmlParseContext* context, const char* attribute); |
| 84 | 88 |
| 85 // The parsed field types. | 89 // The parsed field types. |
| 86 std::vector<AutofillFieldType>* field_types_; | 90 std::vector<AutofillFieldType>* field_types_; |
| 87 | 91 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 110 class AutofillUploadXmlParser : public AutofillXmlParser { | 114 class AutofillUploadXmlParser : public AutofillXmlParser { |
| 111 public: | 115 public: |
| 112 AutofillUploadXmlParser(double* positive_upload_rate, | 116 AutofillUploadXmlParser(double* positive_upload_rate, |
| 113 double* negative_upload_rate); | 117 double* negative_upload_rate); |
| 114 | 118 |
| 115 private: | 119 private: |
| 116 // A callback for the beginning of a new <element>, called by Expat. | 120 // A callback for the beginning of a new <element>, called by Expat. |
| 117 // |context| is a parsing context used to resolve element/attribute names. | 121 // |context| is a parsing context used to resolve element/attribute names. |
| 118 // |name| is the name of the element. | 122 // |name| is the name of the element. |
| 119 // |attrs| is the list of attributes (names and values) for the element. | 123 // |attrs| is the list of attributes (names and values) for the element. |
| 120 virtual void StartElement(buzz::XmlParseContext* context, const char* name, | 124 virtual void StartElement(buzz::XmlParseContext* context, |
| 121 const char** attrs); | 125 const char* name, |
| 126 const char** attrs) OVERRIDE; |
| 122 | 127 |
| 123 // A helper function to retrieve double values from strings. Raises an XML | 128 // A helper function to retrieve double values from strings. Raises an XML |
| 124 // parse error if it fails. | 129 // parse error if it fails. |
| 125 // |context| is the current parsing context. | 130 // |context| is the current parsing context. |
| 126 // |value| is the string to convert. | 131 // |value| is the string to convert. |
| 127 double GetDoubleValue(buzz::XmlParseContext* context, const char* attribute); | 132 double GetDoubleValue(buzz::XmlParseContext* context, const char* attribute); |
| 128 | 133 |
| 129 // True if parsing succeeded. | 134 // True if parsing succeeded. |
| 130 bool succeeded_; | 135 bool succeeded_; |
| 131 | 136 |
| 132 double* positive_upload_rate_; | 137 double* positive_upload_rate_; |
| 133 double* negative_upload_rate_; | 138 double* negative_upload_rate_; |
| 134 | 139 |
| 135 DISALLOW_COPY_AND_ASSIGN(AutofillUploadXmlParser); | 140 DISALLOW_COPY_AND_ASSIGN(AutofillUploadXmlParser); |
| 136 }; | 141 }; |
| 137 | 142 |
| 138 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_XML_PARSER_H_ | 143 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_XML_PARSER_H_ |
| OLD | NEW |