| 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 #include "net/tools/dump_cache/cache_dumper.h" | 5 #include "net/tools/dump_cache/cache_dumper.h" |
| 6 | 6 |
| 7 #include "net/base/io_buffer.h" | 7 #include "net/base/io_buffer.h" |
| 8 #include "net/base/net_errors.h" |
| 8 #include "net/disk_cache/entry_impl.h" | 9 #include "net/disk_cache/entry_impl.h" |
| 9 #include "net/http/http_cache.h" | 10 #include "net/http/http_cache.h" |
| 10 #include "net/http/http_response_headers.h" | 11 #include "net/http/http_response_headers.h" |
| 11 #include "net/http/http_response_info.h" | 12 #include "net/http/http_response_info.h" |
| 12 #include "net/tools/dump_cache/url_to_filename_encoder.h" | 13 #include "net/tools/dump_cache/url_to_filename_encoder.h" |
| 13 | 14 |
| 14 bool CacheDumper::CreateEntry(const std::string& key, | 15 int CacheDumper::CreateEntry(const std::string& key, |
| 15 disk_cache::Entry** entry) { | 16 disk_cache::Entry** entry, |
| 16 return cache_->CreateEntry(key, entry); | 17 net::CompletionCallback* callback) { |
| 18 return cache_->CreateEntry(key, entry, callback); |
| 17 } | 19 } |
| 18 | 20 |
| 19 int CacheDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset, | 21 int CacheDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset, |
| 20 net::IOBuffer* buf, int buf_len, | 22 net::IOBuffer* buf, int buf_len, |
| 21 net::CompletionCallback* callback) { | 23 net::CompletionCallback* callback) { |
| 22 return entry->WriteData(index, offset, buf, buf_len, callback, false); | 24 return entry->WriteData(index, offset, buf, buf_len, callback, false); |
| 23 } | 25 } |
| 24 | 26 |
| 25 void CacheDumper::CloseEntry(disk_cache::Entry* entry, base::Time last_used, | 27 void CacheDumper::CloseEntry(disk_cache::Entry* entry, base::Time last_used, |
| 26 base::Time last_modified) { | 28 base::Time last_modified) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 54 // we keep going even if directory creation failed. | 56 // we keep going even if directory creation failed. |
| 55 pos++; | 57 pos++; |
| 56 } | 58 } |
| 57 // Now create the full path | 59 // Now create the full path |
| 58 return CreateDirectoryW(path.c_str(), NULL) == TRUE; | 60 return CreateDirectoryW(path.c_str(), NULL) == TRUE; |
| 59 #else | 61 #else |
| 60 return file_util::CreateDirectory(path); | 62 return file_util::CreateDirectory(path); |
| 61 #endif | 63 #endif |
| 62 } | 64 } |
| 63 | 65 |
| 64 bool DiskDumper::CreateEntry(const std::string& key, | 66 int DiskDumper::CreateEntry(const std::string& key, |
| 65 disk_cache::Entry** entry) { | 67 disk_cache::Entry** entry, |
| 68 net::CompletionCallback* callback) { |
| 66 FilePath path(path_); | 69 FilePath path(path_); |
| 67 // The URL may not start with a valid protocol; search for it. | 70 // The URL may not start with a valid protocol; search for it. |
| 68 int urlpos = key.find("http"); | 71 int urlpos = key.find("http"); |
| 69 std::string url = urlpos > 0 ? key.substr(urlpos) : key; | 72 std::string url = urlpos > 0 ? key.substr(urlpos) : key; |
| 70 std::string base_path = WideToASCII(path_); | 73 std::string base_path = WideToASCII(path_); |
| 71 std::string new_path = | 74 std::string new_path = |
| 72 net::UrlToFilenameEncoder::Encode(url, base_path, false); | 75 net::UrlToFilenameEncoder::Encode(url, base_path, false); |
| 73 entry_path_ = FilePath(ASCIIToWide(new_path)); | 76 entry_path_ = FilePath(ASCIIToWide(new_path)); |
| 74 | 77 |
| 75 #ifdef WIN32_LARGE_FILENAME_SUPPORT | 78 #ifdef WIN32_LARGE_FILENAME_SUPPORT |
| (...skipping 11 matching lines...) Expand all Loading... |
| 87 | 90 |
| 88 FilePath directory = entry_path_.DirName(); | 91 FilePath directory = entry_path_.DirName(); |
| 89 SafeCreateDirectory(directory.value()); | 92 SafeCreateDirectory(directory.value()); |
| 90 | 93 |
| 91 std::wstring file = entry_path_.value(); | 94 std::wstring file = entry_path_.value(); |
| 92 #ifdef WIN32_LARGE_FILENAME_SUPPORT | 95 #ifdef WIN32_LARGE_FILENAME_SUPPORT |
| 93 entry_ = CreateFileW(file.c_str(), GENERIC_WRITE|GENERIC_READ, 0, 0, | 96 entry_ = CreateFileW(file.c_str(), GENERIC_WRITE|GENERIC_READ, 0, 0, |
| 94 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); | 97 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); |
| 95 if (entry_ == INVALID_HANDLE_VALUE) | 98 if (entry_ == INVALID_HANDLE_VALUE) |
| 96 wprintf(L"CreateFileW (%s) failed: %d\n", file.c_str(), GetLastError()); | 99 wprintf(L"CreateFileW (%s) failed: %d\n", file.c_str(), GetLastError()); |
| 97 return entry_ != INVALID_HANDLE_VALUE; | 100 return (entry_ != INVALID_HANDLE_VALUE) ? net::OK : net::ERR_FAILED; |
| 98 #else | 101 #else |
| 99 entry_ = file_util::OpenFile(entry_path_, "w+"); | 102 entry_ = file_util::OpenFile(entry_path_, "w+"); |
| 100 return entry_ != NULL; | 103 return (entry_ != NULL) ? net::OK : net::ERR_FAILED; |
| 101 #endif | 104 #endif |
| 102 } | 105 } |
| 103 | 106 |
| 104 // Utility Function to create a normalized header string from a | 107 // Utility Function to create a normalized header string from a |
| 105 // HttpResponseInfo. The output will be formatted exactly | 108 // HttpResponseInfo. The output will be formatted exactly |
| 106 // like so: | 109 // like so: |
| 107 // HTTP/<version> <status_code> <status_text>\n | 110 // HTTP/<version> <status_code> <status_text>\n |
| 108 // [<header-name>: <header-values>\n]* | 111 // [<header-name>: <header-values>\n]* |
| 109 // meaning, each line is \n-terminated, and there is no extra whitespace | 112 // meaning, each line is \n-terminated, and there is no extra whitespace |
| 110 // beyond the single space separators shown (of course, values can contain | 113 // beyond the single space separators shown (of course, values can contain |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 203 |
| 201 void DiskDumper::CloseEntry(disk_cache::Entry* entry, base::Time last_used, | 204 void DiskDumper::CloseEntry(disk_cache::Entry* entry, base::Time last_used, |
| 202 base::Time last_modified) { | 205 base::Time last_modified) { |
| 203 #ifdef WIN32_LARGE_FILENAME_SUPPORT | 206 #ifdef WIN32_LARGE_FILENAME_SUPPORT |
| 204 CloseHandle(entry_); | 207 CloseHandle(entry_); |
| 205 #else | 208 #else |
| 206 file_util::CloseFile(entry_); | 209 file_util::CloseFile(entry_); |
| 207 #endif | 210 #endif |
| 208 } | 211 } |
| 209 | 212 |
| OLD | NEW |