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

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

Issue 12192005: Add new simple disk cache backend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remediation to review Created 7 years, 10 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/disk_cache/simple/simple_backend_impl.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/file_util.h"
10 #include "base/location.h"
11 #include "base/message_loop_proxy.h"
12 #include "base/threading/worker_pool.h"
13 #include "net/base/net_errors.h"
14 #include "net/disk_cache/simple/simple_entry_impl.h"
15
16 using base::FilePath;
17 using base::MessageLoopProxy;
18 using base::Time;
19 using base::WorkerPool;
20 using file_util::DirectoryExists;
21 using file_util::CreateDirectory;
22
23 namespace {
24
25 const char* kSimpleBackendSubdirectory = "Simple";
26
27 } // namespace
28
29 namespace disk_cache {
30
31 // static
32 int SimpleBackendImpl::CreateBackend(
33 const FilePath& full_path,
34 bool force,
35 int max_bytes,
36 net::CacheType type,
37 uint32 flags,
38 scoped_refptr<base::TaskRunner> task_runner,
39 net::NetLog* net_log,
40 Backend** backend,
41 const CompletionCallback& callback) {
42 // TODO(gavinp): Use the |net_log|.
43 DCHECK_EQ(net::DISK_CACHE, type);
44 FilePath simple_cache_path =
45 full_path.AppendASCII(kSimpleBackendSubdirectory);
46 WorkerPool::PostTask(FROM_HERE,
47 base::Bind(&SimpleBackendImpl::
48 EnsureCachePathExistsOnWorkerThread,
pasko-google - do not use 2013/02/11 13:59:25 nit: here and below adjust amount of leading space
gavinp 2013/02/11 17:55:50 Previously I had lines like this with FROM_HERE on
pasko-google - do not use 2013/02/11 18:13:44 ouch sorry, this specific leading space is fine, I
gavinp 2013/02/11 18:32:26 Aha! Good catch. Fixed.
49 simple_cache_path,
50 MessageLoopProxy::current(), callback,
51 backend),
52 true);
53 return net::ERR_IO_PENDING;
54 }
55
56 SimpleBackendImpl::~SimpleBackendImpl() {
57 DCHECK(thread_checker_.CalledOnValidThread());
58 }
59
60 net::CacheType SimpleBackendImpl::GetCacheType() const {
61 DCHECK(thread_checker_.CalledOnValidThread());
62 return net::DISK_CACHE;
63 }
64
65 int32 SimpleBackendImpl::GetEntryCount() const {
66 // TODO(gavinp): Provide implementation for this function.
67 return 0;
68 }
69
70 int SimpleBackendImpl::OpenEntry(const std::string& key,
71 Entry** entry,
72 const CompletionCallback& callback) {
73 DCHECK(thread_checker_.CalledOnValidThread());
74 return SimpleEntryImpl::OpenEntry(path_, key, entry, callback);
75 }
76
77 int SimpleBackendImpl::CreateEntry(const std::string& key,
78 Entry** entry,
79 const CompletionCallback& callback) {
80 DCHECK(thread_checker_.CalledOnValidThread());
81 return SimpleEntryImpl::CreateEntry(path_, key, entry, callback);
82 }
83
84 int SimpleBackendImpl::DoomEntry(const std::string& key,
85 const net::CompletionCallback& callback) {
86 DCHECK(thread_checker_.CalledOnValidThread());
87 return SimpleEntryImpl::DoomEntry(path_, key, callback);
88 }
89
90 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) {
91 // TODO(gavinp): Provide implementation for this function.
92 DCHECK(thread_checker_.CalledOnValidThread());
93 return net::ERR_FAILED;
94 }
95
96 int SimpleBackendImpl::DoomEntriesBetween(
97 const Time initial_time,
98 const Time end_time,
99 const CompletionCallback& callback) {
100 // TODO(gavinp): Provide implementation for this function.
101 DCHECK(thread_checker_.CalledOnValidThread());
102 return net::ERR_FAILED;
103 }
104
105 int SimpleBackendImpl::DoomEntriesSince(
106 const Time initial_time,
107 const CompletionCallback& callback) {
108 // TODO(gavinp): Provide implementation for this function.
109 DCHECK(thread_checker_.CalledOnValidThread());
110 return net::ERR_FAILED;
111 }
112
113 int SimpleBackendImpl::OpenNextEntry(void** iter,
114 Entry** next_entry,
115 const CompletionCallback& callback) {
116 DCHECK(thread_checker_.CalledOnValidThread());
117 NOTREACHED() << "Not implemented.";
118 return net::ERR_FAILED;
119 }
120
121 void SimpleBackendImpl::EndEnumeration(void** iter) {
122 DCHECK(thread_checker_.CalledOnValidThread());
123 NOTREACHED() << "Not implemented.";
124 }
125
126 void SimpleBackendImpl::GetStats(
127 std::vector<std::pair<std::string, std::string> >* stats) {
128 DCHECK(thread_checker_.CalledOnValidThread());
129 NOTREACHED() << "Not implemented.";
130 }
131
132 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) {
133 DCHECK(thread_checker_.CalledOnValidThread());
134 NOTREACHED() << "Not implemented.";
135 }
136
137 SimpleBackendImpl::SimpleBackendImpl(
138 const FilePath& path) : path_(path) {
139 }
140
141 // static
142 void SimpleBackendImpl::EnsureCachePathExistsOnWorkerThread(
143 const FilePath& path,
144 const scoped_refptr<base::TaskRunner>& callback_runner,
145 const CompletionCallback& callback,
146 Backend** backend) {
147 int result = net::OK;
148 if (!DirectoryExists(path) && !CreateDirectory(path))
149 result = net::ERR_FAILED;
150 callback_runner->PostTask(FROM_HERE,
151 base::Bind(&SimpleBackendImpl::OnCachePathCreated,
152 result, path, callback, backend));
153 }
154
155 // static
156 void SimpleBackendImpl::OnCachePathCreated(
157 int result,
158 const FilePath& path,
159 const CompletionCallback& callback,
160 Backend** backend) {
161 if (result == net::OK)
162 *backend = new SimpleBackendImpl(path);
163 else
164 *backend = NULL;
165 callback.Run(result);
166 }
167
168 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698