| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/block_files.h" | 5 #include "net/disk_cache/block_files.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/histogram.h" | 8 #include "base/histogram.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 DCHECK(index < 256 || index >= 0); | 189 DCHECK(index < 256 || index >= 0); |
| 190 std::wstring name(path_); | 190 std::wstring name(path_); |
| 191 std::wstring tmp = StringPrintf(L"%ls%d", kBlockName, index); | 191 std::wstring tmp = StringPrintf(L"%ls%d", kBlockName, index); |
| 192 file_util::AppendToPath(&name, tmp); | 192 file_util::AppendToPath(&name, tmp); |
| 193 | 193 |
| 194 return name; | 194 return name; |
| 195 } | 195 } |
| 196 | 196 |
| 197 bool BlockFiles::CreateBlockFile(int index, FileType file_type, bool force) { | 197 bool BlockFiles::CreateBlockFile(int index, FileType file_type, bool force) { |
| 198 std::wstring name = Name(index); | 198 std::wstring name = Name(index); |
| 199 int flags = force ? OS_FILE_CREATE_ALWAYS : OS_FILE_CREATE; | 199 int flags = |
| 200 flags |= OS_FILE_WRITE | OS_FILE_SHARE_READ; | 200 force ? base::PLATFORM_FILE_CREATE_ALWAYS : base::PLATFORM_FILE_CREATE; |
| 201 flags |= base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE; |
| 201 | 202 |
| 202 scoped_refptr<File> file(new File(CreateOSFile(name.c_str(), flags, NULL))); | 203 scoped_refptr<File> file(new File( |
| 204 base::CreatePlatformFile(name.c_str(), flags, NULL))); |
| 203 if (!file->IsValid()) | 205 if (!file->IsValid()) |
| 204 return false; | 206 return false; |
| 205 | 207 |
| 206 BlockFileHeader header; | 208 BlockFileHeader header; |
| 207 header.entry_size = Addr::BlockSizeForFileType(file_type); | 209 header.entry_size = Addr::BlockSizeForFileType(file_type); |
| 208 header.this_file = static_cast<int16>(index); | 210 header.this_file = static_cast<int16>(index); |
| 209 DCHECK(index <= kint16max && index >= 0); | 211 DCHECK(index <= kint16max && index >= 0); |
| 210 | 212 |
| 211 return file->Write(&header, sizeof(header), 0); | 213 return file->Write(&header, sizeof(header), 0); |
| 212 } | 214 } |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 int num_entries = (file_size - sizeof(*header)) / header->entry_size; | 416 int num_entries = (file_size - sizeof(*header)) / header->entry_size; |
| 415 header->max_entries = num_entries; | 417 header->max_entries = num_entries; |
| 416 } | 418 } |
| 417 | 419 |
| 418 FixAllocationCounters(header); | 420 FixAllocationCounters(header); |
| 419 header->updating = 0; | 421 header->updating = 0; |
| 420 return true; | 422 return true; |
| 421 } | 423 } |
| 422 | 424 |
| 423 } // namespace disk_cache | 425 } // namespace disk_cache |
| OLD | NEW |