| 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::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 Loading... |
| 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, |
| 101 Time end_time, |
| 102 const CompletionCallback& callback, |
| 103 int result) { |
| 104 if (result != net::OK) { |
| 105 callback.Run(result); |
| 106 return; |
| 107 } |
| 108 scoped_ptr<std::vector<uint64> > key_hashes( |
| 109 index_->ExtractEntriesBetween(initial_time, end_time).release()); |
| 110 WorkerPool::PostTask(FROM_HERE, |
| 111 base::Bind(&SimpleSynchronousEntry::DoomEntrySet, |
| 112 base::Passed(&key_hashes), |
| 113 path_, |
| 114 MessageLoopProxy::current(), |
| 115 callback), |
| 116 true); |
| 98 } | 117 } |
| 99 | 118 |
| 100 int SimpleBackendImpl::DoomEntriesBetween( | 119 int SimpleBackendImpl::DoomEntriesBetween( |
| 101 const Time initial_time, | 120 const Time initial_time, |
| 102 const Time end_time, | 121 const Time end_time, |
| 103 const CompletionCallback& callback) { | 122 const CompletionCallback& callback) { |
| 104 NOTIMPLEMENTED(); | 123 return index_->ExecuteWhenReady( |
| 105 return net::ERR_FAILED; | 124 base::Bind(&SimpleBackendImpl::IndexReadyForDoom, AsWeakPtr(), |
| 125 initial_time, end_time, callback)); |
| 106 } | 126 } |
| 107 | 127 |
| 108 int SimpleBackendImpl::DoomEntriesSince( | 128 int SimpleBackendImpl::DoomEntriesSince( |
| 109 const Time initial_time, | 129 const Time initial_time, |
| 110 const CompletionCallback& callback) { | 130 const CompletionCallback& callback) { |
| 111 NOTIMPLEMENTED(); | 131 return DoomEntriesBetween(initial_time, Time(), callback); |
| 112 return net::ERR_FAILED; | |
| 113 } | 132 } |
| 114 | 133 |
| 115 int SimpleBackendImpl::OpenNextEntry(void** iter, | 134 int SimpleBackendImpl::OpenNextEntry(void** iter, |
| 116 Entry** next_entry, | 135 Entry** next_entry, |
| 117 const CompletionCallback& callback) { | 136 const CompletionCallback& callback) { |
| 118 NOTIMPLEMENTED(); | 137 NOTIMPLEMENTED(); |
| 119 return net::ERR_FAILED; | 138 return net::ERR_FAILED; |
| 120 } | 139 } |
| 121 | 140 |
| 122 void SimpleBackendImpl::EndEnumeration(void** iter) { | 141 void SimpleBackendImpl::EndEnumeration(void** iter) { |
| 123 NOTIMPLEMENTED(); | 142 NOTIMPLEMENTED(); |
| 124 } | 143 } |
| 125 | 144 |
| 126 void SimpleBackendImpl::GetStats( | 145 void SimpleBackendImpl::GetStats( |
| 127 std::vector<std::pair<std::string, std::string> >* stats) { | 146 std::vector<std::pair<std::string, std::string> >* stats) { |
| 128 NOTIMPLEMENTED(); | 147 NOTIMPLEMENTED(); |
| 129 } | 148 } |
| 130 | 149 |
| 131 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { | 150 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { |
| 132 NOTIMPLEMENTED(); | 151 index_->UseIfExists(key); |
| 133 } | 152 } |
| 134 | 153 |
| 135 void SimpleBackendImpl::InitializeIndex( | 154 void SimpleBackendImpl::InitializeIndex( |
| 136 const CompletionCallback& callback, int result) { | 155 const CompletionCallback& callback, int result) { |
| 137 if (result == net::OK) | 156 if (result == net::OK) |
| 138 index_->Initialize(); | 157 index_->Initialize(); |
| 139 callback.Run(result); | 158 callback.Run(result); |
| 140 } | 159 } |
| 141 | 160 |
| 142 // static | 161 // static |
| 143 void SimpleBackendImpl::CreateDirectory( | 162 void SimpleBackendImpl::CreateDirectory( |
| 144 MessageLoopProxy* io_thread, | 163 MessageLoopProxy* io_thread, |
| 145 const base::FilePath& path, | 164 const base::FilePath& path, |
| 146 const InitializeIndexCallback& initialize_index_callback) { | 165 const InitializeIndexCallback& initialize_index_callback) { |
| 147 int rv = net::OK; | 166 int rv = net::OK; |
| 148 if (!file_util::PathExists(path) && !file_util::CreateDirectory(path)) { | 167 if (!file_util::PathExists(path) && !file_util::CreateDirectory(path)) { |
| 149 LOG(ERROR) << "Simple Cache Backend: failed to create: " << path.value(); | 168 LOG(ERROR) << "Simple Cache Backend: failed to create: " << path.value(); |
| 150 rv = net::ERR_FAILED; | 169 rv = net::ERR_FAILED; |
| 151 } | 170 } |
| 152 | 171 |
| 153 io_thread->PostTask(FROM_HERE, base::Bind(initialize_index_callback, rv)); | 172 io_thread->PostTask(FROM_HERE, base::Bind(initialize_index_callback, rv)); |
| 154 } | 173 } |
| 155 | 174 |
| 156 } // namespace disk_cache | 175 } // namespace disk_cache |
| OLD | NEW |