Patrick Noland | 11e04d40 | 2018-05-02 00:48:56 | [diff] [blame] | 1 | // Copyright 2018 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 | #include "components/ntp_snippets/contextual/contextual_suggestions_result.h" |
| 6 | |
| 7 | #include "components/ntp_snippets/contextual/contextual_suggestion.h" |
| 8 | |
| 9 | namespace contextual_suggestions { |
| 10 | |
| 11 | PeekConditions::PeekConditions() |
| 12 | : confidence(1.0), |
| 13 | page_scroll_percentage(0.0), |
| 14 | minimum_seconds_on_page(0.0), |
| 15 | maximum_number_of_peeks(0.0) {} |
| 16 | |
| 17 | Cluster::Cluster() = default; |
| 18 | |
| 19 | // MSVC doesn't support defaulted move constructors, so we have to define it |
| 20 | // ourselves. |
| 21 | Cluster::Cluster(Cluster&& other) noexcept |
| 22 | : title(std::move(other.title)), |
| 23 | suggestions(std::move(other.suggestions)) {} |
| 24 | |
| 25 | Cluster::Cluster(const Cluster&) = default; |
| 26 | |
| 27 | Cluster::~Cluster() = default; |
| 28 | |
| 29 | ClusterBuilder::ClusterBuilder(const std::string& title) { |
| 30 | cluster_.title = title; |
| 31 | } |
| 32 | |
| 33 | ClusterBuilder::ClusterBuilder(const ClusterBuilder& other) { |
| 34 | cluster_.title = other.cluster_.title; |
| 35 | for (const auto& suggestion : other.cluster_.suggestions) { |
| 36 | AddSuggestion(SuggestionBuilder(suggestion.url) |
| 37 | .Title(suggestion.title) |
| 38 | .PublisherName(suggestion.publisher_name) |
| 39 | .Snippet(suggestion.snippet) |
| 40 | .ImageId(suggestion.image_id) |
| 41 | .FaviconImageId(suggestion.favicon_image_id) |
| 42 | .Build()); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | ClusterBuilder& ClusterBuilder::AddSuggestion(ContextualSuggestion suggestion) { |
| 47 | cluster_.suggestions.emplace_back(std::move(suggestion)); |
| 48 | return *this; |
| 49 | } |
| 50 | |
| 51 | Cluster ClusterBuilder::Build() { |
| 52 | return std::move(cluster_); |
| 53 | } |
| 54 | |
| 55 | ContextualSuggestionsResult::ContextualSuggestionsResult() = default; |
| 56 | |
| 57 | ContextualSuggestionsResult::ContextualSuggestionsResult( |
| 58 | std::string peek_text, |
| 59 | std::vector<Cluster> clusters, |
| 60 | PeekConditions peek_conditions) |
| 61 | : clusters(clusters), |
| 62 | peek_text(peek_text), |
| 63 | peek_conditions(peek_conditions) {} |
| 64 | |
| 65 | ContextualSuggestionsResult::ContextualSuggestionsResult( |
| 66 | const ContextualSuggestionsResult& other) = default; |
| 67 | |
| 68 | // MSVC doesn't support defaulted move constructors, so we have to define it |
| 69 | // ourselves. |
| 70 | ContextualSuggestionsResult::ContextualSuggestionsResult( |
| 71 | ContextualSuggestionsResult&& other) noexcept |
| 72 | : clusters(std::move(other.clusters)), |
| 73 | peek_text(std::move(other.peek_text)), |
| 74 | peek_conditions(std::move(other.peek_conditions)) {} |
| 75 | |
| 76 | ContextualSuggestionsResult::~ContextualSuggestionsResult() = default; |
| 77 | |
| 78 | ContextualSuggestionsResult& ContextualSuggestionsResult::operator=( |
| 79 | ContextualSuggestionsResult&& other) = default; |
| 80 | |
| 81 | } // namespace contextual_suggestions |