Enables compositing support for webview.
[chromium-blink-merge.git] / net / tools / dump_cache / cache_dumper.h
blobdaca8feafb1f87d7b5bb2527608ded413beb7997
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/file_path.h"
11 #include "base/file_util.h"
12 #include "net/disk_cache/backend_impl.h"
14 #ifdef WIN32
15 // Dumping the cache often creates very large filenames, which are tricky
16 // on windows. Most API calls don't support large filenames, including
17 // most of the base library functions. Unfortunately, adding "\\?\" into
18 // the filename support is tricky. Instead, if WIN32_LARGE_FILENAME_SUPPORT
19 // is set, we use direct WIN32 APIs for manipulating the files.
20 #define WIN32_LARGE_FILENAME_SUPPORT
21 #endif
23 // An abstract class for writing cache dump data.
24 class CacheDumpWriter {
25 public:
26 virtual ~CacheDumpWriter() {}
28 // Creates an entry to be written.
29 // On success, populates the |entry|.
30 // Returns a net error code.
31 virtual int CreateEntry(const std::string& key,
32 disk_cache::Entry** entry,
33 const net::CompletionCallback& callback) = 0;
35 // Write to the current entry.
36 // Returns a net error code.
37 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
38 net::IOBuffer* buf, int buf_len,
39 const net::CompletionCallback& callback) = 0;
41 // Close the current entry.
42 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
43 base::Time last_modified) = 0;
46 // Writes data to a cache.
47 class CacheDumper : public CacheDumpWriter {
48 public:
49 explicit CacheDumper(disk_cache::Backend* cache);
51 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
52 const net::CompletionCallback& callback) OVERRIDE;
53 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
54 net::IOBuffer* buf, int buf_len,
55 const net::CompletionCallback& callback) OVERRIDE;
56 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
57 base::Time last_modified) OVERRIDE;
59 private:
60 disk_cache::Backend* cache_;
63 // Writes data to a disk.
64 class DiskDumper : public CacheDumpWriter {
65 public:
66 explicit DiskDumper(const FilePath& path);
68 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry,
69 const net::CompletionCallback& callback) OVERRIDE;
70 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
71 net::IOBuffer* buf, int buf_len,
72 const net::CompletionCallback& callback) OVERRIDE;
73 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
74 base::Time last_modified) OVERRIDE;
76 private:
77 FilePath path_;
78 // This is a bit of a hack. As we get a CreateEntry, we coin the current
79 // entry_path_ where we write that entry to disk. Subsequent calls to
80 // WriteEntry() utilize this path for writing to disk.
81 FilePath entry_path_;
82 std::string entry_url_;
83 #ifdef WIN32_LARGE_FILENAME_SUPPORT
84 HANDLE entry_;
85 #else
86 FILE* entry_;
87 #endif
90 #endif // NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_