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

Unified Diff: chrome/browser/history/content_visit_delegate.cc

Issue 872313005: Remove dependency on visitedlink from history (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@init-prefs
Patch Set: Created 5 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/history/content_visit_delegate.cc
diff --git a/chrome/browser/history/content_visit_delegate.cc b/chrome/browser/history/content_visit_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..76463d320c43be06b18069bb48b1e73b56576c3c
--- /dev/null
+++ b/chrome/browser/history/content_visit_delegate.cc
@@ -0,0 +1,118 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/history/content_visit_delegate.h"
+
+#include "chrome/browser/history/history_backend.h"
+#include "chrome/browser/history/history_service.h"
+#include "components/history/core/browser/history_database.h"
+#include "components/history/core/browser/history_db_task.h"
+#include "components/visitedlink/browser/visitedlink_master.h"
droger 2015/02/02 09:39:20 #include "base/logging.h" #include "base/memory/re
sdefresne 2015/02/04 18:01:54 Done, thank you.
+
+namespace {
+
+// URLIterator from std::vector<GURL>
+class URLIteratorFromURLs : public visitedlink::VisitedLinkMaster::URLIterator {
+ public:
+ explicit URLIteratorFromURLs(const std::vector<GURL>& urls)
+ : itr_(urls.begin()), end_(urls.end()) {}
+
+ // visitedlink::VisitedLinkMaster::URLIterator implementation.
+ const GURL& NextURL() override { return *(itr_++); }
+ bool HasNextURL() const override { return itr_ != end_; }
+
+ private:
+ std::vector<GURL>::const_iterator itr_;
+ std::vector<GURL>::const_iterator end_;
+
+ DISALLOW_COPY_AND_ASSIGN(URLIteratorFromURLs);
+};
+
+// IterateUrlsDBTask bridge HistoryBackend::URLEnumerator to
+// visitedlink::VisitedLinkDelegate::URLEnumerator.
+class IterateUrlsDBTask : public history::HistoryDBTask {
+ public:
+ explicit IterateUrlsDBTask(const scoped_refptr<
+ visitedlink::VisitedLinkDelegate::URLEnumerator>& enumerator);
+ ~IterateUrlsDBTask() override;
+
+ private:
+ // Implementation of history::HistoryDBTask.
+ bool RunOnDBThread(history::HistoryBackend* backend,
+ history::HistoryDatabase* db) override;
+ void DoneRunOnMainThread() override;
+
+ scoped_refptr<visitedlink::VisitedLinkDelegate::URLEnumerator> enumerator_;
+
+ DISALLOW_COPY_AND_ASSIGN(IterateUrlsDBTask);
+};
+
+IterateUrlsDBTask::IterateUrlsDBTask(const scoped_refptr<
+ visitedlink::VisitedLinkDelegate::URLEnumerator>& enumerator)
+ : enumerator_(enumerator) {
+}
+
+IterateUrlsDBTask::~IterateUrlsDBTask() {
+}
+
+bool IterateUrlsDBTask::RunOnDBThread(history::HistoryBackend* backend,
+ history::HistoryDatabase* db) {
+ bool success = false;
+ if (db) {
+ history::HistoryDatabase::URLEnumerator iter;
+ if (db->InitURLEnumeratorForEverything(&iter)) {
+ history::URLRow row;
+ while (iter.GetNextURL(&row))
+ enumerator_->OnURL(row.url());
+ success = true;
+ }
+ }
+ enumerator_->OnComplete(success);
+ return true;
+}
+
+void IterateUrlsDBTask::DoneRunOnMainThread() {
+}
+
+} // namespace
+
+ContentVisitDelegate::ContentVisitDelegate(
+ content::BrowserContext* browser_context)
+ : history_service_(nullptr),
+ visitedlink_master_(
+ new visitedlink::VisitedLinkMaster(browser_context, this, true)) {
+}
+
+ContentVisitDelegate::~ContentVisitDelegate() {
+}
+
+bool ContentVisitDelegate::Init(HistoryService* history_service) {
+ DCHECK(history_service);
+ history_service_ = history_service;
+ return visitedlink_master_->Init();
+}
+
+void ContentVisitDelegate::AddURL(const GURL& url) {
+ visitedlink_master_->AddURL(url);
+}
+
+void ContentVisitDelegate::AddURLs(const std::vector<GURL>& urls) {
+ visitedlink_master_->AddURLs(urls);
+}
+
+void ContentVisitDelegate::DeleteURLs(const std::vector<GURL>& urls) {
+ URLIteratorFromURLs iterator(urls);
+ visitedlink_master_->DeleteURLs(&iterator);
+}
+
+void ContentVisitDelegate::DeleteAllURLs() {
+ visitedlink_master_->DeleteAllURLs();
+}
+
+void ContentVisitDelegate::RebuildTable(
+ const scoped_refptr<URLEnumerator>& enumerator) {
+ DCHECK(history_service_);
+ scoped_ptr<history::HistoryDBTask> task(new IterateUrlsDBTask(enumerator));
+ history_service_->ScheduleDBTask(task.Pass(), &task_tracker_);
+}

Powered by Google App Engine
This is Rietveld 408576698