OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/simple_cache_dumper.h" | 5 #include "net/tools/dump_cache/simple_cache_dumper.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/message_loop/message_loop_proxy.h" | 12 #include "base/message_loop/message_loop_proxy.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "net/base/cache_type.h" | 14 #include "net/base/cache_type.h" |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
17 #include "net/disk_cache/disk_cache.h" | 17 #include "net/disk_cache/disk_cache.h" |
18 #include "net/tools/dump_cache/cache_dumper.h" | 18 #include "net/tools/dump_cache/cache_dumper.h" |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 SimpleCacheDumper::SimpleCacheDumper(base::FilePath input_path, | 22 SimpleCacheDumper::SimpleCacheDumper(base::FilePath input_path, |
23 base::FilePath output_path) | 23 base::FilePath output_path) |
24 : state_(STATE_NONE), | 24 : state_(STATE_NONE), |
25 input_path_(input_path), | 25 input_path_(input_path), |
26 output_path_(output_path), | 26 output_path_(output_path), |
27 writer_(new DiskDumper(output_path)), | 27 writer_(new DiskDumper(output_path)), |
28 cache_thread_(new base::Thread("CacheThead")), | 28 cache_thread_(new base::Thread("CacheThead")), |
29 iter_(NULL), | |
30 src_entry_(NULL), | 29 src_entry_(NULL), |
31 dst_entry_(NULL), | 30 dst_entry_(NULL), |
32 io_callback_(base::Bind(&SimpleCacheDumper::OnIOComplete, | 31 io_callback_(base::Bind(&SimpleCacheDumper::OnIOComplete, |
33 base::Unretained(this))), | 32 base::Unretained(this))), |
34 rv_(0) { | 33 rv_(0) { |
35 } | 34 } |
36 | 35 |
37 SimpleCacheDumper::~SimpleCacheDumper() { | 36 SimpleCacheDumper::~SimpleCacheDumper() { |
38 } | 37 } |
39 | 38 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 disk_cache::kNoRandom); | 142 disk_cache::kNoRandom); |
144 | 143 |
145 state_ = STATE_OPEN_ENTRY; | 144 state_ = STATE_OPEN_ENTRY; |
146 return OK; | 145 return OK; |
147 } | 146 } |
148 | 147 |
149 int SimpleCacheDumper::DoOpenEntry() { | 148 int SimpleCacheDumper::DoOpenEntry() { |
150 DCHECK(!dst_entry_); | 149 DCHECK(!dst_entry_); |
151 DCHECK(!src_entry_); | 150 DCHECK(!src_entry_); |
152 state_ = STATE_OPEN_ENTRY_COMPLETE; | 151 state_ = STATE_OPEN_ENTRY_COMPLETE; |
153 return cache_->OpenNextEntry(&iter_, &src_entry_, io_callback_); | 152 if (!iter_) |
| 153 iter_ = cache_->CreateIterator(); |
| 154 return iter_->OpenNextEntry(&src_entry_, io_callback_); |
154 } | 155 } |
155 | 156 |
156 int SimpleCacheDumper::DoOpenEntryComplete(int rv) { | 157 int SimpleCacheDumper::DoOpenEntryComplete(int rv) { |
157 // ERR_FAILED indicates iteration finished. | 158 // ERR_FAILED indicates iteration finished. |
158 if (rv == ERR_FAILED) { | 159 if (rv == ERR_FAILED) |
159 cache_->EndEnumeration(&iter_); | |
160 return OK; | 160 return OK; |
161 } | |
162 | 161 |
163 if (rv < 0) | 162 if (rv < 0) |
164 return rv; | 163 return rv; |
165 | 164 |
166 state_ = STATE_CREATE_ENTRY; | 165 state_ = STATE_CREATE_ENTRY; |
167 return OK; | 166 return OK; |
168 } | 167 } |
169 | 168 |
170 int SimpleCacheDumper::DoCreateEntry() { | 169 int SimpleCacheDumper::DoCreateEntry() { |
171 DCHECK(!dst_entry_); | 170 DCHECK(!dst_entry_); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 rv = DoLoop(rv); | 263 rv = DoLoop(rv); |
265 | 264 |
266 if (rv != ERR_IO_PENDING) { | 265 if (rv != ERR_IO_PENDING) { |
267 rv_ = rv; | 266 rv_ = rv; |
268 cache_.reset(); | 267 cache_.reset(); |
269 base::MessageLoop::current()->Quit(); | 268 base::MessageLoop::current()->Quit(); |
270 } | 269 } |
271 } | 270 } |
272 | 271 |
273 } // namespace net | 272 } // namespace net |
OLD | NEW |