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

Side by Side Diff: chrome/browser/visitedlink/visitedlink_master.h

Issue 10800005: Do not open file on UI thread in VisitedLinkMaster (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
OLDNEW
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 #ifndef CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_ 5 #ifndef CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_
6 #define CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_ 6 #define CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_
7 7
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include <windows.h> 9 #include <windows.h>
10 #endif 10 #endif
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 rebuild_complete_task_ = task; 109 rebuild_complete_task_ = task;
110 } 110 }
111 111
112 // returns the number of items in the table for testing verification 112 // returns the number of items in the table for testing verification
113 int32 GetUsedCount() const { 113 int32 GetUsedCount() const {
114 return used_items_; 114 return used_items_;
115 } 115 }
116 116
117 // Call to cause the entire database file to be re-written from scratch 117 // Call to cause the entire database file to be re-written from scratch
118 // to disk. Used by the performance tester. 118 // to disk. Used by the performance tester.
119 bool RewriteFile() { 119 void RewriteFile() {
120 return WriteFullTable(); 120 WriteFullTable();
121 } 121 }
122 #endif 122 #endif
123 123
124 private: 124 private:
125 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, Delete); 125 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, Delete);
126 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigDelete); 126 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigDelete);
127 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigImport); 127 FRIEND_TEST_ALL_PREFIXES(VisitedLinkTest, BigImport);
128 128
129 // Object to rebuild the table on the history thread (see the .cc file). 129 // Object to rebuild the table on the history thread (see the .cc file).
130 class TableBuilder; 130 class TableBuilder;
(...skipping 30 matching lines...) Expand all
161 // inserted fingerprint or null_hash_ on failure. 161 // inserted fingerprint or null_hash_ on failure.
162 Hash TryToAddURL(const GURL& url); 162 Hash TryToAddURL(const GURL& url);
163 163
164 // File I/O functions 164 // File I/O functions
165 // ------------------ 165 // ------------------
166 166
167 // Posts the given task to the blocking worker pool with our options. 167 // Posts the given task to the blocking worker pool with our options.
168 void PostIOTask(const tracked_objects::Location& from_here, 168 void PostIOTask(const tracked_objects::Location& from_here,
169 const base::Closure& task); 169 const base::Closure& task);
170 170
171 // Writes the entire table to disk, returning true on success. It will leave 171 // Writes the entire table to disk. It will leave the table file open and
172 // the table file open and the handle to it in file_ 172 // the handle to it will be stored in file_.
173 bool WriteFullTable(); 173 void WriteFullTable();
174 174
175 // Try to load the table from the database file. If the file doesn't exist or 175 // Try to load the table from the database file. If the file doesn't exist or
176 // is corrupt, this will return failure. 176 // is corrupt, this will return failure.
177 bool InitFromFile(); 177 bool InitFromFile();
178 178
179 // Reads the header of the link coloring database from disk. Assumes the 179 // Reads the header of the link coloring database from disk. Assumes the
180 // file pointer is at the beginning of the file and that there are no pending 180 // file pointer is at the beginning of the file and that there are no pending
181 // asynchronous I/O operations. 181 // asynchronous I/O operations.
182 // 182 //
183 // Returns true on success and places the size of the table in num_entries 183 // Returns true on success and places the size of the table in num_entries
184 // and the number of nonzero fingerprints in used_count. This will fail if 184 // and the number of nonzero fingerprints in used_count. This will fail if
185 // the version of the file is not the current version of the database. 185 // the version of the file is not the current version of the database.
186 bool ReadFileHeader(FILE* hfile, int32* num_entries, int32* used_count, 186 bool ReadFileHeader(FILE* hfile, int32* num_entries, int32* used_count,
187 uint8 salt[LINK_SALT_LENGTH]); 187 uint8 salt[LINK_SALT_LENGTH]);
188 188
189 // Fills *filename with the name of the link database filename 189 // Fills *filename with the name of the link database filename
190 bool GetDatabaseFileName(FilePath* filename); 190 bool GetDatabaseFileName(FilePath* filename);
191 191
192 // Wrapper around Window's WriteFile using asynchronous I/O. This will proxy 192 // Wrapper around Window's WriteFile using asynchronous I/O. This will proxy
193 // the write to a background thread. 193 // the write to a background thread.
194 void WriteToFile(FILE* hfile, off_t offset, void* data, int32 data_size); 194 void WriteToFile(FILE** hfile, off_t offset, void* data, int32 data_size);
195 195
196 // Helper function to schedule and asynchronous write of the used count to 196 // Helper function to schedule and asynchronous write of the used count to
197 // disk (this is a common operation). 197 // disk (this is a common operation).
198 void WriteUsedItemCountToFile(); 198 void WriteUsedItemCountToFile();
199 199
200 // Helper function to schedule an asynchronous write of the given range of 200 // Helper function to schedule an asynchronous write of the given range of
201 // hash functions to disk. The range is inclusive on both ends. The range can 201 // hash functions to disk. The range is inclusive on both ends. The range can
202 // wrap around at 0 and this function will handle it. 202 // wrap around at 0 and this function will handle it.
203 void WriteHashRangeToFile(Hash first_hash, Hash last_hash); 203 void WriteHashRangeToFile(Hash first_hash, Hash last_hash);
204 204
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 std::set<Fingerprint> added_since_rebuild_; 330 std::set<Fingerprint> added_since_rebuild_;
331 std::set<Fingerprint> deleted_since_rebuild_; 331 std::set<Fingerprint> deleted_since_rebuild_;
332 332
333 // TODO(brettw) Support deletion, we need to track whether anything was 333 // TODO(brettw) Support deletion, we need to track whether anything was
334 // deleted during the rebuild here. Then we should delete any of these 334 // deleted during the rebuild here. Then we should delete any of these
335 // entries from the complete table later. 335 // entries from the complete table later.
336 // std::vector<Fingerprint> removed_since_rebuild_; 336 // std::vector<Fingerprint> removed_since_rebuild_;
337 337
338 // The currently open file with the table in it. This may be NULL if we're 338 // The currently open file with the table in it. This may be NULL if we're
339 // rebuilding and haven't written a new version yet. Writing to the file may 339 // rebuilding and haven't written a new version yet. Writing to the file may
340 // be safely ignored in this case. 340 // be safely ignored in this case. Also |file_| may be non-NULL but point to
341 FILE* file_; 341 // a NULL pointer. That would mean that opening of the file is already
342 // scheduled in a background thread and any writing to the file can also be
343 // scheduled to the background thread as it's guaranteed to be executed after
344 // the opening.
345 // The class owns both the |file_| pointer and the pointer pointed
346 // by |*file_|.
347 FILE** file_;
342 348
343 // Shared memory consists of a SharedHeader followed by the table. 349 // Shared memory consists of a SharedHeader followed by the table.
344 base::SharedMemory *shared_memory_; 350 base::SharedMemory *shared_memory_;
345 351
346 // When we generate new tables, we increment the serial number of the 352 // When we generate new tables, we increment the serial number of the
347 // shared memory object. 353 // shared memory object.
348 int32 shared_memory_serial_; 354 int32 shared_memory_serial_;
349 355
350 // Number of non-empty items in the table, used to compute fullness. 356 // Number of non-empty items in the table, used to compute fullness.
351 int32 used_items_; 357 int32 used_items_;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 int32 used_count = 0; 394 int32 used_count = 0;
389 for (int32 i = 0; i < table_length_; i++) { 395 for (int32 i = 0; i < table_length_; i++) {
390 if (hash_table_[i]) 396 if (hash_table_[i])
391 used_count++; 397 used_count++;
392 } 398 }
393 DCHECK_EQ(used_count, used_items_); 399 DCHECK_EQ(used_count, used_items_);
394 } 400 }
395 #endif 401 #endif
396 402
397 #endif // CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_ 403 #endif // CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/visitedlink/visitedlink_master.cc » ('j') | chrome/browser/visitedlink/visitedlink_master.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698