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

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

Issue 14295013: Simple Cache: DoomEntriesBetween() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
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::Time; 20 using base::Time;
20 using base::WorkerPool; 21 using base::WorkerPool;
21 using file_util::DirectoryExists; 22 using file_util::DirectoryExists;
22 using file_util::CreateDirectory; 23 using file_util::CreateDirectory;
23 24
24 namespace { 25 namespace {
25 26
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 path_, 65 path_,
65 initialize_index_callback)); 66 initialize_index_callback));
66 return net::ERR_IO_PENDING; 67 return net::ERR_IO_PENDING;
67 } 68 }
68 69
69 net::CacheType SimpleBackendImpl::GetCacheType() const { 70 net::CacheType SimpleBackendImpl::GetCacheType() const {
70 return net::DISK_CACHE; 71 return net::DISK_CACHE;
71 } 72 }
72 73
73 int32 SimpleBackendImpl::GetEntryCount() const { 74 int32 SimpleBackendImpl::GetEntryCount() const {
74 NOTIMPLEMENTED(); 75 return index_->GetEntryCount();
gavinp 2013/04/17 07:41:18 Nice. Can we perhaps do better still though: isn't
felipeg 2013/04/17 16:35:04 In another CL, not this one, please. Also, I coul
pasko-google - do not use 2013/04/17 19:47:52 This should work pretty fast: DirReaderPosix reade
75 return 0;
76 } 76 }
77 77
78 int SimpleBackendImpl::OpenEntry(const std::string& key, 78 int SimpleBackendImpl::OpenEntry(const std::string& key,
79 Entry** entry, 79 Entry** entry,
80 const CompletionCallback& callback) { 80 const CompletionCallback& callback) {
81 return SimpleEntryImpl::OpenEntry( 81 return SimpleEntryImpl::OpenEntry(
82 index_->AsWeakPtr(), path_, key, entry, callback); 82 index_->AsWeakPtr(), path_, key, entry, callback);
83 } 83 }
84 84
85 int SimpleBackendImpl::CreateEntry(const std::string& key, 85 int SimpleBackendImpl::CreateEntry(const std::string& key,
86 Entry** entry, 86 Entry** entry,
87 const CompletionCallback& callback) { 87 const CompletionCallback& callback) {
88 return SimpleEntryImpl::CreateEntry( 88 return SimpleEntryImpl::CreateEntry(
89 index_->AsWeakPtr(), path_, key, entry, callback); 89 index_->AsWeakPtr(), path_, key, entry, callback);
90 } 90 }
91 91
92 int SimpleBackendImpl::DoomEntry(const std::string& key, 92 int SimpleBackendImpl::DoomEntry(const std::string& key,
93 const net::CompletionCallback& callback) { 93 const net::CompletionCallback& callback) {
94 return SimpleEntryImpl::DoomEntry(index_->AsWeakPtr(), path_, key, callback); 94 return SimpleEntryImpl::DoomEntry(index_->AsWeakPtr(), path_, key, callback);
95 } 95 }
96 96
97 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) { 97 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) {
98 NOTIMPLEMENTED(); 98 return DoomEntriesBetween(Time(), Time(), callback);
99 return net::ERR_FAILED; 99 }
100
101 void SimpleBackendImpl::IndexReadyForDoom(const Time initial_time,
102 const Time end_time,
103 const CompletionCallback& callback,
104 int result) {
105 if (result != net::OK) {
106 callback.Run(result);
107 return;
108 }
109 scoped_ptr<std::set<uint64> > key_hashes(
110 index_->PullEntriesBetween(initial_time, end_time));
111 // TODO(pasko): Doom all entries that are known to be open at the moment.
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);
gavinp 2013/04/17 07:41:18 Nice!
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 MessageLoopProxy* io_thread, 165 MessageLoopProxy* 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698