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

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: fix dcheck 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,
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 DCHECK(thread_checker_.CalledOnValidThread());
67 NOTIMPLEMENTED();
68 return 0;
69 }
70
71 int SimpleBackendImpl::OpenEntry(const std::string& key,
72 Entry** entry,
73 const CompletionCallback& callback) {
74 DCHECK(thread_checker_.CalledOnValidThread());
75 return SimpleEntryImpl::OpenEntry(path_, key, entry, callback);
76 }
77
78 int SimpleBackendImpl::CreateEntry(const std::string& key,
79 Entry** entry,
80 const CompletionCallback& callback) {
81 DCHECK(thread_checker_.CalledOnValidThread());
82 return SimpleEntryImpl::CreateEntry(path_, key, entry, callback);
83 }
84
85 int SimpleBackendImpl::DoomEntry(const std::string& key,
86 const net::CompletionCallback& callback) {
87 DCHECK(thread_checker_.CalledOnValidThread());
88 return SimpleEntryImpl::DoomEntry(path_, key, callback);
89 }
90
91 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) {
92 DCHECK(thread_checker_.CalledOnValidThread());
93 NOTIMPLEMENTED();
94 return net::ERR_FAILED;
95 }
96
97 int SimpleBackendImpl::DoomEntriesBetween(
98 const Time initial_time,
99 const Time end_time,
100 const CompletionCallback& callback) {
101 DCHECK(thread_checker_.CalledOnValidThread());
102 NOTIMPLEMENTED();
103 return net::ERR_FAILED;
104 }
105
106 int SimpleBackendImpl::DoomEntriesSince(
107 const Time initial_time,
108 const CompletionCallback& callback) {
109 DCHECK(thread_checker_.CalledOnValidThread());
110 NOTIMPLEMENTED();
111 return net::ERR_FAILED;
112 }
113
114 int SimpleBackendImpl::OpenNextEntry(void** iter,
115 Entry** next_entry,
116 const CompletionCallback& callback) {
117 DCHECK(thread_checker_.CalledOnValidThread());
118 NOTIMPLEMENTED();
119 return net::ERR_FAILED;
120 }
121
122 void SimpleBackendImpl::EndEnumeration(void** iter) {
123 DCHECK(thread_checker_.CalledOnValidThread());
124 NOTIMPLEMENTED();
125 }
126
127 void SimpleBackendImpl::GetStats(
128 std::vector<std::pair<std::string, std::string> >* stats) {
129 DCHECK(thread_checker_.CalledOnValidThread());
130 NOTIMPLEMENTED();
131 }
132
133 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) {
134 DCHECK(thread_checker_.CalledOnValidThread());
135 NOTIMPLEMENTED();
136 }
137
138 SimpleBackendImpl::SimpleBackendImpl(
139 const FilePath& path) : path_(path) {
140 }
141
142 // static
143 void SimpleBackendImpl::EnsureCachePathExistsOnWorkerThread(
144 const FilePath& path,
145 const scoped_refptr<base::TaskRunner>& callback_runner,
146 const CompletionCallback& callback,
147 Backend** backend) {
148 int result = net::OK;
149 if (!DirectoryExists(path) && !CreateDirectory(path))
150 result = net::ERR_FAILED;
151 callback_runner->PostTask(FROM_HERE,
152 base::Bind(&SimpleBackendImpl::OnCachePathCreated,
153 result, path, callback, backend));
154 }
155
156 // static
157 void SimpleBackendImpl::OnCachePathCreated(
158 int result,
159 const FilePath& path,
160 const CompletionCallback& callback,
161 Backend** backend) {
162 if (result == net::OK)
163 *backend = new SimpleBackendImpl(path);
164 else
165 *backend = NULL;
166 callback.Run(result);
167 }
168
169 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698