| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/prerender/prerender_history.h" | 5 #include "chrome/browser/prerender/prerender_history.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 | 14 |
| 15 namespace prerender { | 15 namespace prerender { |
| 16 | 16 |
| 17 PrerenderHistory::PrerenderHistory(size_t max_items) | 17 PrerenderHistory::PrerenderHistory(size_t max_items) |
| 18 : max_items_(max_items) { | 18 : max_items_(max_items) { |
| 19 DCHECK(max_items > 0); | 19 DCHECK(max_items > 0); |
| 20 } | 20 } |
| 21 | 21 |
| 22 PrerenderHistory::~PrerenderHistory() { | 22 PrerenderHistory::~PrerenderHistory() { |
| 23 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 23 } | 24 } |
| 24 | 25 |
| 25 void PrerenderHistory::AddEntry(const Entry& entry) { | 26 void PrerenderHistory::AddEntry(const Entry& entry) { |
| 26 DCHECK(CalledOnValidThread()); | 27 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 27 while (entries_.size() >= max_items_) | 28 while (entries_.size() >= max_items_) |
| 28 entries_.pop_front(); | 29 entries_.pop_front(); |
| 29 entries_.push_back(entry); | 30 entries_.push_back(entry); |
| 30 } | 31 } |
| 31 | 32 |
| 32 void PrerenderHistory::Clear() { | 33 void PrerenderHistory::Clear() { |
| 33 entries_.clear(); | 34 entries_.clear(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 std::unique_ptr<base::Value> PrerenderHistory::CopyEntriesAsValue() const { | 37 std::unique_ptr<base::Value> PrerenderHistory::CopyEntriesAsValue() const { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 50 // integers. | 51 // integers. |
| 51 entry_dict->SetString( | 52 entry_dict->SetString( |
| 52 "end_time", | 53 "end_time", |
| 53 base::Int64ToString((entry.end_time - epoch_start).InMilliseconds())); | 54 base::Int64ToString((entry.end_time - epoch_start).InMilliseconds())); |
| 54 return_list->Append(std::move(entry_dict)); | 55 return_list->Append(std::move(entry_dict)); |
| 55 } | 56 } |
| 56 return std::move(return_list); | 57 return std::move(return_list); |
| 57 } | 58 } |
| 58 | 59 |
| 59 } // namespace prerender | 60 } // namespace prerender |
| OLD | NEW |