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

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

Issue 113591: Fix Acid3 Test 48: LINKTEST, Chromium side.... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: Made waiting more bearable. Created 11 years, 5 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
« no previous file with comments | « chrome/browser/visitedlink_event_listener.cc ('k') | chrome/browser/visitedlink_master.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_MASTER_H__ 5 #ifndef CHROME_BROWSER_VISITEDLINK_MASTER_H__
6 #define CHROME_BROWSER_VISITEDLINK_MASTER_H__ 6 #define CHROME_BROWSER_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 17 matching lines...) Expand all
28 } // namespace base 28 } // namespace base
29 29
30 // Controls the link coloring database. The master controls all writing to the 30 // Controls the link coloring database. The master controls all writing to the
31 // database as well as disk I/O. There should be only one master. 31 // database as well as disk I/O. There should be only one master.
32 // 32 //
33 // This class will optionally defer writing operations to another thread. This 33 // This class will optionally defer writing operations to another thread. This
34 // means that after class destruction, the file may still be open since 34 // means that after class destruction, the file may still be open since
35 // operations are pending on another thread. 35 // operations are pending on another thread.
36 class VisitedLinkMaster : public VisitedLinkCommon { 36 class VisitedLinkMaster : public VisitedLinkCommon {
37 public: 37 public:
38 typedef void (PostNewTableEvent)(base::SharedMemory*); 38 // Listens to the link coloring database events. The master is given this
39 // event as a constructor argument and dispatches events using it.
40 class Listener {
41 public:
42 virtual ~Listener() {}
43
44 // Called when link coloring database has been created or replaced. The
45 // argument is the new table handle.
46 virtual void NewTable(base::SharedMemory*) = 0;
47
48 // Called when new link has been added. The argument is the fingerprint
49 // (hash) of the link.
50 virtual void Add(Fingerprint fingerprint) = 0;
51
52 // Called when link coloring state has been reset. This may occur when
53 // entire or parts of history were deleted.
54 virtual void Reset() = 0;
55 };
39 56
40 // The |file_thread| may be NULL, in which case write operations will be 57 // The |file_thread| may be NULL, in which case write operations will be
41 // synchronous. 58 // synchronous.
59 // The |listener| may not be NULL.
42 VisitedLinkMaster(base::Thread* file_thread, 60 VisitedLinkMaster(base::Thread* file_thread,
43 PostNewTableEvent* poster, 61 Listener* listener,
44 Profile* profile); 62 Profile* profile);
45 63
46 // In unit test mode, we allow the caller to optionally specify the database 64 // In unit test mode, we allow the caller to optionally specify the database
47 // filename so that it can be run from a unit test. The directory where this 65 // filename so that it can be run from a unit test. The directory where this
48 // file resides must exist in this mode. You can also specify the default 66 // file resides must exist in this mode. You can also specify the default
49 // table size to test table resizing. If this parameter is 0, we will use the 67 // table size to test table resizing. If this parameter is 0, we will use the
50 // defaults. 68 // defaults.
51 // 69 //
52 // In the unit test mode, we also allow the caller to provide a history 70 // In the unit test mode, we also allow the caller to provide a history
53 // service pointer (the history service can't be fetched from the browser 71 // service pointer (the history service can't be fetched from the browser
54 // process when we're in unit test mode). This can be NULL to try to access 72 // process when we're in unit test mode). This can be NULL to try to access
55 // the main version, which will probably fail (which can be good for testing 73 // the main version, which will probably fail (which can be good for testing
56 // this failure mode). 74 // this failure mode).
57 // 75 //
58 // When |suppress_rebuild| is set, we'll not attempt to load data from 76 // When |suppress_rebuild| is set, we'll not attempt to load data from
59 // history if the file can't be loaded. This should generally be set for 77 // history if the file can't be loaded. This should generally be set for
60 // testing except when you want to test the rebuild process explicitly. 78 // testing except when you want to test the rebuild process explicitly.
61 VisitedLinkMaster(base::Thread* file_thread, 79 VisitedLinkMaster(base::Thread* file_thread,
62 PostNewTableEvent* poster, 80 Listener* listener,
63 HistoryService* history_service, 81 HistoryService* history_service,
64 bool suppress_rebuild, 82 bool suppress_rebuild,
65 const FilePath& filename, 83 const FilePath& filename,
66 int32 default_table_size); 84 int32 default_table_size);
67 virtual ~VisitedLinkMaster(); 85 virtual ~VisitedLinkMaster();
68 86
69 // Must be called immediately after object creation. Nothing else will work 87 // Must be called immediately after object creation. Nothing else will work
70 // until this is called. Returns true on success, false means that this 88 // until this is called. Returns true on success, false means that this
71 // object won't work. 89 // object won't work.
72 bool Init(); 90 bool Init();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // When creating a fresh new table, we use this many entries. 161 // When creating a fresh new table, we use this many entries.
144 static const unsigned kDefaultTableSize; 162 static const unsigned kDefaultTableSize;
145 163
146 // When the user is deleting a boatload of URLs, we don't really want to do 164 // When the user is deleting a boatload of URLs, we don't really want to do
147 // individual writes for each of them. When the count exceeds this threshold, 165 // individual writes for each of them. When the count exceeds this threshold,
148 // we will write the whole table to disk at once instead of individual items. 166 // we will write the whole table to disk at once instead of individual items.
149 static const size_t kBigDeleteThreshold; 167 static const size_t kBigDeleteThreshold;
150 168
151 // Backend for the constructors initializing the members. 169 // Backend for the constructors initializing the members.
152 void InitMembers(base::Thread* file_thread, 170 void InitMembers(base::Thread* file_thread,
153 PostNewTableEvent* poster, 171 Listener* listener,
154 Profile* profile); 172 Profile* profile);
155 173
156 // If a rebuild is in progress, we save the URL in the temporary list. 174 // If a rebuild is in progress, we save the URL in the temporary list.
157 // Otherwise, we add this to the table. Returns the index of the 175 // Otherwise, we add this to the table. Returns the index of the
158 // inserted fingerprint or null_hash_ on failure. 176 // inserted fingerprint or null_hash_ on failure.
159 Hash TryToAddURL(const GURL& url); 177 Hash TryToAddURL(const GURL& url);
160 178
161 // File I/O functions 179 // File I/O functions
162 // ------------------ 180 // ------------------
163 181
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (hash >= table_length_ - 1) 305 if (hash >= table_length_ - 1)
288 return 0; // Wrap around. 306 return 0; // Wrap around.
289 return hash + 1; 307 return hash + 1;
290 } 308 }
291 inline Hash DecrementHash(Hash hash) { 309 inline Hash DecrementHash(Hash hash) {
292 if (hash <= 0) 310 if (hash <= 0)
293 return table_length_ - 1; // Wrap around. 311 return table_length_ - 1; // Wrap around.
294 return hash - 1; 312 return hash - 1;
295 } 313 }
296 314
297 PostNewTableEvent* post_new_table_event_; 315 Listener* listener_;
298 316
299 #ifndef NDEBUG 317 #ifndef NDEBUG
300 // Indicates whether any asynchronous operation has ever been completed. 318 // Indicates whether any asynchronous operation has ever been completed.
301 // We do some synchronous reads that require that no asynchronous operations 319 // We do some synchronous reads that require that no asynchronous operations
302 // are pending, yet we don't track whether they have been completed. This 320 // are pending, yet we don't track whether they have been completed. This
303 // flag is a sanity check that these reads only happen before any 321 // flag is a sanity check that these reads only happen before any
304 // asynchronous writes have been fired. 322 // asynchronous writes have been fired.
305 bool posted_asynchronous_operation_; 323 bool posted_asynchronous_operation_;
306 #endif 324 #endif
307 325
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 int32 used_count = 0; 399 int32 used_count = 0;
382 for (int32 i = 0; i < table_length_; i++) { 400 for (int32 i = 0; i < table_length_; i++) {
383 if (hash_table_[i]) 401 if (hash_table_[i])
384 used_count++; 402 used_count++;
385 } 403 }
386 DCHECK_EQ(used_count, used_items_); 404 DCHECK_EQ(used_count, used_items_);
387 } 405 }
388 #endif 406 #endif
389 407
390 #endif // CHROME_BROWSER_VISITEDLINK_MASTER_H__ 408 #endif // CHROME_BROWSER_VISITEDLINK_MASTER_H__
OLDNEW
« no previous file with comments | « chrome/browser/visitedlink_event_listener.cc ('k') | chrome/browser/visitedlink_master.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698