summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/flash/internal_entry.h
blob: eeb2793f4c1d6a892bc5afbf5cbbc913ff5f97bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2012 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.

#ifndef NET_DISK_CACHE_FLASH_INTERNAL_ENTRY_H_
#define NET_DISK_CACHE_FLASH_INTERNAL_ENTRY_H_

#include <string>

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "net/base/completion_callback.h"
#include "net/base/net_export.h"
#include "net/disk_cache/flash/format.h"

namespace net {

class IOBuffer;

}  // namespace net

namespace disk_cache {

struct KeyAndStreamSizes {
  KeyAndStreamSizes();
  std::string key;
  int stream_sizes[kFlashLogStoreEntryNumStreams];
};

class LogStore;
class LogStoreEntry;

// Actual entry implementation that does all the work of reading, writing and
// storing data.
class NET_EXPORT_PRIVATE InternalEntry
    : public base::RefCountedThreadSafe<InternalEntry> {
  friend class base::RefCountedThreadSafe<InternalEntry>;
 public:
  InternalEntry(const std::string& key, LogStore* store);
  InternalEntry(int32 id, LogStore* store);

  scoped_ptr<KeyAndStreamSizes> Init();
  int32 GetDataSize(int index) const;
  int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
               const net::CompletionCallback& callback);
  int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
                const net::CompletionCallback& callback);
  void Close();

 private:
  bool WriteKey(LogStoreEntry* entry, const std::string& key);
  bool ReadKey(LogStoreEntry* entry, std::string* key);
  ~InternalEntry();

  LogStore* store_;
  scoped_ptr<LogStoreEntry> entry_;

  DISALLOW_COPY_AND_ASSIGN(InternalEntry);
};

}  // namespace disk_cache

#endif  // NET_DISK_CACHE_FLASH_INTERNAL_ENTRY_H_