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

Side by Side Diff: net/disk_cache/flash/storage.cc

Issue 125643002: Convert most of base and net to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use error_details() Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/flash/storage.h" 5 #include "net/disk_cache/flash/storage.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/platform_file.h"
11 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
12 #include "net/disk_cache/flash/format.h" 11 #include "net/disk_cache/flash/format.h"
13 12
14 namespace disk_cache { 13 namespace disk_cache {
15 14
16 Storage::Storage(const base::FilePath& path, 15 Storage::Storage(const base::FilePath& path,
17 int32 size) 16 int32 size)
18 : path_(path), size_(size) { 17 : path_(path), size_(size) {
19 COMPILE_ASSERT(kFlashPageSize % 2 == 0, invalid_page_size); 18 COMPILE_ASSERT(kFlashPageSize % 2 == 0, invalid_page_size);
20 COMPILE_ASSERT(kFlashBlockSize % kFlashPageSize == 0, invalid_block_size); 19 COMPILE_ASSERT(kFlashBlockSize % kFlashPageSize == 0, invalid_block_size);
21 DCHECK(size_ % kFlashBlockSize == 0); 20 DCHECK(size_ % kFlashBlockSize == 0);
22 } 21 }
23 22
24 bool Storage::Init() { 23 bool Storage::Init() {
25 int flags = base::PLATFORM_FILE_READ | 24 int flags = base::File::FLAG_READ |
26 base::PLATFORM_FILE_WRITE | 25 base::File::FLAG_WRITE |
27 base::PLATFORM_FILE_OPEN_ALWAYS; 26 base::File::FLAG_OPEN_ALWAYS;
28 27
29 file_ = base::CreatePlatformFile(path_, flags, NULL, NULL); 28 file_.Initialize(path_, flags);
30 if (file_ == base::kInvalidPlatformFileValue) 29 if (!file_.IsValid())
31 return false; 30 return false;
32 31
33 // TODO(agayev): if file already exists, do some validation and return either 32 // TODO(agayev): if file already exists, do some validation and return either
34 // true or false based on the result. 33 // true or false based on the result.
35 34
36 #if defined(OS_LINUX) 35 #if defined(OS_LINUX)
37 fallocate(file_, 0, 0, size_); 36 fallocate(file_.GetPlatformFile(), 0, 0, size_);
38 #endif 37 #endif
39 38
40 return true; 39 return true;
41 } 40 }
42 41
43 Storage::~Storage() { 42 Storage::~Storage() {
44 base::ClosePlatformFile(file_);
45 } 43 }
46 44
47 bool Storage::Read(void* buffer, int32 size, int32 offset) { 45 bool Storage::Read(void* buffer, int32 size, int32 offset) {
48 DCHECK(offset >= 0 && offset + size <= size_); 46 DCHECK(offset >= 0 && offset + size <= size_);
49 47
50 int rv = base::ReadPlatformFile(file_, offset, static_cast<char*>(buffer), 48 int rv = file_.Read(offset, static_cast<char*>(buffer), size);
51 size);
52 return rv == size; 49 return rv == size;
53 } 50 }
54 51
55 bool Storage::Write(const void* buffer, int32 size, int32 offset) { 52 bool Storage::Write(const void* buffer, int32 size, int32 offset) {
56 DCHECK(offset >= 0 && offset + size <= size_); 53 DCHECK(offset >= 0 && offset + size <= size_);
57 54
58 int rv = base::WritePlatformFile(file_, offset, 55 int rv = file_.Write(offset, static_cast<const char*>(buffer), size);
59 static_cast<const char*>(buffer), size);
60 return rv == size; 56 return rv == size;
61 } 57 }
62 58
63 } // namespace disk_cache 59 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698