| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 DCHECK(CalledOnValidThread()); | 26 DCHECK(CalledOnValidThread()); |
| 27 while (entries_.size() >= max_items_) | 27 while (entries_.size() >= max_items_) |
| 28 entries_.pop_front(); | 28 entries_.pop_front(); |
| 29 entries_.push_back(entry); | 29 entries_.push_back(entry); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void PrerenderHistory::Clear() { | 32 void PrerenderHistory::Clear() { |
| 33 entries_.clear(); | 33 entries_.clear(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 std::unique_ptr<base::Value> PrerenderHistory::GetEntriesAsValue() const { | 36 std::unique_ptr<base::Value> PrerenderHistory::CopyEntriesAsValue() const { |
| 37 auto return_list = base::MakeUnique<base::ListValue>(); | 37 auto return_list = base::MakeUnique<base::ListValue>(); |
| 38 // Javascript needs times in terms of milliseconds since Jan 1, 1970. | 38 // Javascript needs times in terms of milliseconds since Jan 1, 1970. |
| 39 base::Time epoch_start = base::Time::UnixEpoch(); | 39 base::Time epoch_start = base::Time::UnixEpoch(); |
| 40 for (std::list<Entry>::const_reverse_iterator it = entries_.rbegin(); | 40 for (std::list<Entry>::const_reverse_iterator it = entries_.rbegin(); |
| 41 it != entries_.rend(); | 41 it != entries_.rend(); |
| 42 ++it) { | 42 ++it) { |
| 43 const Entry& entry = *it; | 43 const Entry& entry = *it; |
| 44 auto entry_dict = base::MakeUnique<base::DictionaryValue>(); | 44 auto entry_dict = base::MakeUnique<base::DictionaryValue>(); |
| 45 entry_dict->SetString("url", entry.url.spec()); | 45 entry_dict->SetString("url", entry.url.spec()); |
| 46 entry_dict->SetString("final_status", | 46 entry_dict->SetString("final_status", |
| 47 NameFromFinalStatus(entry.final_status)); | 47 NameFromFinalStatus(entry.final_status)); |
| 48 entry_dict->SetString("origin", NameFromOrigin(entry.origin)); | 48 entry_dict->SetString("origin", NameFromOrigin(entry.origin)); |
| 49 // Use a string to prevent overflow, as Values don't support 64-bit | 49 // Use a string to prevent overflow, as Values don't support 64-bit |
| 50 // integers. | 50 // integers. |
| 51 entry_dict->SetString( | 51 entry_dict->SetString( |
| 52 "end_time", | 52 "end_time", |
| 53 base::Int64ToString((entry.end_time - epoch_start).InMilliseconds())); | 53 base::Int64ToString((entry.end_time - epoch_start).InMilliseconds())); |
| 54 return_list->Append(std::move(entry_dict)); | 54 return_list->Append(std::move(entry_dict)); |
| 55 } | 55 } |
| 56 return std::move(return_list); | 56 return std::move(return_list); |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // namespace prerender | 59 } // namespace prerender |
| OLD | NEW |