This source file includes following definitions.
- GetLastVisit
- AddVisit
- NotifyRenderProcessHostDestruction
- CleanupTransitionList
#include "chrome/browser/history/visit_tracker.h"
#include "base/stl_util.h"
namespace history {
static const size_t kMaxItemsInTransitionList = 96;
static const size_t kResizeBigTransitionListTo = 64;
COMPILE_ASSERT(kResizeBigTransitionListTo < kMaxItemsInTransitionList,
max_items_must_be_larger_than_resize_to);
VisitTracker::VisitTracker() {
}
VisitTracker::~VisitTracker() {
STLDeleteContainerPairSecondPointers(hosts_.begin(), hosts_.end());
}
VisitID VisitTracker::GetLastVisit(const void* host,
int32 page_id,
const GURL& referrer) {
if (referrer.is_empty() || !host)
return 0;
HostList::iterator i = hosts_.find(host);
if (i == hosts_.end())
return 0;
TransitionList& transitions = *i->second;
for (int i = static_cast<int>(transitions.size()) - 1; i >= 0; i--) {
if (transitions[i].page_id <= page_id && transitions[i].url == referrer) {
return transitions[i].visit_id;
}
}
return 0;
}
void VisitTracker::AddVisit(const void* host,
int32 page_id,
const GURL& url,
VisitID visit_id) {
TransitionList* transitions = hosts_[host];
if (!transitions) {
transitions = new TransitionList;
hosts_[host] = transitions;
}
Transition t;
t.url = url;
t.page_id = page_id;
t.visit_id = visit_id;
transitions->push_back(t);
CleanupTransitionList(transitions);
}
void VisitTracker::NotifyRenderProcessHostDestruction(const void* host) {
HostList::iterator i = hosts_.find(host);
if (i == hosts_.end())
return;
delete i->second;
hosts_.erase(i);
}
void VisitTracker::CleanupTransitionList(TransitionList* transitions) {
if (transitions->size() <= kMaxItemsInTransitionList)
return;
transitions->erase(transitions->begin(),
transitions->begin() + kResizeBigTransitionListTo);
}
}