| OLD | NEW |
| 1 // Copyright (c) 2009 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_DUMPER_H_ | 5 #ifndef NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_ |
| 6 #define NET_TOOLS_DUMP_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() {} |
| 26 |
| 25 // Creates an entry to be written. | 27 // Creates an entry to be written. |
| 26 // On success, populates the |entry|. | 28 // On success, populates the |entry|. |
| 27 // Returns true on success, false otherwise. | 29 // Returns true on success, false otherwise. |
| 28 virtual bool CreateEntry(const std::string& key, | 30 virtual bool CreateEntry(const std::string& key, |
| 29 disk_cache::Entry** entry) = 0; | 31 disk_cache::Entry** entry) = 0; |
| 30 | 32 |
| 31 // Write to the current entry. | 33 // Write to the current entry. |
| 32 // Returns true on success, false otherwise. | 34 // Returns true on success, false otherwise. |
| 33 virtual bool WriteEntry(disk_cache::Entry* entry, int stream, int offset, | 35 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset, |
| 34 net::IOBuffer* buf, int buf_len) = 0; | 36 net::IOBuffer* buf, int buf_len, |
| 37 net::CompletionCallback* callback) = 0; |
| 35 | 38 |
| 36 // Close the current entry. | 39 // Close the current entry. |
| 37 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, | 40 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, |
| 38 base::Time last_modified) = 0; | 41 base::Time last_modified) = 0; |
| 39 }; | 42 }; |
| 40 | 43 |
| 41 // Writes data to a cache. | 44 // Writes data to a cache. |
| 42 class CacheDumper : public CacheDumpWriter { | 45 class CacheDumper : public CacheDumpWriter { |
| 43 public: | 46 public: |
| 44 CacheDumper(disk_cache::BackendImpl* cache) : cache_(cache) {}; | 47 explicit CacheDumper(disk_cache::Backend* cache) : cache_(cache) {} |
| 45 | 48 |
| 46 virtual bool CreateEntry(const std::string& key, disk_cache::Entry** entry); | 49 virtual bool CreateEntry(const std::string& key, disk_cache::Entry** entry); |
| 47 virtual bool WriteEntry(disk_cache::Entry* entry, int stream, int offset, | 50 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset, |
| 48 net::IOBuffer* buf, int buf_len); | 51 net::IOBuffer* buf, int buf_len, |
| 52 net::CompletionCallback* callback); |
| 49 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, | 53 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, |
| 50 base::Time last_modified); | 54 base::Time last_modified); |
| 51 | 55 |
| 52 private: | 56 private: |
| 53 disk_cache::BackendImpl* cache_; | 57 disk_cache::Backend* cache_; |
| 54 }; | 58 }; |
| 55 | 59 |
| 56 // Writes data to a disk. | 60 // Writes data to a disk. |
| 57 class DiskDumper : public CacheDumpWriter { | 61 class DiskDumper : public CacheDumpWriter { |
| 58 public: | 62 public: |
| 59 DiskDumper(const std::wstring& path) : path_(path), entry_(NULL) { | 63 explicit DiskDumper(const std::wstring& path) : path_(path), entry_(NULL) { |
| 60 file_util::CreateDirectory(FilePath(path)); | 64 file_util::CreateDirectory(FilePath(path)); |
| 61 }; | 65 } |
| 62 virtual bool CreateEntry(const std::string& key, disk_cache::Entry** entry); | 66 virtual bool CreateEntry(const std::string& key, disk_cache::Entry** entry); |
| 63 virtual bool WriteEntry(disk_cache::Entry* entry, int stream, int offset, | 67 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset, |
| 64 net::IOBuffer* buf, int buf_len); | 68 net::IOBuffer* buf, int buf_len, |
| 69 net::CompletionCallback* callback); |
| 65 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, | 70 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used, |
| 66 base::Time last_modified); | 71 base::Time last_modified); |
| 67 | 72 |
| 68 private: | 73 private: |
| 69 std::wstring path_; | 74 std::wstring path_; |
| 70 // This is a bit of a hack. As we get a CreateEntry, we coin the current | 75 // This is a bit of a hack. As we get a CreateEntry, we coin the current |
| 71 // entry_path_ where we write that entry to disk. Subsequent calls to | 76 // entry_path_ where we write that entry to disk. Subsequent calls to |
| 72 // WriteEntry() utilize this path for writing to disk. | 77 // WriteEntry() utilize this path for writing to disk. |
| 73 FilePath entry_path_; | 78 FilePath entry_path_; |
| 74 std::string entry_url_; | 79 std::string entry_url_; |
| 75 #ifdef WIN32_LARGE_FILENAME_SUPPORT | 80 #ifdef WIN32_LARGE_FILENAME_SUPPORT |
| 76 HANDLE entry_; | 81 HANDLE entry_; |
| 77 #else | 82 #else |
| 78 FILE* entry_; | 83 FILE* entry_; |
| 79 #endif | 84 #endif |
| 80 }; | 85 }; |
| 81 | 86 |
| 82 #endif // NET_TOOLS_DUMP_CACHE_DUMPER_H_ | 87 #endif // NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_ |
| OLD | NEW |