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.
5 #ifndef NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_
6 #define NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_
10 #include "base/files/file_path.h"
11 #include "net/disk_cache/backend_impl.h"
14 // Dumping the cache often creates very large filenames, which are tricky
15 // on windows. Most API calls don't support large filenames, including
16 // most of the base library functions. Unfortunately, adding "\\?\" into
17 // the filename support is tricky. Instead, if WIN32_LARGE_FILENAME_SUPPORT
18 // is set, we use direct WIN32 APIs for manipulating the files.
19 #define WIN32_LARGE_FILENAME_SUPPORT
22 // An abstract class for writing cache dump data.
23 class CacheDumpWriter {
25 virtual ~CacheDumpWriter() {}
27 // Creates an entry to be written.
28 // On success, populates the |entry|.
29 // Returns a net error code.
30 virtual int CreateEntry(const std::string& key,
31 disk_cache::Entry** entry,
32 const net::CompletionCallback& callback) = 0;
34 // Write to the current entry.
35 // Returns a net error code.
36 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
37 net::IOBuffer* buf, int buf_len,
38 const net::CompletionCallback& callback) = 0;
40 // Close the current entry.
41 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
42 base::Time last_modified) = 0;
45 // Writes data to a cache.
46 class CacheDumper : public CacheDumpWriter {
48 explicit CacheDumper(disk_cache::Backend* cache);
50 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
51 const net::CompletionCallback& callback) OVERRIDE;
52 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
53 net::IOBuffer* buf, int buf_len,
54 const net::CompletionCallback& callback) OVERRIDE;
55 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
56 base::Time last_modified) OVERRIDE;
59 disk_cache::Backend* cache_;
62 // Writes data to a disk.
63 class DiskDumper : public CacheDumpWriter {
65 explicit DiskDumper(const base::FilePath& path);
67 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
68 const net::CompletionCallback& callback) OVERRIDE;
69 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
70 net::IOBuffer* buf, int buf_len,
71 const net::CompletionCallback& callback) OVERRIDE;
72 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
73 base::Time last_modified) OVERRIDE;
77 // This is a bit of a hack. As we get a CreateEntry, we coin the current
78 // entry_path_ where we write that entry to disk. Subsequent calls to
79 // WriteEntry() utilize this path for writing to disk.
80 base::FilePath entry_path_;
81 std::string entry_url_;
82 #ifdef WIN32_LARGE_FILENAME_SUPPORT
89 #endif // NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_