OLD | NEW |
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 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
16 | 17 |
17 using base::FilePath; | 18 using base::FilePath; |
18 using base::MessageLoopProxy; | 19 using base::MessageLoopProxy; |
19 using base::SingleThreadTaskRunner; | 20 using base::SingleThreadTaskRunner; |
20 using base::Time; | 21 using base::Time; |
21 using base::WorkerPool; | 22 using base::WorkerPool; |
22 using file_util::DirectoryExists; | 23 using file_util::DirectoryExists; |
23 using file_util::CreateDirectory; | 24 using file_util::CreateDirectory; |
24 | 25 |
25 namespace { | 26 namespace { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 path_, | 66 path_, |
66 initialize_index_callback)); | 67 initialize_index_callback)); |
67 return net::ERR_IO_PENDING; | 68 return net::ERR_IO_PENDING; |
68 } | 69 } |
69 | 70 |
70 net::CacheType SimpleBackendImpl::GetCacheType() const { | 71 net::CacheType SimpleBackendImpl::GetCacheType() const { |
71 return net::DISK_CACHE; | 72 return net::DISK_CACHE; |
72 } | 73 } |
73 | 74 |
74 int32 SimpleBackendImpl::GetEntryCount() const { | 75 int32 SimpleBackendImpl::GetEntryCount() const { |
75 NOTIMPLEMENTED(); | 76 // TODO(pasko): Use directory file count when index is not ready. |
76 return 0; | 77 return index_->GetEntryCount(); |
77 } | 78 } |
78 | 79 |
79 int SimpleBackendImpl::OpenEntry(const std::string& key, | 80 int SimpleBackendImpl::OpenEntry(const std::string& key, |
80 Entry** entry, | 81 Entry** entry, |
81 const CompletionCallback& callback) { | 82 const CompletionCallback& callback) { |
82 return SimpleEntryImpl::OpenEntry(index_.get(), path_, key, entry, callback); | 83 return SimpleEntryImpl::OpenEntry(index_.get(), path_, key, entry, callback); |
83 } | 84 } |
84 | 85 |
85 int SimpleBackendImpl::CreateEntry(const std::string& key, | 86 int SimpleBackendImpl::CreateEntry(const std::string& key, |
86 Entry** entry, | 87 Entry** entry, |
87 const CompletionCallback& callback) { | 88 const CompletionCallback& callback) { |
88 return SimpleEntryImpl::CreateEntry(index_.get(), path_, key, entry, | 89 return SimpleEntryImpl::CreateEntry(index_.get(), path_, key, entry, |
89 callback); | 90 callback); |
90 } | 91 } |
91 | 92 |
92 int SimpleBackendImpl::DoomEntry(const std::string& key, | 93 int SimpleBackendImpl::DoomEntry(const std::string& key, |
93 const net::CompletionCallback& callback) { | 94 const net::CompletionCallback& callback) { |
94 return SimpleEntryImpl::DoomEntry(index_.get(), path_, key, callback); | 95 return SimpleEntryImpl::DoomEntry(index_.get(), path_, key, callback); |
95 } | 96 } |
96 | 97 |
97 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) { | 98 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) { |
98 NOTIMPLEMENTED(); | 99 return DoomEntriesBetween(Time(), Time(), callback); |
99 return net::ERR_FAILED; | 100 } |
| 101 |
| 102 void SimpleBackendImpl::IndexReadyForDoom(Time initial_time, |
| 103 Time end_time, |
| 104 const CompletionCallback& callback, |
| 105 int result) { |
| 106 if (result != net::OK) { |
| 107 callback.Run(result); |
| 108 return; |
| 109 } |
| 110 scoped_ptr<std::vector<uint64> > key_hashes( |
| 111 index_->RemoveEntriesBetween(initial_time, end_time).release()); |
| 112 WorkerPool::PostTask(FROM_HERE, |
| 113 base::Bind(&SimpleSynchronousEntry::DoomEntrySet, |
| 114 base::Passed(&key_hashes), |
| 115 path_, |
| 116 MessageLoopProxy::current(), |
| 117 callback), |
| 118 true); |
100 } | 119 } |
101 | 120 |
102 int SimpleBackendImpl::DoomEntriesBetween( | 121 int SimpleBackendImpl::DoomEntriesBetween( |
103 const Time initial_time, | 122 const Time initial_time, |
104 const Time end_time, | 123 const Time end_time, |
105 const CompletionCallback& callback) { | 124 const CompletionCallback& callback) { |
106 NOTIMPLEMENTED(); | 125 return index_->ExecuteWhenReady( |
107 return net::ERR_FAILED; | 126 base::Bind(&SimpleBackendImpl::IndexReadyForDoom, AsWeakPtr(), |
| 127 initial_time, end_time, callback)); |
108 } | 128 } |
109 | 129 |
110 int SimpleBackendImpl::DoomEntriesSince( | 130 int SimpleBackendImpl::DoomEntriesSince( |
111 const Time initial_time, | 131 const Time initial_time, |
112 const CompletionCallback& callback) { | 132 const CompletionCallback& callback) { |
113 NOTIMPLEMENTED(); | 133 return DoomEntriesBetween(initial_time, Time(), callback); |
114 return net::ERR_FAILED; | |
115 } | 134 } |
116 | 135 |
117 int SimpleBackendImpl::OpenNextEntry(void** iter, | 136 int SimpleBackendImpl::OpenNextEntry(void** iter, |
118 Entry** next_entry, | 137 Entry** next_entry, |
119 const CompletionCallback& callback) { | 138 const CompletionCallback& callback) { |
120 NOTIMPLEMENTED(); | 139 NOTIMPLEMENTED(); |
121 return net::ERR_FAILED; | 140 return net::ERR_FAILED; |
122 } | 141 } |
123 | 142 |
124 void SimpleBackendImpl::EndEnumeration(void** iter) { | 143 void SimpleBackendImpl::EndEnumeration(void** iter) { |
125 NOTIMPLEMENTED(); | 144 NOTIMPLEMENTED(); |
126 } | 145 } |
127 | 146 |
128 void SimpleBackendImpl::GetStats( | 147 void SimpleBackendImpl::GetStats( |
129 std::vector<std::pair<std::string, std::string> >* stats) { | 148 std::vector<std::pair<std::string, std::string> >* stats) { |
130 NOTIMPLEMENTED(); | 149 NOTIMPLEMENTED(); |
131 } | 150 } |
132 | 151 |
133 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { | 152 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { |
134 NOTIMPLEMENTED(); | 153 index_->UseIfExists(key); |
135 } | 154 } |
136 | 155 |
137 void SimpleBackendImpl::InitializeIndex( | 156 void SimpleBackendImpl::InitializeIndex( |
138 const CompletionCallback& callback, int result) { | 157 const CompletionCallback& callback, int result) { |
139 if (result == net::OK) | 158 if (result == net::OK) |
140 index_->Initialize(); | 159 index_->Initialize(); |
141 callback.Run(result); | 160 callback.Run(result); |
142 } | 161 } |
143 | 162 |
144 // static | 163 // static |
145 void SimpleBackendImpl::CreateDirectory( | 164 void SimpleBackendImpl::CreateDirectory( |
146 SingleThreadTaskRunner* io_thread, | 165 SingleThreadTaskRunner* io_thread, |
147 const base::FilePath& path, | 166 const base::FilePath& path, |
148 const InitializeIndexCallback& initialize_index_callback) { | 167 const InitializeIndexCallback& initialize_index_callback) { |
149 int rv = net::OK; | 168 int rv = net::OK; |
150 if (!file_util::PathExists(path) && !file_util::CreateDirectory(path)) { | 169 if (!file_util::PathExists(path) && !file_util::CreateDirectory(path)) { |
151 LOG(ERROR) << "Simple Cache Backend: failed to create: " << path.value(); | 170 LOG(ERROR) << "Simple Cache Backend: failed to create: " << path.value(); |
152 rv = net::ERR_FAILED; | 171 rv = net::ERR_FAILED; |
153 } | 172 } |
154 | 173 |
155 io_thread->PostTask(FROM_HERE, base::Bind(initialize_index_callback, rv)); | 174 io_thread->PostTask(FROM_HERE, base::Bind(initialize_index_callback, rv)); |
156 } | 175 } |
157 | 176 |
158 } // namespace disk_cache | 177 } // namespace disk_cache |
OLD | NEW |