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

Unified Diff: chrome/browser/visitedlink/visitedlink_master.cc

Issue 11573060: Remove VisitedLink dependency on rest of chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pass scoped_refptr<Enumerator> by const ref (instead of by value) Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/visitedlink/visitedlink_master.cc
diff --git a/chrome/browser/visitedlink/visitedlink_master.cc b/chrome/browser/visitedlink/visitedlink_master.cc
index ec3c9e611c2de66ba8f2e9e89d3495010ede105c..06efbf936488f70d57e214e7f337d345ec74cff5 100644
--- a/chrome/browser/visitedlink/visitedlink_master.cc
+++ b/chrome/browser/visitedlink/visitedlink_master.cc
@@ -24,11 +24,11 @@
#include "base/rand_util.h"
#include "base/string_util.h"
#include "base/threading/thread_restrictions.h"
-#include "chrome/browser/history/history.h"
-#include "chrome/browser/history/history_service_factory.h"
-#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/visitedlink/visitedlink_delegate.h"
#include "chrome/browser/visitedlink/visitedlink_event_listener.h"
+#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
+#include "googleurl/src/gurl.h"
using content::BrowserThread;
using file_util::ScopedFILE;
@@ -138,8 +138,7 @@ void AsyncClose(FILE** file) {
// which case it notifies the builder via DisownMaster(). The builder will
// delete itself once rebuilding is complete, and not execute any callback.
class VisitedLinkMaster::TableBuilder
- : public HistoryService::URLEnumerator,
- public base::RefCountedThreadSafe<TableBuilder> {
+ : public VisitedLinkDelegate::URLEnumerator {
public:
TableBuilder(VisitedLinkMaster* master,
const uint8 salt[LINK_SALT_LENGTH]);
@@ -150,14 +149,12 @@ class VisitedLinkMaster::TableBuilder
// table will be being rebuilt simultaneously on the other thread.
void DisownMaster();
- // HistoryService::URLEnumerator
- virtual void OnURL(const history::URLRow& url_row);
+ // VisitedLinkDelegate::URLEnumerator
+ virtual void OnURL(const GURL& url);
virtual void OnComplete(bool succeed);
private:
- friend class base::RefCountedThreadSafe<TableBuilder>;
-
- ~TableBuilder() {}
+ virtual ~TableBuilder() {}
// OnComplete mashals to this function on the main thread to do the
// notification.
@@ -174,30 +171,34 @@ class VisitedLinkMaster::TableBuilder
// Stores the fingerprints we computed on the background thread.
VisitedLinkCommon::Fingerprints fingerprints_;
+
+ DISALLOW_COPY_AND_ASSIGN(TableBuilder);
};
// VisitedLinkMaster ----------------------------------------------------------
-VisitedLinkMaster::VisitedLinkMaster(Profile* profile)
- : profile_(profile) {
- listener_.reset(new VisitedLinkEventListener(profile));
- DCHECK(listener_.get());
+VisitedLinkMaster::VisitedLinkMaster(content::BrowserContext* browser_context,
+ VisitedLinkDelegate* delegate)
+ : browser_context_(browser_context),
+ delegate_(delegate),
+ listener_(new VisitedLinkEventListener(
+ ALLOW_THIS_IN_INITIALIZER_LIST(this), browser_context)) {
InitMembers();
}
VisitedLinkMaster::VisitedLinkMaster(Listener* listener,
- HistoryService* history_service,
+ VisitedLinkDelegate* delegate,
bool suppress_rebuild,
const FilePath& filename,
int32 default_table_size)
- : profile_(NULL) {
+ : browser_context_(NULL),
+ delegate_(delegate) {
listener_.reset(listener);
DCHECK(listener_.get());
InitMembers();
database_name_override_ = filename;
table_size_override_ = default_table_size;
- history_service_override_ = history_service;
suppress_rebuild_ = suppress_rebuild;
}
@@ -220,7 +221,6 @@ void VisitedLinkMaster::InitMembers() {
shared_memory_serial_ = 0;
used_items_ = 0;
table_size_override_ = 0;
- history_service_override_ = NULL;
suppress_rebuild_ = false;
sequence_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken();
@@ -241,7 +241,9 @@ bool VisitedLinkMaster::Init() {
VisitedLinkMaster::Hash VisitedLinkMaster::TryToAddURL(const GURL& url) {
// Extra check that we are not incognito. This should not happen.
- if (profile_ && profile_->IsOffTheRecord()) {
+ // TODO(boliu): Move this check to HistoryService when IsOffTheRecord is
+ // removed from BrowserContext.
+ if (browser_context_ && browser_context_->IsOffTheRecord()) {
NOTREACHED();
return null_hash_;
}
@@ -320,10 +322,12 @@ void VisitedLinkMaster::DeleteAllURLs() {
listener_->Reset();
}
-void VisitedLinkMaster::DeleteURLs(const history::URLRows& rows) {
- typedef std::set<GURL>::const_iterator SetIterator;
+VisitedLinkDelegate* VisitedLinkMaster::GetDelegate() {
+ return delegate_;
+}
- if (rows.empty())
+void VisitedLinkMaster::DeleteURLs(URLIterator* urls) {
+ if (!urls->HasNextURL())
return;
listener_->Reset();
@@ -331,9 +335,8 @@ void VisitedLinkMaster::DeleteURLs(const history::URLRows& rows) {
if (table_builder_) {
// A rebuild is in progress, save this deletion in the temporary list so
// it can be added once rebuild is complete.
- for (history::URLRows::const_iterator i = rows.begin(); i != rows.end();
- ++i) {
- const GURL& url(i->url());
+ while (urls->HasNextURL()) {
+ const GURL& url(urls->NextURL());
if (!url.is_valid())
continue;
@@ -357,9 +360,8 @@ void VisitedLinkMaster::DeleteURLs(const history::URLRows& rows) {
// Compute the deleted URLs' fingerprints and delete them
std::set<Fingerprint> deleted_fingerprints;
- for (history::URLRows::const_iterator i = rows.begin(); i != rows.end();
- ++i) {
- const GURL& url(i->url());
+ while (urls->HasNextURL()) {
+ const GURL& url(urls->NextURL());
if (!url.is_valid())
continue;
deleted_fingerprints.insert(
@@ -581,7 +583,7 @@ bool VisitedLinkMaster::InitFromScratch(bool suppress_rebuild) {
// to disk. We don't want to save explicitly here, since the rebuild may
// not complete, leaving us with an empty but valid visited link database.
// In the future, we won't know we need to try rebuilding again.
- return RebuildTableFromHistory();
+ return RebuildTableFromDelegate();
}
bool VisitedLinkMaster::ReadFileHeader(FILE* file,
@@ -641,10 +643,10 @@ bool VisitedLinkMaster::GetDatabaseFileName(FilePath* filename) {
return true;
}
- if (!profile_ || profile_->GetPath().empty())
+ if (!browser_context_ || browser_context_->GetPath().empty())
return false;
- FilePath profile_dir = profile_->GetPath();
+ FilePath profile_dir = browser_context_->GetPath();
*filename = profile_dir.Append(FILE_PATH_LITERAL("Visited Links"));
return true;
}
@@ -810,31 +812,12 @@ uint32 VisitedLinkMaster::NewTableSizeForCount(int32 item_count) const {
}
// See the TableBuilder definition in the header file for how this works.
-bool VisitedLinkMaster::RebuildTableFromHistory() {
+bool VisitedLinkMaster::RebuildTableFromDelegate() {
DCHECK(!table_builder_);
- if (table_builder_)
- return false;
-
- HistoryService* history_service = history_service_override_;
- if (!history_service && profile_) {
- history_service =
- HistoryServiceFactory::GetForProfile(profile_,
- Profile::EXPLICIT_ACCESS);
- }
-
- if (!history_service) {
- DLOG(WARNING) << "Attempted to rebuild visited link table, but couldn't "
- "obtain a HistoryService.";
- return false;
- }
// TODO(brettw) make sure we have reasonable salt!
table_builder_ = new TableBuilder(this, salt_);
-
- // Make sure the table builder stays live during the call, even if the
- // master is deleted. This is balanced in TableBuilder::OnCompleteMainThread.
- table_builder_->AddRef();
- history_service->IterateURLs(table_builder_);
+ delegate_->RebuildTable(table_builder_);
return true;
}
@@ -958,8 +941,7 @@ void VisitedLinkMaster::TableBuilder::DisownMaster() {
master_ = NULL;
}
-void VisitedLinkMaster::TableBuilder::OnURL(const history::URLRow& url_row) {
- const GURL& url(url_row.url());
+void VisitedLinkMaster::TableBuilder::OnURL(const GURL& url) {
if (!url.is_empty()) {
fingerprints_.push_back(VisitedLinkMaster::ComputeURLFingerprint(
url.spec().data(), url.spec().length(), salt_));
@@ -980,8 +962,4 @@ void VisitedLinkMaster::TableBuilder::OnComplete(bool success) {
void VisitedLinkMaster::TableBuilder::OnCompleteMainThread() {
if (master_)
master_->OnTableRebuildComplete(success_, fingerprints_);
-
- // WILL (generally) DELETE THIS! This balances the AddRef in
- // VisitedLinkMaster::RebuildTableFromHistory.
- Release();
}
« no previous file with comments | « chrome/browser/visitedlink/visitedlink_master.h ('k') | chrome/browser/visitedlink/visitedlink_master_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698