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

Side by Side Diff: components/history/core/browser/history_types.h

Issue 2781263002: Some C++11 cleanup of history types. (Closed)
Patch Set: Fix Android Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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_HISTORY_TYPES_H_ 5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_TYPES_H_
6 #define COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_TYPES_H_ 6 #define COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_TYPES_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 public: 71 public:
72 VisitRow(); 72 VisitRow();
73 VisitRow(URLID arg_url_id, 73 VisitRow(URLID arg_url_id,
74 base::Time arg_visit_time, 74 base::Time arg_visit_time,
75 VisitID arg_referring_visit, 75 VisitID arg_referring_visit,
76 ui::PageTransition arg_transition, 76 ui::PageTransition arg_transition,
77 SegmentID arg_segment_id); 77 SegmentID arg_segment_id);
78 ~VisitRow(); 78 ~VisitRow();
79 79
80 // ID of this row (visit ID, used a a referrer for other visits). 80 // ID of this row (visit ID, used a a referrer for other visits).
81 VisitID visit_id; 81 VisitID visit_id = 0;
82 82
83 // Row ID into the URL table of the URL that this page is. 83 // Row ID into the URL table of the URL that this page is.
84 URLID url_id; 84 URLID url_id = 0;
85 85
86 base::Time visit_time; 86 base::Time visit_time;
87 87
88 // Indicates another visit that was the referring page for this one. 88 // Indicates another visit that was the referring page for this one.
89 // 0 indicates no referrer. 89 // 0 indicates no referrer.
90 VisitID referring_visit; 90 VisitID referring_visit = 0;
91 91
92 // A combination of bits from PageTransition. 92 // A combination of bits from PageTransition.
93 ui::PageTransition transition; 93 ui::PageTransition transition = ui::PAGE_TRANSITION_LINK;
94 94
95 // The segment id (see visitsegment_database.*). 95 // The segment id (see visitsegment_database.*).
96 // If 0, the segment id is null in the table. 96 // If 0, the segment id is null in the table.
97 SegmentID segment_id; 97 SegmentID segment_id = 0;
98 98
99 // Record how much time a user has this visit starting from the user 99 // Record how much time a user has this visit starting from the user
100 // opened this visit to the user closed or ended this visit. 100 // opened this visit to the user closed or ended this visit.
101 // This includes both active and inactive time as long as 101 // This includes both active and inactive time as long as
102 // the visit was present. 102 // the visit was present.
103 base::TimeDelta visit_duration; 103 base::TimeDelta visit_duration;
104 104
105 // Compares two visits based on dates, for sorting. 105 // Compares two visits based on dates, for sorting.
106 bool operator<(const VisitRow& other) { 106 bool operator<(const VisitRow& other) const {
107 return visit_time < other.visit_time; 107 return visit_time < other.visit_time;
108 } 108 }
109 109
110 // We allow the implicit copy constuctor and operator=. 110 // We allow the implicit copy constuctor and operator=.
111 }; 111 };
112 112
113 // We pass around vectors of visits a lot 113 // We pass around vectors of visits a lot
114 typedef std::vector<VisitRow> VisitVector; 114 typedef std::vector<VisitRow> VisitVector;
115 115
116 // The basic information associated with a visit (timestamp, type of visit), 116 // The basic information associated with a visit (timestamp, type of visit),
117 // used by HistoryBackend::AddVisits() to create new visits for a URL. 117 // used by HistoryBackend::AddVisits() to create new visits for a URL.
118 typedef std::pair<base::Time, ui::PageTransition> VisitInfo; 118 typedef std::pair<base::Time, ui::PageTransition> VisitInfo;
119 119
120 // PageVisit ------------------------------------------------------------------ 120 // PageVisit ------------------------------------------------------------------
121 121
122 // Represents a simplified version of a visit for external users. Normally, 122 // Represents a simplified version of a visit for external users. Normally,
123 // views are only interested in the time, and not the other information 123 // views are only interested in the time, and not the other information
124 // associated with a VisitRow. 124 // associated with a VisitRow.
125 struct PageVisit { 125 struct PageVisit {
126 URLID page_id; 126 URLID page_id = 0;
127 base::Time visit_time; 127 base::Time visit_time;
128 }; 128 };
129 129
130 // QueryResults ---------------------------------------------------------------- 130 // QueryResults ----------------------------------------------------------------
131 131
132 // Encapsulates the results of a history query. It supports an ordered list of 132 // Encapsulates the results of a history query. It supports an ordered list of
133 // URLResult objects, plus an efficient way of looking up the index of each time 133 // URLResult objects, plus an efficient way of looking up the index of each time
134 // a given URL appears in those results. 134 // a given URL appears in those results.
135 class QueryResults { 135 class QueryResults {
136 public: 136 public:
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 void DeleteURL(const GURL& url); 198 void DeleteURL(const GURL& url);
199 199
200 // Deletes the given range of items in the result set. 200 // Deletes the given range of items in the result set.
201 void DeleteRange(size_t begin, size_t end); 201 void DeleteRange(size_t begin, size_t end);
202 202
203 private: 203 private:
204 // Maps the given URL to a list of indices into results_ which identify each 204 // Maps the given URL to a list of indices into results_ which identify each
205 // time an entry with that URL appears. Normally, each URL will have one or 205 // time an entry with that URL appears. Normally, each URL will have one or
206 // very few indices after it, so we optimize this to use statically allocated 206 // very few indices after it, so we optimize this to use statically allocated
207 // memory when possible. 207 // memory when possible.
208 typedef std::map<GURL, base::StackVector<size_t, 4> > URLToResultIndices; 208 typedef std::map<GURL, base::StackVector<size_t, 4>> URLToResultIndices;
209 209
210 // Inserts an entry into the |url_to_results_| map saying that the given URL 210 // Inserts an entry into the |url_to_results_| map saying that the given URL
211 // is at the given index in the results_. 211 // is at the given index in the results_.
212 void AddURLUsageAtIndex(const GURL& url, size_t index); 212 void AddURLUsageAtIndex(const GURL& url, size_t index);
213 213
214 // Adds |delta| to each index in url_to_results_ in the range [begin,end] 214 // Adds |delta| to each index in url_to_results_ in the range [begin,end]
215 // (this is inclusive). This is used when inserting or deleting. 215 // (this is inclusive). This is used when inserting or deleting.
216 void AdjustResultMap(size_t begin, size_t end, ptrdiff_t delta); 216 void AdjustResultMap(size_t begin, size_t end, ptrdiff_t delta);
217 217
218 base::Time first_time_searched_; 218 base::Time first_time_searched_;
(...skipping 25 matching lines...) Expand all
244 // text query is empty, this will return the most recent visit within the 244 // text query is empty, this will return the most recent visit within the
245 // time range. 245 // time range.
246 base::Time begin_time; 246 base::Time begin_time;
247 base::Time end_time; 247 base::Time end_time;
248 248
249 // Sets the query time to the last |days_ago| days to the present time. 249 // Sets the query time to the last |days_ago| days to the present time.
250 void SetRecentDayRange(int days_ago); 250 void SetRecentDayRange(int days_ago);
251 251
252 // The maximum number of results to return. The results will be sorted with 252 // The maximum number of results to return. The results will be sorted with
253 // the most recent first, so older results may not be returned if there is not 253 // the most recent first, so older results may not be returned if there is not
254 // enough room. When 0, this will return everything (the default). 254 // enough room. When 0, this will return everything.
255 int max_count; 255 int max_count = 0;
256 256
257 enum DuplicateHandling { 257 enum DuplicateHandling {
258 // Omit visits for which there is a more recent visit to the same URL. 258 // Omit visits for which there is a more recent visit to the same URL.
259 // Each URL in the results will appear only once. 259 // Each URL in the results will appear only once.
260 REMOVE_ALL_DUPLICATES, 260 REMOVE_ALL_DUPLICATES,
261 261
262 // Omit visits for which there is a more recent visit to the same URL on 262 // Omit visits for which there is a more recent visit to the same URL on
263 // the same day. Each URL will appear no more than once per day, where the 263 // the same day. Each URL will appear no more than once per day, where the
264 // day is defined by the local timezone. 264 // day is defined by the local timezone.
265 REMOVE_DUPLICATES_PER_DAY, 265 REMOVE_DUPLICATES_PER_DAY,
266 266
267 // Return all visits without deduping. 267 // Return all visits without deduping.
268 KEEP_ALL_DUPLICATES 268 KEEP_ALL_DUPLICATES
269 }; 269 };
270 270
271 // Allows the caller to specify how duplicate URLs in the result set should 271 // Allows the caller to specify how duplicate URLs in the result set should
272 // be handled. The default is REMOVE_DUPLICATES. 272 // be handled.
273 DuplicateHandling duplicate_policy; 273 DuplicateHandling duplicate_policy = REMOVE_ALL_DUPLICATES;
274 274
275 // Allows the caller to specify the matching algorithm for text queries. 275 // Allows the caller to specify the matching algorithm for text queries.
276 query_parser::MatchingAlgorithm matching_algorithm; 276 query_parser::MatchingAlgorithm matching_algorithm =
277 query_parser::MatchingAlgorithm::DEFAULT;
277 278
278 // Helpers to get the effective parameters values, since a value of 0 means 279 // Helpers to get the effective parameters values, since a value of 0 means
279 // "unspecified". 280 // "unspecified".
280 int EffectiveMaxCount() const; 281 int EffectiveMaxCount() const;
281 int64_t EffectiveBeginTime() const; 282 int64_t EffectiveBeginTime() const;
282 int64_t EffectiveEndTime() const; 283 int64_t EffectiveEndTime() const;
283 }; 284 };
284 285
285 // QueryURLResult ------------------------------------------------------------- 286 // QueryURLResult -------------------------------------------------------------
286 287
287 // QueryURLResult encapsulates the result of a call to HistoryBackend::QueryURL. 288 // QueryURLResult encapsulates the result of a call to HistoryBackend::QueryURL.
288 struct QueryURLResult { 289 struct QueryURLResult {
289 QueryURLResult(); 290 QueryURLResult();
290 ~QueryURLResult(); 291 ~QueryURLResult();
291 292
292 // Indicates whether the call to HistoryBackend::QueryURL was successfull 293 // Indicates whether the call to HistoryBackend::QueryURL was successfull
293 // or not. If false, then both |row| and |visits| fields are undefined. 294 // or not. If false, then both |row| and |visits| fields are undefined.
294 bool success; 295 bool success = false;
295 URLRow row; 296 URLRow row;
296 VisitVector visits; 297 VisitVector visits;
297 }; 298 };
298 299
299 // VisibleVisitCountToHostResult ---------------------------------------------- 300 // VisibleVisitCountToHostResult ----------------------------------------------
300 301
301 // VisibleVisitCountToHostResult encapsulates the result of a call to 302 // VisibleVisitCountToHostResult encapsulates the result of a call to
302 // HistoryBackend::GetVisibleVisitCountToHost. 303 // HistoryBackend::GetVisibleVisitCountToHost.
303 struct VisibleVisitCountToHostResult { 304 struct VisibleVisitCountToHostResult {
304 // Indicates whether the call to HistoryBackend::GetVisibleVisitCountToHost 305 // Indicates whether the call to HistoryBackend::GetVisibleVisitCountToHost
305 // was successful or not. If false, then both |count| and |first_visit| are 306 // was successful or not. If false, then both |count| and |first_visit| are
306 // undefined. 307 // undefined.
307 bool success; 308 bool success = false;
308 int count; 309 int count = 0;
309 base::Time first_visit; 310 base::Time first_visit;
310 }; 311 };
311 312
312 // MostVisitedURL -------------------------------------------------------------- 313 // MostVisitedURL --------------------------------------------------------------
313 314
314 // Holds the per-URL information of the most visited query. 315 // Holds the per-URL information of the most visited query.
315 struct MostVisitedURL { 316 struct MostVisitedURL {
316 MostVisitedURL(); 317 MostVisitedURL();
317 MostVisitedURL(const GURL& url, const base::string16& title);
318 MostVisitedURL(const GURL& url, 318 MostVisitedURL(const GURL& url,
319 const base::string16& title, 319 const base::string16& title,
320 const base::Time& last_forced_time); 320 base::Time last_forced_time = base::Time());
321 MostVisitedURL(const MostVisitedURL& other); 321 MostVisitedURL(const MostVisitedURL& other);
322 MostVisitedURL(MostVisitedURL&& other) noexcept;
322 ~MostVisitedURL(); 323 ~MostVisitedURL();
323 324
324 GURL url; 325 GURL url;
325 base::string16 title; 326 base::string16 title;
326 327
327 // If this is a URL for which we want to force a thumbnail, records the last 328 // If this is a URL for which we want to force a thumbnail, records the last
328 // time it was forced so we can evict it when more recent URLs are requested. 329 // time it was forced so we can evict it when more recent URLs are requested.
329 // If it's not a forced thumbnail, keep a time of 0. 330 // If it's not a forced thumbnail, keep a time of 0.
330 base::Time last_forced_time; 331 base::Time last_forced_time;
331 332
332 RedirectList redirects; 333 RedirectList redirects;
333 334
335 MostVisitedURL& operator=(const MostVisitedURL&);
336
334 bool operator==(const MostVisitedURL& other) const { 337 bool operator==(const MostVisitedURL& other) const {
335 return url == other.url; 338 return url == other.url;
336 } 339 }
337 }; 340 };
338 341
339 // FilteredURL ----------------------------------------------------------------- 342 // FilteredURL -----------------------------------------------------------------
340 343
341 // Holds the per-URL information of the filterd url query. 344 // Holds the per-URL information of the filterd url query.
342 struct FilteredURL { 345 struct FilteredURL {
343 struct ExtendedInfo { 346 struct ExtendedInfo {
344 ExtendedInfo(); 347 ExtendedInfo();
345 // The absolute number of visits. 348 // The absolute number of visits.
346 unsigned int total_visits; 349 unsigned int total_visits = 0;
347 // The number of visits, as seen by the Most Visited NTP pane. 350 // The number of visits, as seen by the Most Visited NTP pane.
348 unsigned int visits; 351 unsigned int visits = 0;
349 // The total number of seconds that the page was open. 352 // The total number of seconds that the page was open.
350 int64_t duration_opened; 353 int64_t duration_opened = 0;
351 // The time when the page was last visited. 354 // The time when the page was last visited.
352 base::Time last_visit_time; 355 base::Time last_visit_time;
353 }; 356 };
354 357
355 FilteredURL(); 358 FilteredURL();
356 explicit FilteredURL(const PageUsageData& data); 359 explicit FilteredURL(const PageUsageData& data);
360 FilteredURL(FilteredURL&& other) noexcept;
357 ~FilteredURL(); 361 ~FilteredURL();
358 362
359 GURL url; 363 GURL url;
360 base::string16 title; 364 base::string16 title;
361 double score; 365 double score = 0.0;
362 ExtendedInfo extended_info; 366 ExtendedInfo extended_info;
363 }; 367 };
364 368
365 // Navigation ----------------------------------------------------------------- 369 // Navigation -----------------------------------------------------------------
366 370
367 // Marshalling structure for AddPage. 371 // Marshalling structure for AddPage.
368 struct HistoryAddPageArgs { 372 struct HistoryAddPageArgs {
369 // The default constructor is equivalent to: 373 // The default constructor is equivalent to:
370 // 374 //
371 // HistoryAddPageArgs( 375 // HistoryAddPageArgs(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 struct TopSitesDelta { 434 struct TopSitesDelta {
431 TopSitesDelta(); 435 TopSitesDelta();
432 TopSitesDelta(const TopSitesDelta& other); 436 TopSitesDelta(const TopSitesDelta& other);
433 ~TopSitesDelta(); 437 ~TopSitesDelta();
434 438
435 MostVisitedURLList deleted; 439 MostVisitedURLList deleted;
436 MostVisitedURLWithRankList added; 440 MostVisitedURLWithRankList added;
437 MostVisitedURLWithRankList moved; 441 MostVisitedURLWithRankList moved;
438 }; 442 };
439 443
440 typedef std::map<GURL, scoped_refptr<base::RefCountedBytes> > URLToThumbnailMap; 444 typedef std::map<GURL, scoped_refptr<base::RefCountedBytes>> URLToThumbnailMap;
441 445
442 // Used when migrating most visited thumbnails out of history and into topsites. 446 // Used when migrating most visited thumbnails out of history and into topsites.
443 struct ThumbnailMigration { 447 struct ThumbnailMigration {
444 ThumbnailMigration(); 448 ThumbnailMigration();
445 ~ThumbnailMigration(); 449 ~ThumbnailMigration();
446 450
447 MostVisitedURLList most_visited; 451 MostVisitedURLList most_visited;
448 URLToThumbnailMap url_to_thumbnail_map; 452 URLToThumbnailMap url_to_thumbnail_map;
449 }; 453 };
450 454
(...skipping 21 matching lines...) Expand all
472 // URL under that origin. 476 // URL under that origin.
473 typedef std::map<GURL, std::pair<int, base::Time>> OriginCountAndLastVisitMap; 477 typedef std::map<GURL, std::pair<int, base::Time>> OriginCountAndLastVisitMap;
474 478
475 // Statistics ----------------------------------------------------------------- 479 // Statistics -----------------------------------------------------------------
476 480
477 // HistoryCountResult encapsulates the result of a call to 481 // HistoryCountResult encapsulates the result of a call to
478 // HistoryBackend::GetHistoryCount. 482 // HistoryBackend::GetHistoryCount.
479 struct HistoryCountResult { 483 struct HistoryCountResult {
480 // Indicates whether the call to HistoryBackend::GetHistoryCount was 484 // Indicates whether the call to HistoryBackend::GetHistoryCount was
481 // successful or not. If false, then |count| is undefined. 485 // successful or not. If false, then |count| is undefined.
482 bool success; 486 bool success = false;
483 int count; 487 int count = 0;
484 }; 488 };
485 489
486 // Favicons ------------------------------------------------------------------- 490 // Favicons -------------------------------------------------------------------
487 491
488 // Used for the mapping between the page and icon. 492 // Used for the mapping between the page and icon.
489 struct IconMapping { 493 struct IconMapping {
490 IconMapping(); 494 IconMapping();
495 IconMapping(const IconMapping&);
496 IconMapping(IconMapping&&) noexcept;
491 ~IconMapping(); 497 ~IconMapping();
492 498
499 IconMapping& operator=(const IconMapping&);
500
493 // The unique id of the mapping. 501 // The unique id of the mapping.
494 IconMappingID mapping_id; 502 IconMappingID mapping_id = 0;
495 503
496 // The url of a web page. 504 // The url of a web page.
497 GURL page_url; 505 GURL page_url;
498 506
499 // The unique id of the icon. 507 // The unique id of the icon.
500 favicon_base::FaviconID icon_id; 508 favicon_base::FaviconID icon_id = 0;
501 509
502 // The url of the icon. 510 // The url of the icon.
503 GURL icon_url; 511 GURL icon_url;
504 512
505 // The type of icon. 513 // The type of icon.
506 favicon_base::IconType icon_type; 514 favicon_base::IconType icon_type = favicon_base::INVALID_ICON;
507 }; 515 };
508 516
509 // Defines a favicon bitmap and its associated pixel size. 517 // Defines a favicon bitmap and its associated pixel size.
510 struct FaviconBitmapIDSize { 518 struct FaviconBitmapIDSize {
511 FaviconBitmapIDSize(); 519 FaviconBitmapIDSize();
512 ~FaviconBitmapIDSize(); 520 ~FaviconBitmapIDSize();
513 521
514 // The unique id of the favicon bitmap. 522 // The unique id of the favicon bitmap.
515 FaviconBitmapID bitmap_id; 523 FaviconBitmapID bitmap_id = 0;
516 524
517 // The pixel dimensions of the associated bitmap. 525 // The pixel dimensions of the associated bitmap.
518 gfx::Size pixel_size; 526 gfx::Size pixel_size;
519 }; 527 };
520 528
521 // Defines a favicon bitmap stored in the history backend. 529 // Defines a favicon bitmap stored in the history backend.
522 struct FaviconBitmap { 530 struct FaviconBitmap {
523 FaviconBitmap(); 531 FaviconBitmap();
524 FaviconBitmap(const FaviconBitmap& other); 532 FaviconBitmap(const FaviconBitmap& other);
525 ~FaviconBitmap(); 533 ~FaviconBitmap();
526 534
527 // The unique id of the bitmap. 535 // The unique id of the bitmap.
528 FaviconBitmapID bitmap_id; 536 FaviconBitmapID bitmap_id = 0;
529 537
530 // The id of the favicon to which the bitmap belongs to. 538 // The id of the favicon to which the bitmap belongs to.
531 favicon_base::FaviconID icon_id; 539 favicon_base::FaviconID icon_id = 0;
532 540
533 // Time at which |bitmap_data| was last updated. 541 // Time at which |bitmap_data| was last updated.
534 base::Time last_updated; 542 base::Time last_updated;
535 543
536 // Time at which |bitmap_data| was last requested. 544 // Time at which |bitmap_data| was last requested.
537 base::Time last_requested; 545 base::Time last_requested;
538 546
539 // The bits of the bitmap. 547 // The bits of the bitmap.
540 scoped_refptr<base::RefCountedMemory> bitmap_data; 548 scoped_refptr<base::RefCountedMemory> bitmap_data;
541 549
(...skipping 11 matching lines...) Expand all
553 void SetTimeRangeForOneDay(base::Time time); 561 void SetTimeRangeForOneDay(base::Time time);
554 562
555 std::set<GURL> urls; 563 std::set<GURL> urls;
556 base::Time begin_time; 564 base::Time begin_time;
557 base::Time end_time; 565 base::Time end_time;
558 }; 566 };
559 567
560 } // namespace history 568 } // namespace history
561 569
562 #endif // COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_TYPES_H_ 570 #endif // COMPONENTS_HISTORY_CORE_BROWSER_HISTORY_TYPES_H_
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend.cc ('k') | components/history/core/browser/history_types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698