Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / history / history_types.h
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 "components/history/core/browser/history_types.h"
9 #include "content/public/common/page_transition_types.h"
10
11 namespace content {
12 class WebContents;
13 }
14
15 namespace history {
16
17 // Identifier for a context to scope page ids. (ContextIDs are used in
18 // comparisons only and are never dereferenced.)
19 // NB: The use of WebContents here is temporary; when the dependency on content
20 // is broken, some other type will take its place.
21 typedef content::WebContents* ContextID;
22
23 // VisitRow -------------------------------------------------------------------
24
25 // Holds all information associated with a specific visit. A visit holds time
26 // and referrer information for one time a URL is visited.
27 class VisitRow {
28  public:
29   VisitRow();
30   VisitRow(URLID arg_url_id,
31            base::Time arg_visit_time,
32            VisitID arg_referring_visit,
33            content::PageTransition arg_transition,
34            SegmentID arg_segment_id);
35   ~VisitRow();
36
37   // ID of this row (visit ID, used a a referrer for other visits).
38   VisitID visit_id;
39
40   // Row ID into the URL table of the URL that this page is.
41   URLID url_id;
42
43   base::Time visit_time;
44
45   // Indicates another visit that was the referring page for this one.
46   // 0 indicates no referrer.
47   VisitID referring_visit;
48
49   // A combination of bits from PageTransition.
50   content::PageTransition transition;
51
52   // The segment id (see visitsegment_database.*).
53   // If 0, the segment id is null in the table.
54   SegmentID segment_id;
55
56   // Record how much time a user has this visit starting from the user
57   // opened this visit to the user closed or ended this visit.
58   // This includes both active and inactive time as long as
59   // the visit was present.
60   base::TimeDelta visit_duration;
61
62   // Compares two visits based on dates, for sorting.
63   bool operator<(const VisitRow& other) {
64     return visit_time < other.visit_time;
65   }
66
67   // We allow the implicit copy constuctor and operator=.
68 };
69
70 // We pass around vectors of visits a lot
71 typedef std::vector<VisitRow> VisitVector;
72
73 // The basic information associated with a visit (timestamp, type of visit),
74 // used by HistoryBackend::AddVisits() to create new visits for a URL.
75 typedef std::pair<base::Time, content::PageTransition> VisitInfo;
76
77 // QueryURLResult -------------------------------------------------------------
78
79 // QueryURLResult encapsulates the result of a call to HistoryBackend::QueryURL.
80 struct QueryURLResult {
81   QueryURLResult();
82   ~QueryURLResult();
83
84   // Indicates whether the call to HistoryBackend::QueryURL was successfull
85   // or not. If false, then both |row| and |visits| fields are undefined.
86   bool success;
87   URLRow row;
88   VisitVector visits;
89 };
90
91 // Navigation -----------------------------------------------------------------
92
93 // Marshalling structure for AddPage.
94 struct HistoryAddPageArgs {
95   // The default constructor is equivalent to:
96   //
97   //   HistoryAddPageArgs(
98   //       GURL(), base::Time(), NULL, 0, GURL(),
99   //       history::RedirectList(), content::PAGE_TRANSITION_LINK,
100   //       SOURCE_BROWSED, false)
101   HistoryAddPageArgs();
102   HistoryAddPageArgs(const GURL& url,
103                      base::Time time,
104                      ContextID context_id,
105                      int32 page_id,
106                      const GURL& referrer,
107                      const history::RedirectList& redirects,
108                      content::PageTransition transition,
109                      VisitSource source,
110                      bool did_replace_entry);
111   ~HistoryAddPageArgs();
112
113   GURL url;
114   base::Time time;
115
116   ContextID context_id;
117   int32 page_id;
118
119   GURL referrer;
120   history::RedirectList redirects;
121   content::PageTransition transition;
122   VisitSource visit_source;
123   bool did_replace_entry;
124 };
125
126 // Abbreviated information about a visit.
127 struct BriefVisitInfo {
128   URLID url_id;
129   base::Time time;
130   content::PageTransition transition;
131 };
132
133 // An observer of VisitDatabase.
134 class VisitDatabaseObserver {
135  public:
136   virtual ~VisitDatabaseObserver();
137   virtual void OnAddVisit(const BriefVisitInfo& info) = 0;
138 };
139
140 }  // namespace history
141
142 #endif  // CHROME_BROWSER_HISTORY_HISTORY_TYPES_H_