Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Unified Diff: third_party/WebKit/WebCore/history/HistoryItem.cpp

Issue 21152: WebKit merge 40668:40722 part 1. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/WebCore/history/HistoryItem.cpp
===================================================================
--- third_party/WebKit/WebCore/history/HistoryItem.cpp (revision 9310)
+++ third_party/WebKit/WebCore/history/HistoryItem.cpp (working copy)
@@ -74,7 +74,7 @@
, m_lastVisitWasFailure(false)
, m_isTargetItem(false)
, m_visitCount(0)
-{
+{
iconDatabase()->retainIconForPageURL(m_urlString);
}
@@ -114,6 +114,8 @@
, m_lastVisitWasFailure(item.m_lastVisitWasFailure)
, m_isTargetItem(item.m_isTargetItem)
, m_visitCount(item.m_visitCount)
+ , m_dailyVisitCounts(item.m_dailyVisitCounts)
+ , m_weeklyVisitCounts(item.m_weeklyVisitCounts)
, m_formContentType(item.m_formContentType)
{
ASSERT(!item.m_cachedPage);
@@ -246,31 +248,93 @@
m_parent = parent;
}
-void HistoryItem::setLastVisitedTime(double time)
+static inline int timeToDay(double time)
{
- if (m_lastVisitedTime != time) {
- m_lastVisitedTime = time;
- m_visitCount++;
+ static const double secondsPerDay = 60 * 60 * 24;
+ return static_cast<int>(ceil(time / secondsPerDay));
+}
+
+void HistoryItem::padDailyCountsForNewVisit(double time)
+{
+ if (m_dailyVisitCounts.isEmpty())
+ m_dailyVisitCounts.prepend(m_visitCount);
+
+ int daysElapsed = timeToDay(time) - timeToDay(m_lastVisitedTime);
+
+ if (daysElapsed < 0)
+ daysElapsed = 0;
+
+ Vector<int> padding;
+ padding.fill(0, daysElapsed);
+ m_dailyVisitCounts.prepend(padding);
+}
+
+static const size_t daysPerWeek = 7;
+static const size_t maxDailyCounts = 2 * daysPerWeek - 1;
+static const size_t maxWeeklyCounts = 5;
+
+void HistoryItem::collapseDailyVisitsToWeekly()
+{
+ while (m_dailyVisitCounts.size() > maxDailyCounts) {
+ int oldestWeekTotal = 0;
+ for (size_t i = 0; i < daysPerWeek; i++)
+ oldestWeekTotal += m_dailyVisitCounts[m_dailyVisitCounts.size() - daysPerWeek + i];
+ m_dailyVisitCounts.shrink(m_dailyVisitCounts.size() - daysPerWeek);
+ m_weeklyVisitCounts.prepend(oldestWeekTotal);
}
+
+ if (m_weeklyVisitCounts.size() > maxWeeklyCounts)
+ m_weeklyVisitCounts.shrink(maxWeeklyCounts);
}
-void HistoryItem::visited(const String& title, double time)
+void HistoryItem::recordVisitAtTime(double time)
{
- m_title = title;
+ padDailyCountsForNewVisit(time);
+
m_lastVisitedTime = time;
m_visitCount++;
+
+ m_dailyVisitCounts[0]++;
+
+ collapseDailyVisitsToWeekly();
}
+void HistoryItem::setLastVisitedTime(double time)
+{
+ if (m_lastVisitedTime != time)
+ recordVisitAtTime(time);
+}
+
+void HistoryItem::visited(const String& title, double time)
+{
+ m_title = title;
+ recordVisitAtTime(time);
+}
+
int HistoryItem::visitCount() const
{
return m_visitCount;
}
+void HistoryItem::recordInitialVisit()
+{
+ ASSERT(!m_visitCount);
+ recordVisitAtTime(m_lastVisitedTime);
+}
+
void HistoryItem::setVisitCount(int count)
{
m_visitCount = count;
}
+void HistoryItem::adoptVisitCounts(Vector<int>& dailyCounts, Vector<int>& weeklyCounts)
+{
+ m_dailyVisitCounts.clear();
+ m_dailyVisitCounts.swap(dailyCounts);
+ m_weeklyVisitCounts.clear();
+ m_weeklyVisitCounts.swap(weeklyCounts);
+}
+
const IntPoint& HistoryItem::scrollPoint() const
{
return m_scrollPoint;
@@ -395,6 +459,9 @@
void HistoryItem::mergeAutoCompleteHints(HistoryItem* otherItem)
{
+ // FIXME: this is broken - we should be merging the daily counts
+ // somehow. but this is to support API that's not really used in
+ // practice so leave it broken for now.
ASSERT(otherItem);
if (otherItem != this)
m_visitCount += otherItem->m_visitCount;
« no previous file with comments | « third_party/WebKit/WebCore/history/HistoryItem.h ('k') | third_party/WebKit/WebCore/html/CanvasRenderingContext2D.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698