Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Side by Side Diff: net/url_request/view_cache_helper.cc

Issue 7326023: about://appcache-internals enhancements (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/url_request/view_cache_helper.h ('k') | webkit/appcache/appcache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/stringprintf.h" 7 #include "base/stringprintf.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/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/disk_cache/disk_cache.h" 11 #include "net/disk_cache/disk_cache.h"
12 #include "net/http/http_cache.h" 12 #include "net/http/http_cache.h"
13 #include "net/http/http_response_headers.h" 13 #include "net/http/http_response_headers.h"
14 #include "net/http/http_response_info.h" 14 #include "net/http/http_response_info.h"
15 #include "net/url_request/url_request_context.h" 15 #include "net/url_request/url_request_context.h"
16 16
17 #define VIEW_CACHE_HEAD \ 17 #define VIEW_CACHE_HEAD \
18 "<html><body><table>" 18 "<html><body><table>"
19 19
20 #define VIEW_CACHE_TAIL \ 20 #define VIEW_CACHE_TAIL \
21 "</table></body></html>" 21 "</table></body></html>"
22 22
23 namespace net { 23 namespace net {
24 24
25 namespace { 25 namespace {
26 26
27 void HexDump(const char *buf, size_t buf_len, std::string* result) {
28 const size_t kMaxRows = 16;
29 int offset = 0;
30
31 const unsigned char *p;
32 while (buf_len) {
33 base::StringAppendF(result, "%08x: ", offset);
34 offset += kMaxRows;
35
36 p = (const unsigned char *) buf;
37
38 size_t i;
39 size_t row_max = std::min(kMaxRows, buf_len);
40
41 // print hex codes:
42 for (i = 0; i < row_max; ++i)
43 base::StringAppendF(result, "%02x ", *p++);
44 for (i = row_max; i < kMaxRows; ++i)
45 result->append(" ");
46
47 // print ASCII glyphs if possible:
48 p = (const unsigned char *) buf;
49 for (i = 0; i < row_max; ++i, ++p) {
50 if (*p < 0x7F && *p > 0x1F) {
51 AppendEscapedCharForHTML(*p, result);
52 } else {
53 result->push_back('.');
54 }
55 }
56
57 result->push_back('\n');
58
59 buf += row_max;
60 buf_len -= row_max;
61 }
62 }
63
64 std::string FormatEntryInfo(disk_cache::Entry* entry, 27 std::string FormatEntryInfo(disk_cache::Entry* entry,
65 const std::string& url_prefix) { 28 const std::string& url_prefix) {
66 std::string key = entry->GetKey(); 29 std::string key = entry->GetKey();
67 GURL url = GURL(url_prefix + key); 30 GURL url = GURL(url_prefix + key);
68 std::string row = 31 std::string row =
69 "<tr><td><a href=\"" + url.spec() + "\">" + EscapeForHTML(key) + 32 "<tr><td><a href=\"" + url.spec() + "\">" + EscapeForHTML(key) +
70 "</a></td></tr>"; 33 "</a></td></tr>";
71 return row; 34 return row;
72 } 35 }
73 36
(...skipping 30 matching lines...) Expand all
104 return GetInfoHTML(key, context, std::string(), out, callback); 67 return GetInfoHTML(key, context, std::string(), out, callback);
105 } 68 }
106 69
107 int ViewCacheHelper::GetContentsHTML(URLRequestContext* context, 70 int ViewCacheHelper::GetContentsHTML(URLRequestContext* context,
108 const std::string& url_prefix, 71 const std::string& url_prefix,
109 std::string* out, 72 std::string* out,
110 CompletionCallback* callback) { 73 CompletionCallback* callback) {
111 return GetInfoHTML(std::string(), context, url_prefix, out, callback); 74 return GetInfoHTML(std::string(), context, url_prefix, out, callback);
112 } 75 }
113 76
77 // static
78 void ViewCacheHelper::HexDump(const char *buf, size_t buf_len,
79 std::string* result) {
80 const size_t kMaxRows = 16;
81 int offset = 0;
82
83 const unsigned char *p;
84 while (buf_len) {
85 base::StringAppendF(result, "%08x: ", offset);
86 offset += kMaxRows;
87
88 p = (const unsigned char *) buf;
89
90 size_t i;
91 size_t row_max = std::min(kMaxRows, buf_len);
92
93 // print hex codes:
94 for (i = 0; i < row_max; ++i)
95 base::StringAppendF(result, "%02x ", *p++);
96 for (i = row_max; i < kMaxRows; ++i)
97 result->append(" ");
98
99 // print ASCII glyphs if possible:
100 p = (const unsigned char *) buf;
101 for (i = 0; i < row_max; ++i, ++p) {
102 if (*p < 0x7F && *p > 0x1F) {
103 AppendEscapedCharForHTML(*p, result);
104 } else {
105 result->push_back('.');
106 }
107 }
108
109 result->push_back('\n');
110
111 buf += row_max;
112 buf_len -= row_max;
113 }
114 }
115
114 //----------------------------------------------------------------------------- 116 //-----------------------------------------------------------------------------
115 117
116 int ViewCacheHelper::GetInfoHTML(const std::string& key, 118 int ViewCacheHelper::GetInfoHTML(const std::string& key,
117 URLRequestContext* context, 119 URLRequestContext* context,
118 const std::string& url_prefix, 120 const std::string& url_prefix,
119 std::string* out, 121 std::string* out,
120 CompletionCallback* callback) { 122 CompletionCallback* callback) {
121 DCHECK(!callback_); 123 DCHECK(!callback_);
122 DCHECK(context); 124 DCHECK(context);
123 key_ = key; 125 key_ = key;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 entry_ = NULL; 348 entry_ = NULL;
347 } 349 }
348 return OK; 350 return OK;
349 } 351 }
350 352
351 void ViewCacheHelper::OnIOComplete(int result) { 353 void ViewCacheHelper::OnIOComplete(int result) {
352 DoLoop(result); 354 DoLoop(result);
353 } 355 }
354 356
355 } // namespace net. 357 } // namespace net.
OLDNEW
« no previous file with comments | « net/url_request/view_cache_helper.h ('k') | webkit/appcache/appcache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698