Index: components/omnibox/suggestion_answer.h |
diff --git a/components/omnibox/suggestion_answer.h b/components/omnibox/suggestion_answer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..db73dbe0163d659f2973428ee960d0fdf788ef8b |
--- /dev/null |
+++ b/components/omnibox/suggestion_answer.h |
@@ -0,0 +1,107 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_OMNIBOX_SUGGESTION_ANSWER_H_ |
+#define COMPONENTS_OMNIBOX_SUGGESTION_ANSWER_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "url/gurl.h" |
+ |
+namespace base { |
+class DictionaryValue; |
+} |
+ |
+// Structured representation of the JSON payload of a suggestion with an answer. |
+// An answer has exactly two image lines, so called because they are a |
+// combination of text and an optional image URL. Each image line has 1 or more |
+// text fields, each of which is required to contain a string and an integer |
+// type. The text fields are contained in a non-empty vector and two optional |
+// named properties, referred to as "additional text" and "status text". |
+// |
+// When represented in the UI, these elements should be styled and layed out |
+// according to the specification at http://goto.google.com/ais_api. |
+class SuggestionAnswer { |
+ public: |
+ class TextField { |
+ public: |
+ TextField(); |
+ ~TextField(); |
+ |
+ static bool ParseTextField( |
groby-ooo-7-16
2014/10/21 00:35:54
Why not have a simple struct, plus a factory? Save
Justin Donnelly
2014/10/21 21:43:54
I like the consistency of design across these thre
|
+ const base::DictionaryValue* field_json, TextField* text_field); |
+ |
+ bool operator==(const TextField& field) const; |
+ bool operator!=(const TextField& field) const; |
+ |
+ const std::string& text() const { return text_; } |
+ int type() const { return type_; } |
+ |
+ void Clear(); |
+ |
+ private: |
+ std::string text_; |
+ int type_; |
+ }; |
+ |
+ typedef std::vector<TextField> TextFields; |
groby-ooo-7-16
2014/10/21 00:35:54
I wonder if TextFields should be a single string +
Justin Donnelly
2014/10/21 21:43:54
My concern with this is that we discussed a simila
|
+ |
+ class ImageLine { |
+ public: |
+ ImageLine(); |
+ ~ImageLine(); |
+ |
+ static bool ParseImageLine( |
+ const base::DictionaryValue* line_json, ImageLine* image_line); |
+ |
+ bool operator==(const ImageLine& line) const; |
+ bool operator!=(const ImageLine& line) const; |
+ |
+ const std::vector<TextField>& text_fields() const { return text_fields_; } |
+ const TextField& additional_text() const { return additional_text_; } |
+ const TextField& status_text() const { return status_text_; } |
+ |
+ bool HasImageURL() const; |
+ const GURL& image_url() const { return image_url_; } |
+ |
+ void Clear(); |
+ |
+ private: |
+ TextFields text_fields_; |
+ TextField additional_text_; |
+ TextField status_text_; |
+ GURL image_url_; |
+ }; |
+ |
+ SuggestionAnswer(); |
+ ~SuggestionAnswer(); |
+ |
+ static bool ParseAnswer( |
+ const std::string& answer_json, SuggestionAnswer* answer); |
+ static bool ParseAnswer( |
+ const base::DictionaryValue* answer_json, SuggestionAnswer* answer); |
+ |
+ bool operator==(const SuggestionAnswer& answer) const; |
+ bool operator!=(const SuggestionAnswer& answer) const; |
+ |
+ const ImageLine& first_line() const { return first_line_; } |
+ const ImageLine& second_line() const { return second_line_; } |
+ int type() const { return type_; } |
+ bool is_valid() const { return is_valid_; } |
+ |
+ // Specify the type of this answer. The string will be interpreted as a base10 |
+ // integer. If it can't be parsed as such, the type will be set to 0. |
+ void SetType(const base::string16& type); |
+ void Clear(); |
+ |
+ private: |
+ ImageLine first_line_; |
+ ImageLine second_line_; |
+ int type_; |
+ bool is_valid_; |
+}; |
+ |
+#endif // COMPONENTS_OMNIBOX_SUGGESTION_ANSWER_H_ |