| 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> |
| 8 #include <utility> |
| 9 |
| 7 #include "base/logging.h" | 10 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/values.h" | 12 #include "base/values.h" |
| 10 | 13 |
| 11 namespace prerender { | 14 namespace prerender { |
| 12 | 15 |
| 13 PrerenderHistory::PrerenderHistory(size_t max_items) | 16 PrerenderHistory::PrerenderHistory(size_t max_items) |
| 14 : max_items_(max_items) { | 17 : max_items_(max_items) { |
| 15 DCHECK(max_items > 0); | 18 DCHECK(max_items > 0); |
| 16 } | 19 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 30 } | 33 } |
| 31 | 34 |
| 32 base::Value* PrerenderHistory::GetEntriesAsValue() const { | 35 base::Value* PrerenderHistory::GetEntriesAsValue() const { |
| 33 base::ListValue* return_list = new base::ListValue(); | 36 base::ListValue* return_list = new base::ListValue(); |
| 34 // Javascript needs times in terms of milliseconds since Jan 1, 1970. | 37 // Javascript needs times in terms of milliseconds since Jan 1, 1970. |
| 35 base::Time epoch_start = base::Time::UnixEpoch(); | 38 base::Time epoch_start = base::Time::UnixEpoch(); |
| 36 for (std::list<Entry>::const_reverse_iterator it = entries_.rbegin(); | 39 for (std::list<Entry>::const_reverse_iterator it = entries_.rbegin(); |
| 37 it != entries_.rend(); | 40 it != entries_.rend(); |
| 38 ++it) { | 41 ++it) { |
| 39 const Entry& entry = *it; | 42 const Entry& entry = *it; |
| 40 base::DictionaryValue* entry_dict = new base::DictionaryValue(); | 43 std::unique_ptr<base::DictionaryValue> entry_dict( |
| 44 new base::DictionaryValue()); |
| 41 entry_dict->SetString("url", entry.url.spec()); | 45 entry_dict->SetString("url", entry.url.spec()); |
| 42 entry_dict->SetString("final_status", | 46 entry_dict->SetString("final_status", |
| 43 NameFromFinalStatus(entry.final_status)); | 47 NameFromFinalStatus(entry.final_status)); |
| 44 entry_dict->SetString("origin", NameFromOrigin(entry.origin)); | 48 entry_dict->SetString("origin", NameFromOrigin(entry.origin)); |
| 45 // 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 |
| 46 // integers. | 50 // integers. |
| 47 entry_dict->SetString( | 51 entry_dict->SetString( |
| 48 "end_time", | 52 "end_time", |
| 49 base::Int64ToString((entry.end_time - epoch_start).InMilliseconds())); | 53 base::Int64ToString((entry.end_time - epoch_start).InMilliseconds())); |
| 50 return_list->Append(entry_dict); | 54 return_list->Append(std::move(entry_dict)); |
| 51 } | 55 } |
| 52 return return_list; | 56 return return_list; |
| 53 } | 57 } |
| 54 | 58 |
| 55 } // namespace prerender | 59 } // namespace prerender |
| OLD | NEW |