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

Unified Diff: components/history/core/browser/url_row.cc

Issue 339433007: Componentize URLDatabase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 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
« no previous file with comments | « components/history/core/browser/url_row.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/history/core/browser/url_row.cc
diff --git a/chrome/browser/history/history_types.cc b/components/history/core/browser/url_row.cc
similarity index 17%
copy from chrome/browser/history/history_types.cc
copy to components/history/core/browser/url_row.cc
index c0d4cbf21e3cc2b875230a1cd089ef31e7bbc42d..1f484c88c2bc8422ec40943bbe3faf17e75653d2 100644
--- a/chrome/browser/history/history_types.cc
+++ b/components/history/core/browser/url_row.cc
@@ -1,19 +1,13 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 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/history_types.h"
+#include "components/history/core/browser/url_row.h"
-#include <limits>
-
-#include "base/logging.h"
-#include "base/stl_util.h"
-#include "chrome/browser/history/page_usage_data.h"
+#include <algorithm>
namespace history {
-// URLRow ----------------------------------------------------------------------
-
URLRow::URLRow() {
Initialize();
}
@@ -62,33 +56,6 @@ void URLRow::Initialize() {
hidden_ = false;
}
-// VisitRow --------------------------------------------------------------------
-
-VisitRow::VisitRow()
- : visit_id(0),
- url_id(0),
- referring_visit(0),
- transition(content::PAGE_TRANSITION_LINK),
- segment_id(0) {
-}
-
-VisitRow::VisitRow(URLID arg_url_id,
- base::Time arg_visit_time,
- VisitID arg_referring_visit,
- content::PageTransition arg_transition,
- SegmentID arg_segment_id)
- : visit_id(0),
- url_id(arg_url_id),
- visit_time(arg_visit_time),
- referring_visit(arg_referring_visit),
- transition(arg_transition),
- segment_id(arg_segment_id) {
-}
-
-VisitRow::~VisitRow() {
-}
-
-// URLResult -------------------------------------------------------------------
URLResult::URLResult()
: blocked_visit_(false) {
@@ -126,319 +93,4 @@ bool URLResult::CompareVisitTime(const URLResult& lhs, const URLResult& rhs) {
return lhs.visit_time() > rhs.visit_time();
}
-// QueryResults ----------------------------------------------------------------
-
-QueryResults::QueryResults() : reached_beginning_(false) {
-}
-
-QueryResults::~QueryResults() {}
-
-const size_t* QueryResults::MatchesForURL(const GURL& url,
- size_t* num_matches) const {
- URLToResultIndices::const_iterator found = url_to_results_.find(url);
- if (found == url_to_results_.end()) {
- if (num_matches)
- *num_matches = 0;
- return NULL;
- }
-
- // All entries in the map should have at least one index, otherwise it
- // shouldn't be in the map.
- DCHECK(!found->second->empty());
- if (num_matches)
- *num_matches = found->second->size();
- return &found->second->front();
-}
-
-void QueryResults::Swap(QueryResults* other) {
- std::swap(first_time_searched_, other->first_time_searched_);
- std::swap(reached_beginning_, other->reached_beginning_);
- results_.swap(other->results_);
- url_to_results_.swap(other->url_to_results_);
-}
-
-void QueryResults::AppendURLBySwapping(URLResult* result) {
- URLResult* new_result = new URLResult;
- new_result->SwapResult(result);
-
- results_.push_back(new_result);
- AddURLUsageAtIndex(new_result->url(), results_.size() - 1);
-}
-
-void QueryResults::DeleteURL(const GURL& url) {
- // Delete all instances of this URL. We re-query each time since each
- // mutation will cause the indices to change.
- while (const size_t* match_indices = MatchesForURL(url, NULL))
- DeleteRange(*match_indices, *match_indices);
-}
-
-void QueryResults::DeleteRange(size_t begin, size_t end) {
- DCHECK(begin <= end && begin < size() && end < size());
-
- // First delete the pointers in the given range and store all the URLs that
- // were modified. We will delete references to these later.
- std::set<GURL> urls_modified;
- for (size_t i = begin; i <= end; i++) {
- urls_modified.insert(results_[i]->url());
- }
-
- // Now just delete that range in the vector en masse (the STL ending is
- // exclusive, while ours is inclusive, hence the +1).
- results_.erase(results_.begin() + begin, results_.begin() + end + 1);
-
- // Delete the indicies referencing the deleted entries.
- for (std::set<GURL>::const_iterator url = urls_modified.begin();
- url != urls_modified.end(); ++url) {
- URLToResultIndices::iterator found = url_to_results_.find(*url);
- if (found == url_to_results_.end()) {
- NOTREACHED();
- continue;
- }
-
- // Need a signed loop type since we do -- which may take us to -1.
- for (int match = 0; match < static_cast<int>(found->second->size());
- match++) {
- if (found->second[match] >= begin && found->second[match] <= end) {
- // Remove this referece from the list.
- found->second->erase(found->second->begin() + match);
- match--;
- }
- }
-
- // Clear out an empty lists if we just made one.
- if (found->second->empty())
- url_to_results_.erase(found);
- }
-
- // Shift all other indices over to account for the removed ones.
- AdjustResultMap(end + 1, std::numeric_limits<size_t>::max(),
- -static_cast<ptrdiff_t>(end - begin + 1));
-}
-
-void QueryResults::AddURLUsageAtIndex(const GURL& url, size_t index) {
- URLToResultIndices::iterator found = url_to_results_.find(url);
- if (found != url_to_results_.end()) {
- // The URL is already in the list, so we can just append the new index.
- found->second->push_back(index);
- return;
- }
-
- // Need to add a new entry for this URL.
- base::StackVector<size_t, 4> new_list;
- new_list->push_back(index);
- url_to_results_[url] = new_list;
-}
-
-void QueryResults::AdjustResultMap(size_t begin, size_t end, ptrdiff_t delta) {
- for (URLToResultIndices::iterator i = url_to_results_.begin();
- i != url_to_results_.end(); ++i) {
- for (size_t match = 0; match < i->second->size(); match++) {
- size_t match_index = i->second[match];
- if (match_index >= begin && match_index <= end)
- i->second[match] += delta;
- }
- }
-}
-
-// QueryOptions ----------------------------------------------------------------
-
-QueryOptions::QueryOptions()
- : max_count(0),
- duplicate_policy(QueryOptions::REMOVE_ALL_DUPLICATES) {
-}
-
-void QueryOptions::SetRecentDayRange(int days_ago) {
- end_time = base::Time::Now();
- begin_time = end_time - base::TimeDelta::FromDays(days_ago);
-}
-
-int64 QueryOptions::EffectiveBeginTime() const {
- return begin_time.ToInternalValue();
-}
-
-int64 QueryOptions::EffectiveEndTime() const {
- return end_time.is_null() ?
- std::numeric_limits<int64>::max() : end_time.ToInternalValue();
-}
-
-int QueryOptions::EffectiveMaxCount() const {
- return max_count ? max_count : std::numeric_limits<int>::max();
-}
-
-// QueryURLResult -------------------------------------------------------------
-
-QueryURLResult::QueryURLResult() : success(false) {
-}
-
-QueryURLResult::~QueryURLResult() {
-}
-
-// KeywordSearchTermVisit -----------------------------------------------------
-
-KeywordSearchTermVisit::KeywordSearchTermVisit() : visits(0) {}
-
-KeywordSearchTermVisit::~KeywordSearchTermVisit() {}
-
-// KeywordSearchTermRow --------------------------------------------------------
-
-KeywordSearchTermRow::KeywordSearchTermRow() : keyword_id(0), url_id(0) {}
-
-KeywordSearchTermRow::~KeywordSearchTermRow() {}
-
-// MostVisitedURL --------------------------------------------------------------
-
-MostVisitedURL::MostVisitedURL() {}
-
-MostVisitedURL::MostVisitedURL(const GURL& url,
- const base::string16& title)
- : url(url),
- title(title) {
-}
-
-MostVisitedURL::MostVisitedURL(const GURL& url,
- const base::string16& title,
- const base::Time& last_forced_time)
- : url(url),
- title(title),
- last_forced_time(last_forced_time) {
-}
-
-MostVisitedURL::~MostVisitedURL() {}
-
-// FilteredURL -----------------------------------------------------------------
-
-FilteredURL::FilteredURL() : score(0.0) {}
-
-FilteredURL::FilteredURL(const PageUsageData& page_data)
- : url(page_data.GetURL()),
- title(page_data.GetTitle()),
- score(page_data.GetScore()) {
-}
-
-FilteredURL::~FilteredURL() {}
-
-// FilteredURL::ExtendedInfo ---------------------------------------------------
-
-FilteredURL::ExtendedInfo::ExtendedInfo()
- : total_visits(0),
- visits(0),
- duration_opened(0) {
-}
-
-// Images ---------------------------------------------------------------------
-
-Images::Images() {}
-
-Images::~Images() {}
-
-// TopSitesDelta --------------------------------------------------------------
-
-TopSitesDelta::TopSitesDelta() {}
-
-TopSitesDelta::~TopSitesDelta() {}
-
-// HistoryAddPageArgs ---------------------------------------------------------
-
-HistoryAddPageArgs::HistoryAddPageArgs()
- : context_id(NULL),
- page_id(0),
- transition(content::PAGE_TRANSITION_LINK),
- visit_source(SOURCE_BROWSED),
- did_replace_entry(false) {}
-
-HistoryAddPageArgs::HistoryAddPageArgs(
- const GURL& url,
- base::Time time,
- ContextID context_id,
- int32 page_id,
- const GURL& referrer,
- const history::RedirectList& redirects,
- content::PageTransition transition,
- VisitSource source,
- bool did_replace_entry)
- : url(url),
- time(time),
- context_id(context_id),
- page_id(page_id),
- referrer(referrer),
- redirects(redirects),
- transition(transition),
- visit_source(source),
- did_replace_entry(did_replace_entry) {
-}
-
-HistoryAddPageArgs::~HistoryAddPageArgs() {}
-
-ThumbnailMigration::ThumbnailMigration() {}
-
-ThumbnailMigration::~ThumbnailMigration() {}
-
-MostVisitedThumbnails::MostVisitedThumbnails() {}
-
-MostVisitedThumbnails::~MostVisitedThumbnails() {}
-
-// Autocomplete thresholds -----------------------------------------------------
-
-const int kLowQualityMatchTypedLimit = 1;
-const int kLowQualityMatchVisitLimit = 4;
-const int kLowQualityMatchAgeLimitInDays = 3;
-
-base::Time AutocompleteAgeThreshold() {
- return (base::Time::Now() -
- base::TimeDelta::FromDays(kLowQualityMatchAgeLimitInDays));
-}
-
-bool RowQualifiesAsSignificant(const URLRow& row,
- const base::Time& threshold) {
- const base::Time& real_threshold =
- threshold.is_null() ? AutocompleteAgeThreshold() : threshold;
- return (row.typed_count() >= kLowQualityMatchTypedLimit) ||
- (row.visit_count() >= kLowQualityMatchVisitLimit) ||
- (row.last_visit() >= real_threshold);
-}
-
-// IconMapping ----------------------------------------------------------------
-
-IconMapping::IconMapping()
- : mapping_id(0), icon_id(0), icon_type(favicon_base::INVALID_ICON) {}
-
-IconMapping::~IconMapping() {}
-
-// FaviconBitmapIDSize ---------------------------------------------------------
-
-FaviconBitmapIDSize::FaviconBitmapIDSize()
- : bitmap_id(0) {
-}
-
-FaviconBitmapIDSize::~FaviconBitmapIDSize() {
-}
-
-// FaviconBitmap --------------------------------------------------------------
-
-FaviconBitmap::FaviconBitmap()
- : bitmap_id(0),
- icon_id(0) {
-}
-
-FaviconBitmap::~FaviconBitmap() {
-}
-
-// VisitDatabaseObserver -------------------------------------------------------
-
-VisitDatabaseObserver::~VisitDatabaseObserver() {}
-
-ExpireHistoryArgs::ExpireHistoryArgs() {
-}
-
-ExpireHistoryArgs::~ExpireHistoryArgs() {
-}
-
-void ExpireHistoryArgs::SetTimeRangeForOneDay(base::Time time) {
- begin_time = time.LocalMidnight();
-
- // Due to DST, leap seconds, etc., the next day at midnight may be more than
- // 24 hours away, so add 36 hours and round back down to midnight.
- end_time = (begin_time + base::TimeDelta::FromHours(36)).LocalMidnight();
-}
-
} // namespace history
« no previous file with comments | « components/history/core/browser/url_row.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698