Home | History | Annotate | Download | only in dump_cache
      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.
      4 
      5 #ifndef NET_TOOLS_DUMP_CACHE_SIMPLE_CACHE_DUMPER_H_
      6 #define NET_TOOLS_DUMP_CACHE_SIMPLE_CACHE_DUMPER_H_
      7 
      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 
     13 class DiskDumper;
     14 
     15 namespace disk_cache {
     16 class Backend;
     17 class Entry;
     18 }  // namespace disk_cache
     19 
     20 namespace net {
     21 
     22 class IOBufferWithSize;
     23 
     24 // A class for dumping the contents of a disk cache to a series of text
     25 // files.  The files will contain the response headers, followed by the
     26 // response body, as if the HTTP response were written directly to disk.
     27 class SimpleCacheDumper {
     28  public:
     29   SimpleCacheDumper(base::FilePath input_path, base::FilePath output_path);
     30   ~SimpleCacheDumper();
     31 
     32   // Dumps the cache to disk. Returns OK if the operation was successful,
     33   // and a net error code otherwise.
     34   int Run();
     35 
     36  private:
     37   enum State {
     38     STATE_NONE,
     39     STATE_CREATE_CACHE,
     40     STATE_CREATE_CACHE_COMPLETE,
     41     STATE_OPEN_ENTRY,
     42     STATE_OPEN_ENTRY_COMPLETE,
     43     STATE_CREATE_ENTRY,
     44     STATE_CREATE_ENTRY_COMPLETE,
     45     STATE_READ_HEADERS,
     46     STATE_READ_HEADERS_COMPLETE,
     47     STATE_WRITE_HEADERS,
     48     STATE_WRITE_HEADERS_COMPLETE,
     49     STATE_READ_BODY,
     50     STATE_READ_BODY_COMPLETE,
     51     STATE_WRITE_BODY,
     52     STATE_WRITE_BODY_COMPLETE,
     53     STATE_DONE,
     54   };
     55 
     56   int DoLoop(int rv);
     57 
     58   int DoCreateCache();
     59   int DoCreateCacheComplete(int rv);
     60   int DoOpenEntry();
     61   int DoOpenEntryComplete(int rv);
     62   int DoCreateEntry();
     63   int DoCreateEntryComplete(int rv);
     64   int DoReadHeaders();
     65   int DoReadHeadersComplete(int rv);
     66   int DoWriteHeaders();
     67   int DoWriteHeadersComplete(int rv);
     68   int DoReadBody();
     69   int DoReadBodyComplete(int rv);
     70   int DoWriteBody();
     71   int DoWriteBodyComplete(int rv);
     72   int DoDone();
     73 
     74   void OnIOComplete(int rv);
     75 
     76   State state_;
     77   base::FilePath input_path_;
     78   base::FilePath output_path_;
     79   scoped_ptr<disk_cache::Backend> cache_;
     80   scoped_ptr<DiskDumper> writer_;
     81   base::Thread* cache_thread_;
     82   void* iter_;
     83   disk_cache::Entry* src_entry_;
     84   disk_cache::Entry* dst_entry_;
     85   CompletionCallback io_callback_;
     86   scoped_refptr<IOBufferWithSize> buf_;
     87   int rv_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(SimpleCacheDumper);
     90 };
     91 
     92 }  // namespace net
     93 
     94 #endif  // NET_TOOLS_DUMP_CACHE_SIMPLE_CACHE_DUMPER_H_
     95