Commit 577751e8 authored by sdefresne's avatar sdefresne Committed by Commit bot

Inject CanAddURLToHistory into TopSitesImpl

Remove dependency on //chrome/browser/history/history_utils.h by
injecting the CanAddURLToHistory function (via a base::Callback)
into TopSitesImpl.

BUG=479174

Review URL: https://codereview.chromium.org/1100763002

Cr-Commit-Position: refs/heads/master@{#327014}
parent c6a64af0
......@@ -4,9 +4,11 @@
#include "chrome/browser/history/top_sites_factory.h"
#include "base/bind.h"
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/history_utils.h"
#include "chrome/browser/history/top_sites_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_constants.h"
......@@ -95,7 +97,8 @@ scoped_refptr<history::TopSites> TopSitesFactory::BuildTopSites(
scoped_refptr<history::TopSitesImpl> top_sites(new history::TopSitesImpl(
profile->GetPrefs(), HistoryServiceFactory::GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS),
prefs::kNtpMostVisitedURLsBlacklist, prepopulated_page_list));
prefs::kNtpMostVisitedURLsBlacklist, prepopulated_page_list,
base::Bind(CanAddURLToHistory)));
top_sites->Init(context->GetPath().Append(chrome::kTopSitesFilename),
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::DB));
......
......@@ -21,7 +21,6 @@
#include "base/strings/utf_string_conversions.h"
#include "base/task_runner.h"
#include "base/values.h"
#include "chrome/browser/history/history_utils.h"
#include "components/history/core/browser/history_backend.h"
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/page_usage_data.h"
......@@ -89,7 +88,8 @@ bool TopSitesImpl::histogram_recorded_ = false;
TopSitesImpl::TopSitesImpl(PrefService* pref_service,
HistoryService* history_service,
const char* blacklist_pref_name,
const PrepopulatedPageList& prepopulated_pages)
const PrepopulatedPageList& prepopulated_pages,
const CanAddURLToHistoryFn& can_add_url_to_history)
: backend_(nullptr),
cache_(new TopSitesCache()),
thread_safe_cache_(new TopSitesCache()),
......@@ -98,10 +98,12 @@ TopSitesImpl::TopSitesImpl(PrefService* pref_service,
pref_service_(pref_service),
blacklist_pref_name_(blacklist_pref_name),
history_service_(history_service),
can_add_url_to_history_(can_add_url_to_history),
loaded_(false),
history_service_observer_(this) {
DCHECK(pref_service_);
DCHECK(blacklist_pref_name_);
DCHECK(!can_add_url_to_history_.is_null());
}
void TopSitesImpl::Init(
......@@ -137,7 +139,7 @@ bool TopSitesImpl::SetPageThumbnail(const GURL& url,
}
}
if (!CanAddURLToHistory(url))
if (!can_add_url_to_history_.Run(url))
return false; // It's not a real webpage.
scoped_refptr<base::RefCountedBytes> thumbnail_data;
......@@ -176,7 +178,7 @@ bool TopSitesImpl::SetPageThumbnailToJPEGBytes(
}
}
if (!CanAddURLToHistory(url))
if (!can_add_url_to_history_.Run(url))
return false; // It's not a real webpage.
if (add_temp_thumbnail) {
......@@ -611,7 +613,7 @@ void TopSitesImpl::OnNavigationCommitted(const GURL& url) {
if (!loaded_ || IsNonForcedFull())
return;
if (!cache_->IsKnownURL(url) && CanAddURLToHistory(url)) {
if (!cache_->IsKnownURL(url) && can_add_url_to_history_.Run(url)) {
// To avoid slamming history we throttle requests when the url updates. To
// do otherwise negatively impacts perf tests.
RestartQueryForTopSitesTimer(GetUpdateDelay());
......
......@@ -53,10 +53,15 @@ class TopSitesImplTest;
// db using TopSitesBackend.
class TopSitesImpl : public TopSites, public HistoryServiceObserver {
public:
// Called to check whether an URL can be added to the history. Must be
// callable multiple time and during the whole lifetime of TopSitesImpl.
using CanAddURLToHistoryFn = base::Callback<bool(const GURL&)>;
TopSitesImpl(PrefService* pref_service,
HistoryService* history_service,
const char* blacklist_pref_name,
const PrepopulatedPageList& prepopulated_pages);
const PrepopulatedPageList& prepopulated_pages,
const CanAddURLToHistoryFn& can_add_url_to_history);
// Initializes TopSitesImpl.
void Init(const base::FilePath& db_name,
......@@ -294,6 +299,9 @@ class TopSitesImpl : public TopSites, public HistoryServiceObserver {
// must outlive TopSitesImpl.
HistoryService* history_service_;
// Can URL be added to the history?
CanAddURLToHistoryFn can_add_url_to_history_;
// Are we loaded?
bool loaded_;
......
......@@ -4,7 +4,9 @@
#include "chrome/browser/thumbnails/thumbnail_service_impl.h"
#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/history/history_utils.h"
#include "chrome/browser/history/top_sites_factory.h"
#include "chrome/browser/history/top_sites_impl.h"
#include "chrome/common/pref_names.h"
......@@ -23,7 +25,8 @@ class MockTopSites : public history::TopSitesImpl {
: history::TopSitesImpl(profile->GetPrefs(),
nullptr,
prefs::kNtpMostVisitedURLsBlacklist,
history::PrepopulatedPageList()),
history::PrepopulatedPageList(),
base::Bind(CanAddURLToHistory)),
capacity_(1) {}
// history::TopSitesImpl overrides.
......
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