Home | History | Annotate | Download | only in browser
      1 // Copyright 2014 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 #include "components/history/core/browser/url_row.h"
      6 
      7 #include <algorithm>
      8 
      9 namespace history {
     10 
     11 URLRow::URLRow() {
     12   Initialize();
     13 }
     14 
     15 URLRow::URLRow(const GURL& url) : url_(url) {
     16   // Initialize will not set the URL, so our initialization above will stay.
     17   Initialize();
     18 }
     19 
     20 URLRow::URLRow(const GURL& url, URLID id) : url_(url) {
     21   // Initialize will not set the URL, so our initialization above will stay.
     22   Initialize();
     23   // Initialize will zero the id_, so set it here.
     24   id_ = id;
     25 }
     26 
     27 URLRow::~URLRow() {
     28 }
     29 
     30 URLRow& URLRow::operator=(const URLRow& other) {
     31   id_ = other.id_;
     32   url_ = other.url_;
     33   title_ = other.title_;
     34   visit_count_ = other.visit_count_;
     35   typed_count_ = other.typed_count_;
     36   last_visit_ = other.last_visit_;
     37   hidden_ = other.hidden_;
     38   return *this;
     39 }
     40 
     41 void URLRow::Swap(URLRow* other) {
     42   std::swap(id_, other->id_);
     43   url_.Swap(&other->url_);
     44   title_.swap(other->title_);
     45   std::swap(visit_count_, other->visit_count_);
     46   std::swap(typed_count_, other->typed_count_);
     47   std::swap(last_visit_, other->last_visit_);
     48   std::swap(hidden_, other->hidden_);
     49 }
     50 
     51 void URLRow::Initialize() {
     52   id_ = 0;
     53   visit_count_ = 0;
     54   typed_count_ = 0;
     55   last_visit_ = base::Time();
     56   hidden_ = false;
     57 }
     58 
     59 
     60 URLResult::URLResult()
     61     : blocked_visit_(false) {
     62 }
     63 
     64 URLResult::URLResult(const GURL& url, base::Time visit_time)
     65     : URLRow(url),
     66       visit_time_(visit_time),
     67       blocked_visit_(false) {
     68 }
     69 
     70 URLResult::URLResult(const GURL& url,
     71                      const query_parser::Snippet::MatchPositions& title_matches)
     72     : URLRow(url) {
     73   title_match_positions_ = title_matches;
     74 }
     75 URLResult::URLResult(const URLRow& url_row)
     76     : URLRow(url_row),
     77       blocked_visit_(false) {
     78 }
     79 
     80 URLResult::~URLResult() {
     81 }
     82 
     83 void URLResult::SwapResult(URLResult* other) {
     84   URLRow::Swap(other);
     85   std::swap(visit_time_, other->visit_time_);
     86   snippet_.Swap(&other->snippet_);
     87   title_match_positions_.swap(other->title_match_positions_);
     88   std::swap(blocked_visit_, other->blocked_visit_);
     89 }
     90 
     91 // static
     92 bool URLResult::CompareVisitTime(const URLResult& lhs, const URLResult& rhs) {
     93   return lhs.visit_time() > rhs.visit_time();
     94 }
     95 
     96 }  // namespace history
     97