summaryrefslogtreecommitdiffstats
path: root/chrome/browser/visitedlink
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-19 04:11:57 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-19 04:11:57 +0000
commit3189013eebc55ea5493186b29f2cee2bc7c0dafc (patch)
treef9c867f92c5fd9325a7d7e6ea9fed638103c4f4b /chrome/browser/visitedlink
parent1946e0c4351fbdfd5b012d3c2aeac2c9218ad027 (diff)
downloadchromium_src-3189013eebc55ea5493186b29f2cee2bc7c0dafc.zip
chromium_src-3189013eebc55ea5493186b29f2cee2bc7c0dafc.tar.gz
chromium_src-3189013eebc55ea5493186b29f2cee2bc7c0dafc.tar.bz2
Hook up the SequencedWorkerPool to the browser thread.
[re-land of 116816 http://codereview.chromium.org/9065009] This does some refactoring of the static data in the browser thread so we only have one global object instead of a bunch fo separate arrays. It also hooks up the visited link master's I/O to use this new system as a proof of concept. Review URL: https://chromiumcodereview.appspot.com/9124033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118236 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/visitedlink')
-rw-r--r--chrome/browser/visitedlink/visitedlink_master.cc22
-rw-r--r--chrome/browser/visitedlink/visitedlink_master.h8
-rw-r--r--chrome/browser/visitedlink/visitedlink_unittest.cc3
3 files changed, 21 insertions, 12 deletions
diff --git a/chrome/browser/visitedlink/visitedlink_master.cc b/chrome/browser/visitedlink/visitedlink_master.cc
index f3fbc85..38c87ca 100644
--- a/chrome/browser/visitedlink/visitedlink_master.cc
+++ b/chrome/browser/visitedlink/visitedlink_master.cc
@@ -191,6 +191,7 @@ void VisitedLinkMaster::InitMembers(Listener* listener, Profile* profile) {
history_service_override_ = NULL;
suppress_rebuild_ = false;
profile_ = profile;
+ sequence_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken();
#ifndef NDEBUG
posted_asynchronous_operation_ = false;
@@ -242,6 +243,12 @@ VisitedLinkMaster::Hash VisitedLinkMaster::TryToAddURL(const GURL& url) {
return AddFingerprint(fingerprint, true);
}
+void VisitedLinkMaster::PostIOTask(const tracked_objects::Location& from_here,
+ const base::Closure& task) {
+ BrowserThread::GetBlockingPool()->PostSequencedWorkerTask(sequence_token_,
+ from_here, task);
+}
+
void VisitedLinkMaster::AddURL(const GURL& url) {
Hash index = TryToAddURL(url);
if (!table_builder_ && index != null_hash_) {
@@ -480,10 +487,7 @@ bool VisitedLinkMaster::WriteFullTable() {
hash_table_, table_length_ * sizeof(Fingerprint));
// The hash table may have shrunk, so make sure this is the end.
- BrowserThread::PostTask(
- BrowserThread::FILE,
- FROM_HERE,
- base::Bind(base::IgnoreResult(&TruncateFile), file_));
+ PostIOTask(FROM_HERE, base::Bind(base::IgnoreResult(&TruncateFile), file_));
return true;
}
@@ -673,11 +677,7 @@ void VisitedLinkMaster::FreeURLTable() {
}
if (!file_)
return;
-
- BrowserThread::PostTask(
- BrowserThread::FILE,
- FROM_HERE,
- base::Bind(base::IgnoreResult(&fclose), file_));
+ PostIOTask(FROM_HERE, base::Bind(base::IgnoreResult(&fclose), file_));
}
bool VisitedLinkMaster::ResizeTableIfNecessary() {
@@ -860,9 +860,7 @@ void VisitedLinkMaster::WriteToFile(FILE* file,
#ifndef NDEBUG
posted_asynchronous_operation_ = true;
#endif
-
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
+ PostIOTask(FROM_HERE,
base::Bind(&AsyncWrite, file, offset,
std::string(static_cast<const char*>(data), data_size)));
}
diff --git a/chrome/browser/visitedlink/visitedlink_master.h b/chrome/browser/visitedlink/visitedlink_master.h
index c84e809..1771afe 100644
--- a/chrome/browser/visitedlink/visitedlink_master.h
+++ b/chrome/browser/visitedlink/visitedlink_master.h
@@ -17,6 +17,7 @@
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/shared_memory.h"
+#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/history/history.h"
#include "chrome/common/visitedlink_common.h"
@@ -163,6 +164,10 @@ class VisitedLinkMaster : public VisitedLinkCommon {
// File I/O functions
// ------------------
+ // Posts the given task to the blocking worker pool with our options.
+ void PostIOTask(const tracked_objects::Location& from_here,
+ const base::Closure& task);
+
// Writes the entire table to disk, returning true on success. It will leave
// the table file open and the handle to it in file_
bool WriteFullTable();
@@ -312,6 +317,9 @@ class VisitedLinkMaster : public VisitedLinkCommon {
// (it knows the path to where the data is stored)
Profile* profile_;
+ // Lazily initialized sequence token for posting file tasks.
+ base::SequencedWorkerPool::SequenceToken sequence_token_;
+
// When non-NULL, indicates we are in database rebuild mode and points to
// the class collecting fingerprint information from the history system.
// The pointer is owned by this class, but it must remain valid while the
diff --git a/chrome/browser/visitedlink/visitedlink_unittest.cc b/chrome/browser/visitedlink/visitedlink_unittest.cc
index 2d52cb0..536384f 100644
--- a/chrome/browser/visitedlink/visitedlink_unittest.cc
+++ b/chrome/browser/visitedlink/visitedlink_unittest.cc
@@ -116,6 +116,9 @@ class VisitedLinkTest : public testing::Test {
// our destroy task.
MessageLoop::current()->Run();
}
+
+ // Wait for all pending file I/O to be completed.
+ BrowserThread::GetBlockingPool()->FlushForTesting();
}
// Loads the database from disk and makes sure that the same URLs are present