OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "components/history/core/browser/history_backend.h" | 5 #include "components/history/core/browser/history_backend.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "components/history/core/browser/history_backend_observer.h" | 30 #include "components/history/core/browser/history_backend_observer.h" |
31 #include "components/history/core/browser/history_client.h" | 31 #include "components/history/core/browser/history_client.h" |
32 #include "components/history/core/browser/history_constants.h" | 32 #include "components/history/core/browser/history_constants.h" |
33 #include "components/history/core/browser/history_database.h" | 33 #include "components/history/core/browser/history_database.h" |
34 #include "components/history/core/browser/history_database_params.h" | 34 #include "components/history/core/browser/history_database_params.h" |
35 #include "components/history/core/browser/history_db_task.h" | 35 #include "components/history/core/browser/history_db_task.h" |
36 #include "components/history/core/browser/in_memory_history_backend.h" | 36 #include "components/history/core/browser/in_memory_history_backend.h" |
37 #include "components/history/core/browser/keyword_search_term.h" | 37 #include "components/history/core/browser/keyword_search_term.h" |
38 #include "components/history/core/browser/page_usage_data.h" | 38 #include "components/history/core/browser/page_usage_data.h" |
39 #include "components/history/core/browser/typed_url_syncable_service.h" | 39 #include "components/history/core/browser/typed_url_syncable_service.h" |
| 40 #include "components/history/core/browser/url_utils.h" |
40 #include "components/history/core/browser/visit_filter.h" | 41 #include "components/history/core/browser/visit_filter.h" |
41 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 42 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
42 #include "sql/error_delegate_util.h" | 43 #include "sql/error_delegate_util.h" |
43 #include "third_party/skia/include/core/SkBitmap.h" | 44 #include "third_party/skia/include/core/SkBitmap.h" |
44 #include "ui/gfx/codec/png_codec.h" | 45 #include "ui/gfx/codec/png_codec.h" |
45 #include "url/gurl.h" | 46 #include "url/gurl.h" |
46 #include "url/url_constants.h" | 47 #include "url/url_constants.h" |
47 | 48 |
48 #if defined(OS_IOS) | 49 #if defined(OS_IOS) |
49 #include "base/ios/scoped_critical_action.h" | 50 #include "base/ios/scoped_critical_action.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 const int kFaviconRefetchDays = 7; | 83 const int kFaviconRefetchDays = 7; |
83 | 84 |
84 // The maximum number of items we'll allow in the redirect list before | 85 // The maximum number of items we'll allow in the redirect list before |
85 // deleting some. | 86 // deleting some. |
86 const int kMaxRedirectCount = 32; | 87 const int kMaxRedirectCount = 32; |
87 | 88 |
88 // The number of days old a history entry can be before it is considered "old" | 89 // The number of days old a history entry can be before it is considered "old" |
89 // and is deleted. | 90 // and is deleted. |
90 const int kExpireDaysThreshold = 90; | 91 const int kExpireDaysThreshold = 90; |
91 | 92 |
| 93 const int kMaxTopHostsForMetrics = 50; |
| 94 |
92 // Converts from PageUsageData to MostVisitedURL. |redirects| is a | 95 // Converts from PageUsageData to MostVisitedURL. |redirects| is a |
93 // list of redirects for this URL. Empty list means no redirects. | 96 // list of redirects for this URL. Empty list means no redirects. |
94 MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data, | 97 MostVisitedURL MakeMostVisitedURL(const PageUsageData& page_data, |
95 const RedirectList& redirects) { | 98 const RedirectList& redirects) { |
96 MostVisitedURL mv; | 99 MostVisitedURL mv; |
97 mv.url = page_data.GetURL(); | 100 mv.url = page_data.GetURL(); |
98 mv.title = page_data.GetTitle(); | 101 mv.title = page_data.GetTitle(); |
99 if (redirects.empty()) { | 102 if (redirects.empty()) { |
100 // Redirects must contain at least the target url. | 103 // Redirects must contain at least the target url. |
101 mv.redirects.push_back(mv.url); | 104 mv.redirects.push_back(mv.url); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 ? end_ts - visit_row.visit_time | 412 ? end_ts - visit_row.visit_time |
410 : TimeDelta::FromMicroseconds(0); | 413 : TimeDelta::FromMicroseconds(0); |
411 db_->UpdateVisitRow(visit_row); | 414 db_->UpdateVisitRow(visit_row); |
412 } | 415 } |
413 } | 416 } |
414 | 417 |
415 TopHostsList HistoryBackend::TopHosts(int num_hosts) const { | 418 TopHostsList HistoryBackend::TopHosts(int num_hosts) const { |
416 if (!db_) | 419 if (!db_) |
417 return TopHostsList(); | 420 return TopHostsList(); |
418 | 421 |
419 return db_->TopHosts(num_hosts); | 422 auto top_hosts = db_->TopHosts(num_hosts); |
| 423 |
| 424 host_ranks_.clear(); |
| 425 int i = 0; |
| 426 for (const auto& host_count : top_hosts) |
| 427 host_ranks_[host_count.first] = ++i; |
| 428 return top_hosts; |
420 } | 429 } |
421 | 430 |
422 void HistoryBackend::AddPage(const HistoryAddPageArgs& request) { | 431 void HistoryBackend::AddPage(const HistoryAddPageArgs& request) { |
423 if (!db_) | 432 if (!db_) |
424 return; | 433 return; |
425 | 434 |
426 // Will be filled with the URL ID and the visit ID of the last addition. | 435 // Will be filled with the URL ID and the visit ID of the last addition. |
427 std::pair<URLID, VisitID> last_ids( | 436 std::pair<URLID, VisitID> last_ids( |
428 0, tracker_.GetLastVisit(request.context_id, request.nav_entry_id, | 437 0, tracker_.GetLastVisit(request.context_id, request.nav_entry_id, |
429 request.referrer)); | 438 request.referrer)); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 db_.reset(); | 727 db_.reset(); |
719 // Forget the first recorded time since the database is closed. | 728 // Forget the first recorded time since the database is closed. |
720 first_recorded_time_ = base::Time(); | 729 first_recorded_time_ = base::Time(); |
721 } | 730 } |
722 if (thumbnail_db_) { | 731 if (thumbnail_db_) { |
723 thumbnail_db_->CommitTransaction(); | 732 thumbnail_db_->CommitTransaction(); |
724 thumbnail_db_.reset(); | 733 thumbnail_db_.reset(); |
725 } | 734 } |
726 } | 735 } |
727 | 736 |
| 737 void HistoryBackend::RecordTopHostsMetrics(const GURL& url) { |
| 738 auto it = host_ranks_.find(HostForTopHosts(url)); |
| 739 int host_rank = |
| 740 it != host_ranks_.end() ? it->second : (kMaxTopHostsForMetrics + 1); |
| 741 |
| 742 UMA_HISTOGRAM_ENUMERATION("History.TopHostsVisitsByRank", host_rank, |
| 743 kMaxTopHostsForMetrics + 2); |
| 744 } |
| 745 |
728 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( | 746 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( |
729 const GURL& url, | 747 const GURL& url, |
730 Time time, | 748 Time time, |
731 VisitID referring_visit, | 749 VisitID referring_visit, |
732 ui::PageTransition transition, | 750 ui::PageTransition transition, |
733 VisitSource visit_source) { | 751 VisitSource visit_source) { |
734 // Top-level frame navigations are visible, everything else is hidden | 752 // Top-level frame navigations are visible, everything else is hidden |
735 bool new_hidden = !ui::PageTransitionIsMainFrame(transition); | 753 bool new_hidden = !ui::PageTransitionIsMainFrame(transition); |
736 | 754 |
737 // NOTE: This code must stay in sync with | 755 // NOTE: This code must stay in sync with |
738 // ExpireHistoryBackend::ExpireURLsForVisits(). | 756 // ExpireHistoryBackend::ExpireURLsForVisits(). |
739 int typed_increment = 0; | 757 int typed_increment = 0; |
740 ui::PageTransition transition_type = | 758 ui::PageTransition transition_type = |
741 ui::PageTransitionStripQualifier(transition); | 759 ui::PageTransitionStripQualifier(transition); |
742 if (ui::PageTransitionIsNewNavigation(transition) && | 760 if (ui::PageTransitionIsNewNavigation(transition) && |
743 ((transition_type == ui::PAGE_TRANSITION_TYPED && | 761 ((transition_type == ui::PAGE_TRANSITION_TYPED && |
744 !ui::PageTransitionIsRedirect(transition)) || | 762 !ui::PageTransitionIsRedirect(transition)) || |
745 transition_type == ui::PAGE_TRANSITION_KEYWORD_GENERATED)) | 763 transition_type == ui::PAGE_TRANSITION_KEYWORD_GENERATED)) |
746 typed_increment = 1; | 764 typed_increment = 1; |
747 | 765 |
| 766 if (!host_ranks_.empty() && visit_source == SOURCE_BROWSED && |
| 767 (transition & ui::PAGE_TRANSITION_CHAIN_END)) { |
| 768 RecordTopHostsMetrics(url); |
| 769 } |
| 770 |
748 // See if this URL is already in the DB. | 771 // See if this URL is already in the DB. |
749 URLRow url_info(url); | 772 URLRow url_info(url); |
750 URLID url_id = db_->GetRowForURL(url, &url_info); | 773 URLID url_id = db_->GetRowForURL(url, &url_info); |
751 if (url_id) { | 774 if (url_id) { |
752 // Update of an existing row. | 775 // Update of an existing row. |
753 if (ui::PageTransitionStripQualifier(transition) != | 776 if (ui::PageTransitionStripQualifier(transition) != |
754 ui::PAGE_TRANSITION_RELOAD) | 777 ui::PAGE_TRANSITION_RELOAD) |
755 url_info.set_visit_count(url_info.visit_count() + 1); | 778 url_info.set_visit_count(url_info.visit_count() + 1); |
756 if (typed_increment) | 779 if (typed_increment) |
757 url_info.set_typed_count(url_info.typed_count() + typed_increment); | 780 url_info.set_typed_count(url_info.typed_count() + typed_increment); |
(...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2650 return true; | 2673 return true; |
2651 } | 2674 } |
2652 | 2675 |
2653 HistoryClient* HistoryBackend::GetHistoryClient() { | 2676 HistoryClient* HistoryBackend::GetHistoryClient() { |
2654 if (history_client_) | 2677 if (history_client_) |
2655 history_client_->BlockUntilBookmarksLoaded(); | 2678 history_client_->BlockUntilBookmarksLoaded(); |
2656 return history_client_; | 2679 return history_client_; |
2657 } | 2680 } |
2658 | 2681 |
2659 } // namespace history | 2682 } // namespace history |
OLD | NEW |