Skip to content

Commit

Permalink
Add GetLastVisitToOrigin to HistoryService
Browse files Browse the repository at this point in the history
Adds a new method, GetLastVisitToOrigin, to the history stack which gets
the last visit to any page on an origin within a time range. This call
is successful if there were no previous visits to that origin but
reports a null base::Time.

Bug: 995437
Change-Id: I56b421161c85076f5b81c61fcf1e31ef08abfe81
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1860733
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Ryan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706968}
  • Loading branch information
Robert Ogden authored and Commit Bot committed Oct 17, 2019
1 parent 49ff7a2 commit 7b0e363
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 125 deletions.
24 changes: 15 additions & 9 deletions components/history/core/browser/history_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,9 @@ class HistoryBackendHelper : public base::SupportsUserData {
~HistoryBackendHelper() override;
};

HistoryBackendHelper::HistoryBackendHelper() {
}
HistoryBackendHelper::HistoryBackendHelper() = default;

HistoryBackendHelper::~HistoryBackendHelper() {
}
HistoryBackendHelper::~HistoryBackendHelper() = default;

// HistoryBackend --------------------------------------------------------------

Expand Down Expand Up @@ -1133,6 +1131,16 @@ HistoryCountResult HistoryBackend::CountUniqueHostsVisitedLastMonth() {
return {!!db_, db_ ? db_->CountUniqueHostsVisitedLastMonth() : 0};
}

HistoryLastVisitToHostResult HistoryBackend::GetLastVisitToHost(
const GURL& host,
base::Time begin_time,
base::Time end_time) {
base::Time last_visit;
return {
db_ && db_->GetLastVisitToHost(host, begin_time, end_time, &last_visit),
last_visit};
}

// Keyword visits --------------------------------------------------------------

void HistoryBackend::SetKeywordSearchTermsForURL(const GURL& url,
Expand Down Expand Up @@ -1226,9 +1234,8 @@ std::vector<DownloadRow> HistoryBackend::QueryDownloads() {
}

// Update a particular download entry.
void HistoryBackend::UpdateDownload(
const DownloadRow& data,
bool should_commit_immediately) {
void HistoryBackend::UpdateDownload(const DownloadRow& data,
bool should_commit_immediately) {
TRACE_EVENT0("browser", "HistoryBackend::UpdateDownload");
if (!db_)
return;
Expand Down Expand Up @@ -2366,8 +2373,7 @@ void HistoryBackend::SendFaviconChangedNotificationForPageAndRedirects(
const GURL& page_url) {
RedirectList redirect_list = GetCachedRecentRedirects(page_url);
if (!redirect_list.empty()) {
std::set<GURL> favicons_changed(redirect_list.begin(),
redirect_list.end());
std::set<GURL> favicons_changed(redirect_list.begin(), redirect_list.end());
NotifyFaviconsChanged(favicons_changed, GURL());
}
}
Expand Down
8 changes: 8 additions & 0 deletions components/history/core/browser/history_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// Returns the number of hosts visited in the last month.
HistoryCountResult CountUniqueHostsVisitedLastMonth();

// Gets the last time any webpage on the given host was visited within the
// time range [|begin_time|, |end_time|). If the given host has not been
// visited in the given time range, the result will have a null base::Time,
// but still report success.
HistoryLastVisitToHostResult GetLastVisitToHost(const GURL& host,
base::Time begin_time,
base::Time end_time);

// Favicon -------------------------------------------------------------------

std::vector<favicon_base::FaviconRawBitmapResult> GetFavicon(
Expand Down
21 changes: 18 additions & 3 deletions components/history/core/browser/history_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,22 @@ void HistoryService::CountUniqueHostsVisitedLastMonth(
std::move(callback));
}

base::CancelableTaskTracker::TaskId HistoryService::GetLastVisitToHost(
const GURL& host,
base::Time begin_time,
base::Time end_time,
GetLastVisitToHostCallback callback,
base::CancelableTaskTracker* tracker) {
DCHECK(backend_task_runner_) << "History service being called after cleanup";
DCHECK(thread_checker_.CalledOnValidThread());

return tracker->PostTaskAndReplyWithResult(
backend_task_runner_.get(), FROM_HERE,
base::BindOnce(&HistoryBackend::GetLastVisitToHost, history_backend_,
host, begin_time, end_time),
std::move(callback));
}

// Downloads -------------------------------------------------------------------

// Handle creation of a download by creating an entry in the history service's
Expand Down Expand Up @@ -760,9 +776,8 @@ void HistoryService::QueryDownloads(DownloadQueryCallback callback) {

// Handle updates for a particular download. This is a 'fire and forget'
// operation, so we don't need to be called back.
void HistoryService::UpdateDownload(
const DownloadRow& data,
bool should_commit_immediately) {
void HistoryService::UpdateDownload(const DownloadRow& data,
bool should_commit_immediately) {
TRACE_EVENT0("browser", "HistoryService::UpdateDownload");
DCHECK(backend_task_runner_) << "History service being called after cleanup";
DCHECK(thread_checker_.CalledOnValidThread());
Expand Down
17 changes: 16 additions & 1 deletion components/history/core/browser/history_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/optional.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string16.h"
#include "base/task/cancelable_task_tracker.h"
Expand All @@ -50,7 +51,7 @@ class TestingProfile;
namespace base {
class FilePath;
class Thread;
}
} // namespace base

namespace favicon {
class FaviconServiceImpl;
Expand Down Expand Up @@ -315,6 +316,20 @@ class HistoryService : public KeyedService {
void CountUniqueHostsVisitedLastMonth(GetHistoryCountCallback callback,
base::CancelableTaskTracker* tracker);

using GetLastVisitToHostCallback =
base::OnceCallback<void(HistoryLastVisitToHostResult)>;

// Gets the last time any webpage on the given host was visited within the
// time range [|begin_time|, |end_time|). If the given host has not been
// visited in the given time age, the callback will be called with a null
// base::Time.
base::CancelableTaskTracker::TaskId GetLastVisitToHost(
const GURL& host,
base::Time begin_time,
base::Time end_time,
GetLastVisitToHostCallback callback,
base::CancelableTaskTracker* tracker);

// Database management operations --------------------------------------------

// Delete all the information related to a single url.
Expand Down
18 changes: 15 additions & 3 deletions components/history/core/browser/history_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ typedef int64_t IconMappingID; // For page url and icon mapping.
// (Warning): Please don't change any existing values while it is ok to add
// new values when needed.
enum VisitSource {
SOURCE_SYNCED = 0, // Synchronized from somewhere else.
SOURCE_BROWSED = 1, // User browsed.
SOURCE_EXTENSION = 2, // Added by an extension.
SOURCE_SYNCED = 0, // Synchronized from somewhere else.
SOURCE_BROWSED = 1, // User browsed.
SOURCE_EXTENSION = 2, // Added by an extension.
SOURCE_FIREFOX_IMPORTED = 3,
SOURCE_IE_IMPORTED = 4,
SOURCE_SAFARI_IMPORTED = 5,
Expand Down Expand Up @@ -432,6 +432,18 @@ struct HistoryCountResult {
int count = 0;
};

// HistoryLastVisitToHostResult encapsulates the result of a call to
// HistoryBackend::GetLastVisitToHost().
struct HistoryLastVisitToHostResult {
// Indicates whether the call was successful or not. This can happen if there
// are internal database errors or the query was called with invalid
// arguments. |success| will be true and |last_visit| will be null if
// the host was never visited before. |last_visit| will always be null if
// |success| is false.
bool success = false;
base::Time last_visit;
};

// Favicons -------------------------------------------------------------------

// Used for the mapping between the page and icon.
Expand Down
Loading

0 comments on commit 7b0e363

Please sign in to comment.