| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <windows.h> | 10 #include <windows.h> |
| 11 #endif | 11 #endif |
| 12 #include <set> | 12 #include <set> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 16 #include "base/file_path.h" | 16 #include "base/file_path.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/shared_memory.h" | 19 #include "base/shared_memory.h" |
| 20 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "chrome/browser/history/history.h" | 21 #include "chrome/browser/history/history.h" |
| 21 #include "chrome/common/visitedlink_common.h" | 22 #include "chrome/common/visitedlink_common.h" |
| 22 | 23 |
| 23 class GURL; | 24 class GURL; |
| 24 class Profile; | 25 class Profile; |
| 25 | 26 |
| 26 // Controls the link coloring database. The master controls all writing to the | 27 // Controls the link coloring database. The master controls all writing to the |
| 27 // database as well as disk I/O. There should be only one master. | 28 // database as well as disk I/O. There should be only one master. |
| 28 // | 29 // |
| 29 // This class will defer writing operations to the file thread. This means that | 30 // This class will defer writing operations to the file thread. This means that |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 void InitMembers(Listener* listener, Profile* profile); | 157 void InitMembers(Listener* listener, Profile* profile); |
| 157 | 158 |
| 158 // If a rebuild is in progress, we save the URL in the temporary list. | 159 // If a rebuild is in progress, we save the URL in the temporary list. |
| 159 // Otherwise, we add this to the table. Returns the index of the | 160 // Otherwise, we add this to the table. Returns the index of the |
| 160 // inserted fingerprint or null_hash_ on failure. | 161 // inserted fingerprint or null_hash_ on failure. |
| 161 Hash TryToAddURL(const GURL& url); | 162 Hash TryToAddURL(const GURL& url); |
| 162 | 163 |
| 163 // File I/O functions | 164 // File I/O functions |
| 164 // ------------------ | 165 // ------------------ |
| 165 | 166 |
| 167 // Posts the given task to the blocking worker pool with our options. |
| 168 void PostIOTask(const tracked_objects::Location& from_here, |
| 169 const base::Closure& task); |
| 170 |
| 166 // Writes the entire table to disk, returning true on success. It will leave | 171 // Writes the entire table to disk, returning true on success. It will leave |
| 167 // the table file open and the handle to it in file_ | 172 // the table file open and the handle to it in file_ |
| 168 bool WriteFullTable(); | 173 bool WriteFullTable(); |
| 169 | 174 |
| 170 // 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 |
| 171 // is corrupt, this will return failure. | 176 // is corrupt, this will return failure. |
| 172 bool InitFromFile(); | 177 bool InitFromFile(); |
| 173 | 178 |
| 174 // 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 |
| 175 // 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 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 // are pending, yet we don't track whether they have been completed. This | 310 // are pending, yet we don't track whether they have been completed. This |
| 306 // flag is a sanity check that these reads only happen before any | 311 // flag is a sanity check that these reads only happen before any |
| 307 // asynchronous writes have been fired. | 312 // asynchronous writes have been fired. |
| 308 bool posted_asynchronous_operation_; | 313 bool posted_asynchronous_operation_; |
| 309 #endif | 314 #endif |
| 310 | 315 |
| 311 // Reference to the user profile that this object belongs to | 316 // Reference to the user profile that this object belongs to |
| 312 // (it knows the path to where the data is stored) | 317 // (it knows the path to where the data is stored) |
| 313 Profile* profile_; | 318 Profile* profile_; |
| 314 | 319 |
| 320 // Lazily initialized sequence token for posting file tasks. |
| 321 base::SequencedWorkerPool::SequenceToken sequence_token_; |
| 322 |
| 315 // When non-NULL, indicates we are in database rebuild mode and points to | 323 // When non-NULL, indicates we are in database rebuild mode and points to |
| 316 // the class collecting fingerprint information from the history system. | 324 // the class collecting fingerprint information from the history system. |
| 317 // The pointer is owned by this class, but it must remain valid while the | 325 // The pointer is owned by this class, but it must remain valid while the |
| 318 // history query is running. We must only delete it when the query is done. | 326 // history query is running. We must only delete it when the query is done. |
| 319 scoped_refptr<TableBuilder> table_builder_; | 327 scoped_refptr<TableBuilder> table_builder_; |
| 320 | 328 |
| 321 // Indicates URLs added and deleted since we started rebuilding the table. | 329 // Indicates URLs added and deleted since we started rebuilding the table. |
| 322 std::set<Fingerprint> added_since_rebuild_; | 330 std::set<Fingerprint> added_since_rebuild_; |
| 323 std::set<Fingerprint> deleted_since_rebuild_; | 331 std::set<Fingerprint> deleted_since_rebuild_; |
| 324 | 332 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 int32 used_count = 0; | 388 int32 used_count = 0; |
| 381 for (int32 i = 0; i < table_length_; i++) { | 389 for (int32 i = 0; i < table_length_; i++) { |
| 382 if (hash_table_[i]) | 390 if (hash_table_[i]) |
| 383 used_count++; | 391 used_count++; |
| 384 } | 392 } |
| 385 DCHECK_EQ(used_count, used_items_); | 393 DCHECK_EQ(used_count, used_items_); |
| 386 } | 394 } |
| 387 #endif | 395 #endif |
| 388 | 396 |
| 389 #endif // CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_ | 397 #endif // CHROME_BROWSER_VISITEDLINK_VISITEDLINK_MASTER_H_ |
| OLD | NEW |