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 cache_(NULL), | |
28 writer_(new DiskDumper(output_path)), | 27 writer_(new DiskDumper(output_path)), |
29 cache_thread_(new base::Thread("CacheThead")), | 28 cache_thread_(new base::Thread("CacheThead")), |
30 iter_(NULL), | 29 iter_(NULL), |
31 src_entry_(NULL), | 30 src_entry_(NULL), |
32 dst_entry_(NULL), | 31 dst_entry_(NULL), |
33 io_callback_(base::Bind(&SimpleCacheDumper::OnIOComplete, | 32 io_callback_(base::Bind(&SimpleCacheDumper::OnIOComplete, |
34 base::Unretained(this))), | 33 base::Unretained(this))), |
35 rv_(0) { | 34 rv_(0) { |
36 } | 35 } |
37 | 36 |
38 SimpleCacheDumper::~SimpleCacheDumper() { | 37 SimpleCacheDumper::~SimpleCacheDumper() { |
39 delete(cache_); | |
40 } | 38 } |
41 | 39 |
42 int SimpleCacheDumper::Run() { | 40 int SimpleCacheDumper::Run() { |
43 base::MessageLoopForIO main_message_loop; | 41 base::MessageLoopForIO main_message_loop; |
44 | 42 |
45 LOG(INFO) << "Reading cache from: " << input_path_.value(); | 43 LOG(INFO) << "Reading cache from: " << input_path_.value(); |
46 LOG(INFO) << "Writing cache to: " << output_path_.value(); | 44 LOG(INFO) << "Writing cache to: " << output_path_.value(); |
47 | 45 |
48 if (!cache_thread_->StartWithOptions( | 46 if (!cache_thread_->StartWithOptions( |
49 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) { | 47 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 cache_thread_->message_loop_proxy().get(), | 131 cache_thread_->message_loop_proxy().get(), |
134 NULL, | 132 NULL, |
135 &cache_, | 133 &cache_, |
136 io_callback_); | 134 io_callback_); |
137 } | 135 } |
138 | 136 |
139 int SimpleCacheDumper::DoCreateCacheComplete(int rv) { | 137 int SimpleCacheDumper::DoCreateCacheComplete(int rv) { |
140 if (rv < 0) | 138 if (rv < 0) |
141 return rv; | 139 return rv; |
142 | 140 |
143 reinterpret_cast<disk_cache::BackendImpl*>(cache_)->SetUpgradeMode(); | 141 reinterpret_cast<disk_cache::BackendImpl*>(cache_.get())->SetUpgradeMode(); |
144 reinterpret_cast<disk_cache::BackendImpl*>(cache_)->SetFlags( | 142 reinterpret_cast<disk_cache::BackendImpl*>(cache_.get())->SetFlags( |
145 disk_cache::kNoRandom); | 143 disk_cache::kNoRandom); |
146 | 144 |
147 state_ = STATE_OPEN_ENTRY; | 145 state_ = STATE_OPEN_ENTRY; |
148 return OK; | 146 return OK; |
149 } | 147 } |
150 | 148 |
151 int SimpleCacheDumper::DoOpenEntry() { | 149 int SimpleCacheDumper::DoOpenEntry() { |
152 DCHECK(!dst_entry_); | 150 DCHECK(!dst_entry_); |
153 DCHECK(!src_entry_); | 151 DCHECK(!src_entry_); |
154 state_ = STATE_OPEN_ENTRY_COMPLETE; | 152 state_ = STATE_OPEN_ENTRY_COMPLETE; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 258 |
261 state_ = STATE_OPEN_ENTRY; | 259 state_ = STATE_OPEN_ENTRY; |
262 return OK; | 260 return OK; |
263 } | 261 } |
264 | 262 |
265 void SimpleCacheDumper::OnIOComplete(int rv) { | 263 void SimpleCacheDumper::OnIOComplete(int rv) { |
266 rv = DoLoop(rv); | 264 rv = DoLoop(rv); |
267 | 265 |
268 if (rv != ERR_IO_PENDING) { | 266 if (rv != ERR_IO_PENDING) { |
269 rv_ = rv; | 267 rv_ = rv; |
270 delete cache_; | 268 cache_.reset(); |
271 cache_ = NULL; | |
272 base::MessageLoop::current()->Quit(); | 269 base::MessageLoop::current()->Quit(); |
273 } | 270 } |
274 } | 271 } |
275 | 272 |
276 } // namespace net | 273 } // namespace net |
OLD | NEW |