OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <iostream> | 5 #include <iostream> |
| 6 #include <memory> |
6 | 7 |
7 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
15 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
16 #include "net/disk_cache/disk_cache.h" | 16 #include "net/disk_cache/disk_cache.h" |
17 #include "net/http/http_cache.h" | 17 #include "net/http/http_cache.h" |
18 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
19 #include "net/http/http_util.h" | 19 #include "net/http/http_util.h" |
20 | 20 |
21 using disk_cache::Backend; | 21 using disk_cache::Backend; |
22 using disk_cache::Entry; | 22 using disk_cache::Entry; |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // Print all of a cache's keys to stdout. | 26 // Print all of a cache's keys to stdout. |
27 bool ListKeys(Backend* cache_backend) { | 27 bool ListKeys(Backend* cache_backend) { |
28 scoped_ptr<Backend::Iterator> entry_iterator = | 28 std::unique_ptr<Backend::Iterator> entry_iterator = |
29 cache_backend->CreateIterator(); | 29 cache_backend->CreateIterator(); |
30 Entry* entry = nullptr; | 30 Entry* entry = nullptr; |
31 net::TestCompletionCallback cb; | 31 net::TestCompletionCallback cb; |
32 int rv = entry_iterator->OpenNextEntry(&entry, cb.callback()); | 32 int rv = entry_iterator->OpenNextEntry(&entry, cb.callback()); |
33 while (cb.GetResult(rv) == net::OK) { | 33 while (cb.GetResult(rv) == net::OK) { |
34 std::string url = entry->GetKey(); | 34 std::string url = entry->GetKey(); |
35 std::cout << url << std::endl; | 35 std::cout << url << std::endl; |
36 entry->Close(); | 36 entry->Close(); |
37 entry = nullptr; | 37 entry = nullptr; |
38 rv = entry_iterator->OpenNextEntry(&entry, cb.callback()); | 38 rv = entry_iterator->OpenNextEntry(&entry, cb.callback()); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 if (cache_backend_type == "simple") { | 145 if (cache_backend_type == "simple") { |
146 backend_type = net::CACHE_BACKEND_SIMPLE; | 146 backend_type = net::CACHE_BACKEND_SIMPLE; |
147 } else if (cache_backend_type == "blockfile") { | 147 } else if (cache_backend_type == "blockfile") { |
148 backend_type = net::CACHE_BACKEND_BLOCKFILE; | 148 backend_type = net::CACHE_BACKEND_BLOCKFILE; |
149 } else { | 149 } else { |
150 std::cerr << "Unknown cache type." << std::endl; | 150 std::cerr << "Unknown cache type." << std::endl; |
151 PrintHelp(); | 151 PrintHelp(); |
152 return 1; | 152 return 1; |
153 } | 153 } |
154 | 154 |
155 scoped_ptr<Backend> cache_backend; | 155 std::unique_ptr<Backend> cache_backend; |
156 net::TestCompletionCallback cb; | 156 net::TestCompletionCallback cb; |
157 int rv = disk_cache::CreateCacheBackend( | 157 int rv = disk_cache::CreateCacheBackend( |
158 net::DISK_CACHE, backend_type, cache_path, INT_MAX, false, | 158 net::DISK_CACHE, backend_type, cache_path, INT_MAX, false, |
159 message_loop.task_runner(), nullptr, &cache_backend, cb.callback()); | 159 message_loop.task_runner(), nullptr, &cache_backend, cb.callback()); |
160 if (cb.GetResult(rv) != net::OK) { | 160 if (cb.GetResult(rv) != net::OK) { |
161 std::cerr << "Invalid cache." << std::endl; | 161 std::cerr << "Invalid cache." << std::endl; |
162 return 1; | 162 return 1; |
163 } | 163 } |
164 | 164 |
165 bool successful_command = false; | 165 bool successful_command = false; |
(...skipping 28 matching lines...) Expand all Loading... |
194 return 1; | 194 return 1; |
195 } | 195 } |
196 std::string key(args[3]); | 196 std::string key(args[3]); |
197 successful_command = DeleteKey(cache_backend.get(), key); | 197 successful_command = DeleteKey(cache_backend.get(), key); |
198 } else { | 198 } else { |
199 std::cerr << "Unknown subcommand." << std::endl; | 199 std::cerr << "Unknown subcommand." << std::endl; |
200 PrintHelp(); | 200 PrintHelp(); |
201 } | 201 } |
202 return !successful_command; | 202 return !successful_command; |
203 } | 203 } |
OLD | NEW |