OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_ | 5 #ifndef NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_ |
6 #define NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_ | 6 #define NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "net/disk_cache/backend_impl.h" | 11 #include "net/disk_cache/backend_impl.h" |
12 | 12 |
13 #ifdef WIN32 | 13 #ifdef WIN32 |
14 // Dumping the cache often creates very large filenames, which are tricky | 14 // Dumping the cache often creates very large filenames, which are tricky |
15 // on windows. Most API calls don't support large filenames, including | 15 // on windows. Most API calls don't support large filenames, including |
16 // most of the base library functions. Unfortunately, adding "\\?\" into | 16 // most of the base library functions. Unfortunately, adding "\\?\" into |
17 // the filename support is tricky. Instead, if WIN32_LARGE_FILENAME_SUPPORT | 17 // the filename support is tricky. Instead, if WIN32_LARGE_FILENAME_SUPPORT |
18 // is set, we use direct WIN32 APIs for manipulating the files. | 18 // is set, we use direct WIN32 APIs for manipulating the files. |
19 #define WIN32_LARGE_FILENAME_SUPPORT | 19 #define WIN32_LARGE_FILENAME_SUPPORT |
20 #endif | 20 #endif |
21 | 21 |
22 // An abstract class for writing cache dump data. | 22 // An abstract class for writing cache dump data. |
23 class CacheDumpWriter { | 23 class CacheDumpWriter { |
24 public: | 24 public: |
25 virtual ~CacheDumpWriter() {} | 25 virtual ~CacheDumpWriter() {} |
26 | 26 |
27 // Creates an entry to be written. | 27 // Creates an entry to be written. |
28 // On success, populates the |entry|. | 28 // On success, populates the |entry|. |
29 // Returns true on success, false otherwise. | 29 // Returns a net error code. |
30 virtual bool CreateEntry(const std::string& key, | 30 virtual int CreateEntry(const std::string& key, |
31 disk_cache::Entry** entry) = 0; | 31 disk_cache::Entry** entry, |
| 32 net::CompletionCallback* callback) = 0; |
32 | 33 |
33 // Write to the current entry. | 34 // Write to the current entry. |
34 // Returns true on success, false otherwise. | 35 // Returns a net error code. |
35 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset, | 36 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset, |
36 net::IOBuffer* buf, int buf_len, | 37 net::IOBuffer* buf, int buf_len, |
37 net::CompletionCallback* callback) = 0; | 38 net::CompletionCallback* callback) = 0; |
38 | 39 |
39 // Close the current entry. | 40 // Close the current entry. |
40 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, | 41 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, |
41 base::Time last_modified) = 0; | 42 base::Time last_modified) = 0; |
42 }; | 43 }; |
43 | 44 |
44 // Writes data to a cache. | 45 // Writes data to a cache. |
45 class CacheDumper : public CacheDumpWriter { | 46 class CacheDumper : public CacheDumpWriter { |
46 public: | 47 public: |
47 explicit CacheDumper(disk_cache::Backend* cache) : cache_(cache) {} | 48 explicit CacheDumper(disk_cache::Backend* cache) : cache_(cache) {} |
48 | 49 |
49 virtual bool CreateEntry(const std::string& key, disk_cache::Entry** entry); | 50 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry, |
| 51 net::CompletionCallback* callback); |
50 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset, | 52 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset, |
51 net::IOBuffer* buf, int buf_len, | 53 net::IOBuffer* buf, int buf_len, |
52 net::CompletionCallback* callback); | 54 net::CompletionCallback* callback); |
53 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, | 55 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, |
54 base::Time last_modified); | 56 base::Time last_modified); |
55 | 57 |
56 private: | 58 private: |
57 disk_cache::Backend* cache_; | 59 disk_cache::Backend* cache_; |
58 }; | 60 }; |
59 | 61 |
60 // Writes data to a disk. | 62 // Writes data to a disk. |
61 class DiskDumper : public CacheDumpWriter { | 63 class DiskDumper : public CacheDumpWriter { |
62 public: | 64 public: |
63 explicit DiskDumper(const std::wstring& path) : path_(path), entry_(NULL) { | 65 explicit DiskDumper(const std::wstring& path) : path_(path), entry_(NULL) { |
64 file_util::CreateDirectory(FilePath(path)); | 66 file_util::CreateDirectory(FilePath(path)); |
65 } | 67 } |
66 virtual bool CreateEntry(const std::string& key, disk_cache::Entry** entry); | 68 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry, |
| 69 net::CompletionCallback* callback); |
67 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset, | 70 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset, |
68 net::IOBuffer* buf, int buf_len, | 71 net::IOBuffer* buf, int buf_len, |
69 net::CompletionCallback* callback); | 72 net::CompletionCallback* callback); |
70 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, | 73 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, |
71 base::Time last_modified); | 74 base::Time last_modified); |
72 | 75 |
73 private: | 76 private: |
74 std::wstring path_; | 77 std::wstring path_; |
75 // This is a bit of a hack. As we get a CreateEntry, we coin the current | 78 // This is a bit of a hack. As we get a CreateEntry, we coin the current |
76 // entry_path_ where we write that entry to disk. Subsequent calls to | 79 // entry_path_ where we write that entry to disk. Subsequent calls to |
77 // WriteEntry() utilize this path for writing to disk. | 80 // WriteEntry() utilize this path for writing to disk. |
78 FilePath entry_path_; | 81 FilePath entry_path_; |
79 std::string entry_url_; | 82 std::string entry_url_; |
80 #ifdef WIN32_LARGE_FILENAME_SUPPORT | 83 #ifdef WIN32_LARGE_FILENAME_SUPPORT |
81 HANDLE entry_; | 84 HANDLE entry_; |
82 #else | 85 #else |
83 FILE* entry_; | 86 FILE* entry_; |
84 #endif | 87 #endif |
85 }; | 88 }; |
86 | 89 |
87 #endif // NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_ | 90 #endif // NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_ |
OLD | NEW |