Index: components/autofill/core/browser/autofill_xml_parser.h |
diff --git a/components/autofill/core/browser/autofill_xml_parser.h b/components/autofill/core/browser/autofill_xml_parser.h |
index 9c7d8dfdd039e8ee9f5e1b9611fb1664c81799a0..460dd3fb4add121af283d31540e0107baa2fa952 100644 |
--- a/components/autofill/core/browser/autofill_xml_parser.h |
+++ b/components/autofill/core/browser/autofill_xml_parser.h |
@@ -8,99 +8,37 @@ |
#include <string> |
#include <vector> |
-#include "base/basictypes.h" |
-#include "base/compiler_specific.h" |
-#include "base/memory/scoped_ptr.h" |
-#include "components/autofill/core/browser/autofill_server_field_info.h" |
-#include "components/autofill/core/browser/field_types.h" |
#include "components/autofill/core/browser/form_structure.h" |
-#include "third_party/webrtc/libjingle/xmllite/xmlparser.h" |
namespace autofill { |
-// The base class that contains common functionality between |
-// AutofillQueryXmlParser and AutofillUploadXmlParser. |
-class AutofillXmlParser : public buzz::XmlParseHandler { |
- public: |
- AutofillXmlParser(); |
- ~AutofillXmlParser() override; |
+struct AutofillServerFieldInfo; |
- // Returns true if no parsing errors were encountered. |
- bool succeeded() const { return succeeded_; } |
- |
- private: |
- // A callback for the end of an </element>, called by Expat. |
- // |context| is a parsing context used to resolve element/attribute names. |
- // |name| is the name of the element. |
- void EndElement(buzz::XmlParseContext* context, const char* name) override; |
- |
- // The callback for character data between tags (<element>text...</element>). |
- // |context| is a parsing context used to resolve element/attribute names. |
- // |text| is a pointer to the beginning of character data (not null |
- // terminated). |
- // |len| is the length of the string pointed to by text. |
- void CharacterData(buzz::XmlParseContext* context, |
- const char* text, |
- int len) override; |
- |
- // The callback for parsing errors. |
- // |context| is a parsing context used to resolve names. |
- // |error_code| is a code representing the parsing error. |
- void Error(buzz::XmlParseContext* context, XML_Error error_code) override; |
- |
- // True if parsing succeeded. |
- bool succeeded_; |
- |
- DISALLOW_COPY_AND_ASSIGN(AutofillXmlParser); |
-}; |
- |
-// The XML parse handler for parsing Autofill query responses. A typical |
-// response looks like: |
+// The XML parser for parsing Autofill query responses. A typical response |
+// looks like: |
// |
-// <autofillqueryresponse> |
+// <autofillqueryresponse uploadrequired="true"> |
// <field autofilltype="0" /> |
// <field autofilltype="1" /> |
// <field autofilltype="3" /> |
// <field autofilltype="2" /> |
+// <field autofilltype="61" defaultvalue="default" /> |
// </autofillqueryresponse> |
// |
// Fields are returned in the same order they were sent to the server. |
// autofilltype: The server's guess at what type of field this is. 0 |
// is unknown, other types are documented in |
// components/autofill/core/browser/field_types.h. |
-class AutofillQueryXmlParser : public AutofillXmlParser { |
- public: |
- AutofillQueryXmlParser(std::vector<AutofillServerFieldInfo>* field_infos, |
- UploadRequired* upload_required); |
- ~AutofillQueryXmlParser() override; |
- |
- private: |
- // A callback for the beginning of a new <element>, called by Expat. |
- // |context| is a parsing context used to resolve element/attribute names. |
- // |name| is the name of the element. |
- // |attrs| is the list of attributes (names and values) for the element. |
- void StartElement(buzz::XmlParseContext* context, |
- const char* name, |
- const char** attrs) override; |
- |
- // A helper function to retrieve integer values from strings. Raises an |
- // XML parse error if it fails. |
- // |context| is the current parsing context. |
- // |value| is the string to convert. |
- int GetIntValue(buzz::XmlParseContext* context, const char* attribute); |
- |
- // The parsed <field type, default value> pairs. |
- std::vector<AutofillServerFieldInfo>* field_infos_; |
- |
- // A flag indicating whether the client should upload Autofill data when this |
- // form is submitted. |
- UploadRequired* upload_required_; |
- |
- DISALLOW_COPY_AND_ASSIGN(AutofillQueryXmlParser); |
-}; |
- |
-// The XML parser for handling Autofill upload responses. Typical upload |
-// responses look like: |
+// |
+// Parses |xml| and on success returns true and fills |field_infos| based on the |
+// <field> tags and |upload_required| based on the uploadrequired attribute of |
+// the autofillqueryresponse tag. On failure returns false. |
+bool ParseAutofillQueryXml(std::string xml, |
+ std::vector<AutofillServerFieldInfo>* field_infos, |
+ UploadRequired* upload_required); |
+ |
+// The XML parser for Autofill upload responses. Typical upload responses look |
+// like: |
// |
// <autofilluploadresponse negativeuploadrate="0.00125" positiveuploadrate="1"/> |
// |
@@ -110,34 +48,12 @@ class AutofillQueryXmlParser : public AutofillXmlParser { |
// the form matches what's in the users profile. |
// The negative upload rate is typically much lower than the positive upload |
// rate. |
-class AutofillUploadXmlParser : public AutofillXmlParser { |
- public: |
- AutofillUploadXmlParser(double* positive_upload_rate, |
- double* negative_upload_rate); |
- |
- private: |
- // A callback for the beginning of a new <element>, called by Expat. |
- // |context| is a parsing context used to resolve element/attribute names. |
- // |name| is the name of the element. |
- // |attrs| is the list of attributes (names and values) for the element. |
- void StartElement(buzz::XmlParseContext* context, |
- const char* name, |
- const char** attrs) override; |
- |
- // A helper function to retrieve double values from strings. Raises an XML |
- // parse error if it fails. |
- // |context| is the current parsing context. |
- // |value| is the string to convert. |
- double GetDoubleValue(buzz::XmlParseContext* context, const char* attribute); |
- |
- // True if parsing succeeded. |
- bool succeeded_; |
- |
- double* positive_upload_rate_; |
- double* negative_upload_rate_; |
- |
- DISALLOW_COPY_AND_ASSIGN(AutofillUploadXmlParser); |
-}; |
+// |
+// Parses |xml| and on success returns true and fills the upload rates based on |
+// the attributes of the autofilluploadresponse tag. On failure returns false. |
+bool ParseAutofillUploadXml(std::string xml, |
+ double* positive_upload_rate, |
+ double* negative_upload_rate); |
} // namespace autofill |