blob: ebd3c491d394261e98bffcc424f4a77e140200f4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// Copyright 2018 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.
#include "components/ntp_snippets/contextual/cluster.h"
#include "components/ntp_snippets/contextual/contextual_suggestion.h"
namespace contextual_suggestions {
Cluster::Cluster() = default;
// MSVC doesn't support defaulted move constructors, so we have to define it
// ourselves.
Cluster::Cluster(Cluster&& other) noexcept
: title(std::move(other.title)),
suggestions(std::move(other.suggestions)) {}
Cluster::~Cluster() = default;
ClusterBuilder::ClusterBuilder(const std::string& title) {
cluster_.title = title;
}
ClusterBuilder::ClusterBuilder(const ClusterBuilder& other) {
cluster_.title = other.cluster_.title;
for (const auto& suggestion : other.cluster_.suggestions) {
AddSuggestion(SuggestionBuilder(suggestion.url)
.Title(suggestion.title)
.PublisherName(suggestion.publisher_name)
.Snippet(suggestion.snippet)
.ImageId(suggestion.image_id)
.FaviconImageId(suggestion.favicon_image_id)
.FaviconImageUrl(suggestion.favicon_image_url)
.Build());
}
}
ClusterBuilder& ClusterBuilder::AddSuggestion(ContextualSuggestion suggestion) {
cluster_.suggestions.emplace_back(std::move(suggestion));
return *this;
}
Cluster ClusterBuilder::Build() {
return std::move(cluster_);
}
} // namespace contextual_suggestions
|