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

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: first round of comments 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 // TODO(pasko): Use directory file count when index is not ready.
75 return 0; 76 return index_->GetEntryCount();
76 } 77 }
77 78
78 int SimpleBackendImpl::OpenEntry(const std::string& key, 79 int SimpleBackendImpl::OpenEntry(const std::string& key,
79 Entry** entry, 80 Entry** entry,
80 const CompletionCallback& callback) { 81 const CompletionCallback& callback) {
81 return SimpleEntryImpl::OpenEntry(index_, path_, key, entry, callback); 82 return SimpleEntryImpl::OpenEntry(index_, path_, key, entry, callback);
82 } 83 }
83 84
84 int SimpleBackendImpl::CreateEntry(const std::string& key, 85 int SimpleBackendImpl::CreateEntry(const std::string& key,
85 Entry** entry, 86 Entry** entry,
86 const CompletionCallback& callback) { 87 const CompletionCallback& callback) {
87 return SimpleEntryImpl::CreateEntry(index_, path_, key, entry, callback); 88 return SimpleEntryImpl::CreateEntry(index_, path_, key, entry, callback);
88 } 89 }
89 90
90 int SimpleBackendImpl::DoomEntry(const std::string& key, 91 int SimpleBackendImpl::DoomEntry(const std::string& key,
91 const net::CompletionCallback& callback) { 92 const net::CompletionCallback& callback) {
92 return SimpleEntryImpl::DoomEntry(index_, path_, key, callback); 93 return SimpleEntryImpl::DoomEntry(index_, path_, key, callback);
93 } 94 }
94 95
95 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) { 96 int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) {
96 NOTIMPLEMENTED(); 97 return DoomEntriesBetween(Time(), Time(), callback);
97 return net::ERR_FAILED; 98 }
99
100 void SimpleBackendImpl::IndexReadyForDoom(Time initial_time, Time end_time,
101 const CompletionCallback& callback,
102 int result) {
103 if (result != net::OK) {
104 callback.Run(result);
105 return;
106 }
107 scoped_ptr<std::set<uint64> > key_hashes(
108 index_->ExtractEntriesBetween(initial_time, end_time));
109 WorkerPool::PostTask(FROM_HERE,
110 base::Bind(&SimpleSynchronousEntry::DoomEntrySet,
111 base::Passed(&key_hashes),
112 path_,
113 MessageLoopProxy::current(),
114 callback),
115 true);
98 } 116 }
99 117
100 int SimpleBackendImpl::DoomEntriesBetween( 118 int SimpleBackendImpl::DoomEntriesBetween(
101 const Time initial_time, 119 const Time initial_time,
102 const Time end_time, 120 const Time end_time,
103 const CompletionCallback& callback) { 121 const CompletionCallback& callback) {
104 NOTIMPLEMENTED(); 122 return index_->ExecuteWhenReady(
105 return net::ERR_FAILED; 123 base::Bind(&SimpleBackendImpl::IndexReadyForDoom, AsWeakPtr(),
124 initial_time, end_time, callback));
106 } 125 }
107 126
108 int SimpleBackendImpl::DoomEntriesSince( 127 int SimpleBackendImpl::DoomEntriesSince(
109 const Time initial_time, 128 const Time initial_time,
110 const CompletionCallback& callback) { 129 const CompletionCallback& callback) {
111 NOTIMPLEMENTED(); 130 return DoomEntriesBetween(initial_time, Time(), callback);
112 return net::ERR_FAILED;
113 } 131 }
114 132
115 int SimpleBackendImpl::OpenNextEntry(void** iter, 133 int SimpleBackendImpl::OpenNextEntry(void** iter,
116 Entry** next_entry, 134 Entry** next_entry,
117 const CompletionCallback& callback) { 135 const CompletionCallback& callback) {
118 NOTIMPLEMENTED(); 136 NOTIMPLEMENTED();
119 return net::ERR_FAILED; 137 return net::ERR_FAILED;
120 } 138 }
121 139
122 void SimpleBackendImpl::EndEnumeration(void** iter) { 140 void SimpleBackendImpl::EndEnumeration(void** iter) {
123 NOTIMPLEMENTED(); 141 NOTIMPLEMENTED();
124 } 142 }
125 143
126 void SimpleBackendImpl::GetStats( 144 void SimpleBackendImpl::GetStats(
127 std::vector<std::pair<std::string, std::string> >* stats) { 145 std::vector<std::pair<std::string, std::string> >* stats) {
128 NOTIMPLEMENTED(); 146 NOTIMPLEMENTED();
129 } 147 }
130 148
131 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { 149 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) {
132 NOTIMPLEMENTED(); 150 index_->UseIfExists(key);
133 } 151 }
134 152
135 void SimpleBackendImpl::InitializeIndex( 153 void SimpleBackendImpl::InitializeIndex(
136 const CompletionCallback& callback, int result) { 154 const CompletionCallback& callback, int result) {
137 if (result == net::OK) 155 if (result == net::OK)
138 index_->Initialize(); 156 index_->Initialize();
139 callback.Run(result); 157 callback.Run(result);
140 } 158 }
141 159
142 // static 160 // static
143 void SimpleBackendImpl::CreateDirectory( 161 void SimpleBackendImpl::CreateDirectory(
144 MessageLoopProxy* io_thread, 162 MessageLoopProxy* io_thread,
145 const base::FilePath& path, 163 const base::FilePath& path,
146 const InitializeIndexCallback& initialize_index_callback) { 164 const InitializeIndexCallback& initialize_index_callback) {
147 int rv = net::OK; 165 int rv = net::OK;
148 if (!file_util::PathExists(path) && !file_util::CreateDirectory(path)) { 166 if (!file_util::PathExists(path) && !file_util::CreateDirectory(path)) {
149 LOG(ERROR) << "Simple Cache Backend: failed to create: " << path.value(); 167 LOG(ERROR) << "Simple Cache Backend: failed to create: " << path.value();
150 rv = net::ERR_FAILED; 168 rv = net::ERR_FAILED;
151 } 169 }
152 170
153 io_thread->PostTask(FROM_HERE, base::Bind(initialize_index_callback, rv)); 171 io_thread->PostTask(FROM_HERE, base::Bind(initialize_index_callback, rv));
154 } 172 }
155 173
156 } // namespace disk_cache 174 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698