Home | History | Annotate | Download | only in history
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_TYPES_H_
      6 #define CHROME_BROWSER_HISTORY_HISTORY_TYPES_H_
      7 
      8 #include <deque>
      9 #include <map>
     10 #include <set>
     11 #include <string>
     12 #include <vector>
     13 
     14 #include "base/basictypes.h"
     15 #include "base/containers/stack_container.h"
     16 #include "base/memory/ref_counted_memory.h"
     17 #include "base/memory/scoped_vector.h"
     18 #include "base/strings/string16.h"
     19 #include "base/time/time.h"
     20 #include "chrome/common/ref_counted_util.h"
     21 #include "components/favicon_base/favicon_types.h"
     22 #include "components/history/core/common/thumbnail_score.h"
     23 #include "components/query_parser/snippet.h"
     24 #include "components/search_engines/template_url_id.h"
     25 #include "content/public/common/page_transition_types.h"
     26 #include "ui/gfx/image/image.h"
     27 #include "ui/gfx/size.h"
     28 #include "url/gurl.h"
     29 
     30 class PageUsageData;
     31 
     32 namespace history {
     33 
     34 // Forward declaration for friend statements.
     35 class HistoryBackend;
     36 class URLDatabase;
     37 
     38 // Structure to hold redirect lists for URLs.  For a redirect chain
     39 // A -> B -> C, and entry in the map would look like "A => {B -> C}".
     40 typedef std::map<GURL, scoped_refptr<RefCountedVector<GURL> > > RedirectMap;
     41 
     42 // Container for a list of URLs.
     43 typedef std::vector<GURL> RedirectList;
     44 
     45 typedef int64 FaviconBitmapID; // Identifier for a bitmap in a favicon.
     46 typedef int64 SegmentID;  // URL segments for the most visited view.
     47 typedef int64 IconMappingID; // For page url and icon mapping.
     48 
     49 // Identifier for a context to scope page ids.
     50 typedef const void* ContextID;
     51 
     52 // URLRow ---------------------------------------------------------------------
     53 
     54 typedef int64 URLID;
     55 
     56 // Holds all information globally associated with one URL (one row in the
     57 // URL table).
     58 //
     59 // This keeps track of dirty bits, which are currently unused:
     60 //
     61 // TODO(brettw) the dirty bits are broken in a number of respects. First, the
     62 // database will want to update them on a const object, so they need to be
     63 // mutable.
     64 //
     65 // Second, there is a problem copying. If you make a copy of this structure
     66 // (as we allow since we put this into vectors in various places) then the
     67 // dirty bits will not be in sync for these copies.
     68 class URLRow {
     69  public:
     70   URLRow();
     71 
     72   explicit URLRow(const GURL& url);
     73 
     74   // We need to be able to set the id of a URLRow that's being passed through
     75   // an IPC message.  This constructor should probably not be used otherwise.
     76   URLRow(const GURL& url, URLID id);
     77 
     78   virtual ~URLRow();
     79   URLRow& operator=(const URLRow& other);
     80 
     81   URLID id() const { return id_; }
     82 
     83   // Sets the id of the row. The id should only be manually set when a row has
     84   // been retrieved from the history database or other dataset based on criteria
     85   // other than its id (i.e. by URL) and when the id has not yet been set in the
     86   // row.
     87   void set_id(URLID id) { id_ = id; }
     88 
     89   const GURL& url() const { return url_; }
     90 
     91   const base::string16& title() const {
     92     return title_;
     93   }
     94   void set_title(const base::string16& title) {
     95     // The title is frequently set to the same thing, so we don't bother
     96     // updating unless the string has changed.
     97     if (title != title_) {
     98       title_ = title;
     99     }
    100   }
    101 
    102   // The number of times this URL has been visited. This will often match the
    103   // number of entries in the visit table for this URL, but won't always. It's
    104   // really designed for autocomplete ranking, so some "useless" transitions
    105   // from the visit table aren't counted in this tally.
    106   int visit_count() const {
    107     return visit_count_;
    108   }
    109   void set_visit_count(int visit_count) {
    110     visit_count_ = visit_count;
    111   }
    112 
    113   // Number of times the URL was typed in the Omnibox. This "should" match
    114   // the number of TYPED transitions in the visit table. It's used primarily
    115   // for faster autocomplete ranking. If you need to know the actual number of
    116   // TYPED transitions, you should query the visit table since there could be
    117   // something out of sync.
    118   int typed_count() const {
    119     return typed_count_;
    120   }
    121   void set_typed_count(int typed_count) {
    122     typed_count_ = typed_count;
    123   }
    124 
    125   base::Time last_visit() const {
    126     return last_visit_;
    127   }
    128   void set_last_visit(base::Time last_visit) {
    129     last_visit_ = last_visit;
    130   }
    131 
    132   // If this is set, we won't autocomplete this URL.
    133   bool hidden() const {
    134     return hidden_;
    135   }
    136   void set_hidden(bool hidden) {
    137     hidden_ = hidden;
    138   }
    139 
    140   // Helper functor that determines if an URLRow refers to a given URL.
    141   class URLRowHasURL {
    142    public:
    143     explicit URLRowHasURL(const GURL& url) : url_(url) {}
    144 
    145     bool operator()(const URLRow& row) {
    146       return row.url() == url_;
    147     }
    148 
    149    private:
    150     const GURL& url_;
    151   };
    152 
    153  protected:
    154   // Swaps the contents of this URLRow with another, which allows it to be
    155   // destructively copied without memory allocations.
    156   void Swap(URLRow* other);
    157 
    158  private:
    159   // This class writes directly into this structure and clears our dirty bits
    160   // when reading out of the DB.
    161   friend class URLDatabase;
    162   friend class HistoryBackend;
    163 
    164   // Initializes all values that need initialization to their defaults.
    165   // This excludes objects which autoinitialize such as strings.
    166   void Initialize();
    167 
    168   // The row ID of this URL from the history database. This is immutable except
    169   // when retrieving the row from the database or when determining if the URL
    170   // referenced by the URLRow already exists in the database.
    171   URLID id_;
    172 
    173   // The URL of this row. Immutable except for the database which sets it
    174   // when it pulls them out. If clients want to change it, they must use
    175   // the constructor to make a new one.
    176   GURL url_;
    177 
    178   base::string16 title_;
    179 
    180   // Total number of times this URL has been visited.
    181   int visit_count_;
    182 
    183   // Number of times this URL has been manually entered in the URL bar.
    184   int typed_count_;
    185 
    186   // The date of the last visit of this URL, which saves us from having to
    187   // loop up in the visit table for things like autocomplete and expiration.
    188   base::Time last_visit_;
    189 
    190   // Indicates this entry should now be shown in typical UI or queries, this
    191   // is usually for subframes.
    192   bool hidden_;
    193 
    194   // We support the implicit copy constuctor and operator=.
    195 };
    196 typedef std::vector<URLRow> URLRows;
    197 
    198 // The enumeration of all possible sources of visits is listed below.
    199 // The source will be propagated along with a URL or a visit item
    200 // and eventually be stored in the history database,
    201 // visit_source table specifically.
    202 // Different from page transition types, they describe the origins of visits.
    203 // (Warning): Please don't change any existing values while it is ok to add
    204 // new values when needed.
    205 enum VisitSource {
    206   SOURCE_SYNCED = 0,         // Synchronized from somewhere else.
    207   SOURCE_BROWSED = 1,        // User browsed.
    208   SOURCE_EXTENSION = 2,      // Added by an extension.
    209   SOURCE_FIREFOX_IMPORTED = 3,
    210   SOURCE_IE_IMPORTED = 4,
    211   SOURCE_SAFARI_IMPORTED = 5,
    212 };
    213 
    214 typedef int64 VisitID;
    215 // Structure to hold the mapping between each visit's id and its source.
    216 typedef std::map<VisitID, VisitSource> VisitSourceMap;
    217 
    218 // VisitRow -------------------------------------------------------------------
    219 
    220 // Holds all information associated with a specific visit. A visit holds time
    221 // and referrer information for one time a URL is visited.
    222 class VisitRow {
    223  public:
    224   VisitRow();
    225   VisitRow(URLID arg_url_id,
    226            base::Time arg_visit_time,
    227            VisitID arg_referring_visit,
    228            content::PageTransition arg_transition,
    229            SegmentID arg_segment_id);
    230   ~VisitRow();
    231 
    232   // ID of this row (visit ID, used a a referrer for other visits).
    233   VisitID visit_id;
    234 
    235   // Row ID into the URL table of the URL that this page is.
    236   URLID url_id;
    237 
    238   base::Time visit_time;
    239 
    240   // Indicates another visit that was the referring page for this one.
    241   // 0 indicates no referrer.
    242   VisitID referring_visit;
    243 
    244   // A combination of bits from PageTransition.
    245   content::PageTransition transition;
    246 
    247   // The segment id (see visitsegment_database.*).
    248   // If 0, the segment id is null in the table.
    249   SegmentID segment_id;
    250 
    251   // Record how much time a user has this visit starting from the user
    252   // opened this visit to the user closed or ended this visit.
    253   // This includes both active and inactive time as long as
    254   // the visit was present.
    255   base::TimeDelta visit_duration;
    256 
    257   // Compares two visits based on dates, for sorting.
    258   bool operator<(const VisitRow& other) {
    259     return visit_time < other.visit_time;
    260   }
    261 
    262   // We allow the implicit copy constuctor and operator=.
    263 };
    264 
    265 // We pass around vectors of visits a lot
    266 typedef std::vector<VisitRow> VisitVector;
    267 
    268 // The basic information associated with a visit (timestamp, type of visit),
    269 // used by HistoryBackend::AddVisits() to create new visits for a URL.
    270 typedef std::pair<base::Time, content::PageTransition> VisitInfo;
    271 
    272 // PageVisit ------------------------------------------------------------------
    273 
    274 // Represents a simplified version of a visit for external users. Normally,
    275 // views are only interested in the time, and not the other information
    276 // associated with a VisitRow.
    277 struct PageVisit {
    278   URLID page_id;
    279   base::Time visit_time;
    280 };
    281 
    282 // URLResult -------------------------------------------------------------------
    283 
    284 class URLResult : public URLRow {
    285  public:
    286   URLResult();
    287   URLResult(const GURL& url, base::Time visit_time);
    288   // Constructor that create a URLResult from the specified URL and title match
    289   // positions from title_matches.
    290   URLResult(const GURL& url,
    291             const query_parser::Snippet::MatchPositions& title_matches);
    292   explicit URLResult(const URLRow& url_row);
    293   virtual ~URLResult();
    294 
    295   base::Time visit_time() const { return visit_time_; }
    296   void set_visit_time(base::Time visit_time) { visit_time_ = visit_time; }
    297 
    298   const query_parser::Snippet& snippet() const { return snippet_; }
    299 
    300   bool blocked_visit() const { return blocked_visit_; }
    301   void set_blocked_visit(bool blocked_visit) {
    302     blocked_visit_ = blocked_visit;
    303   }
    304 
    305   // If this is a title match, title_match_positions contains an entry for
    306   // every word in the title that matched one of the query parameters. Each
    307   // entry contains the start and end of the match.
    308   const query_parser::Snippet::MatchPositions& title_match_positions() const {
    309     return title_match_positions_;
    310   }
    311 
    312   void SwapResult(URLResult* other);
    313 
    314   static bool CompareVisitTime(const URLResult& lhs, const URLResult& rhs);
    315 
    316  private:
    317   friend class HistoryBackend;
    318 
    319   // The time that this result corresponds to.
    320   base::Time visit_time_;
    321 
    322   // These values are typically set by HistoryBackend.
    323   query_parser::Snippet snippet_;
    324   query_parser::Snippet::MatchPositions title_match_positions_;
    325 
    326   // Whether a managed user was blocked when attempting to visit this URL.
    327   bool blocked_visit_;
    328 
    329   // We support the implicit copy constructor and operator=.
    330 };
    331 
    332 // QueryResults ----------------------------------------------------------------
    333 
    334 // Encapsulates the results of a history query. It supports an ordered list of
    335 // URLResult objects, plus an efficient way of looking up the index of each time
    336 // a given URL appears in those results.
    337 class QueryResults {
    338  public:
    339   typedef std::vector<URLResult*> URLResultVector;
    340 
    341   QueryResults();
    342   ~QueryResults();
    343 
    344   // Indicates the first time that the query includes results for (queries are
    345   // clipped at the beginning, so it will always include to the end of the time
    346   // queried).
    347   //
    348   // If the number of results was clipped as a result of the max count, this
    349   // will be the time of the first query returned. If there were fewer results
    350   // than we were allowed to return, this represents the first date considered
    351   // in the query (this will be before the first result if there was time
    352   // queried with no results).
    353   //
    354   // TODO(brettw): bug 1203054: This field is not currently set properly! Do
    355   // not use until the bug is fixed.
    356   base::Time first_time_searched() const { return first_time_searched_; }
    357   void set_first_time_searched(base::Time t) { first_time_searched_ = t; }
    358   // Note: If you need end_time_searched, it can be added.
    359 
    360   void set_reached_beginning(bool reached) { reached_beginning_ = reached; }
    361   bool reached_beginning() { return reached_beginning_; }
    362 
    363   size_t size() const { return results_.size(); }
    364   bool empty() const { return results_.empty(); }
    365 
    366   URLResult& back() { return *results_.back(); }
    367   const URLResult& back() const { return *results_.back(); }
    368 
    369   URLResult& operator[](size_t i) { return *results_[i]; }
    370   const URLResult& operator[](size_t i) const { return *results_[i]; }
    371 
    372   URLResultVector::const_iterator begin() const { return results_.begin(); }
    373   URLResultVector::const_iterator end() const { return results_.end(); }
    374   URLResultVector::const_reverse_iterator rbegin() const {
    375     return results_.rbegin();
    376   }
    377   URLResultVector::const_reverse_iterator rend() const {
    378     return results_.rend();
    379   }
    380 
    381   // Returns a pointer to the beginning of an array of all matching indices
    382   // for entries with the given URL. The array will be |*num_matches| long.
    383   // |num_matches| can be NULL if the caller is not interested in the number of
    384   // results (commonly it will only be interested in the first one and can test
    385   // the pointer for NULL).
    386   //
    387   // When there is no match, it will return NULL and |*num_matches| will be 0.
    388   const size_t* MatchesForURL(const GURL& url, size_t* num_matches) const;
    389 
    390   // Swaps the current result with another. This allows ownership to be
    391   // efficiently transferred without copying.
    392   void Swap(QueryResults* other);
    393 
    394   // Adds the given result to the map, using swap() on the members to avoid
    395   // copying (there are a lot of strings and vectors). This means the parameter
    396   // object will be cleared after this call.
    397   void AppendURLBySwapping(URLResult* result);
    398 
    399   // Removes all instances of the given URL from the result set.
    400   void DeleteURL(const GURL& url);
    401 
    402   // Deletes the given range of items in the result set.
    403   void DeleteRange(size_t begin, size_t end);
    404 
    405  private:
    406   // Maps the given URL to a list of indices into results_ which identify each
    407   // time an entry with that URL appears. Normally, each URL will have one or
    408   // very few indices after it, so we optimize this to use statically allocated
    409   // memory when possible.
    410   typedef std::map<GURL, base::StackVector<size_t, 4> > URLToResultIndices;
    411 
    412   // Inserts an entry into the |url_to_results_| map saying that the given URL
    413   // is at the given index in the results_.
    414   void AddURLUsageAtIndex(const GURL& url, size_t index);
    415 
    416   // Adds |delta| to each index in url_to_results_ in the range [begin,end]
    417   // (this is inclusive). This is used when inserting or deleting.
    418   void AdjustResultMap(size_t begin, size_t end, ptrdiff_t delta);
    419 
    420   base::Time first_time_searched_;
    421 
    422   // Whether the query reaches the beginning of the database.
    423   bool reached_beginning_;
    424 
    425   // The ordered list of results. The pointers inside this are owned by this
    426   // QueryResults object.
    427   ScopedVector<URLResult> results_;
    428 
    429   // Maps URLs to entries in results_.
    430   URLToResultIndices url_to_results_;
    431 
    432   DISALLOW_COPY_AND_ASSIGN(QueryResults);
    433 };
    434 
    435 // QueryOptions ----------------------------------------------------------------
    436 
    437 struct QueryOptions {
    438   QueryOptions();
    439 
    440   // The time range to search for matches in. The beginning is inclusive and
    441   // the ending is exclusive. Either one (or both) may be null.
    442   //
    443   // This will match only the one recent visit of a URL. For text search
    444   // queries, if the URL was visited in the given time period, but has also
    445   // been visited more recently than that, it will not be returned. When the
    446   // text query is empty, this will return the most recent visit within the
    447   // time range.
    448   base::Time begin_time;
    449   base::Time end_time;
    450 
    451   // Sets the query time to the last |days_ago| days to the present time.
    452   void SetRecentDayRange(int days_ago);
    453 
    454   // The maximum number of results to return. The results will be sorted with
    455   // the most recent first, so older results may not be returned if there is not
    456   // enough room. When 0, this will return everything (the default).
    457   int max_count;
    458 
    459   enum DuplicateHandling {
    460     // Omit visits for which there is a more recent visit to the same URL.
    461     // Each URL in the results will appear only once.
    462     REMOVE_ALL_DUPLICATES,
    463 
    464     // Omit visits for which there is a more recent visit to the same URL on
    465     // the same day. Each URL will appear no more than once per day, where the
    466     // day is defined by the local timezone.
    467     REMOVE_DUPLICATES_PER_DAY,
    468 
    469     // Return all visits without deduping.
    470     KEEP_ALL_DUPLICATES
    471   };
    472 
    473   // Allows the caller to specify how duplicate URLs in the result set should
    474   // be handled. The default is REMOVE_DUPLICATES.
    475   DuplicateHandling duplicate_policy;
    476 
    477   // Helpers to get the effective parameters values, since a value of 0 means
    478   // "unspecified".
    479   int EffectiveMaxCount() const;
    480   int64 EffectiveBeginTime() const;
    481   int64 EffectiveEndTime() const;
    482 };
    483 
    484 // KeywordSearchTermVisit -----------------------------------------------------
    485 
    486 // KeywordSearchTermVisit is returned from GetMostRecentKeywordSearchTerms. It
    487 // gives the time and search term of the keyword visit.
    488 struct KeywordSearchTermVisit {
    489   KeywordSearchTermVisit();
    490   ~KeywordSearchTermVisit();
    491 
    492   base::string16 term;    // The search term that was used.
    493   int visits;       // The visit count.
    494   base::Time time;  // The time of the most recent visit.
    495 };
    496 
    497 // KeywordSearchTermRow --------------------------------------------------------
    498 
    499 // Used for URLs that have a search term associated with them.
    500 struct KeywordSearchTermRow {
    501   KeywordSearchTermRow();
    502   ~KeywordSearchTermRow();
    503 
    504   TemplateURLID keyword_id;  // ID of the keyword.
    505   URLID url_id;              // ID of the url.
    506   base::string16 term;             // The search term that was used.
    507 };
    508 
    509 // MostVisitedURL --------------------------------------------------------------
    510 
    511 // Holds the per-URL information of the most visited query.
    512 struct MostVisitedURL {
    513   MostVisitedURL();
    514   MostVisitedURL(const GURL& url, const base::string16& title);
    515   MostVisitedURL(const GURL& url,
    516                  const base::string16& title,
    517                  const base::Time& last_forced_time);
    518   ~MostVisitedURL();
    519 
    520   GURL url;
    521   base::string16 title;
    522 
    523   // If this is a URL for which we want to force a thumbnail, records the last
    524   // time it was forced so we can evict it when more recent URLs are requested.
    525   // If it's not a forced thumbnail, keep a time of 0.
    526   base::Time last_forced_time;
    527 
    528   RedirectList redirects;
    529 
    530   bool operator==(const MostVisitedURL& other) {
    531     return url == other.url;
    532   }
    533 };
    534 
    535 // FilteredURL -----------------------------------------------------------------
    536 
    537 // Holds the per-URL information of the filterd url query.
    538 struct FilteredURL {
    539   struct ExtendedInfo {
    540     ExtendedInfo();
    541     // The absolute number of visits.
    542     unsigned int total_visits;
    543     // The number of visits, as seen by the Most Visited NTP pane.
    544     unsigned int visits;
    545     // The total number of seconds that the page was open.
    546     int64 duration_opened;
    547     // The time when the page was last visited.
    548     base::Time last_visit_time;
    549   };
    550 
    551   FilteredURL();
    552   explicit FilteredURL(const PageUsageData& data);
    553   ~FilteredURL();
    554 
    555   GURL url;
    556   base::string16 title;
    557   double score;
    558   ExtendedInfo extended_info;
    559 };
    560 
    561 // Navigation -----------------------------------------------------------------
    562 
    563 // Marshalling structure for AddPage.
    564 struct HistoryAddPageArgs {
    565   // The default constructor is equivalent to:
    566   //
    567   //   HistoryAddPageArgs(
    568   //       GURL(), base::Time(), NULL, 0, GURL(),
    569   //       history::RedirectList(), content::PAGE_TRANSITION_LINK,
    570   //       SOURCE_BROWSED, false)
    571   HistoryAddPageArgs();
    572   HistoryAddPageArgs(const GURL& url,
    573                      base::Time time,
    574                      ContextID context_id,
    575                      int32 page_id,
    576                      const GURL& referrer,
    577                      const history::RedirectList& redirects,
    578                      content::PageTransition transition,
    579                      VisitSource source,
    580                      bool did_replace_entry);
    581   ~HistoryAddPageArgs();
    582 
    583   GURL url;
    584   base::Time time;
    585 
    586   ContextID context_id;
    587   int32 page_id;
    588 
    589   GURL referrer;
    590   history::RedirectList redirects;
    591   content::PageTransition transition;
    592   VisitSource visit_source;
    593   bool did_replace_entry;
    594 };
    595 
    596 // TopSites -------------------------------------------------------------------
    597 
    598 typedef std::vector<MostVisitedURL> MostVisitedURLList;
    599 typedef std::vector<FilteredURL> FilteredURLList;
    600 
    601 // Used by TopSites to store the thumbnails.
    602 struct Images {
    603   Images();
    604   ~Images();
    605 
    606   scoped_refptr<base::RefCountedMemory> thumbnail;
    607   ThumbnailScore thumbnail_score;
    608 
    609   // TODO(brettw): this will eventually store the favicon.
    610   // scoped_refptr<base::RefCountedBytes> favicon;
    611 };
    612 
    613 struct MostVisitedURLWithRank {
    614   MostVisitedURL url;
    615   int rank;
    616 };
    617 
    618 typedef std::vector<MostVisitedURLWithRank> MostVisitedURLWithRankList;
    619 
    620 struct TopSitesDelta {
    621   TopSitesDelta();
    622   ~TopSitesDelta();
    623 
    624   MostVisitedURLList deleted;
    625   MostVisitedURLWithRankList added;
    626   MostVisitedURLWithRankList moved;
    627 };
    628 
    629 typedef std::map<GURL, scoped_refptr<base::RefCountedBytes> > URLToThumbnailMap;
    630 
    631 // Used when migrating most visited thumbnails out of history and into topsites.
    632 struct ThumbnailMigration {
    633   ThumbnailMigration();
    634   ~ThumbnailMigration();
    635 
    636   MostVisitedURLList most_visited;
    637   URLToThumbnailMap url_to_thumbnail_map;
    638 };
    639 
    640 typedef std::map<GURL, Images> URLToImagesMap;
    641 
    642 class MostVisitedThumbnails
    643     : public base::RefCountedThreadSafe<MostVisitedThumbnails> {
    644  public:
    645   MostVisitedThumbnails();
    646 
    647   MostVisitedURLList most_visited;
    648   URLToImagesMap url_to_images_map;
    649 
    650  private:
    651   friend class base::RefCountedThreadSafe<MostVisitedThumbnails>;
    652   virtual ~MostVisitedThumbnails();
    653 
    654   DISALLOW_COPY_AND_ASSIGN(MostVisitedThumbnails);
    655 };
    656 
    657 // Autocomplete thresholds -----------------------------------------------------
    658 
    659 // Constants which specify, when considered altogether, 'significant'
    660 // history items. These are used to filter out insignificant items
    661 // for consideration as autocomplete candidates.
    662 extern const int kLowQualityMatchTypedLimit;
    663 extern const int kLowQualityMatchVisitLimit;
    664 extern const int kLowQualityMatchAgeLimitInDays;
    665 
    666 // Returns the date threshold for considering an history item as significant.
    667 base::Time AutocompleteAgeThreshold();
    668 
    669 // Return true if |row| qualifies as an autocomplete candidate. If |time_cache|
    670 // is_null() then this function determines a new time threshold each time it is
    671 // called. Since getting system time can be costly (such as for cases where
    672 // this function will be called in a loop over many history items), you can
    673 // provide a non-null |time_cache| by simply initializing |time_cache| with
    674 // AutocompleteAgeThreshold() (or any other desired time in the past).
    675 bool RowQualifiesAsSignificant(const URLRow& row, const base::Time& threshold);
    676 
    677 // Favicons -------------------------------------------------------------------
    678 
    679 // Used for the mapping between the page and icon.
    680 struct IconMapping {
    681   IconMapping();
    682   ~IconMapping();
    683 
    684   // The unique id of the mapping.
    685   IconMappingID mapping_id;
    686 
    687   // The url of a web page.
    688   GURL page_url;
    689 
    690   // The unique id of the icon.
    691   favicon_base::FaviconID icon_id;
    692 
    693   // The url of the icon.
    694   GURL icon_url;
    695 
    696   // The type of icon.
    697   favicon_base::IconType icon_type;
    698 };
    699 
    700 // Defines a favicon bitmap and its associated pixel size.
    701 struct FaviconBitmapIDSize {
    702   FaviconBitmapIDSize();
    703   ~FaviconBitmapIDSize();
    704 
    705   // The unique id of the favicon bitmap.
    706   FaviconBitmapID bitmap_id;
    707 
    708   // The pixel dimensions of the associated bitmap.
    709   gfx::Size pixel_size;
    710 };
    711 
    712 // Defines a favicon bitmap stored in the history backend.
    713 struct FaviconBitmap {
    714   FaviconBitmap();
    715   ~FaviconBitmap();
    716 
    717   // The unique id of the bitmap.
    718   FaviconBitmapID bitmap_id;
    719 
    720   // The id of the favicon to which the bitmap belongs to.
    721   favicon_base::FaviconID icon_id;
    722 
    723   // Time at which |bitmap_data| was last updated.
    724   base::Time last_updated;
    725 
    726   // The bits of the bitmap.
    727   scoped_refptr<base::RefCountedMemory> bitmap_data;
    728 
    729   // The pixel dimensions of bitmap_data.
    730   gfx::Size pixel_size;
    731 };
    732 
    733 // Abbreviated information about a visit.
    734 struct BriefVisitInfo {
    735   URLID url_id;
    736   base::Time time;
    737   content::PageTransition transition;
    738 };
    739 
    740 // An observer of VisitDatabase.
    741 class VisitDatabaseObserver {
    742  public:
    743   virtual ~VisitDatabaseObserver();
    744   virtual void OnAddVisit(const BriefVisitInfo& info) = 0;
    745 };
    746 
    747 struct ExpireHistoryArgs {
    748   ExpireHistoryArgs();
    749   ~ExpireHistoryArgs();
    750 
    751   // Sets |begin_time| and |end_time| to the beginning and end of the day (in
    752   // local time) on which |time| occurs.
    753   void SetTimeRangeForOneDay(base::Time time);
    754 
    755   std::set<GURL> urls;
    756   base::Time begin_time;
    757   base::Time end_time;
    758 };
    759 
    760 }  // namespace history
    761 
    762 #endif  // CHROME_BROWSER_HISTORY_HISTORY_TYPES_H_
    763