Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: net/disk_cache/simple/simple_index_file.cc

Issue 2867693004: Snapshot of all changes to get jumbo in blink and content.
Patch Set: Rebased again Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | net/disk_cache/simple/simple_synchronous_entry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/files/memory_mapped_file.h" 12 #include "base/files/memory_mapped_file.h"
13 #include "base/hash.h" 13 #include "base/hash.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/numerics/safe_conversions.h" 16 #include "base/numerics/safe_conversions.h"
17 #include "base/pickle.h" 17 #include "base/pickle.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/task_runner_util.h" 19 #include "base/task_runner_util.h"
20 #include "base/threading/thread_restrictions.h" 20 #include "base/threading/thread_restrictions.h"
21 #include "net/disk_cache/simple/simple_backend_version.h" 21 #include "net/disk_cache/simple/simple_backend_version.h"
22 #include "net/disk_cache/simple/simple_entry_format.h" 22 #include "net/disk_cache/simple/simple_entry_format.h"
23 #include "net/disk_cache/simple/simple_histogram_macros.h" 23 #include "net/disk_cache/simple/simple_histogram_macros.h"
24 #include "net/disk_cache/simple/simple_index.h" 24 #include "net/disk_cache/simple/simple_index.h"
25 #include "net/disk_cache/simple/simple_synchronous_entry.h" 25 #include "net/disk_cache/simple/simple_synchronous_entry.h"
26 #include "net/disk_cache/simple/simple_util.h" 26 #include "net/disk_cache/simple/simple_util.h"
27 #include "third_party/zlib/zlib.h" 27 #include "third_party/zlib/zlib.h"
28 28
29 using base::File;
30
31 namespace disk_cache { 29 namespace disk_cache {
32 namespace { 30 namespace {
33 31
34 const int kEntryFilesHashLength = 16; 32 const int kEntryFilesHashLength = 16;
35 const int kEntryFilesSuffixLength = 2; 33 const int kEntryFilesSuffixLength = 2;
36 34
37 // Limit on how big a file we are willing to work with, to avoid crashes 35 // Limit on how big a file we are willing to work with, to avoid crashes
38 // when its corrupt. 36 // when its corrupt.
39 const int kMaxEntriesInIndex = 1000000; 37 const int kMaxEntriesInIndex = 1000000;
40 38
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 quality = STALE_INDEX_MISSED_ENTRIES; 101 quality = STALE_INDEX_MISSED_ENTRIES;
104 else if (extra_entry_count > 0) 102 else if (extra_entry_count > 0)
105 quality = STALE_INDEX_EXTRA_ENTRIES; 103 quality = STALE_INDEX_EXTRA_ENTRIES;
106 else 104 else
107 quality = STALE_INDEX_OK; 105 quality = STALE_INDEX_OK;
108 SIMPLE_CACHE_UMA(ENUMERATION, "StaleIndexQuality", cache_type, quality, 106 SIMPLE_CACHE_UMA(ENUMERATION, "StaleIndexQuality", cache_type, quality,
109 STALE_INDEX_MAX); 107 STALE_INDEX_MAX);
110 } 108 }
111 109
112 bool WritePickleFile(base::Pickle* pickle, const base::FilePath& file_name) { 110 bool WritePickleFile(base::Pickle* pickle, const base::FilePath& file_name) {
113 File file( 111 base::File file(
114 file_name, 112 file_name,
115 File::FLAG_CREATE_ALWAYS | File::FLAG_WRITE | File::FLAG_SHARE_DELETE); 113 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | base::File::FLAG _SHARE_DELETE);
116 if (!file.IsValid()) 114 if (!file.IsValid())
117 return false; 115 return false;
118 116
119 int bytes_written = 117 int bytes_written =
120 file.Write(0, static_cast<const char*>(pickle->data()), pickle->size()); 118 file.Write(0, static_cast<const char*>(pickle->data()), pickle->size());
121 if (bytes_written != base::checked_cast<int>(pickle->size())) { 119 if (bytes_written != base::checked_cast<int>(pickle->size())) {
122 simple_util::SimpleCacheDeleteFile(file_name); 120 simple_util::SimpleCacheDeleteFile(file_name);
123 return false; 121 return false;
124 } 122 }
125 return true; 123 return true;
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } 461 }
464 UmaRecordIndexInitMethod(out_result->init_method, cache_type); 462 UmaRecordIndexInitMethod(out_result->init_method, cache_type);
465 } 463 }
466 464
467 // static 465 // static
468 void SimpleIndexFile::SyncLoadFromDisk(const base::FilePath& index_filename, 466 void SimpleIndexFile::SyncLoadFromDisk(const base::FilePath& index_filename,
469 base::Time* out_last_cache_seen_by_index, 467 base::Time* out_last_cache_seen_by_index,
470 SimpleIndexLoadResult* out_result) { 468 SimpleIndexLoadResult* out_result) {
471 out_result->Reset(); 469 out_result->Reset();
472 470
473 File file(index_filename, File::FLAG_OPEN | File::FLAG_READ | 471 base::File file(index_filename, base::File::FLAG_OPEN | base::File::FLAG_READ |
474 File::FLAG_SHARE_DELETE | 472 base::File::FLAG_SHARE_DELETE |
475 File::FLAG_SEQUENTIAL_SCAN); 473 base::File::FLAG_SEQUENTIAL_SCAN);
476 if (!file.IsValid()) 474 if (!file.IsValid())
477 return; 475 return;
478 476
479 // Sanity-check the length. We don't want to crash trying to read some corrupt 477 // Sanity-check the length. We don't want to crash trying to read some corrupt
480 // 10GiB file or such. 478 // 10GiB file or such.
481 int64_t file_length = file.GetLength(); 479 int64_t file_length = file.GetLength();
482 if (file_length < 0 || file_length > kMaxIndexFileSizeBytes) { 480 if (file_length < 0 || file_length > kMaxIndexFileSizeBytes) {
483 simple_util::SimpleCacheDeleteFile(index_filename); 481 simple_util::SimpleCacheDeleteFile(index_filename);
484 return; 482 return;
485 } 483 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 bool SimpleIndexFile::LegacyIsIndexFileStale( 603 bool SimpleIndexFile::LegacyIsIndexFileStale(
606 base::Time cache_last_modified, 604 base::Time cache_last_modified,
607 const base::FilePath& index_file_path) { 605 const base::FilePath& index_file_path) {
608 base::Time index_mtime; 606 base::Time index_mtime;
609 if (!simple_util::GetMTime(index_file_path, &index_mtime)) 607 if (!simple_util::GetMTime(index_file_path, &index_mtime))
610 return true; 608 return true;
611 return index_mtime < cache_last_modified; 609 return index_mtime < cache_last_modified;
612 } 610 }
613 611
614 } // namespace disk_cache 612 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | net/disk_cache/simple/simple_synchronous_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698