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/blockfile/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 int CreateEntry(const std::string
& key
,
51 disk_cache::Entry
** entry
,
52 const net::CompletionCallback
& callback
) override
;
53 int WriteEntry(disk_cache::Entry
* entry
,
58 const net::CompletionCallback
& callback
) override
;
59 void CloseEntry(disk_cache::Entry
* entry
,
61 base::Time last_modified
) override
;
64 disk_cache::Backend
* cache_
;
67 // Writes data to a disk.
68 class DiskDumper
: public CacheDumpWriter
{
70 explicit DiskDumper(const base::FilePath
& path
);
72 int CreateEntry(const std::string
& key
,
73 disk_cache::Entry
** entry
,
74 const net::CompletionCallback
& callback
) override
;
75 int WriteEntry(disk_cache::Entry
* entry
,
80 const net::CompletionCallback
& callback
) override
;
81 void CloseEntry(disk_cache::Entry
* entry
,
83 base::Time last_modified
) override
;
87 // This is a bit of a hack. As we get a CreateEntry, we coin the current
88 // entry_path_ where we write that entry to disk. Subsequent calls to
89 // WriteEntry() utilize this path for writing to disk.
90 base::FilePath entry_path_
;
91 std::string entry_url_
;
92 #ifdef WIN32_LARGE_FILENAME_SUPPORT
99 #endif // NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_