Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / net / disk_cache / simple / simple_backend_impl.h
blob0c7ba8cf8cb762991f178e97eb60bf0fcbf78dfd
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
3 // found in the LICENSE file.
5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_
8 #include <string>
9 #include <utility>
10 #include <vector>
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/task_runner.h"
15 #include "net/base/cache_type.h"
16 #include "net/disk_cache/disk_cache.h"
18 namespace disk_cache {
20 // SimpleBackendImpl is a new cache backend that stores entries in individual
21 // files.
23 // It is currently a work in progress, missing many features of a real cache,
24 // such as eviction.
26 // See http://www.chromium.org/developers/design-documents/network-stack/disk-cache/very-simple-backend
28 class SimpleIndex;
30 class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend {
31 public:
32 SimpleBackendImpl(const base::FilePath& path, int max_bytes,
33 net::CacheType type,
34 const scoped_refptr<base::TaskRunner>& cache_thread,
35 net::NetLog* net_log);
37 int Init(const CompletionCallback& callback);
39 virtual ~SimpleBackendImpl();
41 // From Backend:
42 virtual net::CacheType GetCacheType() const OVERRIDE;
43 virtual int32 GetEntryCount() const OVERRIDE;
44 virtual int OpenEntry(const std::string& key, Entry** entry,
45 const CompletionCallback& callback) OVERRIDE;
46 virtual int CreateEntry(const std::string& key, Entry** entry,
47 const CompletionCallback& callback) OVERRIDE;
48 virtual int DoomEntry(const std::string& key,
49 const CompletionCallback& callback) OVERRIDE;
50 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE;
51 virtual int DoomEntriesBetween(base::Time initial_time,
52 base::Time end_time,
53 const CompletionCallback& callback) OVERRIDE;
54 virtual int DoomEntriesSince(base::Time initial_time,
55 const CompletionCallback& callback) OVERRIDE;
56 virtual int OpenNextEntry(void** iter, Entry** next_entry,
57 const CompletionCallback& callback) OVERRIDE;
58 virtual void EndEnumeration(void** iter) OVERRIDE;
59 virtual void GetStats(
60 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE;
61 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE;
63 private:
64 // Must run on Cache Thread.
65 void InitializeIndex(base::MessageLoopProxy* io_thread,
66 const CompletionCallback& callback);
68 const base::FilePath path_;
70 scoped_ptr<SimpleIndex> index_;
71 const scoped_refptr<base::TaskRunner> cache_thread_;
74 } // namespace disk_cache
76 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_BACKEND_IMPL_H_