Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: chrome/browser/autofill/autofill_xml_parser.h

Issue 12434004: Move remaining Autofill code to //components/autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix long lines Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_AUTOFILL_XML_PARSER_H_
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_XML_PARSER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/autofill/autofill_server_field_info.h"
15 #include "chrome/browser/autofill/field_types.h"
16 #include "chrome/browser/autofill/form_structure.h"
17 #include "components/autofill/common/web_element_descriptor.h"
18 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h"
19
20 // The base class that contains common functionality between
21 // AutofillQueryXmlParser and AutofillUploadXmlParser.
22 class AutofillXmlParser : public buzz::XmlParseHandler {
23 public:
24 AutofillXmlParser();
25 virtual ~AutofillXmlParser();
26
27 // Returns true if no parsing errors were encountered.
28 bool succeeded() const { return succeeded_; }
29
30 private:
31 // A callback for the end of an </element>, called by Expat.
32 // |context| is a parsing context used to resolve element/attribute names.
33 // |name| is the name of the element.
34 virtual void EndElement(buzz::XmlParseContext* context,
35 const char* name) OVERRIDE;
36
37 // The callback for character data between tags (<element>text...</element>).
38 // |context| is a parsing context used to resolve element/attribute names.
39 // |text| is a pointer to the beginning of character data (not null
40 // terminated).
41 // |len| is the length of the string pointed to by text.
42 virtual void CharacterData(buzz::XmlParseContext* context,
43 const char* text,
44 int len) OVERRIDE;
45
46 // The callback for parsing errors.
47 // |context| is a parsing context used to resolve names.
48 // |error_code| is a code representing the parsing error.
49 virtual void Error(buzz::XmlParseContext* context,
50 XML_Error error_code) OVERRIDE;
51
52 // True if parsing succeeded.
53 bool succeeded_;
54
55 DISALLOW_COPY_AND_ASSIGN(AutofillXmlParser);
56 };
57
58 // The XML parse handler for parsing Autofill query responses. A typical
59 // response looks like:
60 //
61 // <autofillqueryresponse experimentid="1">
62 // <field autofilltype="0" />
63 // <field autofilltype="1" />
64 // <field autofilltype="3" />
65 // <field autofilltype="2" />
66 // </autofillqueryresponse>
67 //
68 // Fields are returned in the same order they were sent to the server.
69 // autofilltype: The server's guess at what type of field this is. 0 is
70 // unknown, other types are documented in chrome/browser/autofill/field_types.h.
71 class AutofillQueryXmlParser : public AutofillXmlParser {
72 public:
73 AutofillQueryXmlParser(std::vector<AutofillServerFieldInfo>* field_infos,
74 UploadRequired* upload_required,
75 std::string* experiment_id);
76 virtual ~AutofillQueryXmlParser();
77
78 int current_page_number() const { return current_page_number_; }
79
80 int total_pages() const { return total_pages_; }
81
82 // Returns the proceed element for multipage Autofill flows if the current
83 // page is part of such a flow or NULL otherwise.
84 const autofill::WebElementDescriptor* proceed_element_descriptor() const {
85 return proceed_element_descriptor_.get();
86 }
87
88 private:
89 // A callback for the beginning of a new <element>, called by Expat.
90 // |context| is a parsing context used to resolve element/attribute names.
91 // |name| is the name of the element.
92 // |attrs| is the list of attributes (names and values) for the element.
93 virtual void StartElement(buzz::XmlParseContext* context,
94 const char* name,
95 const char** attrs) OVERRIDE;
96
97 // A helper function to retrieve integer values from strings. Raises an
98 // XML parse error if it fails.
99 // |context| is the current parsing context.
100 // |value| is the string to convert.
101 int GetIntValue(buzz::XmlParseContext* context, const char* attribute);
102
103 // The parsed <field type, default value> pairs.
104 std::vector<AutofillServerFieldInfo>* field_infos_;
105
106 // A flag indicating whether the client should upload Autofill data when this
107 // form is submitted.
108 UploadRequired* upload_required_;
109
110 // Page number of present page in multipage autofill flow.
111 int current_page_number_;
112
113 // Total number of pages in multipage autofill flow.
114 int total_pages_;
115
116 // Proceed element for multipage Autofill flow.
117 scoped_ptr<autofill::WebElementDescriptor> proceed_element_descriptor_;
118
119 // The server experiment to which this query response belongs.
120 // For the default server implementation, this is empty.
121 std::string* experiment_id_;
122
123 DISALLOW_COPY_AND_ASSIGN(AutofillQueryXmlParser);
124 };
125
126 // The XML parser for handling Autofill upload responses. Typical upload
127 // responses look like:
128 //
129 // <autofilluploadresponse negativeuploadrate="0.00125" positiveuploadrate="1"/>
130 //
131 // The positive upload rate is the percentage of uploads to send to the server
132 // when something in the users profile matches what they have entered in a form.
133 // The negative upload rate is the percentage of uploads to send when nothing in
134 // the form matches what's in the users profile.
135 // The negative upload rate is typically much lower than the positive upload
136 // rate.
137 class AutofillUploadXmlParser : public AutofillXmlParser {
138 public:
139 AutofillUploadXmlParser(double* positive_upload_rate,
140 double* negative_upload_rate);
141
142 private:
143 // A callback for the beginning of a new <element>, called by Expat.
144 // |context| is a parsing context used to resolve element/attribute names.
145 // |name| is the name of the element.
146 // |attrs| is the list of attributes (names and values) for the element.
147 virtual void StartElement(buzz::XmlParseContext* context,
148 const char* name,
149 const char** attrs) OVERRIDE;
150
151 // A helper function to retrieve double values from strings. Raises an XML
152 // parse error if it fails.
153 // |context| is the current parsing context.
154 // |value| is the string to convert.
155 double GetDoubleValue(buzz::XmlParseContext* context, const char* attribute);
156
157 // True if parsing succeeded.
158 bool succeeded_;
159
160 double* positive_upload_rate_;
161 double* negative_upload_rate_;
162
163 DISALLOW_COPY_AND_ASSIGN(AutofillUploadXmlParser);
164 };
165
166 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_XML_PARSER_H_
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_type_unittest.cc ('k') | chrome/browser/autofill/autofill_xml_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698