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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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_version_upgrade.h" 5 #include "net/disk_cache/simple/simple_version_upgrade.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 8
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.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/logging.h" 13 #include "base/logging.h"
14 #include "base/pickle.h" 14 #include "base/pickle.h"
15 #include "net/disk_cache/simple/simple_backend_version.h" 15 #include "net/disk_cache/simple/simple_backend_version.h"
16 #include "net/disk_cache/simple/simple_entry_format_history.h" 16 #include "net/disk_cache/simple/simple_entry_format_history.h"
17 #include "third_party/zlib/zlib.h" 17 #include "third_party/zlib/zlib.h"
18 18
19 namespace { 19 namespace {
20 20
21 // It is not possible to upgrade cache structures on disk that are of version 21 // It is not possible to upgrade cache structures on disk that are of version
22 // below this, the entire cache should be dropped for them. 22 // below this, the entire cache should be dropped for them.
23 const uint32 kMinVersionAbleToUpgrade = 5; 23 const uint32_t kMinVersionAbleToUpgrade = 5;
24 24
25 const char kFakeIndexFileName[] = "index"; 25 const char kFakeIndexFileName[] = "index";
26 const char kIndexFileName[] = "the-real-index"; 26 const char kIndexFileName[] = "the-real-index";
27 27
28 void LogMessageFailedUpgradeFromVersion(int version) { 28 void LogMessageFailedUpgradeFromVersion(int version) {
29 LOG(ERROR) << "Failed to upgrade Simple Cache from version: " << version; 29 LOG(ERROR) << "Failed to upgrade Simple Cache from version: " << version;
30 } 30 }
31 31
32 bool WriteFakeIndexFile(const base::FilePath& file_name) { 32 bool WriteFakeIndexFile(const base::FilePath& file_name) {
33 base::File file(file_name, base::File::FLAG_CREATE | base::File::FLAG_WRITE); 33 base::File file(file_name, base::File::FLAG_CREATE | base::File::FLAG_WRITE);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 reinterpret_cast<char*>(&file_header), 148 reinterpret_cast<char*>(&file_header),
149 sizeof(file_header)); 149 sizeof(file_header));
150 if (bytes_read != sizeof(file_header) || 150 if (bytes_read != sizeof(file_header) ||
151 file_header.initial_magic_number != 151 file_header.initial_magic_number !=
152 disk_cache::simplecache_v5::kSimpleInitialMagicNumber) { 152 disk_cache::simplecache_v5::kSimpleInitialMagicNumber) {
153 LOG(ERROR) << "File structure does not match the disk cache backend."; 153 LOG(ERROR) << "File structure does not match the disk cache backend.";
154 return false; 154 return false;
155 } 155 }
156 fake_index_file.Close(); 156 fake_index_file.Close();
157 157
158 uint32 version_from = file_header.version; 158 uint32_t version_from = file_header.version;
159 if (version_from < kMinVersionAbleToUpgrade || 159 if (version_from < kMinVersionAbleToUpgrade ||
160 version_from > kSimpleVersion) { 160 version_from > kSimpleVersion) {
161 LOG(ERROR) << "Inconsistent cache version."; 161 LOG(ERROR) << "Inconsistent cache version.";
162 return false; 162 return false;
163 } 163 }
164 bool upgrade_needed = (version_from != kSimpleVersion); 164 bool upgrade_needed = (version_from != kSimpleVersion);
165 if (version_from == kMinVersionAbleToUpgrade) { 165 if (version_from == kMinVersionAbleToUpgrade) {
166 // Upgrade only the index for V4 -> V5 move. 166 // Upgrade only the index for V4 -> V5 move.
167 if (!UpgradeIndexV5V6(path)) { 167 if (!UpgradeIndexV5V6(path)) {
168 LogMessageFailedUpgradeFromVersion(file_header.version); 168 LogMessageFailedUpgradeFromVersion(file_header.version);
(...skipping 21 matching lines...) Expand all
190 } 190 }
191 } 191 }
192 // Verify during the test stage that the upgraders are implemented for all 192 // Verify during the test stage that the upgraders are implemented for all
193 // versions. The release build would cause backend initialization failure 193 // versions. The release build would cause backend initialization failure
194 // which would then later lead to removing all files known to the backend. 194 // which would then later lead to removing all files known to the backend.
195 DCHECK_EQ(kSimpleVersion, version_from); 195 DCHECK_EQ(kSimpleVersion, version_from);
196 return false; 196 return false;
197 } 197 }
198 198
199 } // namespace disk_cache 199 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_version_upgrade.h ('k') | net/disk_cache/simple/simple_version_upgrade_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698