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

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

Issue 339433007: Componentize URLDatabase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 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 CHROME_BROWSER_HISTORY_HISTORY_TYPES_H_ 5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_URL_ROW_H_
6 #define CHROME_BROWSER_HISTORY_HISTORY_TYPES_H_ 6 #define COMPONENTS_HISTORY_CORE_BROWSER_URL_ROW_H_
7
8 #include <deque>
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <vector>
13 7
14 #include "base/basictypes.h" 8 #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" 9 #include "base/strings/string16.h"
19 #include "base/time/time.h" 10 #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/browser/keyword_id.h"
23 #include "components/history/core/common/thumbnail_score.h"
24 #include "components/query_parser/snippet.h" 11 #include "components/query_parser/snippet.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" 12 #include "url/gurl.h"
29 13
30 class PageUsageData;
31
32 namespace history { 14 namespace history {
33 15
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; 16 typedef int64 URLID;
55 17
56 // Holds all information globally associated with one URL (one row in the 18 // Holds all information globally associated with one URL (one row in the
57 // URL table). 19 // URL table).
58 // 20 //
59 // This keeps track of dirty bits, which are currently unused: 21 // This keeps track of dirty bits, which are currently unused:
60 // 22 //
61 // TODO(brettw) the dirty bits are broken in a number of respects. First, the 23 // 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 24 // database will want to update them on a const object, so they need to be
63 // mutable. 25 // mutable.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 base::Time last_visit_; 150 base::Time last_visit_;
189 151
190 // Indicates this entry should now be shown in typical UI or queries, this 152 // Indicates this entry should now be shown in typical UI or queries, this
191 // is usually for subframes. 153 // is usually for subframes.
192 bool hidden_; 154 bool hidden_;
193 155
194 // We support the implicit copy constuctor and operator=. 156 // We support the implicit copy constuctor and operator=.
195 }; 157 };
196 typedef std::vector<URLRow> URLRows; 158 typedef std::vector<URLRow> URLRows;
197 159
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 160
284 class URLResult : public URLRow { 161 class URLResult : public URLRow {
285 public: 162 public:
286 URLResult(); 163 URLResult();
287 URLResult(const GURL& url, base::Time visit_time); 164 URLResult(const GURL& url, base::Time visit_time);
288 // Constructor that create a URLResult from the specified URL and title match 165 // Constructor that create a URLResult from the specified URL and title match
289 // positions from title_matches. 166 // positions from title_matches.
290 URLResult(const GURL& url, 167 URLResult(const GURL& url,
291 const query_parser::Snippet::MatchPositions& title_matches); 168 const query_parser::Snippet::MatchPositions& title_matches);
292 explicit URLResult(const URLRow& url_row); 169 explicit URLResult(const URLRow& url_row);
(...skipping 29 matching lines...) Expand all
322 // These values are typically set by HistoryBackend. 199 // These values are typically set by HistoryBackend.
323 query_parser::Snippet snippet_; 200 query_parser::Snippet snippet_;
324 query_parser::Snippet::MatchPositions title_match_positions_; 201 query_parser::Snippet::MatchPositions title_match_positions_;
325 202
326 // Whether a managed user was blocked when attempting to visit this URL. 203 // Whether a managed user was blocked when attempting to visit this URL.
327 bool blocked_visit_; 204 bool blocked_visit_;
328 205
329 // We support the implicit copy constructor and operator=. 206 // We support the implicit copy constructor and operator=.
330 }; 207 };
331 208
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 // QueryURLResult -------------------------------------------------------------
485
486 // QueryURLResult encapsulate the result of a call to HistoryBackend::QueryURL.
487 struct QueryURLResult {
488 QueryURLResult();
489 ~QueryURLResult();
490
491 // Indicates whether the call to HistoryBackend::QueryURL was successfull
492 // or not. If false, then both |row| and |visits| fields are undefined.
493 bool success;
494 URLRow row;
495 VisitVector visits;
496 };
497
498 // KeywordSearchTermVisit -----------------------------------------------------
499
500 // KeywordSearchTermVisit is returned from GetMostRecentKeywordSearchTerms. It
501 // gives the time and search term of the keyword visit.
502 struct KeywordSearchTermVisit {
503 KeywordSearchTermVisit();
504 ~KeywordSearchTermVisit();
505
506 base::string16 term; // The search term that was used.
507 int visits; // The visit count.
508 base::Time time; // The time of the most recent visit.
509 };
510
511 // KeywordSearchTermRow --------------------------------------------------------
512
513 // Used for URLs that have a search term associated with them.
514 struct KeywordSearchTermRow {
515 KeywordSearchTermRow();
516 ~KeywordSearchTermRow();
517
518 KeywordID keyword_id; // ID of the keyword.
519 URLID url_id; // ID of the url.
520 base::string16 term; // The search term that was used.
521 };
522
523 // MostVisitedURL --------------------------------------------------------------
524
525 // Holds the per-URL information of the most visited query.
526 struct MostVisitedURL {
527 MostVisitedURL();
528 MostVisitedURL(const GURL& url, const base::string16& title);
529 MostVisitedURL(const GURL& url,
530 const base::string16& title,
531 const base::Time& last_forced_time);
532 ~MostVisitedURL();
533
534 GURL url;
535 base::string16 title;
536
537 // If this is a URL for which we want to force a thumbnail, records the last
538 // time it was forced so we can evict it when more recent URLs are requested.
539 // If it's not a forced thumbnail, keep a time of 0.
540 base::Time last_forced_time;
541
542 RedirectList redirects;
543
544 bool operator==(const MostVisitedURL& other) {
545 return url == other.url;
546 }
547 };
548
549 // FilteredURL -----------------------------------------------------------------
550
551 // Holds the per-URL information of the filterd url query.
552 struct FilteredURL {
553 struct ExtendedInfo {
554 ExtendedInfo();
555 // The absolute number of visits.
556 unsigned int total_visits;
557 // The number of visits, as seen by the Most Visited NTP pane.
558 unsigned int visits;
559 // The total number of seconds that the page was open.
560 int64 duration_opened;
561 // The time when the page was last visited.
562 base::Time last_visit_time;
563 };
564
565 FilteredURL();
566 explicit FilteredURL(const PageUsageData& data);
567 ~FilteredURL();
568
569 GURL url;
570 base::string16 title;
571 double score;
572 ExtendedInfo extended_info;
573 };
574
575 // Navigation -----------------------------------------------------------------
576
577 // Marshalling structure for AddPage.
578 struct HistoryAddPageArgs {
579 // The default constructor is equivalent to:
580 //
581 // HistoryAddPageArgs(
582 // GURL(), base::Time(), NULL, 0, GURL(),
583 // history::RedirectList(), content::PAGE_TRANSITION_LINK,
584 // SOURCE_BROWSED, false)
585 HistoryAddPageArgs();
586 HistoryAddPageArgs(const GURL& url,
587 base::Time time,
588 ContextID context_id,
589 int32 page_id,
590 const GURL& referrer,
591 const history::RedirectList& redirects,
592 content::PageTransition transition,
593 VisitSource source,
594 bool did_replace_entry);
595 ~HistoryAddPageArgs();
596
597 GURL url;
598 base::Time time;
599
600 ContextID context_id;
601 int32 page_id;
602
603 GURL referrer;
604 history::RedirectList redirects;
605 content::PageTransition transition;
606 VisitSource visit_source;
607 bool did_replace_entry;
608 };
609
610 // TopSites -------------------------------------------------------------------
611
612 typedef std::vector<MostVisitedURL> MostVisitedURLList;
613 typedef std::vector<FilteredURL> FilteredURLList;
614
615 // Used by TopSites to store the thumbnails.
616 struct Images {
617 Images();
618 ~Images();
619
620 scoped_refptr<base::RefCountedMemory> thumbnail;
621 ThumbnailScore thumbnail_score;
622
623 // TODO(brettw): this will eventually store the favicon.
624 // scoped_refptr<base::RefCountedBytes> favicon;
625 };
626
627 struct MostVisitedURLWithRank {
628 MostVisitedURL url;
629 int rank;
630 };
631
632 typedef std::vector<MostVisitedURLWithRank> MostVisitedURLWithRankList;
633
634 struct TopSitesDelta {
635 TopSitesDelta();
636 ~TopSitesDelta();
637
638 MostVisitedURLList deleted;
639 MostVisitedURLWithRankList added;
640 MostVisitedURLWithRankList moved;
641 };
642
643 typedef std::map<GURL, scoped_refptr<base::RefCountedBytes> > URLToThumbnailMap;
644
645 // Used when migrating most visited thumbnails out of history and into topsites.
646 struct ThumbnailMigration {
647 ThumbnailMigration();
648 ~ThumbnailMigration();
649
650 MostVisitedURLList most_visited;
651 URLToThumbnailMap url_to_thumbnail_map;
652 };
653
654 typedef std::map<GURL, Images> URLToImagesMap;
655
656 class MostVisitedThumbnails
657 : public base::RefCountedThreadSafe<MostVisitedThumbnails> {
658 public:
659 MostVisitedThumbnails();
660
661 MostVisitedURLList most_visited;
662 URLToImagesMap url_to_images_map;
663
664 private:
665 friend class base::RefCountedThreadSafe<MostVisitedThumbnails>;
666 virtual ~MostVisitedThumbnails();
667
668 DISALLOW_COPY_AND_ASSIGN(MostVisitedThumbnails);
669 };
670
671 // Autocomplete thresholds -----------------------------------------------------
672
673 // Constants which specify, when considered altogether, 'significant'
674 // history items. These are used to filter out insignificant items
675 // for consideration as autocomplete candidates.
676 extern const int kLowQualityMatchTypedLimit;
677 extern const int kLowQualityMatchVisitLimit;
678 extern const int kLowQualityMatchAgeLimitInDays;
679
680 // Returns the date threshold for considering an history item as significant.
681 base::Time AutocompleteAgeThreshold();
682
683 // Return true if |row| qualifies as an autocomplete candidate. If |time_cache|
684 // is_null() then this function determines a new time threshold each time it is
685 // called. Since getting system time can be costly (such as for cases where
686 // this function will be called in a loop over many history items), you can
687 // provide a non-null |time_cache| by simply initializing |time_cache| with
688 // AutocompleteAgeThreshold() (or any other desired time in the past).
689 bool RowQualifiesAsSignificant(const URLRow& row, const base::Time& threshold);
690
691 // Favicons -------------------------------------------------------------------
692
693 // Used for the mapping between the page and icon.
694 struct IconMapping {
695 IconMapping();
696 ~IconMapping();
697
698 // The unique id of the mapping.
699 IconMappingID mapping_id;
700
701 // The url of a web page.
702 GURL page_url;
703
704 // The unique id of the icon.
705 favicon_base::FaviconID icon_id;
706
707 // The url of the icon.
708 GURL icon_url;
709
710 // The type of icon.
711 favicon_base::IconType icon_type;
712 };
713
714 // Defines a favicon bitmap and its associated pixel size.
715 struct FaviconBitmapIDSize {
716 FaviconBitmapIDSize();
717 ~FaviconBitmapIDSize();
718
719 // The unique id of the favicon bitmap.
720 FaviconBitmapID bitmap_id;
721
722 // The pixel dimensions of the associated bitmap.
723 gfx::Size pixel_size;
724 };
725
726 // Defines a favicon bitmap stored in the history backend.
727 struct FaviconBitmap {
728 FaviconBitmap();
729 ~FaviconBitmap();
730
731 // The unique id of the bitmap.
732 FaviconBitmapID bitmap_id;
733
734 // The id of the favicon to which the bitmap belongs to.
735 favicon_base::FaviconID icon_id;
736
737 // Time at which |bitmap_data| was last updated.
738 base::Time last_updated;
739
740 // The bits of the bitmap.
741 scoped_refptr<base::RefCountedMemory> bitmap_data;
742
743 // The pixel dimensions of bitmap_data.
744 gfx::Size pixel_size;
745 };
746
747 // Abbreviated information about a visit.
748 struct BriefVisitInfo {
749 URLID url_id;
750 base::Time time;
751 content::PageTransition transition;
752 };
753
754 // An observer of VisitDatabase.
755 class VisitDatabaseObserver {
756 public:
757 virtual ~VisitDatabaseObserver();
758 virtual void OnAddVisit(const BriefVisitInfo& info) = 0;
759 };
760
761 struct ExpireHistoryArgs {
762 ExpireHistoryArgs();
763 ~ExpireHistoryArgs();
764
765 // Sets |begin_time| and |end_time| to the beginning and end of the day (in
766 // local time) on which |time| occurs.
767 void SetTimeRangeForOneDay(base::Time time);
768
769 std::set<GURL> urls;
770 base::Time begin_time;
771 base::Time end_time;
772 };
773
774 } // namespace history 209 } // namespace history
775 210
776 #endif // CHROME_BROWSER_HISTORY_HISTORY_TYPES_H_ 211 #endif // COMPONENTS_HISTORY_CORE_BROWSER_URL_ROW_H_
OLDNEW
« no previous file with comments | « components/history/core/browser/url_database_unittest.cc ('k') | components/history/core/browser/url_row.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698