summaryrefslogtreecommitdiff
path: root/chromium/net/disk_cache/flash/log_store_entry.h
blob: 579194913af4503dc26c2bf8b67f3f4392e61d34 (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
64
65
// 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_LOG_STORE_ENTRY_H_
#define NET_DISK_CACHE_FLASH_LOG_STORE_ENTRY_H_

#include <vector>

#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "net/base/net_export.h"
#include "net/disk_cache/flash/format.h"

namespace net {
class IOBuffer;
};

namespace disk_cache {

class LogStore;

class NET_EXPORT_PRIVATE LogStoreEntry {
 public:
  explicit LogStoreEntry(LogStore* store);
  LogStoreEntry(LogStore* store, int32 id);
  ~LogStoreEntry();

  bool Init();
  bool Close();

  int32 id() const;
  bool IsNew() const;
  int32 GetDataSize(int index) const;

  int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len);
  int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len);
  void Delete();

 private:
  struct Stream {
    Stream();
    ~Stream();
    int offset;
    int size;
    std::vector<char> write_buffer;
  };

  bool InvalidStream(int stream_index) const;
  int32 Size() const;
  bool Save();

  LogStore* store_;
  int32 id_;
  Stream streams_[kFlashLogStoreEntryNumStreams];
  bool init_;
  bool closed_;
  bool deleted_;

  DISALLOW_COPY_AND_ASSIGN(LogStoreEntry);
};

}  // namespace disk_cache

#endif  // NET_DISK_CACHE_FLASH_LOG_STORE_ENTRY_H_