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
3 // found in the LICENSE file.
5 #ifndef NET_TOOLS_DUMP_CACHE_SIMPLE_CACHE_DUMPER_H_
6 #define NET_TOOLS_DUMP_CACHE_SIMPLE_CACHE_DUMPER_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/thread.h"
11 #include "net/base/completion_callback.h"
12 #include "net/disk_cache/disk_cache.h"
18 class IOBufferWithSize
;
20 // A class for dumping the contents of a disk cache to a series of text
21 // files. The files will contain the response headers, followed by the
22 // response body, as if the HTTP response were written directly to disk.
23 class SimpleCacheDumper
{
25 SimpleCacheDumper(base::FilePath input_path
, base::FilePath output_path
);
28 // Dumps the cache to disk. Returns OK if the operation was successful,
29 // and a net error code otherwise.
36 STATE_CREATE_CACHE_COMPLETE
,
38 STATE_OPEN_ENTRY_COMPLETE
,
40 STATE_CREATE_ENTRY_COMPLETE
,
42 STATE_READ_HEADERS_COMPLETE
,
44 STATE_WRITE_HEADERS_COMPLETE
,
46 STATE_READ_BODY_COMPLETE
,
48 STATE_WRITE_BODY_COMPLETE
,
55 int DoCreateCacheComplete(int rv
);
57 int DoOpenEntryComplete(int rv
);
59 int DoCreateEntryComplete(int rv
);
61 int DoReadHeadersComplete(int rv
);
63 int DoWriteHeadersComplete(int rv
);
65 int DoReadBodyComplete(int rv
);
67 int DoWriteBodyComplete(int rv
);
70 void OnIOComplete(int rv
);
73 base::FilePath input_path_
;
74 base::FilePath output_path_
;
75 scoped_ptr
<disk_cache::Backend
> cache_
;
76 scoped_ptr
<DiskDumper
> writer_
;
77 base::Thread
* cache_thread_
;
78 scoped_ptr
<disk_cache::Backend::Iterator
> iter_
;
79 disk_cache::Entry
* src_entry_
;
80 disk_cache::Entry
* dst_entry_
;
81 CompletionCallback io_callback_
;
82 scoped_refptr
<IOBufferWithSize
> buf_
;
85 DISALLOW_COPY_AND_ASSIGN(SimpleCacheDumper
);
90 #endif // NET_TOOLS_DUMP_CACHE_SIMPLE_CACHE_DUMPER_H_