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