Chromium Code Reviews| Index: chrome/browser/history/history.cc |
| diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc |
| index 4b454f03694077183579ebf75c677f35d8e03594..af1e4a1a4bf90c17308b10a6a2455b6d903d6c38 100644 |
| --- a/chrome/browser/history/history.cc |
| +++ b/chrome/browser/history/history.cc |
| @@ -107,6 +107,26 @@ void RunWithFaviconResults( |
| callback.Run(results->bitmap_results, results->size_map); |
| } |
| +class URLIteratorFromURLRows : public VisitedLinkMaster::URLIterator { |
| + public: |
| + URLIteratorFromURLRows(const history::URLRows& url_rows) |
| + : url_rows_(url_rows), |
| + itr_(url_rows_.begin()) { |
| + } |
| + |
| + virtual const GURL& next() { |
| + return (itr_++)->url(); |
| + } |
| + |
| + virtual bool has_next() const { |
| + return itr_ == url_rows_.end(); |
| + } |
| + |
| + private: |
| + const history::URLRows& url_rows_; |
| + history::URLRows::const_iterator itr_; |
| +}; |
| + |
| } // namespace |
| // Sends messages from the backend to us on the main thread. This must be a |
| @@ -204,12 +224,16 @@ HistoryService::HistoryService(Profile* profile) |
| : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| thread_(new base::Thread(kHistoryThreadName)), |
| profile_(profile), |
| + visitedlink_master_(new VisitedLinkMaster( |
| + profile, ALLOW_THIS_IN_INITIALIZER_LIST(this))), |
| backend_loaded_(false), |
| current_backend_id_(-1), |
| bookmark_service_(NULL), |
| no_db_(false), |
| needs_top_sites_migration_(false) { |
| DCHECK(profile_); |
| + bool result = visitedlink_master_->Init(); |
| + DCHECK(result); // TODO(boliu): should never fail |
| registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
| content::Source<Profile>(profile_)); |
| registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_REMOVED, |
| @@ -468,10 +492,8 @@ void HistoryService::AddPage(const history::HistoryAddPageArgs& add_page_args) { |
| return; |
| // Add link & all redirects to visited link list. |
| - VisitedLinkMaster* visited_links; |
| - if (profile_ && |
| - (visited_links = VisitedLinkMaster::FromProfile(profile_))) { |
| - visited_links->AddURL(add_page_args.url); |
| + if (visitedlink_master_) { |
| + visitedlink_master_->AddURL(add_page_args.url); |
| if (!add_page_args.redirects.empty()) { |
| // We should not be asked to add a page in the middle of a redirect chain. |
| @@ -481,7 +503,7 @@ void HistoryService::AddPage(const history::HistoryAddPageArgs& add_page_args) { |
| // 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++) |
| - visited_links->AddURL(add_page_args.redirects[i]); |
| + visitedlink_master_->AddURL(add_page_args.redirects[i]); |
| } |
| } |
| @@ -526,11 +548,8 @@ void HistoryService::AddPageWithDetails(const GURL& url, |
| return; |
| // Add to the visited links system. |
| - VisitedLinkMaster* visited_links; |
| - if (profile_ && |
| - (visited_links = VisitedLinkMaster::FromProfile(profile_))) { |
| - visited_links->AddURL(url); |
| - } |
| + if (visitedlink_master_) |
| + visitedlink_master_->AddURL(url); |
| history::URLRow row(url); |
| row.set_title(title); |
| @@ -550,16 +569,14 @@ void HistoryService::AddPagesWithDetails(const history::URLRows& info, |
| history::VisitSource visit_source) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| // Add to the visited links system. |
| - VisitedLinkMaster* visited_links; |
| - if (profile_ && |
| - (visited_links = VisitedLinkMaster::FromProfile(profile_))) { |
| + if (visitedlink_master_) { |
| 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()); |
| - visited_links->AddURLs(urls); |
| + visitedlink_master_->AddURLs(urls); |
| } |
| ScheduleAndForget(PRIORITY_NORMAL, |
| @@ -716,11 +733,6 @@ void HistoryService::SetImportedFavicons( |
| &HistoryBackend::SetImportedFavicons, favicon_usage); |
| } |
| -void HistoryService::IterateURLs(URLEnumerator* enumerator) { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| - ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::IterateURLs, enumerator); |
| -} |
| - |
| HistoryService::Handle HistoryService::QueryURL( |
| const GURL& url, |
| bool want_visits, |
| @@ -898,17 +910,16 @@ void HistoryService::Observe(int type, |
| // 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 (!profile_) |
| - return; // No profile, probably unit testing. |
| - content::Details<history::URLsDeletedDetails> deleted_details(details); |
| - VisitedLinkMaster* visited_links = |
| - VisitedLinkMaster::FromProfile(profile_); |
| - if (!visited_links) |
| - return; // Nobody to update. |
| - if (deleted_details->all_history) |
| - visited_links->DeleteAllURLs(); |
| - else // Delete individual ones. |
| - visited_links->DeleteURLs(deleted_details->rows); |
| + if (visitedlink_master_) { |
| + content::Details<history::URLsDeletedDetails> deleted_details(details); |
| + |
| + if (deleted_details->all_history) |
| + visitedlink_master_->DeleteAllURLs(); |
|
joth
2012/12/20 01:39:29
nit: include { } when there's an else part.
boliu
2012/12/29 01:48:12
Done.
|
| + else { |
| + URLIteratorFromURLRows iterator(deleted_details->rows); |
| + visitedlink_master_->DeleteURLs(&iterator); |
| + } |
| + } |
| break; |
| } |
| @@ -922,6 +933,23 @@ void HistoryService::Observe(int type, |
| } |
| } |
| +bool HistoryService::IsEquivalentContext(content::BrowserContext* context1, |
| + content::BrowserContext* context2) { |
| + DCHECK(context1); |
| + DCHECK(context2); |
| + |
| + Profile* profile1 = Profile::FromBrowserContext(context1); |
| + Profile* profile2 = Profile::FromBrowserContext(context2); |
| + |
| + return profile1->IsSameProfile(profile2); |
| +} |
| + |
| +void HistoryService::RebuildTable( |
| + VisitedLinkDelegate::URLEnumerator* enumerator) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + ScheduleAndForget(PRIORITY_NORMAL, &HistoryBackend::IterateURLs, enumerator); |
| +} |
| + |
| bool HistoryService::Init(const FilePath& history_dir, |
| BookmarkService* bookmark_service, |
| bool no_db) { |