Commit 5b5550a3 authored by atwilson@chromium.org's avatar atwilson@chromium.org

Now gracefully deals with TypedURLs with no typed visits.

BUG=94308
TEST=Run unit tests - I don't have any way to reproduce the corrupted DB this CL works around.


Review URL: http://codereview.chromium.org/7747040

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98673 0039d316-1c4b-4281-b951-d872f2087c98
parent 1acce7fa
......@@ -594,6 +594,11 @@ void TypedUrlModelAssociator::WriteToTypedUrlSpecifics(
if (transition == PageTransition::TYPED)
++typed_count;
}
// We should have at least one typed visit. This can sometimes happen if
// the history DB has an inaccurate count for some reason (there's been
// bugs in the history code in the past which has left users in the wild
// with incorrect counts - http://crbug.com/84258).
DCHECK(typed_count > 0);
if (typed_count > kMaxTypedUrlVisits) {
only_typed = true;
......@@ -628,6 +633,16 @@ void TypedUrlModelAssociator::WriteToTypedUrlSpecifics(
typed_url->add_visit_transitions(visit->transition);
}
DCHECK_EQ(skip_count, 0);
if (typed_url->visits_size() == 0) {
// If we get here, it's because we don't actually have any TYPED visits
// even though the visit's typed_count > 0 (corrupted typed_count). So
// let's go ahead and add a RELOAD visit at the most recent visit since
// it's not legal to have an empty visit array (yet another workaround
// for http://crbug.com/84258).
typed_url->add_visits(url.last_visit().ToInternalValue());
typed_url->add_visit_transitions(PageTransition::RELOAD);
}
CHECK_GT(typed_url->visits_size(), 0);
CHECK_LE(typed_url->visits_size(), kMaxTypedUrlVisits);
CHECK_EQ(typed_url->visits_size(), typed_url->visit_transitions_size());
......
......@@ -311,3 +311,19 @@ TEST_F(TypedUrlModelAssociatorTest, TooManyTypedVisits) {
typed_url.visit_transitions(i)));
}
}
TEST_F(TypedUrlModelAssociatorTest, NoTypedVisits) {
history::VisitVector visits;
history::URLRow url(MakeTypedUrlRow("http://pie.com/", "pie",
1, 1000, false, &visits));
sync_pb::TypedUrlSpecifics typed_url;
TypedUrlModelAssociator::WriteToTypedUrlSpecifics(url, visits, &typed_url);
// URLs with no typed URL visits should be translated to a URL with one
// reload visit.
EXPECT_EQ(1, typed_url.visits_size());
EXPECT_EQ(typed_url.visit_transitions_size(), typed_url.visits_size());
// First two typed visits should be skipped.
EXPECT_EQ(1000, typed_url.visits(0));
EXPECT_EQ(PageTransition::RELOAD, static_cast<PageTransition::Type>(
typed_url.visit_transitions(0)));
}
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