| 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), |
| 29 src_entry_(NULL), | 30 src_entry_(NULL), |
| 30 dst_entry_(NULL), | 31 dst_entry_(NULL), |
| 31 io_callback_(base::Bind(&SimpleCacheDumper::OnIOComplete, | 32 io_callback_(base::Bind(&SimpleCacheDumper::OnIOComplete, |
| 32 base::Unretained(this))), | 33 base::Unretained(this))), |
| 33 rv_(0) { | 34 rv_(0) { |
| 34 } | 35 } |
| 35 | 36 |
| 36 SimpleCacheDumper::~SimpleCacheDumper() { | 37 SimpleCacheDumper::~SimpleCacheDumper() { |
| 37 } | 38 } |
| 38 | 39 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 disk_cache::kNoRandom); | 143 disk_cache::kNoRandom); |
| 143 | 144 |
| 144 state_ = STATE_OPEN_ENTRY; | 145 state_ = STATE_OPEN_ENTRY; |
| 145 return OK; | 146 return OK; |
| 146 } | 147 } |
| 147 | 148 |
| 148 int SimpleCacheDumper::DoOpenEntry() { | 149 int SimpleCacheDumper::DoOpenEntry() { |
| 149 DCHECK(!dst_entry_); | 150 DCHECK(!dst_entry_); |
| 150 DCHECK(!src_entry_); | 151 DCHECK(!src_entry_); |
| 151 state_ = STATE_OPEN_ENTRY_COMPLETE; | 152 state_ = STATE_OPEN_ENTRY_COMPLETE; |
| 152 if (!iter_) | 153 return cache_->OpenNextEntry(&iter_, &src_entry_, io_callback_); |
| 153 iter_ = cache_->CreateIterator(); | |
| 154 return iter_->OpenNextEntry(&src_entry_, io_callback_); | |
| 155 } | 154 } |
| 156 | 155 |
| 157 int SimpleCacheDumper::DoOpenEntryComplete(int rv) { | 156 int SimpleCacheDumper::DoOpenEntryComplete(int rv) { |
| 158 // ERR_FAILED indicates iteration finished. | 157 // ERR_FAILED indicates iteration finished. |
| 159 if (rv == ERR_FAILED) | 158 if (rv == ERR_FAILED) { |
| 159 cache_->EndEnumeration(&iter_); |
| 160 return OK; | 160 return OK; |
| 161 } |
| 161 | 162 |
| 162 if (rv < 0) | 163 if (rv < 0) |
| 163 return rv; | 164 return rv; |
| 164 | 165 |
| 165 state_ = STATE_CREATE_ENTRY; | 166 state_ = STATE_CREATE_ENTRY; |
| 166 return OK; | 167 return OK; |
| 167 } | 168 } |
| 168 | 169 |
| 169 int SimpleCacheDumper::DoCreateEntry() { | 170 int SimpleCacheDumper::DoCreateEntry() { |
| 170 DCHECK(!dst_entry_); | 171 DCHECK(!dst_entry_); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 rv = DoLoop(rv); | 264 rv = DoLoop(rv); |
| 264 | 265 |
| 265 if (rv != ERR_IO_PENDING) { | 266 if (rv != ERR_IO_PENDING) { |
| 266 rv_ = rv; | 267 rv_ = rv; |
| 267 cache_.reset(); | 268 cache_.reset(); |
| 268 base::MessageLoop::current()->Quit(); | 269 base::MessageLoop::current()->Quit(); |
| 269 } | 270 } |
| 270 } | 271 } |
| 271 | 272 |
| 272 } // namespace net | 273 } // namespace net |
| OLD | NEW |