Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / net / tools / dump_cache / cache_dumper.h
blob9b071d7c3268520e1e39359abdc0ef03f8bf67ab
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_CACHE_DUMPER_H_
6 #define NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_
8 #include <string>
10 #include "base/files/file_path.h"
11 #include "net/disk_cache/blockfile/backend_impl.h"
13 #ifdef WIN32
14 // Dumping the cache often creates very large filenames, which are tricky
15 // on windows. Most API calls don't support large filenames, including
16 // most of the base library functions. Unfortunately, adding "\\?\" into
17 // the filename support is tricky. Instead, if WIN32_LARGE_FILENAME_SUPPORT
18 // is set, we use direct WIN32 APIs for manipulating the files.
19 #define WIN32_LARGE_FILENAME_SUPPORT
20 #endif
22 // An abstract class for writing cache dump data.
23 class CacheDumpWriter {
24 public:
25 virtual ~CacheDumpWriter() {}
27 // Creates an entry to be written.
28 // On success, populates the |entry|.
29 // Returns a net error code.
30 virtual int CreateEntry(const std::string& key,
31 disk_cache::Entry** entry,
32 const net::CompletionCallback& callback) = 0;
34 // Write to the current entry.
35 // Returns a net error code.
36 virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
37 net::IOBuffer* buf, int buf_len,
38 const net::CompletionCallback& callback) = 0;
40 // Close the current entry.
41 virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
42 base::Time last_modified) = 0;
45 // Writes data to a cache.
46 class CacheDumper : public CacheDumpWriter {
47 public:
48 explicit CacheDumper(disk_cache::Backend* cache);
50 int CreateEntry(const std::string& key,
51 disk_cache::Entry** entry,
52 const net::CompletionCallback& callback) override;
53 int WriteEntry(disk_cache::Entry* entry,
54 int stream,
55 int offset,
56 net::IOBuffer* buf,
57 int buf_len,
58 const net::CompletionCallback& callback) override;
59 void CloseEntry(disk_cache::Entry* entry,
60 base::Time last_used,
61 base::Time last_modified) override;
63 private:
64 disk_cache::Backend* cache_;
67 // Writes data to a disk.
68 class DiskDumper : public CacheDumpWriter {
69 public:
70 explicit DiskDumper(const base::FilePath& path);
72 int CreateEntry(const std::string& key,
73 disk_cache::Entry** entry,
74 const net::CompletionCallback& callback) override;
75 int WriteEntry(disk_cache::Entry* entry,
76 int stream,
77 int offset,
78 net::IOBuffer* buf,
79 int buf_len,
80 const net::CompletionCallback& callback) override;
81 void CloseEntry(disk_cache::Entry* entry,
82 base::Time last_used,
83 base::Time last_modified) override;
85 private:
86 base::FilePath path_;
87 // This is a bit of a hack. As we get a CreateEntry, we coin the current
88 // entry_path_ where we write that entry to disk. Subsequent calls to
89 // WriteEntry() utilize this path for writing to disk.
90 base::FilePath entry_path_;
91 std::string entry_url_;
92 #ifdef WIN32_LARGE_FILENAME_SUPPORT
93 HANDLE entry_;
94 #else
95 FILE* entry_;
96 #endif
99 #endif // NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_