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

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

Issue 182093002: Remove the flash specific disk cache backend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
« no previous file with comments | « net/disk_cache/flash/storage.h ('k') | net/disk_cache/flash/storage_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/disk_cache/flash/storage.h"
6
7 #include <fcntl.h>
8
9 #include "base/logging.h"
10 #include "net/base/net_errors.h"
11 #include "net/disk_cache/flash/format.h"
12
13 namespace disk_cache {
14
15 Storage::Storage(const base::FilePath& path,
16 int32 size)
17 : path_(path), size_(size) {
18 COMPILE_ASSERT(kFlashPageSize % 2 == 0, invalid_page_size);
19 COMPILE_ASSERT(kFlashBlockSize % kFlashPageSize == 0, invalid_block_size);
20 DCHECK(size_ % kFlashBlockSize == 0);
21 }
22
23 bool Storage::Init() {
24 int flags = base::File::FLAG_READ |
25 base::File::FLAG_WRITE |
26 base::File::FLAG_OPEN_ALWAYS;
27
28 file_.Initialize(path_, flags);
29 if (!file_.IsValid())
30 return false;
31
32 // TODO(agayev): if file already exists, do some validation and return either
33 // true or false based on the result.
34
35 #if defined(OS_LINUX)
36 fallocate(file_.GetPlatformFile(), 0, 0, size_);
37 #endif
38
39 return true;
40 }
41
42 Storage::~Storage() {
43 }
44
45 bool Storage::Read(void* buffer, int32 size, int32 offset) {
46 DCHECK(offset >= 0 && offset + size <= size_);
47
48 int rv = file_.Read(offset, static_cast<char*>(buffer), size);
49 return rv == size;
50 }
51
52 bool Storage::Write(const void* buffer, int32 size, int32 offset) {
53 DCHECK(offset >= 0 && offset + size <= size_);
54
55 int rv = file_.Write(offset, static_cast<const char*>(buffer), size);
56 return rv == size;
57 }
58
59 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/flash/storage.h ('k') | net/disk_cache/flash/storage_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698