Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: net/disk_cache/simple/simple_index_file.h

Issue 17265007: Unlink corrupt SimpleCache index files immediately after load. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tryable Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector>
9 10
10 #include "base/basictypes.h" 11 #include "base/basictypes.h"
11 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
12 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
13 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/pickle.h" 17 #include "base/pickle.h"
17 #include "base/port.h" 18 #include "base/port.h"
18 #include "net/base/net_export.h" 19 #include "net/base/net_export.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 uint64 magic_number_; 60 uint64 magic_number_;
60 uint32 version_; 61 uint32 version_;
61 uint64 number_of_entries_; 62 uint64 number_of_entries_;
62 uint64 cache_size_; // Total cache storage size in bytes. 63 uint64 cache_size_; // Total cache storage size in bytes.
63 }; 64 };
64 65
65 typedef base::Callback<void( 66 typedef base::Callback<void(
66 scoped_ptr<SimpleIndex::EntrySet>, bool force_index_flush)> 67 scoped_ptr<SimpleIndex::EntrySet>, bool force_index_flush)>
67 IndexCompletionCallback; 68 IndexCompletionCallback;
68 69
69 explicit SimpleIndexFile(base::SingleThreadTaskRunner* cache_thread, 70 SimpleIndexFile(base::SingleThreadTaskRunner* cache_thread,
70 base::TaskRunner* worker_pool, 71 base::TaskRunner* worker_pool,
71 const base::FilePath& index_file_directory); 72 const base::FilePath& index_file_directory);
72 virtual ~SimpleIndexFile(); 73 virtual ~SimpleIndexFile();
73 74
74 // Get index entries based on current disk context. 75 // Get index entries based on current disk context.
75 virtual void LoadIndexEntries( 76 virtual void LoadIndexEntries(
76 scoped_refptr<base::SingleThreadTaskRunner> response_thread, 77 scoped_refptr<base::SingleThreadTaskRunner> response_thread,
77 const SimpleIndexFile::IndexCompletionCallback& completion_callback); 78 const SimpleIndexFile::IndexCompletionCallback& completion_callback);
78 79
79 // Write the specified set of entries to disk. 80 // Write the specified set of entries to disk.
80 virtual void WriteToDisk(const SimpleIndex::EntrySet& entry_set, 81 virtual void WriteToDisk(const SimpleIndex::EntrySet& entry_set,
81 uint64 cache_size, 82 uint64 cache_size,
82 const base::TimeTicks& start, 83 const base::TimeTicks& start,
83 bool app_on_background); 84 bool app_on_background);
84 85
85 // Doom the entries specified in |entry_hashes|, calling |reply_callback| 86 // Doom the entries specified in |entry_hashes|, calling |reply_callback|
86 // with the result on the current thread when done. 87 // with the result on the current thread when done.
87 virtual void DoomEntrySet(scoped_ptr<std::vector<uint64> > entry_hashes, 88 virtual void DoomEntrySet(scoped_ptr<std::vector<uint64> > entry_hashes,
88 const base::Callback<void(int)>& reply_callback); 89 const base::Callback<void(int)>& reply_callback);
89 90
90 private: 91 private:
91 FRIEND_TEST_ALL_PREFIXES(SimpleIndexFileTest, IsIndexFileCorrupt); 92 friend class TestSimpleIndexFile;
92 FRIEND_TEST_ALL_PREFIXES(SimpleIndexFileTest, IsIndexFileStale);
93 FRIEND_TEST_ALL_PREFIXES(SimpleIndexFileTest, Serialize);
94 93
95 // Using the mtime of the file and its mtime, detects if the index file is 94 // Using the mtime of the file and its mtime, detects if the index file is
96 // stale. 95 // stale.
97 static bool IsIndexFileStale(const base::FilePath& index_filename); 96 static bool IsIndexFileStale(const base::FilePath& index_filename);
98 97
99 // Load the index file from disk, deserializing it and returning the 98 // Load the index file from disk, deserializing it and returning the
100 // corresponding EntrySet in a scoped_ptr<>, if successful. 99 // corresponding EntrySet in a scoped_ptr<>, if successful.
101 // Uppon failure, the scoped_ptr<> will contain NULL. 100 // Uppon failure, the scoped_ptr<> will contain NULL.
102 static scoped_ptr<SimpleIndex::EntrySet> LoadFromDisk( 101 static scoped_ptr<SimpleIndex::EntrySet> LoadFromDisk(
103 const base::FilePath& index_filename); 102 const base::FilePath& index_filename);
(...skipping 26 matching lines...) Expand all
130 129
131 static const char kIndexFileName[]; 130 static const char kIndexFileName[];
132 131
133 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile); 132 DISALLOW_COPY_AND_ASSIGN(SimpleIndexFile);
134 }; 133 };
135 134
136 135
137 } // namespace disk_cache 136 } // namespace disk_cache
138 137
139 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_ 138 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_INDEX_FILE_H_
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_index_file.cc » ('j') | net/disk_cache/simple/simple_index_file_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698