1 // Copyright (c) 2012 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. 4 5 #ifndef NET_DISK_CACHE_FLASH_INTERNAL_ENTRY_H_ 6 #define NET_DISK_CACHE_FLASH_INTERNAL_ENTRY_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "net/base/completion_callback.h" 13 #include "net/base/net_export.h" 14 #include "net/disk_cache/flash/format.h" 15 16 namespace net { 17 18 class IOBuffer; 19 20 } // namespace net 21 22 namespace disk_cache { 23 24 struct KeyAndStreamSizes { 25 KeyAndStreamSizes(); 26 std::string key; 27 int stream_sizes[kFlashLogStoreEntryNumStreams]; 28 }; 29 30 class LogStore; 31 class LogStoreEntry; 32 33 // Actual entry implementation that does all the work of reading, writing and 34 // storing data. 35 class NET_EXPORT_PRIVATE InternalEntry 36 : public base::RefCountedThreadSafe<InternalEntry> { 37 friend class base::RefCountedThreadSafe<InternalEntry>; 38 public: 39 InternalEntry(const std::string& key, LogStore* store); 40 InternalEntry(int32 id, LogStore* store); 41 42 scoped_ptr<KeyAndStreamSizes> Init(); 43 int32 GetDataSize(int index) const; 44 int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, 45 const net::CompletionCallback& callback); 46 int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, 47 const net::CompletionCallback& callback); 48 void Close(); 49 50 private: 51 bool WriteKey(LogStoreEntry* entry, const std::string& key); 52 bool ReadKey(LogStoreEntry* entry, std::string* key); 53 ~InternalEntry(); 54 55 LogStore* store_; 56 scoped_ptr<LogStoreEntry> entry_; 57 58 DISALLOW_COPY_AND_ASSIGN(InternalEntry); 59 }; 60 61 } // namespace disk_cache 62 63 #endif // NET_DISK_CACHE_FLASH_INTERNAL_ENTRY_H_ 64