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

Side by Side Diff: net/disk_cache/simple/simple_index.cc

Issue 14022012: Code quality and standards in SimpleBackend. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remediate 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/simple/simple_index.h" 5 #include "net/disk_cache/simple/simple_index.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/pickle.h" 14 #include "base/pickle.h"
15 #include "base/task_runner.h" 15 #include "base/task_runner.h"
16 #include "base/threading/worker_pool.h" 16 #include "base/threading/worker_pool.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/disk_cache/simple/simple_entry_format.h" 18 #include "net/disk_cache/simple/simple_entry_format.h"
19 #include "net/disk_cache/simple/simple_index_file.h" 19 #include "net/disk_cache/simple/simple_index_file.h"
20 #include "net/disk_cache/simple/simple_util.h" 20 #include "net/disk_cache/simple/simple_util.h"
21 21
22 namespace disk_cache { 22 namespace disk_cache {
23 23
24 EntryMetadata::EntryMetadata() : 24 EntryMetadata::EntryMetadata() : hash_key_(0),
rvargas (doing something else) 2013/04/18 17:31:50 nit: this initializer list has to start on the nex
25 hash_key_(0), 25 last_used_time_(0),
26 last_used_time_(0), 26 entry_size_(0) {
27 entry_size_(0) 27 }
28 {}
29 28
30 29
31 EntryMetadata::EntryMetadata(uint64 hash_key, 30 EntryMetadata::EntryMetadata(uint64 hash_key,
32 base::Time last_used_time, 31 base::Time last_used_time,
33 uint64 entry_size) : 32 uint64 entry_size) :
34 hash_key_(hash_key), 33 hash_key_(hash_key),
35 last_used_time_(last_used_time.ToInternalValue()), 34 last_used_time_(last_used_time.ToInternalValue()),
36 entry_size_(entry_size) 35 entry_size_(entry_size) {
37 {} 36 }
38 37
39 base::Time EntryMetadata::GetLastUsedTime() const { 38 base::Time EntryMetadata::GetLastUsedTime() const {
40 return base::Time::FromInternalValue(last_used_time_); 39 return base::Time::FromInternalValue(last_used_time_);
41 } 40 }
42 41
43 void EntryMetadata::SetLastUsedTime(const base::Time& last_used_time) { 42 void EntryMetadata::SetLastUsedTime(const base::Time& last_used_time) {
44 last_used_time_ = last_used_time.ToInternalValue(); 43 last_used_time_ = last_used_time.ToInternalValue();
45 } 44 }
46 45
47 void EntryMetadata::Serialize(Pickle* pickle) const { 46 void EntryMetadata::Serialize(Pickle* pickle) const {
(...skipping 15 matching lines...) Expand all
63 62
64 void EntryMetadata::MergeWith(const EntryMetadata& from) { 63 void EntryMetadata::MergeWith(const EntryMetadata& from) {
65 DCHECK_EQ(hash_key_, from.hash_key_); 64 DCHECK_EQ(hash_key_, from.hash_key_);
66 if (last_used_time_ == 0) 65 if (last_used_time_ == 0)
67 last_used_time_ = from.last_used_time_; 66 last_used_time_ = from.last_used_time_;
68 if (entry_size_ == 0) 67 if (entry_size_ == 0)
69 entry_size_ = from.entry_size_; 68 entry_size_ = from.entry_size_;
70 } 69 }
71 70
72 SimpleIndex::SimpleIndex( 71 SimpleIndex::SimpleIndex(
73 const scoped_refptr<base::TaskRunner>& cache_thread, 72 base::SingleThreadTaskRunner* cache_thread,
74 const scoped_refptr<base::TaskRunner>& io_thread, 73 base::SingleThreadTaskRunner* io_thread,
75 const base::FilePath& path) 74 const base::FilePath& path)
76 : cache_size_(0), 75 : cache_size_(0),
77 initialized_(false), 76 initialized_(false),
78 index_filename_(path.AppendASCII("simple-index")), 77 index_filename_(path.AppendASCII("simple-index")),
79 cache_thread_(cache_thread), 78 cache_thread_(cache_thread),
80 io_thread_(io_thread) {} 79 io_thread_(io_thread) {}
81 80
82 SimpleIndex::~SimpleIndex() { 81 SimpleIndex::~SimpleIndex() {
83 DCHECK(io_thread_checker_.CalledOnValidThread()); 82 DCHECK(io_thread_checker_.CalledOnValidThread());
84 } 83 }
85 84
86 void SimpleIndex::Initialize() { 85 void SimpleIndex::Initialize() {
87 DCHECK(io_thread_checker_.CalledOnValidThread()); 86 DCHECK(io_thread_checker_.CalledOnValidThread());
88 IndexCompletionCallback merge_callback = 87 IndexCompletionCallback merge_callback =
89 base::Bind(&SimpleIndex::MergeInitializingSet, this); 88 base::Bind(&SimpleIndex::MergeInitializingSet, AsWeakPtr());
90 base::WorkerPool::PostTask(FROM_HERE, 89 base::WorkerPool::PostTask(FROM_HERE,
91 base::Bind(&SimpleIndex::LoadFromDisk, 90 base::Bind(&SimpleIndex::LoadFromDisk,
92 index_filename_, 91 index_filename_,
93 io_thread_, 92 io_thread_,
94 merge_callback), 93 merge_callback),
95 true); 94 true);
96 } 95 }
97 96
98 void SimpleIndex::Insert(const std::string& key) { 97 void SimpleIndex::Insert(const std::string& key) {
99 DCHECK(io_thread_checker_.CalledOnValidThread()); 98 DCHECK(io_thread_checker_.CalledOnValidThread());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 const disk_cache::EntryMetadata& entry_metadata, 154 const disk_cache::EntryMetadata& entry_metadata,
156 EntrySet* entry_set) { 155 EntrySet* entry_set) {
157 DCHECK(entry_set); 156 DCHECK(entry_set);
158 entry_set->insert( 157 entry_set->insert(
159 std::make_pair(entry_metadata.GetHashKey(), entry_metadata)); 158 std::make_pair(entry_metadata.GetHashKey(), entry_metadata));
160 } 159 }
161 160
162 // static 161 // static
163 void SimpleIndex::LoadFromDisk( 162 void SimpleIndex::LoadFromDisk(
164 const base::FilePath& index_filename, 163 const base::FilePath& index_filename,
165 const scoped_refptr<base::TaskRunner>& io_thread, 164 base::SingleThreadTaskRunner* io_thread,
166 const IndexCompletionCallback& completion_callback) { 165 const IndexCompletionCallback& completion_callback) {
167 scoped_ptr<EntrySet> index_file_entries = 166 scoped_ptr<EntrySet> index_file_entries =
168 SimpleIndexFile::LoadFromDisk(index_filename); 167 SimpleIndexFile::LoadFromDisk(index_filename);
169 168
170 if (!index_file_entries.get()) 169 if (!index_file_entries.get())
171 index_file_entries = SimpleIndex::RestoreFromDisk(index_filename); 170 index_file_entries = SimpleIndex::RestoreFromDisk(index_filename);
172 171
173 io_thread->PostTask(FROM_HERE, 172 io_thread->PostTask(FROM_HERE,
174 base::Bind(completion_callback, 173 base::Bind(completion_callback,
175 base::Passed(&index_file_entries))); 174 base::Passed(&index_file_entries)));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 cache_size_); 278 cache_size_);
280 scoped_ptr<Pickle> pickle = SimpleIndexFile::Serialize(index_metadata, 279 scoped_ptr<Pickle> pickle = SimpleIndexFile::Serialize(index_metadata,
281 entries_set_); 280 entries_set_);
282 cache_thread_->PostTask(FROM_HERE, base::Bind( 281 cache_thread_->PostTask(FROM_HERE, base::Bind(
283 &SimpleIndex::WriteToDiskInternal, 282 &SimpleIndex::WriteToDiskInternal,
284 index_filename_, 283 index_filename_,
285 base::Passed(&pickle))); 284 base::Passed(&pickle)));
286 } 285 }
287 286
288 } // namespace disk_cache 287 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698