diff options
author | sdefresne <sdefresne@chromium.org> | 2015-02-18 08:18:47 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-18 16:19:52 +0000 |
commit | d4d9fe44d9fcfa7a3c00fe8cdc9569a8690c28a7 (patch) | |
tree | 148111818ea4d8dc0b45fa9543af5d7558919a22 | |
parent | f31153ac1c030b4ccf176709afe0db2447fd6c8b (diff) | |
download | chromium_src-d4d9fe44d9fcfa7a3c00fe8cdc9569a8690c28a7.zip chromium_src-d4d9fe44d9fcfa7a3c00fe8cdc9569a8690c28a7.tar.gz chromium_src-d4d9fe44d9fcfa7a3c00fe8cdc9569a8690c28a7.tar.bz2 |
Remove dependency on Profile from HistoryService
Introduce an abstract interface history::VisitDelegate to abstract
visitedlink::VisitedLinkMaster from visitedlink component that has
a dependency on //content and thus cannot be used on iOS.
Provides an implementation of history::VisitDelegate that forward
to visitedlink::VisitedLinkMaster and inject it into HistoryService
via the HistoryServiceFactory.
Remove dependency on visitedlink component from HistoryService and
HistoryBackend.
Fix file that dependended on the forward-declaration of Profile
from history_service.h
Cleanup //chrome/browser/history/DEPS.
Fix typos and some style issues.
BUG=453790
Review URL: https://codereview.chromium.org/872313005
Cr-Commit-Position: refs/heads/master@{#316836}
22 files changed, 334 insertions, 150 deletions
diff --git a/chrome/browser/autocomplete/shortcuts_provider_unittest.cc b/chrome/browser/autocomplete/shortcuts_provider_unittest.cc index e5546bd..b2e4da3 100644 --- a/chrome/browser/autocomplete/shortcuts_provider_unittest.cc +++ b/chrome/browser/autocomplete/shortcuts_provider_unittest.cc @@ -314,6 +314,7 @@ void ShortcutsProviderTest::TearDown() { // Run all pending tasks or else some threads hold on to the message loop // and prevent it from being deleted. message_loop_.RunUntilIdle(); + profile_.DestroyHistoryService(); provider_ = NULL; } diff --git a/chrome/browser/history/DEPS b/chrome/browser/history/DEPS index 030f20e..7dfc95c 100644 --- a/chrome/browser/history/DEPS +++ b/chrome/browser/history/DEPS @@ -29,8 +29,6 @@ include_rules = [ "!chrome/browser/ui/browser_finder.h", "!components/bookmarks/browser/bookmark_utils.h", "!components/dom_distiller/core/url_constants.h", - "!components/visitedlink/browser/visitedlink_delegate.h", - "!components/visitedlink/browser/visitedlink_master.h", ] specific_include_rules = { @@ -54,6 +52,11 @@ specific_include_rules = { "+components/bookmarks/browser", "+components/keyed_service/content", ], + # Those files will move to //components/history/content/browser and thus + # can depend on //content even indirectly. + 'content_.*\.(cc|h)': [ + "+components/visitedlink/browser", + ], # TODO(sdefresne): Bring this list to zero. # # Do not add to the list of temporarily-allowed dependencies below, diff --git a/chrome/browser/history/content_visit_delegate.cc b/chrome/browser/history/content_visit_delegate.cc new file mode 100644 index 0000000..6bd3935 --- /dev/null +++ b/chrome/browser/history/content_visit_delegate.cc @@ -0,0 +1,121 @@ +// 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 "base/logging.h" +#include "base/memory/ref_counted.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" +#include "url/gurl.h" + +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_); +} diff --git a/chrome/browser/history/content_visit_delegate.h b/chrome/browser/history/content_visit_delegate.h new file mode 100644 index 0000000..df98c72 --- /dev/null +++ b/chrome/browser/history/content_visit_delegate.h @@ -0,0 +1,51 @@ +// 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. + +#ifndef CHROME_BROWSER_HISTORY_CONTENT_VISIT_DELEGATE_H_ +#define CHROME_BROWSER_HISTORY_CONTENT_VISIT_DELEGATE_H_ + +#include <vector> + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "base/task/cancelable_task_tracker.h" +#include "components/history/core/browser/visit_delegate.h" +#include "components/visitedlink/browser/visitedlink_delegate.h" + +namespace content { +class BrowserContext; +} + +namespace visitedlink { +class VisitedLinkMaster; +} + +// ContentVisitDelegate bridge history::VisitDelegate events to +// visitedlink::VisitedLinkMaster. +class ContentVisitDelegate : public history::VisitDelegate, + public visitedlink::VisitedLinkDelegate { + public: + explicit ContentVisitDelegate(content::BrowserContext* browser_context); + ~ContentVisitDelegate() override; + + private: + // Implementation of history::VisitDelegate. + bool Init(HistoryService* history_service) override; + void AddURL(const GURL& url) override; + void AddURLs(const std::vector<GURL>& urls) override; + void DeleteURLs(const std::vector<GURL>& urls) override; + void DeleteAllURLs() override; + + // Implementation of visitedlink::VisitedLinkDelegate. + void RebuildTable(const scoped_refptr< + visitedlink::VisitedLinkDelegate::URLEnumerator>& enumerator) override; + + HistoryService* history_service_; // Weak. + scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_; + base::CancelableTaskTracker task_tracker_; + + DISALLOW_COPY_AND_ASSIGN(ContentVisitDelegate); +}; + +#endif // CHROME_BROWSER_HISTORY_CONTENT_VISIT_DELEGATE_H_ diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index 26c7133..0bbbf400 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -172,8 +172,7 @@ bool QueuedHistoryDBTask::is_canceled() { return is_canceled_.Run(); } -bool QueuedHistoryDBTask::Run(HistoryBackend* backend, - HistoryDatabase* db) { +bool QueuedHistoryDBTask::Run(HistoryBackend* backend, HistoryDatabase* db) { return task_->RunOnDBThread(backend, db); } @@ -924,23 +923,6 @@ void HistoryBackend::AddPageNoVisitForBookmark(const GURL& url, db_->AddURL(url_info); } -void HistoryBackend::IterateURLs( - const scoped_refptr<visitedlink::VisitedLinkDelegate::URLEnumerator>& - iterator) { - if (db_) { - HistoryDatabase::URLEnumerator e; - if (db_->InitURLEnumeratorForEverything(&e)) { - URLRow info; - while (e.GetNextURL(&info)) { - iterator->OnURL(info.url()); - } - iterator->OnComplete(true); // Success. - return; - } - } - iterator->OnComplete(false); // Failure. -} - bool HistoryBackend::GetAllTypedURLs(URLRows* urls) { if (db_) return db_->GetAllTypedUrls(urls); diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h index 0750ac7..75a0121 100644 --- a/chrome/browser/history/history_backend.h +++ b/chrome/browser/history/history_backend.h @@ -25,7 +25,6 @@ #include "components/history/core/browser/keyword_id.h" #include "components/history/core/browser/thumbnail_database.h" #include "components/history/core/browser/visit_tracker.h" -#include "components/visitedlink/browser/visitedlink_delegate.h" #include "sql/init_status.h" #if defined(OS_ANDROID) @@ -220,9 +219,6 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, void ScheduleAutocomplete(const base::Callback< void(history::HistoryBackend*, history::URLDatabase*)>& callback); - void IterateURLs( - const scoped_refptr<visitedlink::VisitedLinkDelegate::URLEnumerator>& - enumerator); void QueryURL(const GURL& url, bool want_visits, QueryURLResult* query_url_result); diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index 6f3a46d..9eeca2a 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -22,6 +22,7 @@ #include "base/strings/string16.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/history/content_visit_delegate.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/in_memory_history_backend.h" @@ -3041,8 +3042,8 @@ TEST_F(HistoryBackendTest, RemoveNotification) { GURL url("http://www.google.com"); HistoryClientMock history_client; history_client.AddBookmark(url); - scoped_ptr<HistoryService> service( - new HistoryService(&history_client, profile.get())); + scoped_ptr<HistoryService> service(new HistoryService( + &history_client, scoped_ptr<history::VisitDelegate>())); EXPECT_TRUE( service->Init(profile->GetPrefs()->GetString(prefs::kAcceptLanguages), TestHistoryDatabaseParamsForPath(profile->GetPath()))); diff --git a/chrome/browser/history/history_service.cc b/chrome/browser/history/history_service.cc index 61d4cdf..2e25db8 100644 --- a/chrome/browser/history/history_service.cc +++ b/chrome/browser/history/history_service.cc @@ -42,12 +42,10 @@ #include "components/history/core/browser/in_memory_database.h" #include "components/history/core/browser/keyword_search_term.h" #include "components/history/core/browser/visit_database.h" +#include "components/history/core/browser/visit_delegate.h" #include "components/history/core/browser/visit_filter.h" #include "components/history/core/browser/web_history_service.h" #include "components/history/core/common/thumbnail_score.h" -#include "components/visitedlink/browser/visitedlink_master.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/download_item.h" #include "sync/api/sync_error_factory.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -82,26 +80,6 @@ void RunWithVisibleVisitCountToHostResult( callback.Run(result->success, result->count, result->first_visit); } -// Extract history::URLRows into GURLs for VisitedLinkMaster. -class URLIteratorFromURLRows - : public visitedlink::VisitedLinkMaster::URLIterator { - public: - explicit URLIteratorFromURLRows(const history::URLRows& url_rows) - : itr_(url_rows.begin()), - end_(url_rows.end()) { - } - - const GURL& NextURL() override { return (itr_++)->url(); } - - bool HasNextURL() const override { return itr_ != end_; } - - private: - history::URLRows::const_iterator itr_; - history::URLRows::const_iterator end_; - - DISALLOW_COPY_AND_ASSIGN(URLIteratorFromURLRows); -}; - // Callback from WebHistoryService::ExpireWebHistory(). void ExpireWebHistoryComplete(bool success) { // Ignore the result. @@ -214,18 +192,18 @@ class HistoryService::BackendDelegate : public HistoryBackend::Delegate { // history thread. HistoryService::HistoryService() : thread_(new base::Thread(kHistoryThreadName)), - history_client_(NULL), + history_client_(nullptr), backend_loaded_(false), no_db_(false), weak_ptr_factory_(this) { } HistoryService::HistoryService( - history::HistoryClient* history_client, Profile* profile) + history::HistoryClient* history_client, + scoped_ptr<history::VisitDelegate> visit_delegate) : thread_(new base::Thread(kHistoryThreadName)), + visit_delegate_(visit_delegate.Pass()), history_client_(history_client), - visitedlink_master_(new visitedlink::VisitedLinkMaster( - profile, this, true)), backend_loaded_(false), no_db_(false), weak_ptr_factory_(this) { @@ -253,7 +231,7 @@ void HistoryService::ClearCachedDataForContextID( history::URLDatabase* HistoryService::InMemoryDatabase() { DCHECK(thread_checker_.CalledOnValidThread()); - return in_memory_backend_ ? in_memory_backend_->db() : NULL; + return in_memory_backend_ ? in_memory_backend_->db() : nullptr; } bool HistoryService::GetTypedCountForURL(const GURL& url, int* typed_count) { @@ -404,7 +382,7 @@ void HistoryService::AddPage(const GURL& url, history::VisitSource visit_source) { DCHECK(thread_checker_.CalledOnValidThread()); AddPage( - history::HistoryAddPageArgs(url, time, NULL, 0, GURL(), + history::HistoryAddPageArgs(url, time, nullptr, 0, GURL(), history::RedirectList(), ui::PAGE_TRANSITION_LINK, visit_source, false)); @@ -421,19 +399,17 @@ void HistoryService::AddPage(const history::HistoryAddPageArgs& add_page_args) { if (!CanAddURL(add_page_args.url)) return; - // Add link & all redirects to visited link list. - if (visitedlink_master_) { - visitedlink_master_->AddURL(add_page_args.url); - + // Inform VisitedDelegate of all links and redirects. + if (visit_delegate_) { if (!add_page_args.redirects.empty()) { - // We should not be asked to add a page in the middle of a redirect chain. - DCHECK_EQ(add_page_args.url, - add_page_args.redirects[add_page_args.redirects.size() - 1]); - - // We need the !redirects.empty() condition above since size_t is unsigned - // and will wrap around when we subtract one from a 0 size. - for (size_t i = 0; i < add_page_args.redirects.size() - 1; i++) - visitedlink_master_->AddURL(add_page_args.redirects[i]); + // We should not be asked to add a page in the middle of a redirect chain, + // and thus add_page_args.url should be the last element in the array + // add_page_args.redirects which mean we can use VisitDelegate::AddURLs() + // with the whole array. + DCHECK_EQ(add_page_args.url, add_page_args.redirects.back()); + visit_delegate_->AddURLs(add_page_args.redirects); + } else { + visit_delegate_->AddURL(add_page_args.url); } } @@ -487,9 +463,9 @@ void HistoryService::AddPageWithDetails(const GURL& url, if (!CanAddURL(url)) return; - // Add to the visited links system. - if (visitedlink_master_) - visitedlink_master_->AddURL(url); + // Inform VisitDelegate of the URL. + if (visit_delegate_) + visit_delegate_->AddURL(url); history::URLRow row(url); row.set_title(title); @@ -510,15 +486,14 @@ void HistoryService::AddPagesWithDetails(const history::URLRows& info, history::VisitSource visit_source) { DCHECK(thread_) << "History service being called after cleanup"; DCHECK(thread_checker_.CalledOnValidThread()); - // Add to the visited links system. - if (visitedlink_master_) { + + // Inform the VisitDelegate of the URLs + if (!info.empty() && visit_delegate_) { std::vector<GURL> urls; urls.reserve(info.size()); - for (history::URLRows::const_iterator i = info.begin(); i != info.end(); - ++i) - urls.push_back(i->url()); - - visitedlink_master_->AddURLs(urls); + for (const auto& row : info) + urls.push_back(row.url()); + visit_delegate_->AddURLs(urls); } ScheduleTask(PRIORITY_NORMAL, @@ -750,7 +725,7 @@ void HistoryService::QueryDownloads( DCHECK(thread_checker_.CalledOnValidThread()); std::vector<history::DownloadRow>* rows = new std::vector<history::DownloadRow>(); - scoped_ptr<std::vector<history::DownloadRow> > scoped_rows(rows); + scoped_ptr<std::vector<history::DownloadRow>> scoped_rows(rows); // Beware! The first Bind() does not simply |scoped_rows.get()| because // base::Passed(&scoped_rows) nullifies |scoped_rows|, and compilers do not // guarantee that the first Bind's arguments are evaluated before the second @@ -936,26 +911,18 @@ void HistoryService::Cleanup() { ScheduleTask(PRIORITY_NORMAL, closing_task); closing_task.Reset(); HistoryBackend* raw_ptr = history_backend_.get(); - history_backend_ = NULL; + history_backend_ = nullptr; thread_->message_loop()->ReleaseSoon(FROM_HERE, raw_ptr); } // Delete the thread, which joins with the background thread. We defensively - // NULL the pointer before deleting it in case somebody tries to use it + // nullptr the pointer before deleting it in case somebody tries to use it // during shutdown, but this shouldn't happen. base::Thread* thread = thread_; - thread_ = NULL; + thread_ = nullptr; delete thread; } -void HistoryService::RebuildTable( - const scoped_refptr<URLEnumerator>& enumerator) { - DCHECK(thread_) << "History service being called after cleanup"; - DCHECK(thread_checker_.CalledOnValidThread()); - ScheduleTask(PRIORITY_NORMAL, base::Bind(&HistoryBackend::IterateURLs, - history_backend_.get(), enumerator)); -} - bool HistoryService::Init( bool no_db, const std::string& languages, @@ -991,10 +958,8 @@ bool HistoryService::Init( base::Bind(&HistoryBackend::Init, history_backend_.get(), languages, no_db_, history_database_params)); - if (visitedlink_master_) { - bool result = visitedlink_master_->Init(); - DCHECK(result); - } + if (visit_delegate_ && !visit_delegate_->Init(this)) + return false; return true; } @@ -1220,21 +1185,23 @@ void HistoryService::NotifyURLsDeleted(bool all_history, if (!thread_) return; - // Update the visited link system for deleted URLs. We will update the - // visited link system for added URLs as soon as we get the add - // notification (we don't have to wait for the backend, which allows us to - // be faster to update the state). + // Inform the VisitDelegate of the deleted URLs. We will inform the delegate + // of added URLs as soon as we get the add notification (we don't have to wait + // for the backend, which allows us to be faster to update the state). // // For deleted URLs, we don't typically know what will be deleted since // delete notifications are by time. We would also like to be more // respectful of privacy and never tell the user something is gone when it // isn't. Therefore, we update the delete URLs after the fact. - if (visitedlink_master_) { + if (visit_delegate_) { if (all_history) { - visitedlink_master_->DeleteAllURLs(); + visit_delegate_->DeleteAllURLs(); } else { - URLIteratorFromURLRows iterator(deleted_rows); - visitedlink_master_->DeleteURLs(&iterator); + std::vector<GURL> urls; + urls.reserve(deleted_rows.size()); + for (const auto& row : deleted_rows) + urls.push_back(row.url()); + visit_delegate_->DeleteURLs(urls); } } diff --git a/chrome/browser/history/history_service.h b/chrome/browser/history/history_service.h index 8b2b4b0..55b8858 100644 --- a/chrome/browser/history/history_service.h +++ b/chrome/browser/history/history_service.h @@ -29,7 +29,6 @@ #include "components/favicon_base/favicon_usage_data.h" #include "components/history/core/browser/keyword_id.h" #include "components/keyed_service/core/keyed_service.h" -#include "components/visitedlink/browser/visitedlink_delegate.h" #include "sql/init_status.h" #include "sync/api/syncable_service.h" #include "ui/base/page_transition_types.h" @@ -39,9 +38,7 @@ class AndroidHistoryProviderService; #endif class GURL; -class HistoryService; class PageUsageRequest; -class Profile; class SkBitmap; namespace base { @@ -49,10 +46,6 @@ class FilePath; class Thread; } -namespace visitedlink { -class VisitedLinkMaster; -} - namespace history { struct DownloadRow; @@ -71,6 +64,7 @@ class InMemoryURLIndexTest; struct KeywordSearchTermVisit; class PageUsageData; class URLDatabase; +class VisitDelegate; class VisitFilter; class WebHistoryService; @@ -81,19 +75,18 @@ class WebHistoryService; // // This service is thread safe. Each request callback is invoked in the // thread that made the request. -class HistoryService : public syncer::SyncableService, - public KeyedService, - public visitedlink::VisitedLinkDelegate { +class HistoryService : public syncer::SyncableService, public KeyedService { public: // Miscellaneous commonly-used types. typedef std::vector<history::PageUsageData*> PageUsageDataList; - // Must call Init after construction. The |history::HistoryClient| object - // must be valid for the whole lifetime of |HistoryService|. - HistoryService(history::HistoryClient* client, Profile* profile); - // The empty constructor is provided only for testing. + // Must call Init after construction. The empty constructor provided only for + // unit tests. When using the full constructor, |history_client| and |profile| + // should only be null during testing, while |visit_delegate| may be null if + // the embedder use another way to track visited links. HistoryService(); - + HistoryService(history::HistoryClient* history_client, + scoped_ptr<history::VisitDelegate> visit_delegate); ~HistoryService() override; // Initializes the history service, returning true on success. On false, do @@ -119,7 +112,7 @@ class HistoryService : public syncer::SyncableService, void ClearCachedDataForContextID(history::ContextID context_id); // Triggers the backend to load if it hasn't already, and then returns the - // in-memory URL database. The returned pointer MAY BE NULL if the in-memory + // in-memory URL database. The returned pointer may be null if the in-memory // database has not been loaded yet. This pointer is owned by the history // system. Callers should not store or cache this value. // @@ -161,7 +154,7 @@ class HistoryService : public syncer::SyncableService, // are only unique inside a given context, so we need that to differentiate // them. // - // The context/page ids can be NULL if there is no meaningful tracking + // The context/page ids can be null if there is no meaningful tracking // information that can be performed on the given URL. The 'nav_entry_id' // should be the unique ID of the current navigation entry in the given // process. @@ -393,9 +386,8 @@ class HistoryService : public syncer::SyncableService, // Implemented by the caller of 'QueryDownloads' below, and is called when the // history service has retrieved a list of all download state. The call - typedef base::Callback<void( - scoped_ptr<std::vector<history::DownloadRow> >)> - DownloadQueryCallback; + typedef base::Callback<void(scoped_ptr<std::vector<history::DownloadRow>>)> + DownloadQueryCallback; // Begins a history request to retrieve the state of all downloads in the // history db. 'callback' runs when the history service request is complete, @@ -550,7 +542,7 @@ class HistoryService : public syncer::SyncableService, // Called on shutdown, this will tell the history backend to complete and // will release pointers to it. No other functions should be called once // cleanup has happened that may dispatch to the history thread (because it - // will be NULL). + // will be null). // // In practice, this will be called by the service manager (BrowserProcess) // when it is being destroyed. Because that reference is being destroyed, it @@ -558,9 +550,6 @@ class HistoryService : public syncer::SyncableService, // still in memory (pending requests may be holding a reference to us). void Cleanup(); - // Implementation of visitedlink::VisitedLinkDelegate. - void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override; - // Low-level Init(). Same as the public version, but adds a |no_db| parameter // that is only set by unittests which causes the backend to not init its DB. bool Init(bool no_db, @@ -812,14 +801,14 @@ class HistoryService : public syncer::SyncableService, // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; + // The history service will inform its VisitDelegate of URLs recorded and + // removed from the history database. This may be null during testing. + scoped_ptr<history::VisitDelegate> visit_delegate_; + // The history client, may be null when testing. The object should otherwise // outlive |HistoryService|. history::HistoryClient* history_client_; - // Used for propagating link highlighting data across renderers. May be null - // in tests. - scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_; - // Has the backend finished loading? The backend is loaded once Init has // completed. bool backend_loaded_; diff --git a/chrome/browser/history/history_service_factory.cc b/chrome/browser/history/history_service_factory.cc index 1c39d82..6295ea9 100644 --- a/chrome/browser/history/history_service_factory.cc +++ b/chrome/browser/history/history_service_factory.cc @@ -10,6 +10,7 @@ #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" #include "chrome/browser/history/chrome_history_client.h" #include "chrome/browser/history/chrome_history_client_factory.h" +#include "chrome/browser/history/content_visit_delegate.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/profiles/profile.h" @@ -77,7 +78,8 @@ KeyedService* HistoryServiceFactory::BuildServiceInstanceFor( content::BrowserContext* context) const { Profile* profile = Profile::FromBrowserContext(context); scoped_ptr<HistoryService> history_service(new HistoryService( - ChromeHistoryClientFactory::GetForProfile(profile), profile)); + ChromeHistoryClientFactory::GetForProfile(profile), + scoped_ptr<history::VisitDelegate>(new ContentVisitDelegate(profile)))); if (!history_service->Init( profile->GetPrefs()->GetString(prefs::kAcceptLanguages), history::HistoryDatabaseParamsForPath(profile->GetPath()))) { diff --git a/chrome/browser/safe_browsing/incident_reporting/last_download_finder_unittest.cc b/chrome/browser/safe_browsing/incident_reporting/last_download_finder_unittest.cc index 7c4726a09..d007508 100644 --- a/chrome/browser/safe_browsing/incident_reporting/last_download_finder_unittest.cc +++ b/chrome/browser/safe_browsing/incident_reporting/last_download_finder_unittest.cc @@ -15,6 +15,7 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/history/chrome_history_client.h" #include "chrome/browser/history/chrome_history_client_factory.h" +#include "chrome/browser/history/content_visit_delegate.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/web_history_service_factory.h" @@ -54,8 +55,9 @@ KeyedService* BuildHistoryService(content::BrowserContext* context) { return NULL; } - HistoryService* history_service = new HistoryService( - ChromeHistoryClientFactory::GetForProfile(profile), profile); + HistoryService* history_service = + new HistoryService(ChromeHistoryClientFactory::GetForProfile(profile), + scoped_ptr<history::VisitDelegate>()); if (history_service->Init( profile->GetPrefs()->GetString(prefs::kAcceptLanguages), history::HistoryDatabaseParamsForPath(profile->GetPath()))) { diff --git a/chrome/browser/safe_browsing/incident_reporting/off_domain_inclusion_detector_unittest.cc b/chrome/browser/safe_browsing/incident_reporting/off_domain_inclusion_detector_unittest.cc index cbc03fa..67b779e 100644 --- a/chrome/browser/safe_browsing/incident_reporting/off_domain_inclusion_detector_unittest.cc +++ b/chrome/browser/safe_browsing/incident_reporting/off_domain_inclusion_detector_unittest.cc @@ -13,6 +13,7 @@ #include "base/time/time.h" #include "chrome/browser/history/chrome_history_client.h" #include "chrome/browser/history/chrome_history_client_factory.h" +#include "chrome/browser/history/content_visit_delegate.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/web_history_service_factory.h" @@ -67,8 +68,9 @@ KeyedService* BuildHistoryService(content::BrowserContext* context) { return NULL; } - HistoryService* history_service = new HistoryService( - ChromeHistoryClientFactory::GetForProfile(profile), profile); + HistoryService* history_service = + new HistoryService(ChromeHistoryClientFactory::GetForProfile(profile), + scoped_ptr<history::VisitDelegate>()); if (history_service->Init( profile->GetPrefs()->GetString(prefs::kAcceptLanguages), history::HistoryDatabaseParamsForPath(profile->GetPath()))) { diff --git a/chrome/browser/safe_browsing/malware_details_history.h b/chrome/browser/safe_browsing/malware_details_history.h index 7482cc5..012a748 100644 --- a/chrome/browser/safe_browsing/malware_details_history.h +++ b/chrome/browser/safe_browsing/malware_details_history.h @@ -26,6 +26,8 @@ namespace safe_browsing { typedef std::vector<GURL> RedirectChain; } +class Profile; + class MalwareDetailsRedirectsCollector : public base::RefCountedThreadSafe< MalwareDetailsRedirectsCollector, diff --git a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc index 2cd6cfb..f0d6578 100644 --- a/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc +++ b/chrome/browser/sync/glue/bookmark_data_type_controller_unittest.cc @@ -51,12 +51,11 @@ namespace { class HistoryMock : public HistoryService { public: - explicit HistoryMock(history::HistoryClient* client, Profile* profile) - : HistoryService(client, profile) {} + HistoryMock() : HistoryService() {} MOCK_METHOD0(BackendLoaded, bool(void)); protected: - virtual ~HistoryMock() {} + ~HistoryMock() override {} }; KeyedService* BuildChromeBookmarkClient(content::BrowserContext* context) { @@ -87,7 +86,7 @@ KeyedService* BuildBookmarkModel(content::BrowserContext* context) { } KeyedService* BuildHistoryService(content::BrowserContext* profile) { - return new HistoryMock(NULL, static_cast<Profile*>(profile)); + return new HistoryMock; } } // namespace diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc index 899b220..c02c67d 100644 --- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc +++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc @@ -113,11 +113,10 @@ class HistoryBackendMock : public HistoryBackend { class HistoryServiceMock : public HistoryService { public: - HistoryServiceMock(history::HistoryClient* client, Profile* profile) - : HistoryService(client, profile), backend_(NULL) {} + HistoryServiceMock() : HistoryService(), backend_(nullptr) {} - virtual void ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task, - base::CancelableTaskTracker* tracker) override { + void ScheduleDBTask(scoped_ptr<history::HistoryDBTask> task, + base::CancelableTaskTracker* tracker) override { history::HistoryDBTask* task_raw = task.get(); task_runner_->PostTaskAndReply( FROM_HERE, @@ -144,7 +143,7 @@ class HistoryServiceMock : public HistoryService { } private: - virtual ~HistoryServiceMock() {} + ~HistoryServiceMock() override {} void RunTaskOnDBThread(history::HistoryDBTask* task) { EXPECT_TRUE(task->RunOnDBThread(backend_.get(), NULL)); @@ -162,7 +161,7 @@ KeyedService* BuildFakeProfileInvalidationProvider( } KeyedService* BuildHistoryService(content::BrowserContext* profile) { - return new HistoryServiceMock(NULL, static_cast<Profile*>(profile)); + return new HistoryServiceMock; } class TestTypedUrlModelAssociator : public TypedUrlModelAssociator { diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 726c9a8..7d894d4 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1521,6 +1521,8 @@ 'browser/history/chrome_history_client.h', 'browser/history/chrome_history_client_factory.cc', 'browser/history/chrome_history_client_factory.h', + 'browser/history/content_visit_delegate.cc', + 'browser/history/content_visit_delegate.h', 'browser/history/delete_directive_handler.cc', 'browser/history/delete_directive_handler.h', 'browser/history/history_backend.cc', diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index e2870aa1..6e45f0b 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -23,6 +23,7 @@ #include "chrome/browser/favicon/favicon_service_factory.h" #include "chrome/browser/history/chrome_history_client.h" #include "chrome/browser/history/chrome_history_client_factory.h" +#include "chrome/browser/history/content_visit_delegate.h" #include "chrome/browser/history/history_backend.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" @@ -214,9 +215,10 @@ KeyedService* BuildFaviconService(content::BrowserContext* profile) { } KeyedService* BuildHistoryService(content::BrowserContext* context) { - Profile* profile = static_cast<Profile*>(context); + Profile* profile = Profile::FromBrowserContext(context); HistoryService* history_service = new HistoryService( - ChromeHistoryClientFactory::GetForProfile(profile), profile); + ChromeHistoryClientFactory::GetForProfile(profile), + scoped_ptr<history::VisitDelegate>(new ContentVisitDelegate(profile))); return history_service; } diff --git a/components/history.gypi b/components/history.gypi index 4d6474c..384fc9c 100644 --- a/components/history.gypi +++ b/components/history.gypi @@ -85,6 +85,8 @@ 'history/core/browser/url_utils.h', 'history/core/browser/visit_database.cc', 'history/core/browser/visit_database.h', + 'history/core/browser/visit_delegate.cc', + 'history/core/browser/visit_delegate.h', 'history/core/browser/visit_filter.cc', 'history/core/browser/visit_filter.h', 'history/core/browser/visit_tracker.cc', diff --git a/components/history/core/browser/BUILD.gn b/components/history/core/browser/BUILD.gn index 437eaeb..c2e1bde 100644 --- a/components/history/core/browser/BUILD.gn +++ b/components/history/core/browser/BUILD.gn @@ -62,6 +62,8 @@ static_library("browser") { "url_utils.h", "visit_database.cc", "visit_database.h", + "visit_delegate.cc", + "visit_delegate.h", "visit_filter.cc", "visit_filter.h", "visit_tracker.cc", diff --git a/components/history/core/browser/url_database.h b/components/history/core/browser/url_database.h index fb3d2f0..c6b3529 100644 --- a/components/history/core/browser/url_database.h +++ b/components/history/core/browser/url_database.h @@ -137,7 +137,7 @@ class URLDatabase { public: URLEnumerator(); - // Retreives the next url. Returns false if no more urls are available + // Retrieves the next url. Returns false if no more urls are available. bool GetNextURL(URLRow* r); private: @@ -153,8 +153,6 @@ class URLDatabase { // more than 3 times. bool InitURLEnumeratorForSignificant(URLEnumerator* enumerator); - // Favicons ------------------------------------------------------------------ - // Autocomplete -------------------------------------------------------------- // Fills the given array with URLs matching the given prefix. They will be diff --git a/components/history/core/browser/visit_delegate.cc b/components/history/core/browser/visit_delegate.cc new file mode 100644 index 0000000..5df16c5 --- /dev/null +++ b/components/history/core/browser/visit_delegate.cc @@ -0,0 +1,15 @@ +// 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 "components/history/core/browser/visit_delegate.h" + +namespace history { + +VisitDelegate::VisitDelegate() { +} + +VisitDelegate::~VisitDelegate() { +} + +} // namespace history diff --git a/components/history/core/browser/visit_delegate.h b/components/history/core/browser/visit_delegate.h new file mode 100644 index 0000000..a60e7a2 --- /dev/null +++ b/components/history/core/browser/visit_delegate.h @@ -0,0 +1,46 @@ +// 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. + +#ifndef COMPONENTS_HISTORY_CORE_BROWSER_VISIT_DELEGATE_H_ +#define COMPONENTS_HISTORY_CORE_BROWSER_VISIT_DELEGATE_H_ + +#include <vector> + +#include "base/macros.h" + +class GURL; +class HistoryService; + +namespace history { + +// VisitDelegate gets notified about URLs recorded as visited by the +// HistoryService. +class VisitDelegate { + public: + VisitDelegate(); + virtual ~VisitDelegate(); + + // Called once HistoryService initialization is complete. Returns true if the + // initialization succeeded, false otherwise. + virtual bool Init(HistoryService* history_service) = 0; + + // Called when an URL is recorded by HistoryService. + virtual void AddURL(const GURL& url) = 0; + + // Called when a list of URLs are recorded by HistoryService. + virtual void AddURLs(const std::vector<GURL>& urls) = 0; + + // Called when a list of URLs are removed from HistoryService. + virtual void DeleteURLs(const std::vector<GURL>& urls) = 0; + + // Called when all URLs are removed from HistoryService. + virtual void DeleteAllURLs() = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(VisitDelegate); +}; + +} // namespace history + +#endif // COMPONENTS_HISTORY_CORE_BROWSER_VISIT_DELEGATE_H_ |