Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 COMPONENTS_OMNIBOX_SUGGESTION_ANSWER_H_ | |
| 6 #define COMPONENTS_OMNIBOX_SUGGESTION_ANSWER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "url/gurl.h" | |
| 13 | |
| 14 namespace base { | |
| 15 class DictionaryValue; | |
| 16 } | |
| 17 | |
| 18 // Structured representation of the JSON payload of a suggestion with an answer. | |
| 19 // An answer has exactly two image lines, so called because they are a | |
| 20 // combination of text and an optional image URL. Each image line has 1 or more | |
| 21 // text fields, each of which is required to contain a string and an integer | |
| 22 // type. The text fields are contained in a non-empty vector and two optional | |
| 23 // named properties, referred to as "additional text" and "status text". | |
| 24 // | |
| 25 // When represented in the UI, these elements should be styled and layed out | |
| 26 // according to the specification at http://goto.google.com/ais_api. | |
| 27 class SuggestionAnswer { | |
| 28 public: | |
| 29 class TextField { | |
| 30 public: | |
| 31 TextField(); | |
| 32 ~TextField(); | |
| 33 | |
| 34 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
| |
| 35 const base::DictionaryValue* field_json, TextField* text_field); | |
| 36 | |
| 37 bool operator==(const TextField& field) const; | |
| 38 bool operator!=(const TextField& field) const; | |
| 39 | |
| 40 const std::string& text() const { return text_; } | |
| 41 int type() const { return type_; } | |
| 42 | |
| 43 void Clear(); | |
| 44 | |
| 45 private: | |
| 46 std::string text_; | |
| 47 int type_; | |
| 48 }; | |
| 49 | |
| 50 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
| |
| 51 | |
| 52 class ImageLine { | |
| 53 public: | |
| 54 ImageLine(); | |
| 55 ~ImageLine(); | |
| 56 | |
| 57 static bool ParseImageLine( | |
| 58 const base::DictionaryValue* line_json, ImageLine* image_line); | |
| 59 | |
| 60 bool operator==(const ImageLine& line) const; | |
| 61 bool operator!=(const ImageLine& line) const; | |
| 62 | |
| 63 const std::vector<TextField>& text_fields() const { return text_fields_; } | |
| 64 const TextField& additional_text() const { return additional_text_; } | |
| 65 const TextField& status_text() const { return status_text_; } | |
| 66 | |
| 67 bool HasImageURL() const; | |
| 68 const GURL& image_url() const { return image_url_; } | |
| 69 | |
| 70 void Clear(); | |
| 71 | |
| 72 private: | |
| 73 TextFields text_fields_; | |
| 74 TextField additional_text_; | |
| 75 TextField status_text_; | |
| 76 GURL image_url_; | |
| 77 }; | |
| 78 | |
| 79 SuggestionAnswer(); | |
| 80 ~SuggestionAnswer(); | |
| 81 | |
| 82 static bool ParseAnswer( | |
| 83 const std::string& answer_json, SuggestionAnswer* answer); | |
| 84 static bool ParseAnswer( | |
| 85 const base::DictionaryValue* answer_json, SuggestionAnswer* answer); | |
| 86 | |
| 87 bool operator==(const SuggestionAnswer& answer) const; | |
| 88 bool operator!=(const SuggestionAnswer& answer) const; | |
| 89 | |
| 90 const ImageLine& first_line() const { return first_line_; } | |
| 91 const ImageLine& second_line() const { return second_line_; } | |
| 92 int type() const { return type_; } | |
| 93 bool is_valid() const { return is_valid_; } | |
| 94 | |
| 95 // Specify the type of this answer. The string will be interpreted as a base10 | |
| 96 // integer. If it can't be parsed as such, the type will be set to 0. | |
| 97 void SetType(const base::string16& type); | |
| 98 void Clear(); | |
| 99 | |
| 100 private: | |
| 101 ImageLine first_line_; | |
| 102 ImageLine second_line_; | |
| 103 int type_; | |
| 104 bool is_valid_; | |
| 105 }; | |
| 106 | |
| 107 #endif // COMPONENTS_OMNIBOX_SUGGESTION_ANSWER_H_ | |
| OLD | NEW |