| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "net/disk_cache/simple/simple_index.h" | 5 #include "net/disk_cache/simple/simple_index.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 DCHECK(it); | 128 DCHECK(it); |
| 129 int64 tmp_last_used_time; | 129 int64 tmp_last_used_time; |
| 130 uint64 tmp_entry_size; | 130 uint64 tmp_entry_size; |
| 131 if (!it->ReadInt64(&tmp_last_used_time) || !it->ReadUInt64(&tmp_entry_size)) | 131 if (!it->ReadInt64(&tmp_last_used_time) || !it->ReadUInt64(&tmp_entry_size)) |
| 132 return false; | 132 return false; |
| 133 SetLastUsedTime(base::Time::FromInternalValue(tmp_last_used_time)); | 133 SetLastUsedTime(base::Time::FromInternalValue(tmp_last_used_time)); |
| 134 entry_size_ = tmp_entry_size; | 134 entry_size_ = tmp_entry_size; |
| 135 return true; | 135 return true; |
| 136 } | 136 } |
| 137 | 137 |
| 138 SimpleIndex::SimpleIndex(base::SingleThreadTaskRunner* io_thread, | 138 SimpleIndex::SimpleIndex( |
| 139 SimpleIndexDelegate* delegate, | 139 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, |
| 140 net::CacheType cache_type, | 140 SimpleIndexDelegate* delegate, |
| 141 scoped_ptr<SimpleIndexFile> index_file) | 141 net::CacheType cache_type, |
| 142 scoped_ptr<SimpleIndexFile> index_file) |
| 142 : delegate_(delegate), | 143 : delegate_(delegate), |
| 143 cache_type_(cache_type), | 144 cache_type_(cache_type), |
| 144 cache_size_(0), | 145 cache_size_(0), |
| 145 max_size_(0), | 146 max_size_(0), |
| 146 high_watermark_(0), | 147 high_watermark_(0), |
| 147 low_watermark_(0), | 148 low_watermark_(0), |
| 148 eviction_in_progress_(false), | 149 eviction_in_progress_(false), |
| 149 initialized_(false), | 150 initialized_(false), |
| 150 index_file_(index_file.Pass()), | 151 index_file_(index_file.Pass()), |
| 151 io_thread_(io_thread), | 152 io_thread_(io_thread), |
| 152 // Creating the callback once so it is reused every time | 153 // Creating the callback once so it is reused every time |
| 153 // write_to_disk_timer_.Start() is called. | 154 // write_to_disk_timer_.Start() is called. |
| 154 write_to_disk_cb_(base::Bind(&SimpleIndex::WriteToDisk, AsWeakPtr())), | 155 write_to_disk_cb_(base::Bind(&SimpleIndex::WriteToDisk, AsWeakPtr())), |
| 155 app_on_background_(false) {} | 156 app_on_background_(false) { |
| 157 } |
| 156 | 158 |
| 157 SimpleIndex::~SimpleIndex() { | 159 SimpleIndex::~SimpleIndex() { |
| 158 DCHECK(io_thread_checker_.CalledOnValidThread()); | 160 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 159 | 161 |
| 160 // Fail all callbacks waiting for the index to come up. | 162 // Fail all callbacks waiting for the index to come up. |
| 161 for (CallbackList::iterator it = to_run_when_initialized_.begin(), | 163 for (CallbackList::iterator it = to_run_when_initialized_.begin(), |
| 162 end = to_run_when_initialized_.end(); it != end; ++it) { | 164 end = to_run_when_initialized_.end(); it != end; ++it) { |
| 163 it->Run(net::ERR_ABORTED); | 165 it->Run(net::ERR_ABORTED); |
| 164 } | 166 } |
| 165 } | 167 } |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 start - last_write_to_disk_); | 473 start - last_write_to_disk_); |
| 472 } | 474 } |
| 473 } | 475 } |
| 474 last_write_to_disk_ = start; | 476 last_write_to_disk_ = start; |
| 475 | 477 |
| 476 index_file_->WriteToDisk(entries_set_, cache_size_, | 478 index_file_->WriteToDisk(entries_set_, cache_size_, |
| 477 start, app_on_background_); | 479 start, app_on_background_); |
| 478 } | 480 } |
| 479 | 481 |
| 480 } // namespace disk_cache | 482 } // namespace disk_cache |
| OLD | NEW |