Commit b5056af5 authored by Yao Xiao's avatar Yao Xiao Committed by Commit Bot

Add the publicly_routable field to URLResult

Previously we added this field to the "visits" table. This CL adds the
field to URLResult and fills in this field inside
HistoryBackend::QueryHistoryBasic and HistoryBackend::QueryHistoryText.

Bug: 1062736
Change-Id: I8e0690a43f1c5648dc5b2bd611a06ae92c62afba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2211051
Commit-Queue: Yao Xiao <yaoxia@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770963}
parent 62918507
...@@ -1488,6 +1488,7 @@ void HistoryBackend::QueryHistoryBasic(const QueryOptions& options, ...@@ -1488,6 +1488,7 @@ void HistoryBackend::QueryHistoryBasic(const QueryOptions& options,
} }
url_result.set_visit_time(visit.visit_time); url_result.set_visit_time(visit.visit_time);
url_result.set_publicly_routable(visit.publicly_routable);
// Set whether the visit was blocked for a managed user by looking at the // Set whether the visit was blocked for a managed user by looking at the
// transition type. // transition type.
...@@ -1521,6 +1522,7 @@ void HistoryBackend::QueryHistoryText(const base::string16& text_query, ...@@ -1521,6 +1522,7 @@ void HistoryBackend::QueryHistoryText(const base::string16& text_query,
for (size_t j = 0; j < visits.size(); j++) { for (size_t j = 0; j < visits.size(); j++) {
URLResult url_result(text_match); URLResult url_result(text_match);
url_result.set_visit_time(visits[j].visit_time); url_result.set_visit_time(visits[j].visit_time);
url_result.set_publicly_routable(visits[j].publicly_routable);
matching_visits.push_back(url_result); matching_visits.push_back(url_result);
} }
} }
......
...@@ -3873,6 +3873,53 @@ TEST_F(HistoryBackendTest, PubliclyRoutableColumn) { ...@@ -3873,6 +3873,53 @@ TEST_F(HistoryBackendTest, PubliclyRoutableColumn) {
ASSERT_FALSE(visits5[1].publicly_routable); ASSERT_FALSE(visits5[1].publicly_routable);
} }
TEST_F(HistoryBackendTest, PubliclyRoutableFieldInQueryResult) {
const GURL url1("http://foo1.com");
const GURL url2("http://foo2.com");
// Add a page visit to url1 that has a private IP address.
HistoryAddPageArgs request1(url1, base::Time::FromDoubleT(1), nullptr, 0,
GURL(), {}, ui::PAGE_TRANSITION_TYPED, false,
history::SOURCE_BROWSED, false, true, false);
backend_->AddPage(request1);
// Add a page visit to url2 that has a publicly routable IP address.
HistoryAddPageArgs request2(url2, base::Time::FromDoubleT(2), nullptr, 0,
GURL(), {}, ui::PAGE_TRANSITION_TYPED, false,
history::SOURCE_BROWSED, false, true, true);
backend_->AddPage(request2);
// Add a page visit to url1 that has a publicly routable IP address.
HistoryAddPageArgs request3(url1, base::Time::FromDoubleT(3), nullptr, 0,
GURL(), {}, ui::PAGE_TRANSITION_TYPED, false,
history::SOURCE_BROWSED, false, true, true);
backend_->AddPage(request3);
QueryOptions options;
options.duplicate_policy = QueryOptions::KEEP_ALL_DUPLICATES;
base::string16 text_query = {};
QueryResults results;
results = backend_->QueryHistory(text_query, options);
ASSERT_EQ(results.size(), 3u);
EXPECT_EQ(results[0].url(), url1);
EXPECT_TRUE(results[0].publicly_routable());
EXPECT_EQ(results[1].url(), url2);
EXPECT_TRUE(results[1].publicly_routable());
EXPECT_EQ(results[2].url(), url1);
EXPECT_FALSE(results[2].publicly_routable());
text_query = base::UTF8ToUTF16("foo");
results = backend_->QueryHistory(text_query, options);
ASSERT_EQ(results.size(), 3u);
EXPECT_EQ(results[0].url(), url1);
EXPECT_TRUE(results[0].publicly_routable());
EXPECT_EQ(results[1].url(), url2);
EXPECT_TRUE(results[1].publicly_routable());
EXPECT_EQ(results[2].url(), url1);
EXPECT_FALSE(results[2].publicly_routable());
}
// Common implementation for the two tests below, given that the only difference // Common implementation for the two tests below, given that the only difference
// between them is the type of the notification sent out. // between them is the type of the notification sent out.
void InMemoryHistoryBackendTest::TestAddingAndChangingURLRows( void InMemoryHistoryBackendTest::TestAddingAndChangingURLRows(
......
...@@ -57,6 +57,7 @@ URLResult::URLResult(const URLResult& other) = default; ...@@ -57,6 +57,7 @@ URLResult::URLResult(const URLResult& other) = default;
URLResult::URLResult(URLResult&& other) noexcept URLResult::URLResult(URLResult&& other) noexcept
: URLRow(std::move(other)), : URLRow(std::move(other)),
visit_time_(other.visit_time_), visit_time_(other.visit_time_),
publicly_routable_(other.publicly_routable_),
snippet_(std::move(other.snippet_)), snippet_(std::move(other.snippet_)),
title_match_positions_(std::move(other.title_match_positions_)), title_match_positions_(std::move(other.title_match_positions_)),
blocked_visit_(other.blocked_visit_) {} blocked_visit_(other.blocked_visit_) {}
...@@ -69,6 +70,7 @@ URLResult& URLResult::operator=(const URLResult&) = default; ...@@ -69,6 +70,7 @@ URLResult& URLResult::operator=(const URLResult&) = default;
void URLResult::SwapResult(URLResult* other) { void URLResult::SwapResult(URLResult* other) {
URLRow::Swap(other); URLRow::Swap(other);
std::swap(visit_time_, other->visit_time_); std::swap(visit_time_, other->visit_time_);
std::swap(publicly_routable_, other->publicly_routable_);
snippet_.Swap(&other->snippet_); snippet_.Swap(&other->snippet_);
title_match_positions_.swap(other->title_match_positions_); title_match_positions_.swap(other->title_match_positions_);
std::swap(blocked_visit_, other->blocked_visit_); std::swap(blocked_visit_, other->blocked_visit_);
......
...@@ -165,6 +165,11 @@ class URLResult : public URLRow { ...@@ -165,6 +165,11 @@ class URLResult : public URLRow {
base::Time visit_time() const { return visit_time_; } base::Time visit_time() const { return visit_time_; }
void set_visit_time(base::Time visit_time) { visit_time_ = visit_time; } void set_visit_time(base::Time visit_time) { visit_time_ = visit_time; }
bool publicly_routable() const { return publicly_routable_; }
void set_publicly_routable(bool publicly_routable) {
publicly_routable_ = publicly_routable;
}
const query_parser::Snippet& snippet() const { return snippet_; } const query_parser::Snippet& snippet() const { return snippet_; }
bool blocked_visit() const { return blocked_visit_; } bool blocked_visit() const { return blocked_visit_; }
...@@ -189,6 +194,10 @@ class URLResult : public URLRow { ...@@ -189,6 +194,10 @@ class URLResult : public URLRow {
// The time that this result corresponds to. // The time that this result corresponds to.
base::Time visit_time_; base::Time visit_time_;
// Indicates whether the IP of this URL was publicly routable. See
// VisitRow::publicly_routable for details.
bool publicly_routable_ = false;
// These values are typically set by HistoryBackend. // These values are typically set by HistoryBackend.
query_parser::Snippet snippet_; query_parser::Snippet snippet_;
query_parser::Snippet::MatchPositions title_match_positions_; query_parser::Snippet::MatchPositions title_match_positions_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment