forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EoC] Replace legacy fetching with skeleton
Replace JsonFetcher with ContextualSuggestionsFetch. Add no-op/null implementations of methods. Move Cluster definition to its own file. Make ContextualSuggestion a struct, and give it a builder. Adjust bridge to properly use new ContextualSuggestion struct. Add deps on services/network and content/public. R:fgorski@chromium.org, mmenke@chromium.org Bug: 807697 Change-Id: I6a41937a3ae934283f57a8516e2017531adb063d Reviewed-on: https://chromium-review.googlesource.com/1000174 Commit-Queue: Filip Gorski <fgorski@chromium.org> Reviewed-by: Christian Dullweber <dullweber@chromium.org> Reviewed-by: Filip Gorski <fgorski@chromium.org> Reviewed-by: Matt Menke <mmenke@chromium.org> Cr-Commit-Position: refs/heads/master@{#550099}
- Loading branch information
Patrick Noland
authored and
Commit Bot
committed
Apr 12, 2018
1 parent
09fa83a
commit ed66cd5
Showing
25 changed files
with
399 additions
and
1,455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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) | ||
.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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. | ||
|
||
#ifndef COMPONENTS_NTP_SNIPPETS_CONTEXTUAL_CLUSTER_H_ | ||
#define COMPONENTS_NTP_SNIPPETS_CONTEXTUAL_CLUSTER_H_ | ||
|
||
#include "components/ntp_snippets/contextual/contextual_suggestion.h" | ||
|
||
using ntp_snippets::ContextualSuggestion; | ||
using ntp_snippets::SuggestionBuilder; | ||
|
||
namespace contextual_suggestions { | ||
|
||
// A structure representing a suggestion cluster. | ||
struct Cluster { | ||
Cluster(); | ||
Cluster(Cluster&&) noexcept; | ||
~Cluster(); | ||
|
||
std::string title; | ||
std::vector<ContextualSuggestion> suggestions; | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(Cluster); | ||
}; | ||
|
||
// Allows concise construction of a cluster and copying, which cluster | ||
// doesn't allow. | ||
class ClusterBuilder { | ||
public: | ||
ClusterBuilder(const std::string& title); | ||
|
||
// Allow copying for ease of validation when testing. | ||
ClusterBuilder(const ClusterBuilder& other); | ||
ClusterBuilder& AddSuggestion(ContextualSuggestion suggestion); | ||
Cluster Build(); | ||
|
||
private: | ||
Cluster cluster_; | ||
}; | ||
|
||
using FetchClustersCallback = | ||
base::OnceCallback<void(std::string peek_text, | ||
std::vector<Cluster> clusters)>; | ||
|
||
} // namespace contextual_suggestions | ||
|
||
#endif // COMPONENTS_NTP_SNIPPETS_CONTEXTUAL_CLUSTER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.