OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_URL_ROW_H_ | 5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_URL_ROW_H_ |
6 #define COMPONENTS_HISTORY_CORE_BROWSER_URL_ROW_H_ | 6 #define COMPONENTS_HISTORY_CORE_BROWSER_URL_ROW_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "components/query_parser/snippet.h" | 12 #include "components/query_parser/snippet.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 namespace history { | 15 namespace history { |
16 | 16 |
17 typedef int64_t URLID; | 17 typedef int64_t URLID; |
18 | 18 |
19 // Holds all information globally associated with one URL (one row in the | 19 // Holds all information globally associated with one URL (one row in the |
20 // URL table). | 20 // URL table). |
21 // | |
22 // This keeps track of dirty bits, which are currently unused: | |
23 // | |
24 // TODO(brettw) the dirty bits are broken in a number of respects. First, the | |
25 // database will want to update them on a const object, so they need to be | |
26 // mutable. | |
27 // | |
28 // Second, there is a problem copying. If you make a copy of this structure | |
29 // (as we allow since we put this into vectors in various places) then the | |
30 // dirty bits will not be in sync for these copies. | |
31 class URLRow { | 21 class URLRow { |
32 public: | 22 public: |
33 URLRow(); | 23 URLRow(); |
34 | 24 |
35 explicit URLRow(const GURL& url); | 25 explicit URLRow(const GURL& url); |
36 | 26 |
37 // We need to be able to set the id of a URLRow that's being passed through | 27 // We need to be able to set the id of a URLRow that's being passed through |
38 // an IPC message. This constructor should probably not be used otherwise. | 28 // an IPC message. This constructor should probably not be used otherwise. |
39 URLRow(const GURL& url, URLID id); | 29 URLRow(const GURL& url, URLID id); |
40 | 30 |
41 URLRow(const URLRow& other); | 31 URLRow(const URLRow& other); |
| 32 URLRow(URLRow&&) noexcept; |
42 | 33 |
43 virtual ~URLRow(); | 34 virtual ~URLRow(); |
44 URLRow& operator=(const URLRow& other); | 35 URLRow& operator=(const URLRow& other); |
45 | 36 |
46 URLID id() const { return id_; } | 37 URLID id() const { return id_; } |
47 | 38 |
48 // Sets the id of the row. The id should only be manually set when a row has | 39 // Sets the id of the row. The id should only be manually set when a row has |
49 // been retrieved from the history database or other dataset based on criteria | 40 // been retrieved from the history database or other dataset based on criteria |
50 // other than its id (i.e. by URL) and when the id has not yet been set in the | 41 // other than its id (i.e. by URL) and when the id has not yet been set in the |
51 // row. | 42 // row. |
52 void set_id(URLID id) { id_ = id; } | 43 void set_id(URLID id) { id_ = id; } |
53 | 44 |
| 45 void set_url(const GURL& url) { url_ = url; } |
54 const GURL& url() const { return url_; } | 46 const GURL& url() const { return url_; } |
55 | 47 |
56 const base::string16& title() const { | 48 const base::string16& title() const { |
57 return title_; | 49 return title_; |
58 } | 50 } |
59 void set_title(const base::string16& title) { | 51 void set_title(const base::string16& title) { |
60 // The title is frequently set to the same thing, so we don't bother | 52 // The title is frequently set to the same thing, so we don't bother |
61 // updating unless the string has changed. | 53 // updating unless the string has changed. |
62 if (title != title_) { | 54 if (title != title_) { |
63 title_ = title; | 55 title_ = title; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 private: | 106 private: |
115 const GURL& url_; | 107 const GURL& url_; |
116 }; | 108 }; |
117 | 109 |
118 protected: | 110 protected: |
119 // Swaps the contents of this URLRow with another, which allows it to be | 111 // Swaps the contents of this URLRow with another, which allows it to be |
120 // destructively copied without memory allocations. | 112 // destructively copied without memory allocations. |
121 void Swap(URLRow* other); | 113 void Swap(URLRow* other); |
122 | 114 |
123 private: | 115 private: |
124 // This class writes directly into this structure and clears our dirty bits | |
125 // when reading out of the DB. | |
126 friend class URLDatabase; | |
127 friend class HistoryBackend; | |
128 | |
129 // Initializes all values that need initialization to their defaults. | |
130 // This excludes objects which autoinitialize such as strings. | |
131 void Initialize(); | |
132 | |
133 // The row ID of this URL from the history database. This is immutable except | 116 // The row ID of this URL from the history database. This is immutable except |
134 // when retrieving the row from the database or when determining if the URL | 117 // when retrieving the row from the database or when determining if the URL |
135 // referenced by the URLRow already exists in the database. | 118 // referenced by the URLRow already exists in the database. |
136 URLID id_; | 119 URLID id_ = 0; |
137 | 120 |
138 // The URL of this row. Immutable except for the database which sets it | 121 // The URL of this row. Immutable except for the database which sets it |
139 // when it pulls them out. If clients want to change it, they must use | 122 // when it pulls them out. If clients want to change it, they must use |
140 // the constructor to make a new one. | 123 // the constructor to make a new one. |
141 GURL url_; | 124 GURL url_; |
142 | 125 |
143 base::string16 title_; | 126 base::string16 title_; |
144 | 127 |
145 // Total number of times this URL has been visited. | 128 // Total number of times this URL has been visited. |
146 int visit_count_; | 129 int visit_count_ = 0; |
147 | 130 |
148 // Number of times this URL has been manually entered in the URL bar. | 131 // Number of times this URL has been manually entered in the URL bar. |
149 int typed_count_; | 132 int typed_count_ = 0; |
150 | 133 |
151 // The date of the last visit of this URL, which saves us from having to | 134 // The date of the last visit of this URL, which saves us from having to |
152 // loop up in the visit table for things like autocomplete and expiration. | 135 // loop up in the visit table for things like autocomplete and expiration. |
153 base::Time last_visit_; | 136 base::Time last_visit_; |
154 | 137 |
155 // Indicates this entry should now be shown in typical UI or queries, this | 138 // Indicates this entry should now be shown in typical UI or queries, this |
156 // is usually for subframes. | 139 // is usually for subframes. |
157 bool hidden_; | 140 bool hidden_ = false; |
158 | 141 |
159 // We support the implicit copy constuctor and operator=. | 142 // We support the implicit copy constuctor and operator=. |
160 }; | 143 }; |
161 typedef std::vector<URLRow> URLRows; | 144 typedef std::vector<URLRow> URLRows; |
162 | 145 |
163 | 146 |
164 class URLResult : public URLRow { | 147 class URLResult : public URLRow { |
165 public: | 148 public: |
166 URLResult(); | 149 URLResult(); |
167 URLResult(const GURL& url, base::Time visit_time); | 150 URLResult(const GURL& url, base::Time visit_time); |
168 // Constructor that create a URLResult from the specified URL and title match | 151 URLResult(const URLRow& url_row); |
169 // positions from title_matches. | |
170 URLResult(const GURL& url, | |
171 const query_parser::Snippet::MatchPositions& title_matches); | |
172 explicit URLResult(const URLRow& url_row); | |
173 URLResult(const URLResult& other); | 152 URLResult(const URLResult& other); |
| 153 URLResult(URLResult&&) noexcept; |
174 ~URLResult() override; | 154 ~URLResult() override; |
175 | 155 |
| 156 URLResult& operator=(const URLResult&); |
| 157 |
176 base::Time visit_time() const { return visit_time_; } | 158 base::Time visit_time() const { return visit_time_; } |
177 void set_visit_time(base::Time visit_time) { visit_time_ = visit_time; } | 159 void set_visit_time(base::Time visit_time) { visit_time_ = visit_time; } |
178 | 160 |
179 const query_parser::Snippet& snippet() const { return snippet_; } | 161 const query_parser::Snippet& snippet() const { return snippet_; } |
180 | 162 |
181 bool blocked_visit() const { return blocked_visit_; } | 163 bool blocked_visit() const { return blocked_visit_; } |
182 void set_blocked_visit(bool blocked_visit) { | 164 void set_blocked_visit(bool blocked_visit) { |
183 blocked_visit_ = blocked_visit; | 165 blocked_visit_ = blocked_visit; |
184 } | 166 } |
185 | 167 |
(...skipping 12 matching lines...) Expand all Loading... |
198 friend class HistoryBackend; | 180 friend class HistoryBackend; |
199 | 181 |
200 // The time that this result corresponds to. | 182 // The time that this result corresponds to. |
201 base::Time visit_time_; | 183 base::Time visit_time_; |
202 | 184 |
203 // These values are typically set by HistoryBackend. | 185 // These values are typically set by HistoryBackend. |
204 query_parser::Snippet snippet_; | 186 query_parser::Snippet snippet_; |
205 query_parser::Snippet::MatchPositions title_match_positions_; | 187 query_parser::Snippet::MatchPositions title_match_positions_; |
206 | 188 |
207 // Whether a managed user was blocked when attempting to visit this URL. | 189 // Whether a managed user was blocked when attempting to visit this URL. |
208 bool blocked_visit_; | 190 bool blocked_visit_ = false; |
209 | 191 |
210 // We support the implicit copy constructor and operator=. | 192 // We support the implicit copy constructor and operator=. |
211 }; | 193 }; |
212 | 194 |
213 } // namespace history | 195 } // namespace history |
214 | 196 |
215 #endif // COMPONENTS_HISTORY_CORE_BROWSER_URL_ROW_H_ | 197 #endif // COMPONENTS_HISTORY_CORE_BROWSER_URL_ROW_H_ |
OLD | NEW |