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_file.h" | 5 #include "net/disk_cache/simple/simple_index_file.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 base::Closure task = base::Bind(&SimpleIndexFile::SyncLoadIndexEntries, | 271 base::Closure task = base::Bind(&SimpleIndexFile::SyncLoadIndexEntries, |
272 cache_type_, | 272 cache_type_, |
273 cache_last_modified, cache_directory_, | 273 cache_last_modified, cache_directory_, |
274 index_file_, out_result); | 274 index_file_, out_result); |
275 worker_pool_->PostTaskAndReply(FROM_HERE, task, callback); | 275 worker_pool_->PostTaskAndReply(FROM_HERE, task, callback); |
276 } | 276 } |
277 | 277 |
278 void SimpleIndexFile::WriteToDisk(const SimpleIndex::EntrySet& entry_set, | 278 void SimpleIndexFile::WriteToDisk(const SimpleIndex::EntrySet& entry_set, |
279 uint64 cache_size, | 279 uint64 cache_size, |
280 const base::TimeTicks& start, | 280 const base::TimeTicks& start, |
281 bool app_on_background) { | 281 bool app_on_background, |
| 282 const base::Closure& callback) { |
282 IndexMetadata index_metadata(entry_set.size(), cache_size); | 283 IndexMetadata index_metadata(entry_set.size(), cache_size); |
283 scoped_ptr<Pickle> pickle = Serialize(index_metadata, entry_set); | 284 scoped_ptr<Pickle> pickle = Serialize(index_metadata, entry_set); |
284 cache_thread_->PostTask(FROM_HERE, | 285 base::Closure task = |
285 base::Bind(&SimpleIndexFile::SyncWriteToDisk, | 286 base::Bind(&SimpleIndexFile::SyncWriteToDisk, |
286 cache_type_, | 287 cache_type_, cache_directory_, index_file_, temp_index_file_, |
287 cache_directory_, | 288 base::Passed(&pickle), start, app_on_background); |
288 index_file_, | 289 if (callback.is_null()) |
289 temp_index_file_, | 290 cache_thread_->PostTask(FROM_HERE, task); |
290 base::Passed(&pickle), | 291 else |
291 base::TimeTicks::Now(), | 292 cache_thread_->PostTaskAndReply(FROM_HERE, task, callback); |
292 app_on_background)); | |
293 } | 293 } |
294 | 294 |
295 // static | 295 // static |
296 void SimpleIndexFile::SyncLoadIndexEntries( | 296 void SimpleIndexFile::SyncLoadIndexEntries( |
297 net::CacheType cache_type, | 297 net::CacheType cache_type, |
298 base::Time cache_last_modified, | 298 base::Time cache_last_modified, |
299 const base::FilePath& cache_directory, | 299 const base::FilePath& cache_directory, |
300 const base::FilePath& index_file_path, | 300 const base::FilePath& index_file_path, |
301 SimpleIndexLoadResult* out_result) { | 301 SimpleIndexLoadResult* out_result) { |
302 // Load the index and find its age. | 302 // Load the index and find its age. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 bool SimpleIndexFile::LegacyIsIndexFileStale( | 473 bool SimpleIndexFile::LegacyIsIndexFileStale( |
474 base::Time cache_last_modified, | 474 base::Time cache_last_modified, |
475 const base::FilePath& index_file_path) { | 475 const base::FilePath& index_file_path) { |
476 base::Time index_mtime; | 476 base::Time index_mtime; |
477 if (!simple_util::GetMTime(index_file_path, &index_mtime)) | 477 if (!simple_util::GetMTime(index_file_path, &index_mtime)) |
478 return true; | 478 return true; |
479 return index_mtime < cache_last_modified; | 479 return index_mtime < cache_last_modified; |
480 } | 480 } |
481 | 481 |
482 } // namespace disk_cache | 482 } // namespace disk_cache |
OLD | NEW |