Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "components/omnibox/browser/suggestion_answer.h" | 5 #include "components/omnibox/browser/suggestion_answer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 AppendWithSpace(status_text_.get(), &result); | 175 AppendWithSpace(status_text_.get(), &result); |
| 176 return result; | 176 return result; |
| 177 } | 177 } |
| 178 | 178 |
| 179 // SuggestionAnswer ------------------------------------------------------------ | 179 // SuggestionAnswer ------------------------------------------------------------ |
| 180 | 180 |
| 181 SuggestionAnswer::SuggestionAnswer() : type_(-1) {} | 181 SuggestionAnswer::SuggestionAnswer() : type_(-1) {} |
| 182 SuggestionAnswer::SuggestionAnswer(const SuggestionAnswer& answer) | 182 SuggestionAnswer::SuggestionAnswer(const SuggestionAnswer& answer) |
| 183 : first_line_(answer.first_line_), | 183 : first_line_(answer.first_line_), |
| 184 second_line_(answer.second_line_), | 184 second_line_(answer.second_line_), |
| 185 type_(answer.type_) {} | 185 type_(answer.type_), |
| 186 second_line_size_(answer.second_line_size_) {} | |
|
groby-ooo-7-16
2016/06/23 20:49:27
Since this is just a default copy ctor, let's do t
Kevin Bailey
2016/06/23 21:49:22
sgtm
Kevin Bailey
2016/06/28 15:59:32
Done.
| |
| 186 | 187 |
| 187 SuggestionAnswer::~SuggestionAnswer() {} | 188 SuggestionAnswer::~SuggestionAnswer() {} |
| 188 | 189 |
| 189 // static | 190 // static |
| 190 std::unique_ptr<SuggestionAnswer> SuggestionAnswer::ParseAnswer( | 191 std::unique_ptr<SuggestionAnswer> SuggestionAnswer::ParseAnswer( |
| 191 const base::DictionaryValue* answer_json) { | 192 const base::DictionaryValue* answer_json) { |
| 192 auto result = base::WrapUnique(new SuggestionAnswer); | 193 auto result = base::WrapUnique(new SuggestionAnswer); |
| 193 | 194 |
| 194 const base::ListValue* lines_json; | 195 const base::ListValue* lines_json; |
| 195 if (!answer_json->GetList(kAnswerJsonLines, &lines_json) || | 196 if (!answer_json->GetList(kAnswerJsonLines, &lines_json) || |
| 196 lines_json->GetSize() != 2) | 197 lines_json->GetSize() != 2) |
| 197 return nullptr; | 198 return nullptr; |
| 198 | 199 |
| 199 const base::DictionaryValue* first_line_json; | 200 const base::DictionaryValue* first_line_json; |
| 200 if (!lines_json->GetDictionary(0, &first_line_json) || | 201 if (!lines_json->GetDictionary(0, &first_line_json) || |
| 201 !ImageLine::ParseImageLine(first_line_json, &result->first_line_)) | 202 !ImageLine::ParseImageLine(first_line_json, &result->first_line_)) |
| 202 return nullptr; | 203 return nullptr; |
| 203 | 204 |
| 204 const base::DictionaryValue* second_line_json; | 205 const base::DictionaryValue* second_line_json; |
| 205 if (!lines_json->GetDictionary(1, &second_line_json) || | 206 if (!lines_json->GetDictionary(1, &second_line_json) || |
| 206 !ImageLine::ParseImageLine(second_line_json, &result->second_line_)) | 207 !ImageLine::ParseImageLine(second_line_json, &result->second_line_)) |
| 207 return nullptr; | 208 return nullptr; |
| 208 | 209 |
| 210 for (const auto& text_field : result->second_line_.text_fields()) { | |
| 211 if (text_field.has_num_lines()) { | |
| 212 result->second_line_size_ = text_field.num_lines(); | |
| 213 break; | |
| 214 } | |
| 215 } | |
| 216 | |
| 209 return result; | 217 return result; |
| 210 } | 218 } |
| 211 | 219 |
| 212 bool SuggestionAnswer::Equals(const SuggestionAnswer& answer) const { | 220 bool SuggestionAnswer::Equals(const SuggestionAnswer& answer) const { |
| 213 return type_ == answer.type_ && | 221 return type_ == answer.type_ && |
| 214 first_line_.Equals(answer.first_line_) && | 222 first_line_.Equals(answer.first_line_) && |
| 215 second_line_.Equals(answer.second_line_); | 223 second_line_.Equals(answer.second_line_); |
| 216 } | 224 } |
| 217 | 225 |
| 218 void SuggestionAnswer::AddImageURLsTo(std::vector<GURL>* urls) const { | 226 void SuggestionAnswer::AddImageURLsTo(std::vector<GURL>* urls) const { |
| 219 if (first_line_.image_url().is_valid()) | 227 if (first_line_.image_url().is_valid()) |
| 220 urls->push_back(first_line_.image_url()); | 228 urls->push_back(first_line_.image_url()); |
| 221 if (second_line_.image_url().is_valid()) | 229 if (second_line_.image_url().is_valid()) |
| 222 urls->push_back(second_line_.image_url()); | 230 urls->push_back(second_line_.image_url()); |
| 223 } | 231 } |
| OLD | NEW |