This source file includes following definitions.
- AddEntry
- Clear
- GetEntriesAsValue
#include "chrome/browser/prerender/prerender_history.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
namespace prerender {
PrerenderHistory::PrerenderHistory(size_t max_items)
: max_items_(max_items) {
DCHECK(max_items > 0);
}
PrerenderHistory::~PrerenderHistory() {
}
void PrerenderHistory::AddEntry(const Entry& entry) {
DCHECK(CalledOnValidThread());
while (entries_.size() >= max_items_)
entries_.pop_front();
entries_.push_back(entry);
}
void PrerenderHistory::Clear() {
entries_.clear();
}
base::Value* PrerenderHistory::GetEntriesAsValue() const {
base::ListValue* return_list = new base::ListValue();
base::Time epoch_start = base::Time::UnixEpoch();
for (std::list<Entry>::const_reverse_iterator it = entries_.rbegin();
it != entries_.rend();
++it) {
const Entry& entry = *it;
base::DictionaryValue* entry_dict = new base::DictionaryValue();
entry_dict->SetString("url", entry.url.spec());
entry_dict->SetString("final_status",
NameFromFinalStatus(entry.final_status));
entry_dict->SetString("origin", NameFromOrigin(entry.origin));
entry_dict->SetString(
"end_time",
base::Int64ToString((entry.end_time - epoch_start).InMilliseconds()));
return_list->Append(entry_dict);
}
return return_list;
}
}