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

Side by Side Diff: net/disk_cache/simple/simple_backend_impl.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_backend_impl.h" 5 #include "net/disk_cache/simple/simple_backend_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "base/threading/worker_pool.h" 12 #include "base/threading/worker_pool.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/disk_cache/simple/simple_entry_impl.h" 14 #include "net/disk_cache/simple/simple_entry_impl.h"
15 #include "net/disk_cache/simple/simple_index.h" 15 #include "net/disk_cache/simple/simple_index.h"
16 16
17 using base::FilePath; 17 using base::FilePath;
18 using base::MessageLoopProxy; 18 using base::MessageLoopProxy;
19 using base::SingleThreadTaskRunner;
19 using base::Time; 20 using base::Time;
20 using base::WorkerPool; 21 using base::WorkerPool;
21 using file_util::DirectoryExists; 22 using file_util::DirectoryExists;
22 using file_util::CreateDirectory; 23 using file_util::CreateDirectory;
23 24
24 namespace { 25 namespace {
25 26
26 // Must run on IO Thread. 27 // Must run on IO Thread.
27 void DeleteBackendImpl(disk_cache::Backend** backend, 28 void DeleteBackendImpl(disk_cache::Backend** backend,
28 const net::CompletionCallback& callback, 29 const net::CompletionCallback& callback,
29 int result) { 30 int result) {
30 DCHECK(*backend); 31 DCHECK(*backend);
31 delete *backend; 32 delete *backend;
32 *backend = NULL; 33 *backend = NULL;
33 callback.Run(result); 34 callback.Run(result);
34 } 35 }
35 36
36 } // namespace 37 } // namespace
37 38
38 namespace disk_cache { 39 namespace disk_cache {
39 40
40 SimpleBackendImpl::SimpleBackendImpl( 41 SimpleBackendImpl::SimpleBackendImpl(
41 const FilePath& path, 42 const FilePath& path,
42 int max_bytes, 43 int max_bytes,
43 net::CacheType type, 44 net::CacheType type,
44 const scoped_refptr<base::TaskRunner>& cache_thread, 45 base::SingleThreadTaskRunner* cache_thread,
45 net::NetLog* net_log) 46 net::NetLog* net_log)
46 : path_(path), 47 : path_(path),
47 index_(new SimpleIndex(cache_thread, 48 index_(new SimpleIndex(cache_thread,
48 MessageLoopProxy::current(), // io_thread 49 MessageLoopProxy::current(), // io_thread
49 path)), 50 path)),
50 cache_thread_(cache_thread) {} 51 cache_thread_(cache_thread) {}
51 52
52 SimpleBackendImpl::~SimpleBackendImpl() { 53 SimpleBackendImpl::~SimpleBackendImpl() {
53 index_->WriteToDisk(); 54 index_->WriteToDisk();
54 } 55 }
(...skipping 16 matching lines...) Expand all
71 } 72 }
72 73
73 int32 SimpleBackendImpl::GetEntryCount() const { 74 int32 SimpleBackendImpl::GetEntryCount() const {
74 NOTIMPLEMENTED(); 75 NOTIMPLEMENTED();
75 return 0; 76 return 0;
76 } 77 }
77 78
78 int SimpleBackendImpl::OpenEntry(const std::string& key, 79 int SimpleBackendImpl::OpenEntry(const std::string& key,
79 Entry** entry, 80 Entry** entry,
80 const CompletionCallback& callback) { 81 const CompletionCallback& callback) {
81 return SimpleEntryImpl::OpenEntry(index_, path_, key, entry, callback); 82 return SimpleEntryImpl::OpenEntry(index_.get(), path_, key, entry, callback);
82 } 83 }
83 84
84 int SimpleBackendImpl::CreateEntry(const std::string& key, 85 int SimpleBackendImpl::CreateEntry(const std::string& key,
85 Entry** entry, 86 Entry** entry,
86 const CompletionCallback& callback) { 87 const CompletionCallback& callback) {
87 return SimpleEntryImpl::CreateEntry(index_, path_, key, entry, callback); 88 return SimpleEntryImpl::CreateEntry(index_.get(), path_, key, entry,
89 callback);
88 } 90 }
89 91
90 int SimpleBackendImpl::DoomEntry(const std::string& key, 92 int SimpleBackendImpl::DoomEntry(const std::string& key,
91 const net::CompletionCallback& callback) { 93 const net::CompletionCallback& callback) {
92 return SimpleEntryImpl::DoomEntry(index_, path_, key, callback); 94 return SimpleEntryImpl::DoomEntry(index_.get(), path_, key, callback);
93 } 95 }
94 96
95 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) { 97 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) {
96 NOTIMPLEMENTED(); 98 NOTIMPLEMENTED();
97 return net::ERR_FAILED; 99 return net::ERR_FAILED;
98 } 100 }
99 101
100 int SimpleBackendImpl::DoomEntriesBetween( 102 int SimpleBackendImpl::DoomEntriesBetween(
101 const Time initial_time, 103 const Time initial_time,
102 const Time end_time, 104 const Time end_time,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 136
135 void SimpleBackendImpl::InitializeIndex( 137 void SimpleBackendImpl::InitializeIndex(
136 const CompletionCallback& callback, int result) { 138 const CompletionCallback& callback, int result) {
137 if (result == net::OK) 139 if (result == net::OK)
138 index_->Initialize(); 140 index_->Initialize();
139 callback.Run(result); 141 callback.Run(result);
140 } 142 }
141 143
142 // static 144 // static
143 void SimpleBackendImpl::CreateDirectory( 145 void SimpleBackendImpl::CreateDirectory(
144 MessageLoopProxy* io_thread, 146 SingleThreadTaskRunner* io_thread,
145 const base::FilePath& path, 147 const base::FilePath& path,
146 const InitializeIndexCallback& initialize_index_callback) { 148 const InitializeIndexCallback& initialize_index_callback) {
147 int rv = net::OK; 149 int rv = net::OK;
148 if (!file_util::PathExists(path) && !file_util::CreateDirectory(path)) { 150 if (!file_util::PathExists(path) && !file_util::CreateDirectory(path)) {
149 LOG(ERROR) << "Simple Cache Backend: failed to create: " << path.value(); 151 LOG(ERROR) << "Simple Cache Backend: failed to create: " << path.value();
150 rv = net::ERR_FAILED; 152 rv = net::ERR_FAILED;
151 } 153 }
152 154
153 io_thread->PostTask(FROM_HERE, base::Bind(initialize_index_callback, rv)); 155 io_thread->PostTask(FROM_HERE, base::Bind(initialize_index_callback, rv));
154 } 156 }
155 157
156 } // namespace disk_cache 158 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698