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_backend_impl.cc

Issue 12192005: Add new simple disk cache backend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix 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
« no previous file with comments | « net/disk_cache/simple/simple_backend_impl.h ('k') | net/disk_cache/simple/simple_disk_format.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::EnsureCachePathExists,
48 simple_cache_path,
49 MessageLoopProxy::current(), callback,
50 backend),
51 true);
52 return net::ERR_IO_PENDING;
53 }
54
55 SimpleBackendImpl::~SimpleBackendImpl() {
56 }
57
58 net::CacheType SimpleBackendImpl::GetCacheType() const {
59 return net::DISK_CACHE;
60 }
61
62 int32 SimpleBackendImpl::GetEntryCount() const {
63 NOTIMPLEMENTED();
64 return 0;
65 }
66
67 int SimpleBackendImpl::OpenEntry(const std::string& key,
68 Entry** entry,
69 const CompletionCallback& callback) {
70 return SimpleEntryImpl::OpenEntry(path_, key, entry, callback);
71 }
72
73 int SimpleBackendImpl::CreateEntry(const std::string& key,
74 Entry** entry,
75 const CompletionCallback& callback) {
76 return SimpleEntryImpl::CreateEntry(path_, key, entry, callback);
77 }
78
79 int SimpleBackendImpl::DoomEntry(const std::string& key,
80 const net::CompletionCallback& callback) {
81 return SimpleEntryImpl::DoomEntry(path_, key, callback);
82 }
83
84 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) {
85 NOTIMPLEMENTED();
86 return net::ERR_FAILED;
87 }
88
89 int SimpleBackendImpl::DoomEntriesBetween(
90 const Time initial_time,
91 const Time end_time,
92 const CompletionCallback& callback) {
93 NOTIMPLEMENTED();
94 return net::ERR_FAILED;
95 }
96
97 int SimpleBackendImpl::DoomEntriesSince(
98 const Time initial_time,
99 const CompletionCallback& callback) {
100 NOTIMPLEMENTED();
101 return net::ERR_FAILED;
102 }
103
104 int SimpleBackendImpl::OpenNextEntry(void** iter,
105 Entry** next_entry,
106 const CompletionCallback& callback) {
107 NOTIMPLEMENTED();
108 return net::ERR_FAILED;
109 }
110
111 void SimpleBackendImpl::EndEnumeration(void** iter) {
112 NOTIMPLEMENTED();
113 }
114
115 void SimpleBackendImpl::GetStats(
116 std::vector<std::pair<std::string, std::string> >* stats) {
117 NOTIMPLEMENTED();
118 }
119
120 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) {
121 NOTIMPLEMENTED();
122 }
123
124 SimpleBackendImpl::SimpleBackendImpl(
125 const FilePath& path) : path_(path) {
126 }
127
128 // static
129 void SimpleBackendImpl::EnsureCachePathExists(
130 const FilePath& path,
131 const scoped_refptr<base::TaskRunner>& callback_runner,
132 const CompletionCallback& callback,
133 Backend** backend) {
134 int result = net::OK;
135 if (!DirectoryExists(path) && !CreateDirectory(path))
136 result = net::ERR_FAILED;
137 callback_runner->PostTask(FROM_HERE,
138 base::Bind(&SimpleBackendImpl::OnCachePathCreated,
139 result, path, callback, backend));
140 }
141
142 // static
143 void SimpleBackendImpl::OnCachePathCreated(int result,
144 const FilePath& path,
145 const CompletionCallback& callback,
146 Backend** backend) {
147 if (result == net::OK)
148 *backend = new SimpleBackendImpl(path);
149 else
150 *backend = NULL;
151 callback.Run(result);
152 }
153
154 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_backend_impl.h ('k') | net/disk_cache/simple/simple_disk_format.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698