ipfs-chromium
cache_requestor.h
1 #ifndef CACHE_REQUESTOR_H_
2 #define CACHE_REQUESTOR_H_
3 
4 #include <net/base/cache_type.h>
5 #include <net/base/io_buffer.h>
6 #include <net/disk_cache/disk_cache.h>
7 
8 #include <base/memory/raw_ref.h>
9 #include <base/memory/scoped_refptr.h>
10 #include <base/time/time.h>
11 
12 #include <ipfs_client/gw/requestor.h>
13 #include <ipfs_client/ipld/block_source.h>
14 
15 #include <vocab/byte_view.h>
16 
17 #include <memory>
18 
19 namespace ipfs {
20 
21 class BlockStorage;
22 class InterRequestState;
23 
26 class CacheRequestor : public gw::Requestor {
27  public:
28  CacheRequestor(InterRequestState&, base::FilePath);
29  ~CacheRequestor() noexcept override;
30  void Store(std::string key, std::string headers, ByteView body);
31  void Expire(std::string const& key);
32 
33  std::string_view name() const override;
34 
35  private:
36  struct Task {
37  Task();
38  Task(Task const&);
39  ~Task() noexcept;
40  std::string key;
41  ipld::BlockSource::Clock::time_point start =
42  ipld::BlockSource::Clock::now();
43  std::string header;
44  std::string body;
45  scoped_refptr<net::IOBufferWithSize> buf;
46  std::shared_ptr<disk_cache::Entry> entry;
47  gw::RequestPtr request;
48  ipld::BlockSource orig_src;
49  };
50  raw_ref<InterRequestState> state_;
51  std::unique_ptr<disk_cache::Backend> cache_;
52  bool startup_pending_ = false;
53  base::FilePath path_;
54 
55  void Start();
56 
57  void StartFetch(Task& t, net::RequestPriority priority);
58  void Assign(disk_cache::BackendResult);
59  void OnOpen(Task, disk_cache::EntryResult);
60  void OnHeaderRead(Task, int);
61  void OnBodyRead(Task, int);
62 
63  void OnEntryCreated(std::string c,
64  std::string h,
65  std::string b,
66  disk_cache::EntryResult);
67  void OnHeaderWritten(scoped_refptr<net::StringIOBuffer> buf,
68  std::string body,
69  std::shared_ptr<disk_cache::Entry> entry,
70  int);
71  void Miss(Task&);
72  HandleOutcome handle(RequestPtr) override;
73 };
74 } // namespace ipfs
75 
76 #endif // CACHE_REQUESTOR_H_
Definition: cache_requestor.h:26
std::string_view name() const override
Definition: requestor.h:22