Index: net/disk_cache/simple/simple_backend_impl.cc |
diff --git a/net/disk_cache/simple/simple_backend_impl.cc b/net/disk_cache/simple/simple_backend_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0b530a522146222587ebb45d7dabf664440164b7 |
--- /dev/null |
+++ b/net/disk_cache/simple/simple_backend_impl.cc |
@@ -0,0 +1,168 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "net/disk_cache/simple/simple_backend_impl.h" |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "base/file_util.h" |
+#include "base/location.h" |
+#include "base/message_loop_proxy.h" |
+#include "base/threading/worker_pool.h" |
+#include "net/base/net_errors.h" |
+#include "net/disk_cache/simple/simple_entry_impl.h" |
+ |
+using base::FilePath; |
+using base::MessageLoopProxy; |
+using base::Time; |
+using base::WorkerPool; |
+using file_util::DirectoryExists; |
+using file_util::CreateDirectory; |
+ |
+namespace { |
+ |
+const char* kSimpleBackendSubdirectory = "Simple"; |
+ |
+} // namespace |
+ |
+namespace disk_cache { |
+ |
+// static |
+int SimpleBackendImpl::CreateBackend( |
+ const FilePath& full_path, |
+ bool force, |
+ int max_bytes, |
+ net::CacheType type, |
+ uint32 flags, |
+ scoped_refptr<base::TaskRunner> task_runner, |
+ net::NetLog* net_log, |
+ Backend** backend, |
+ const CompletionCallback& callback) { |
+ // TODO(gavinp): Use the |net_log|. |
+ DCHECK_EQ(net::DISK_CACHE, type); |
+ FilePath simple_cache_path = |
+ full_path.AppendASCII(kSimpleBackendSubdirectory); |
+ WorkerPool::PostTask(FROM_HERE, |
+ base::Bind(&SimpleBackendImpl:: |
+ EnsureCachePathExistsOnWorkerThread, |
pasko-google - do not use
2013/02/11 13:59:25
nit: here and below adjust amount of leading space
gavinp
2013/02/11 17:55:50
Previously I had lines like this with FROM_HERE on
pasko-google - do not use
2013/02/11 18:13:44
ouch sorry, this specific leading space is fine, I
gavinp
2013/02/11 18:32:26
Aha! Good catch. Fixed.
|
+ simple_cache_path, |
+ MessageLoopProxy::current(), callback, |
+ backend), |
+ true); |
+ return net::ERR_IO_PENDING; |
+} |
+ |
+SimpleBackendImpl::~SimpleBackendImpl() { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+} |
+ |
+net::CacheType SimpleBackendImpl::GetCacheType() const { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ return net::DISK_CACHE; |
+} |
+ |
+int32 SimpleBackendImpl::GetEntryCount() const { |
+ // TODO(gavinp): Provide implementation for this function. |
+ return 0; |
+} |
+ |
+int SimpleBackendImpl::OpenEntry(const std::string& key, |
+ Entry** entry, |
+ const CompletionCallback& callback) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ return SimpleEntryImpl::OpenEntry(path_, key, entry, callback); |
+} |
+ |
+int SimpleBackendImpl::CreateEntry(const std::string& key, |
+ Entry** entry, |
+ const CompletionCallback& callback) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ return SimpleEntryImpl::CreateEntry(path_, key, entry, callback); |
+} |
+ |
+int SimpleBackendImpl::DoomEntry(const std::string& key, |
+ const net::CompletionCallback& callback) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ return SimpleEntryImpl::DoomEntry(path_, key, callback); |
+} |
+ |
+int SimpleBackendImpl::DoomAllEntries(const CompletionCallback& callback) { |
+ // TODO(gavinp): Provide implementation for this function. |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ return net::ERR_FAILED; |
+} |
+ |
+int SimpleBackendImpl::DoomEntriesBetween( |
+ const Time initial_time, |
+ const Time end_time, |
+ const CompletionCallback& callback) { |
+ // TODO(gavinp): Provide implementation for this function. |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ return net::ERR_FAILED; |
+} |
+ |
+int SimpleBackendImpl::DoomEntriesSince( |
+ const Time initial_time, |
+ const CompletionCallback& callback) { |
+ // TODO(gavinp): Provide implementation for this function. |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ return net::ERR_FAILED; |
+} |
+ |
+int SimpleBackendImpl::OpenNextEntry(void** iter, |
+ Entry** next_entry, |
+ const CompletionCallback& callback) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ NOTREACHED() << "Not implemented."; |
+ return net::ERR_FAILED; |
+} |
+ |
+void SimpleBackendImpl::EndEnumeration(void** iter) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ NOTREACHED() << "Not implemented."; |
+} |
+ |
+void SimpleBackendImpl::GetStats( |
+ std::vector<std::pair<std::string, std::string> >* stats) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ NOTREACHED() << "Not implemented."; |
+} |
+ |
+void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ NOTREACHED() << "Not implemented."; |
+} |
+ |
+SimpleBackendImpl::SimpleBackendImpl( |
+ const FilePath& path) : path_(path) { |
+} |
+ |
+// static |
+void SimpleBackendImpl::EnsureCachePathExistsOnWorkerThread( |
+ const FilePath& path, |
+ const scoped_refptr<base::TaskRunner>& callback_runner, |
+ const CompletionCallback& callback, |
+ Backend** backend) { |
+ int result = net::OK; |
+ if (!DirectoryExists(path) && !CreateDirectory(path)) |
+ result = net::ERR_FAILED; |
+ callback_runner->PostTask(FROM_HERE, |
+ base::Bind(&SimpleBackendImpl::OnCachePathCreated, |
+ result, path, callback, backend)); |
+} |
+ |
+// static |
+void SimpleBackendImpl::OnCachePathCreated( |
+ int result, |
+ const FilePath& path, |
+ const CompletionCallback& callback, |
+ Backend** backend) { |
+ if (result == net::OK) |
+ *backend = new SimpleBackendImpl(path); |
+ else |
+ *backend = NULL; |
+ callback.Run(result); |
+} |
+ |
+} // namespace disk_cache |