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

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

Issue 14265009: FlashCache refactorings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More refactorings. Created 7 years, 8 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
« no previous file with comments | « net/disk_cache/flash/log_store.h ('k') | net/disk_cache/flash/log_store_entry_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
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 "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "net/disk_cache/flash/format.h" 8 #include "net/disk_cache/flash/format.h"
9 #include "net/disk_cache/flash/log_store.h" 9 #include "net/disk_cache/flash/log_store.h"
10 #include "net/disk_cache/flash/segment.h" 10 #include "net/disk_cache/flash/segment.h"
11 #include "net/disk_cache/flash/storage.h" 11 #include "net/disk_cache/flash/storage.h"
12 12
13 namespace disk_cache { 13 namespace disk_cache {
14 14
15 LogStore::LogStore(Storage* storage) 15 LogStore::LogStore(const base::FilePath& path, int32 size)
16 : storage_(storage), 16 : storage_(path, size),
17 num_segments_(storage->size() / kFlashSegmentSize), 17 num_segments_(size / kFlashSegmentSize),
18 open_segments_(num_segments_), 18 open_segments_(num_segments_),
19 write_index_(0), 19 write_index_(0),
20 current_entry_id_(-1), 20 current_entry_id_(-1),
21 current_entry_num_bytes_left_to_write_(0), 21 current_entry_num_bytes_left_to_write_(0),
22 init_(false), 22 init_(false),
23 closed_(false) { 23 closed_(false) {
24 DCHECK(storage->size() % kFlashSegmentSize == 0); 24 DCHECK(size % kFlashSegmentSize == 0);
25 } 25 }
26 26
27 LogStore::~LogStore() { 27 LogStore::~LogStore() {
28 DCHECK(!init_ || closed_); 28 DCHECK(!init_ || closed_);
29 STLDeleteElements(&open_segments_); 29 STLDeleteElements(&open_segments_);
30 } 30 }
31 31
32 bool LogStore::Init() { 32 bool LogStore::Init() {
33 DCHECK(!init_); 33 DCHECK(!init_);
34 if (!storage_.Init())
35 return false;
36
34 // TODO(agayev): Once we start persisting segment metadata to disk, we will 37 // TODO(agayev): Once we start persisting segment metadata to disk, we will
35 // start from where we left off during the last shutdown. 38 // start from where we left off during the last shutdown.
36 scoped_ptr<Segment> segment(new Segment(write_index_, false, storage_)); 39 scoped_ptr<Segment> segment(new Segment(write_index_, false, &storage_));
37 if (!segment->Init()) 40 if (!segment->Init())
38 return false; 41 return false;
39 42
40 segment->AddUser(); 43 segment->AddUser();
41 open_segments_[write_index_] = segment.release(); 44 open_segments_[write_index_] = segment.release();
42 init_ = true; 45 init_ = true;
43 return true; 46 return true;
44 } 47 }
45 48
46 bool LogStore::Close() { 49 bool LogStore::Close() {
(...skipping 15 matching lines...) Expand all
62 if (!open_segments_[write_index_]->Close()) 65 if (!open_segments_[write_index_]->Close())
63 return false; 66 return false;
64 67
65 open_segments_[write_index_]->ReleaseUser(); 68 open_segments_[write_index_]->ReleaseUser();
66 if (open_segments_[write_index_]->HasNoUsers()) { 69 if (open_segments_[write_index_]->HasNoUsers()) {
67 delete open_segments_[write_index_]; 70 delete open_segments_[write_index_];
68 open_segments_[write_index_] = NULL; 71 open_segments_[write_index_] = NULL;
69 } 72 }
70 73
71 write_index_ = GetNextSegmentIndex(); 74 write_index_ = GetNextSegmentIndex();
72 scoped_ptr<Segment> segment(new Segment(write_index_, false, storage_)); 75 scoped_ptr<Segment> segment(new Segment(write_index_, false, &storage_));
73 if (!segment->Init()) 76 if (!segment->Init())
74 return false; 77 return false;
75 78
76 segment->AddUser(); 79 segment->AddUser();
77 open_segments_[write_index_] = segment.release(); 80 open_segments_[write_index_] = segment.release();
78 } 81 }
79 82
80 *id = open_segments_[write_index_]->write_offset(); 83 *id = open_segments_[write_index_]->write_offset();
81 open_segments_[write_index_]->StoreOffset(*id); 84 open_segments_[write_index_]->StoreOffset(*id);
82 current_entry_id_ = *id; 85 current_entry_id_ = *id;
(...skipping 29 matching lines...) Expand all
112 int32 index = id / disk_cache::kFlashSegmentSize; 115 int32 index = id / disk_cache::kFlashSegmentSize;
113 if (open_segments_[index]) { 116 if (open_segments_[index]) {
114 if (!open_segments_[index]->HaveOffset(id)) 117 if (!open_segments_[index]->HaveOffset(id))
115 return false; 118 return false;
116 open_segments_[index]->AddUser(); 119 open_segments_[index]->AddUser();
117 open_entries_.insert(id); 120 open_entries_.insert(id);
118 return true; 121 return true;
119 } 122 }
120 123
121 // Segment is not open. 124 // Segment is not open.
122 scoped_ptr<Segment> segment(new Segment(index, true, storage_)); 125 scoped_ptr<Segment> segment(new Segment(index, true, &storage_));
123 if (!segment->Init() || !segment->HaveOffset(id)) 126 if (!segment->Init() || !segment->HaveOffset(id))
124 return false; 127 return false;
125 128
126 segment->AddUser(); 129 segment->AddUser();
127 open_segments_[index] = segment.release(); 130 open_segments_[index] = segment.release();
128 open_entries_.insert(id); 131 open_entries_.insert(id);
129 return true; 132 return true;
130 } 133 }
131 134
132 bool LogStore::ReadData(int32 id, void* buffer, int32 size, 135 bool LogStore::ReadData(int32 id, void* buffer, int32 size,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 return next_index; 176 return next_index;
174 } 177 }
175 178
176 bool LogStore::InUse(int32 index) const { 179 bool LogStore::InUse(int32 index) const {
177 DCHECK(init_ && !closed_); 180 DCHECK(init_ && !closed_);
178 DCHECK(index >= 0 && index < num_segments_); 181 DCHECK(index >= 0 && index < num_segments_);
179 return open_segments_[index] != NULL; 182 return open_segments_[index] != NULL;
180 } 183 }
181 184
182 } // namespace disk_cache 185 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/flash/log_store.h ('k') | net/disk_cache/flash/log_store_entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698