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

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

Issue 11269008: Cache backend for devices with flash storage (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Misc. Created 8 years, 1 month 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 (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 "base/logging.h" 5 #include "base/logging.h"
6 #include "net/disk_cache/flash/format.h" 6 #include "net/disk_cache/flash/format.h"
7 #include "net/disk_cache/flash/segment.h" 7 #include "net/disk_cache/flash/segment.h"
8 #include "net/disk_cache/flash/storage.h" 8 #include "net/disk_cache/flash/storage.h"
9 9
10 namespace disk_cache { 10 namespace disk_cache {
11 11
12 Segment::Segment(int32 index, bool read_only, Storage* storage) 12 Segment::Segment(int32 index, bool read_only, Storage* storage)
13 : read_only_(read_only), 13 : read_only_(read_only),
14 init_(false), 14 init_(false),
15 storage_(storage), 15 storage_(storage),
16 offset_(index * kFlashSegmentSize), 16 offset_(index * kFlashSegmentSize),
17 summary_offset_(offset_ + kFlashSegmentSize - kFlashSummarySize), 17 summary_offset_(offset_ + kFlashSegmentSize - kFlashSummarySize),
18 write_offset_(offset_) { 18 write_offset_(offset_) {
19 DCHECK(storage); 19 DCHECK(storage);
20 DCHECK(storage->size() % kFlashSegmentSize == 0); 20 DCHECK(storage->size() % kFlashSegmentSize == 0);
21 DCHECK(offset_ >= 0 && offset_ + kFlashSegmentSize <= storage->size());
22 } 21 }
23 22
24 Segment::~Segment() { 23 Segment::~Segment() {
25 DCHECK(read_only_); 24 DCHECK(!init_ || read_only_);
26 } 25 }
27 26
28 bool Segment::Init() { 27 bool Segment::Init() {
29 if (init_) 28 if (init_)
30 return false; 29 return false;
31 30
31 if (offset_ < 0 || offset_ + kFlashSegmentSize > storage_->size())
32 return false;
33
32 if (!read_only_) { 34 if (!read_only_) {
33 init_ = true; 35 init_ = true;
34 return true; 36 return true;
35 } 37 }
36 38
37 int32 summary[kFlashMaxEntryCount + 1]; 39 int32 summary[kFlashMaxEntryCount + 1];
38 if (!storage_->Read(summary, kFlashSummarySize, summary_offset_)) 40 if (!storage_->Read(summary, kFlashSummarySize, summary_offset_))
39 return false; 41 return false;
40 42
41 size_t entry_count = summary[0]; 43 size_t entry_count = summary[0];
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 read_only_ = true; 92 read_only_ = true;
91 return true; 93 return true;
92 } 94 }
93 95
94 bool Segment::CanHold(int32 size) const { 96 bool Segment::CanHold(int32 size) const {
95 return header_offsets_.size() < kFlashMaxEntryCount && 97 return header_offsets_.size() < kFlashMaxEntryCount &&
96 write_offset_ + size <= summary_offset_; 98 write_offset_ + size <= summary_offset_;
97 } 99 }
98 100
99 } // namespace disk_cache 101 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698