OLD | NEW |
---|---|
(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/very_simple/very_simple_backend_impl.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/callback.h" | |
9 #include "base/file_util.h" | |
10 #include "base/message_loop_proxy.h" | |
11 #include "base/threading/worker_pool.h" | |
12 #include "net/base/net_errors.h" | |
13 #include "net/disk_cache/very_simple/very_simple_entry_impl.h" | |
rvargas (doing something else)
2013/02/06 03:28:40
How about renaming everything to simple, instead o
gavinp
2013/02/08 23:17:51
Done.
| |
14 | |
15 using base::Bind; | |
pasko-google - do not use
2013/02/05 21:20:33
nit:
although allowed by our style, in net/ the u
gavinp
2013/02/08 23:17:51
Done, although with grumpiness.
pasko-google - do not use
2013/02/11 13:59:25
I understand your pain and grumpiness, please also
| |
16 using base::Callback; | |
17 using base::MessageLoopProxy; | |
18 using base::Time; | |
19 using base::WorkerPool; | |
20 | |
21 namespace disk_cache { | |
22 | |
23 namespace { | |
rvargas (doing something else)
2013/02/06 03:28:40
nit: can this be outside of disk_cache namespace?
gavinp
2013/02/08 23:17:51
Done.
| |
24 | |
25 typedef Callback<VerySimpleBackendImpl*(void)> FactoryCallback; | |
26 | |
27 void EnsureCachePathExists( | |
28 const FilePath& path, | |
29 const scoped_refptr<base::TaskRunner> callback_runner, | |
30 const Backend::CompletionCallback& callback) { | |
31 int result = net::OK; | |
32 if (!file_util::DirectoryExists(path) && !file_util::CreateDirectory(path)) | |
33 result = net::ERR_FAILED; | |
34 callback_runner->PostTask(FROM_HERE, Bind(callback, result)); | |
35 } | |
36 | |
37 void OnCachePathCreated(const FactoryCallback& factory_callback, | |
38 disk_cache::Backend** backend, | |
39 const Backend::CompletionCallback& callback, | |
40 int result) { | |
41 if (result == net::OK) | |
42 *backend = factory_callback.Run(); | |
43 else | |
44 *backend = NULL; | |
45 callback.Run(result); | |
46 } | |
47 | |
48 } // namespace | |
49 | |
50 VerySimpleBackendImpl::BackendFactory::BackendFactory(const FilePath& path) | |
51 : path_(path) { | |
52 VLOG(0) << "VerySimpleBackendImpl::BackendFactory::CreateBackend()"; | |
pasko-google - do not use
2013/02/05 21:20:33
identical message as below, high log level, please
rvargas (doing something else)
2013/02/06 03:28:40
Don't add tracing logs
gavinp
2013/02/08 23:17:51
Done.
| |
53 } | |
54 | |
55 VerySimpleBackendImpl::BackendFactory::~BackendFactory() { | |
56 } | |
57 | |
58 int VerySimpleBackendImpl::BackendFactory::CreateBackend( | |
59 net::NetLog* net_log, | |
60 disk_cache::Backend** backend, | |
61 const CompletionCallback& callback) { | |
62 VLOG(0) << "VerySimpleBackendImpl::BackendFactory::CreateBackend()"; | |
63 | |
64 base::WorkerPool::PostTask( | |
rvargas (doing something else)
2013/02/06 03:28:40
nit: first argument here.
gavinp
2013/02/08 23:17:51
Done.
| |
65 FROM_HERE, Bind(&EnsureCachePathExists, path_, | |
66 MessageLoopProxy::current(), | |
67 Bind(&OnCachePathCreated, | |
68 Bind(&VerySimpleBackendImpl::Create, | |
rvargas (doing something else)
2013/02/06 03:28:40
wow, three nested Binds :(
Can we just split this
gavinp
2013/02/08 23:17:51
Goes to show that a dedicated programmer can write
| |
69 path_), | |
70 backend, callback)), | |
71 true); | |
72 return net::ERR_IO_PENDING; | |
73 } | |
74 | |
75 VerySimpleBackendImpl::~VerySimpleBackendImpl() { | |
76 DCHECK(thread_checker_.CalledOnValidThread()); | |
rvargas (doing something else)
2013/02/06 03:28:40
nit: seems overkill, considering that all methods
gavinp
2013/02/08 23:17:51
I agree it is overkill technically. I am including
pasko-google - do not use
2013/02/11 13:59:25
+1, these DCHECKs are good for documentation
rvargas (doing something else)
2013/02/13 01:48:46
I would agree with that if the class had a mixed t
gavinp
2013/02/14 15:29:55
Done.
| |
77 } | |
78 | |
79 net::CacheType VerySimpleBackendImpl::GetCacheType() const { | |
80 DCHECK(thread_checker_.CalledOnValidThread()); | |
81 return net::DISK_CACHE; | |
82 } | |
83 | |
84 int32 VerySimpleBackendImpl::GetEntryCount() const { | |
85 return 0; | |
rvargas (doing something else)
2013/02/06 03:28:40
Todo?
gavinp
2013/02/08 23:17:51
Todo!
| |
86 } | |
87 | |
88 int VerySimpleBackendImpl::OpenEntry(const std::string& key, | |
89 Entry** entry, | |
90 const CompletionCallback& callback) { | |
91 DCHECK(thread_checker_.CalledOnValidThread()); | |
92 return VerySimpleEntryImpl::OpenEntry(path_, key, entry, callback); | |
93 } | |
94 | |
95 int VerySimpleBackendImpl::CreateEntry(const std::string& key, | |
96 Entry** entry, | |
97 const CompletionCallback& callback) { | |
98 DCHECK(thread_checker_.CalledOnValidThread()); | |
99 return VerySimpleEntryImpl::CreateEntry(path_, key, entry, callback); | |
100 } | |
101 | |
102 int VerySimpleBackendImpl::DoomEntry(const std::string& key, | |
103 const net::CompletionCallback& callback) { | |
104 DCHECK(thread_checker_.CalledOnValidThread()); | |
105 return VerySimpleEntryImpl::DoomEntry(path_, key, callback); | |
106 } | |
107 | |
108 int VerySimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) { | |
109 DCHECK(thread_checker_.CalledOnValidThread()); | |
110 return net::ERR_FAILED; | |
rvargas (doing something else)
2013/02/06 03:28:40
Todo? etc
gavinp
2013/02/08 23:17:51
Done.
| |
111 } | |
112 | |
113 int VerySimpleBackendImpl::DoomEntriesBetween( | |
114 const Time initial_time, | |
115 const Time end_time, | |
116 const CompletionCallback& callback) { | |
117 DCHECK(thread_checker_.CalledOnValidThread()); | |
118 return net::ERR_FAILED; | |
119 } | |
120 | |
121 int VerySimpleBackendImpl::DoomEntriesSince( | |
122 const Time initial_time, | |
123 const CompletionCallback& callback) { | |
124 DCHECK(thread_checker_.CalledOnValidThread()); | |
125 return net::ERR_FAILED; | |
126 } | |
127 | |
128 int VerySimpleBackendImpl::OpenNextEntry(void** iter, | |
129 Entry** next_entry, | |
130 const CompletionCallback& callback) { | |
131 DCHECK(thread_checker_.CalledOnValidThread()); | |
132 return net::ERR_FAILED; | |
pasko-google - do not use
2013/02/05 21:20:33
Just curious, do the callers always workaround suc
gavinp
2013/02/08 23:17:51
I'll go deadly DCHECK, since I don't know.
| |
133 } | |
134 | |
135 void VerySimpleBackendImpl::EndEnumeration(void** iter) { | |
136 DCHECK(thread_checker_.CalledOnValidThread()); | |
137 } | |
138 | |
139 void VerySimpleBackendImpl::GetStats( | |
140 std::vector<std::pair<std::string, std::string> >* stats) { | |
141 DCHECK(thread_checker_.CalledOnValidThread()); | |
142 } | |
143 | |
144 void VerySimpleBackendImpl::OnExternalCacheHit(const std::string& key) { | |
145 DCHECK(thread_checker_.CalledOnValidThread()); | |
146 } | |
147 | |
148 VerySimpleBackendImpl::VerySimpleBackendImpl( | |
149 const FilePath& path) : path_(path) { | |
rvargas (doing something else)
2013/02/06 03:28:40
The general idea is that at this point contents of
gavinp
2013/02/08 23:17:51
Yes. That was true in the patch you were reviewing
rvargas (doing something else)
2013/02/13 01:48:46
What I meant is that the structure of SimpleBacken
gavinp
2013/02/14 15:29:55
Yeah. Currently Egor plans to chase this and get i
| |
150 } | |
151 | |
152 // static | |
153 VerySimpleBackendImpl* VerySimpleBackendImpl::Create(const FilePath& path) { | |
154 return new VerySimpleBackendImpl(path); | |
pasko-google - do not use
2013/02/05 21:20:33
simpler would be to do this one liner in OnCachePa
gavinp
2013/02/08 23:17:51
Happy to. I think I was being too averse to making
| |
155 } | |
156 | |
157 } // namespace disk_cache | |
OLD | NEW |