Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / tools / dump_cache / cache_dumper.h
blob9c5837ce56679dff09f1aca9c9e95934ff6f8124
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_
8 #include <string>
10 #include "base/files/file_path.h"
11 #include "net/disk_cache/blockfile/backend_impl.h"
13 #ifdef WIN32
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
20 #endif
22 // An abstract class for writing cache dump data.
23 class CacheDumpWriter {
24 public:
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 {
47 public:
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;
58 private:
59 disk_cache::Backend* cache_;
62 // Writes data to a disk.
63 class DiskDumper : public CacheDumpWriter {
64 public:
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;
75 private:
76 base::FilePath path_;
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
83 HANDLE entry_;
84 #else
85 FILE* entry_;
86 #endif
89 #endif // NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_