| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/url_request/view_cache_helper.h" | 5 #include "net/url_request/view_cache_helper.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "net/base/escape.h" | 8 #include "net/base/escape.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/disk_cache/disk_cache.h" | 10 #include "net/disk_cache/disk_cache.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 static std::string FormatEntryInfo(disk_cache::Entry* entry, | 59 static std::string FormatEntryInfo(disk_cache::Entry* entry, |
| 60 const std::string& url_prefix) { | 60 const std::string& url_prefix) { |
| 61 std::string key = entry->GetKey(); | 61 std::string key = entry->GetKey(); |
| 62 GURL url = GURL(url_prefix + key); | 62 GURL url = GURL(url_prefix + key); |
| 63 std::string row = | 63 std::string row = |
| 64 "<tr><td><a href=\"" + url.spec() + "\">" + EscapeForHTML(key) + | 64 "<tr><td><a href=\"" + url.spec() + "\">" + EscapeForHTML(key) + |
| 65 "</a></td></tr>"; | 65 "</a></td></tr>"; |
| 66 return row; | 66 return row; |
| 67 } | 67 } |
| 68 | 68 |
| 69 static std::string FormatEntryDetails(disk_cache::Entry* entry) { | 69 static std::string FormatEntryDetails(disk_cache::Entry* entry, |
| 70 int num_entry_data_indices) { |
| 70 std::string result = EscapeForHTML(entry->GetKey()); | 71 std::string result = EscapeForHTML(entry->GetKey()); |
| 71 | 72 |
| 72 net::HttpResponseInfo response; | 73 net::HttpResponseInfo response; |
| 73 bool truncated; | 74 bool truncated; |
| 74 if (net::HttpCache::ReadResponseInfo(entry, &response, &truncated) && | 75 if (net::HttpCache::ReadResponseInfo(entry, &response, &truncated) && |
| 75 response.headers) { | 76 response.headers) { |
| 76 if (truncated) | 77 if (truncated) |
| 77 result.append("<pre>RESPONSE_INFO_TRUNCATED</pre>"); | 78 result.append("<pre>RESPONSE_INFO_TRUNCATED</pre>"); |
| 78 | 79 |
| 79 result.append("<hr><pre>"); | 80 result.append("<hr><pre>"); |
| 80 result.append(EscapeForHTML(response.headers->GetStatusLine())); | 81 result.append(EscapeForHTML(response.headers->GetStatusLine())); |
| 81 result.push_back('\n'); | 82 result.push_back('\n'); |
| 82 | 83 |
| 83 void* iter = NULL; | 84 void* iter = NULL; |
| 84 std::string name, value; | 85 std::string name, value; |
| 85 while (response.headers->EnumerateHeaderLines(&iter, &name, &value)) { | 86 while (response.headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 86 result.append(EscapeForHTML(name)); | 87 result.append(EscapeForHTML(name)); |
| 87 result.append(": "); | 88 result.append(": "); |
| 88 result.append(EscapeForHTML(value)); | 89 result.append(EscapeForHTML(value)); |
| 89 result.push_back('\n'); | 90 result.push_back('\n'); |
| 90 } | 91 } |
| 91 result.append("</pre>"); | 92 result.append("</pre>"); |
| 92 } | 93 } |
| 93 | 94 |
| 94 for (int i = 0; i < 2; ++i) { | 95 for (int i = 0; i < num_entry_data_indices; ++i) { |
| 95 result.append("<hr><pre>"); | 96 result.append("<hr><pre>"); |
| 96 | 97 |
| 97 int data_size = entry->GetDataSize(i); | 98 int data_size = entry->GetDataSize(i); |
| 98 | 99 |
| 99 if (data_size) { | 100 if (data_size) { |
| 100 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(data_size); | 101 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(data_size); |
| 101 if (entry->ReadData(i, 0, buffer, data_size, NULL) == data_size) | 102 if (entry->ReadData(i, 0, buffer, data_size, NULL) == data_size) |
| 102 HexDump(buffer->data(), data_size, &result); | 103 HexDump(buffer->data(), data_size, &result); |
| 103 } | 104 } |
| 104 | 105 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 void* iter = NULL; | 154 void* iter = NULL; |
| 154 disk_cache::Entry* entry; | 155 disk_cache::Entry* entry; |
| 155 while (disk_cache->OpenNextEntry(&iter, &entry)) { | 156 while (disk_cache->OpenNextEntry(&iter, &entry)) { |
| 156 data->append(FormatEntryInfo(entry, url_prefix)); | 157 data->append(FormatEntryInfo(entry, url_prefix)); |
| 157 entry->Close(); | 158 entry->Close(); |
| 158 } | 159 } |
| 159 data->append(VIEW_CACHE_TAIL); | 160 data->append(VIEW_CACHE_TAIL); |
| 160 } else { | 161 } else { |
| 161 disk_cache::Entry* entry; | 162 disk_cache::Entry* entry; |
| 162 if (disk_cache->OpenEntry(key, &entry)) { | 163 if (disk_cache->OpenEntry(key, &entry)) { |
| 163 data->assign(FormatEntryDetails(entry)); | 164 data->assign(FormatEntryDetails( |
| 165 entry, net::HttpCache::kNumCacheEntryDataIndices)); |
| 164 entry->Close(); | 166 entry->Close(); |
| 165 } else { | 167 } else { |
| 166 data->assign("no matching cache entry for: " + EscapeForHTML(key)); | 168 data->assign("no matching cache entry for: " + EscapeForHTML(key)); |
| 167 } | 169 } |
| 168 } | 170 } |
| 169 } | 171 } |
| 170 | 172 |
| 171 // static | 173 // static |
| 172 void ViewCacheHelper::GetStatisticsHTML(URLRequestContext* context, | 174 void ViewCacheHelper::GetStatisticsHTML(URLRequestContext* context, |
| 173 std::string* data) { | 175 std::string* data) { |
| 174 disk_cache::Backend* disk_cache = GetDiskCache(context); | 176 disk_cache::Backend* disk_cache = GetDiskCache(context); |
| 175 if (!disk_cache) { | 177 if (!disk_cache) { |
| 176 data->append("no disk cache"); | 178 data->append("no disk cache"); |
| 177 return; | 179 return; |
| 178 } | 180 } |
| 179 data->append(FormatStatistics(disk_cache)); | 181 data->append(FormatStatistics(disk_cache)); |
| 180 } | 182 } |
| OLD | NEW |