Commit af186af4 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Migrate VisitedLinkMaster off of BlockingPool

R=sky@chromium.org

Bug: 667892
Change-Id: Ia354d4cc615983d0ac6650a98a70903484e5ecb8
Reviewed-on: https://chromium-review.googlesource.com/657807
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarBrett Wilson <brettw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501424}
parent 8ecd07bb
...@@ -228,9 +228,7 @@ VisitedLinkMaster::VisitedLinkMaster(content::BrowserContext* browser_context, ...@@ -228,9 +228,7 @@ VisitedLinkMaster::VisitedLinkMaster(content::BrowserContext* browser_context,
delegate_(delegate), delegate_(delegate),
listener_(base::MakeUnique<VisitedLinkEventListener>(browser_context)), listener_(base::MakeUnique<VisitedLinkEventListener>(browser_context)),
persist_to_disk_(persist_to_disk), persist_to_disk_(persist_to_disk),
table_is_loading_from_file_(false),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
InitMembers();
} }
VisitedLinkMaster::VisitedLinkMaster(Listener* listener, VisitedLinkMaster::VisitedLinkMaster(Listener* listener,
...@@ -239,14 +237,11 @@ VisitedLinkMaster::VisitedLinkMaster(Listener* listener, ...@@ -239,14 +237,11 @@ VisitedLinkMaster::VisitedLinkMaster(Listener* listener,
bool suppress_rebuild, bool suppress_rebuild,
const base::FilePath& filename, const base::FilePath& filename,
int32_t default_table_size) int32_t default_table_size)
: browser_context_(NULL), : delegate_(delegate),
delegate_(delegate),
persist_to_disk_(persist_to_disk), persist_to_disk_(persist_to_disk),
table_is_loading_from_file_(false),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
listener_.reset(listener); listener_.reset(listener);
DCHECK(listener_.get()); DCHECK(listener_.get());
InitMembers();
database_name_override_ = filename; database_name_override_ = filename;
table_size_override_ = default_table_size; table_size_override_ = default_table_size;
...@@ -277,15 +272,6 @@ VisitedLinkMaster::~VisitedLinkMaster() { ...@@ -277,15 +272,6 @@ VisitedLinkMaster::~VisitedLinkMaster() {
} }
} }
void VisitedLinkMaster::InitMembers() {
file_ = NULL;
shared_memory_serial_ = 0;
used_items_ = 0;
table_size_override_ = 0;
suppress_rebuild_ = false;
sequence_token_ = base::SequencedWorkerPool::GetSequenceToken();
}
bool VisitedLinkMaster::Init() { bool VisitedLinkMaster::Init() {
// Create the temporary table. If the table is rebuilt that temporary table // Create the temporary table. If the table is rebuilt that temporary table
// will be became the main table. // will be became the main table.
...@@ -357,8 +343,7 @@ VisitedLinkMaster::Hash VisitedLinkMaster::TryToAddURL(const GURL& url) { ...@@ -357,8 +343,7 @@ VisitedLinkMaster::Hash VisitedLinkMaster::TryToAddURL(const GURL& url) {
void VisitedLinkMaster::PostIOTask(const base::Location& from_here, void VisitedLinkMaster::PostIOTask(const base::Location& from_here,
const base::Closure& task) { const base::Closure& task) {
DCHECK(persist_to_disk_); DCHECK(persist_to_disk_);
BrowserThread::GetBlockingPool()->PostSequencedWorkerTask(sequence_token_, file_task_runner_->PostTask(from_here, task);
from_here, task);
} }
void VisitedLinkMaster::AddURL(const GURL& url) { void VisitedLinkMaster::AddURL(const GURL& url) {
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/threading/sequenced_worker_pool.h" #include "base/sequenced_task_runner.h"
#include "base/task_scheduler/post_task.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/visitedlink/common/visitedlink_common.h" #include "components/visitedlink/common/visitedlink_common.h"
#include "mojo/public/cpp/system/buffer.h" #include "mojo/public/cpp/system/buffer.h"
...@@ -208,9 +209,6 @@ class VisitedLinkMaster : public VisitedLinkCommon { ...@@ -208,9 +209,6 @@ class VisitedLinkMaster : public VisitedLinkCommon {
// we will write the whole table to disk at once instead of individual items. // we will write the whole table to disk at once instead of individual items.
static const size_t kBigDeleteThreshold; static const size_t kBigDeleteThreshold;
// Backend for the constructors initializing the members.
void InitMembers();
// If a rebuild is in progress, we save the URL in the temporary list. // If a rebuild is in progress, we save the URL in the temporary list.
// Otherwise, we add this to the table. Returns the index of the // Otherwise, we add this to the table. Returns the index of the
// inserted fingerprint or null_hash_ on failure. // inserted fingerprint or null_hash_ on failure.
...@@ -397,7 +395,7 @@ class VisitedLinkMaster : public VisitedLinkCommon { ...@@ -397,7 +395,7 @@ class VisitedLinkMaster : public VisitedLinkCommon {
// Reference to the browser context that this object belongs to // Reference to the browser context that this object belongs to
// (it knows the path to where the data is stored) // (it knows the path to where the data is stored)
content::BrowserContext* browser_context_; content::BrowserContext* browser_context_ = nullptr;
// Client owns the delegate and is responsible for it being valid through // Client owns the delegate and is responsible for it being valid through
// the life time this VisitedLinkMaster. // the life time this VisitedLinkMaster.
...@@ -406,8 +404,11 @@ class VisitedLinkMaster : public VisitedLinkCommon { ...@@ -406,8 +404,11 @@ class VisitedLinkMaster : public VisitedLinkCommon {
// VisitedLinkEventListener to handle incoming events. // VisitedLinkEventListener to handle incoming events.
std::unique_ptr<Listener> listener_; std::unique_ptr<Listener> listener_;
// Lazily initialized sequence token for posting file tasks. // Task runner for posting file tasks.
base::SequencedWorkerPool::SequenceToken sequence_token_; scoped_refptr<base::SequencedTaskRunner> file_task_runner_ =
base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN});
// When non-NULL, indicates we are in database rebuild mode and points to // When non-NULL, indicates we are in database rebuild mode and points to
// the class collecting fingerprint information from the history system. // the class collecting fingerprint information from the history system.
...@@ -433,7 +434,7 @@ class VisitedLinkMaster : public VisitedLinkCommon { ...@@ -433,7 +434,7 @@ class VisitedLinkMaster : public VisitedLinkCommon {
// guaranteed to be executed after the opening. // guaranteed to be executed after the opening.
// The class owns both the |file_| pointer and the pointer pointed // The class owns both the |file_| pointer and the pointer pointed
// by |*file_|. // by |*file_|.
FILE** file_; FILE** file_ = nullptr;
// If true, will try to persist the hash table to disk. Will rebuild from // If true, will try to persist the hash table to disk. Will rebuild from
// VisitedLinkDelegate::RebuildTable if there are disk corruptions. // VisitedLinkDelegate::RebuildTable if there are disk corruptions.
...@@ -449,13 +450,13 @@ class VisitedLinkMaster : public VisitedLinkCommon { ...@@ -449,13 +450,13 @@ class VisitedLinkMaster : public VisitedLinkCommon {
// When we generate new tables, we increment the serial number of the // When we generate new tables, we increment the serial number of the
// shared memory object. // shared memory object.
int32_t shared_memory_serial_; int32_t shared_memory_serial_ = 0;
// Number of non-empty items in the table, used to compute fullness. // Number of non-empty items in the table, used to compute fullness.
int32_t used_items_; int32_t used_items_ = 0;
// We set this to true to avoid writing to the database file. // We set this to true to avoid writing to the database file.
bool table_is_loading_from_file_; bool table_is_loading_from_file_ = false;
// Testing values ----------------------------------------------------------- // Testing values -----------------------------------------------------------
// //
...@@ -469,7 +470,7 @@ class VisitedLinkMaster : public VisitedLinkCommon { ...@@ -469,7 +470,7 @@ class VisitedLinkMaster : public VisitedLinkCommon {
base::FilePath database_name_override_; base::FilePath database_name_override_;
// When nonzero, overrides the table size for new databases for testing // When nonzero, overrides the table size for new databases for testing
int32_t table_size_override_; int32_t table_size_override_ = 0;
// When set, indicates the task that should be run after the next rebuild from // When set, indicates the task that should be run after the next rebuild from
// history is complete. // history is complete.
...@@ -478,7 +479,7 @@ class VisitedLinkMaster : public VisitedLinkCommon { ...@@ -478,7 +479,7 @@ class VisitedLinkMaster : public VisitedLinkCommon {
// Set to prevent us from attempting to rebuild the database from global // Set to prevent us from attempting to rebuild the database from global
// history if we have an error opening the file. This is used for testing, // history if we have an error opening the file. This is used for testing,
// will be false in production. // will be false in production.
bool suppress_rebuild_; bool suppress_rebuild_ = false;
base::WeakPtrFactory<VisitedLinkMaster> weak_ptr_factory_; base::WeakPtrFactory<VisitedLinkMaster> weak_ptr_factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment