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

Side by Side Diff: components/history/core/browser/history_backend.cc

Issue 1179953005: Add History.TopHostsVisitsByRank UMA metric. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@is_allowed
Patch Set: Edits per mpearson. Created 5 years, 6 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 (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
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
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;
bengr 2015/06/13 00:21:14 Is that big enough?
twifkak 2015/06/16 20:25:23 Bigger would be better, since the median of Histor
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
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 = 1;
426 for (const auto& host_count : top_hosts) {
bengr 2015/06/13 00:21:14 Not required, but you could make this slightly mor
twifkak 2015/06/16 20:25:23 Done. I chose the other way because strahinja does
427 host_ranks_[host_count.first] = i;
428 ++i;
429 }
430 return top_hosts;
420 } 431 }
421 432
422 void HistoryBackend::AddPage(const HistoryAddPageArgs& request) { 433 void HistoryBackend::AddPage(const HistoryAddPageArgs& request) {
423 if (!db_) 434 if (!db_)
424 return; 435 return;
425 436
426 // Will be filled with the URL ID and the visit ID of the last addition. 437 // Will be filled with the URL ID and the visit ID of the last addition.
427 std::pair<URLID, VisitID> last_ids( 438 std::pair<URLID, VisitID> last_ids(
428 0, tracker_.GetLastVisit(request.context_id, request.nav_entry_id, 439 0, tracker_.GetLastVisit(request.context_id, request.nav_entry_id,
429 request.referrer)); 440 request.referrer));
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 db_.reset(); 729 db_.reset();
719 // Forget the first recorded time since the database is closed. 730 // Forget the first recorded time since the database is closed.
720 first_recorded_time_ = base::Time(); 731 first_recorded_time_ = base::Time();
721 } 732 }
722 if (thumbnail_db_) { 733 if (thumbnail_db_) {
723 thumbnail_db_->CommitTransaction(); 734 thumbnail_db_->CommitTransaction();
724 thumbnail_db_.reset(); 735 thumbnail_db_.reset();
725 } 736 }
726 } 737 }
727 738
739 void HistoryBackend::RecordTopHostsMetrics(const GURL& url) {
740 int host_rank = host_ranks_[HostForTopHosts(url)];
sky 2015/06/15 17:28:17 This always results in inserting into host_ranks_,
twifkak 2015/06/16 20:25:23 Oof, fail. Done.
Mark P 2015/06/16 20:54:31 This makes me think you should either have unit te
twifkak 2015/06/17 00:05:23 A unit test (or about:histograms) wouldn't have ca
741 if (host_rank == 0 || host_rank > kMaxTopHostsForMetrics)
742 host_rank = kMaxTopHostsForMetrics + 1;
743
744 UMA_HISTOGRAM_ENUMERATION("History.TopHostsVisitsByRank", host_rank,
sky 2015/06/15 17:28:17 Not being familiar with TopHosts, I'm not sure how
twifkak 2015/06/16 20:25:23 TopHosts will be computed approximately once or tw
sky 2015/06/30 19:17:26 Sure, but then how realistic is your metric if it
twifkak 2015/06/30 21:14:43 My intended use for this metric is to gather data
745 kMaxTopHostsForMetrics + 2);
746 }
747
728 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( 748 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit(
729 const GURL& url, 749 const GURL& url,
730 Time time, 750 Time time,
731 VisitID referring_visit, 751 VisitID referring_visit,
732 ui::PageTransition transition, 752 ui::PageTransition transition,
733 VisitSource visit_source) { 753 VisitSource visit_source) {
734 // Top-level frame navigations are visible, everything else is hidden 754 // Top-level frame navigations are visible, everything else is hidden
735 bool new_hidden = !ui::PageTransitionIsMainFrame(transition); 755 bool new_hidden = !ui::PageTransitionIsMainFrame(transition);
736 756
737 // NOTE: This code must stay in sync with 757 // NOTE: This code must stay in sync with
738 // ExpireHistoryBackend::ExpireURLsForVisits(). 758 // ExpireHistoryBackend::ExpireURLsForVisits().
739 int typed_increment = 0; 759 int typed_increment = 0;
740 ui::PageTransition transition_type = 760 ui::PageTransition transition_type =
741 ui::PageTransitionStripQualifier(transition); 761 ui::PageTransitionStripQualifier(transition);
742 if (ui::PageTransitionIsNewNavigation(transition) && 762 if (ui::PageTransitionIsNewNavigation(transition) &&
743 ((transition_type == ui::PAGE_TRANSITION_TYPED && 763 ((transition_type == ui::PAGE_TRANSITION_TYPED &&
744 !ui::PageTransitionIsRedirect(transition)) || 764 !ui::PageTransitionIsRedirect(transition)) ||
745 transition_type == ui::PAGE_TRANSITION_KEYWORD_GENERATED)) 765 transition_type == ui::PAGE_TRANSITION_KEYWORD_GENERATED))
746 typed_increment = 1; 766 typed_increment = 1;
747 767
768 if (!host_ranks_.empty() && visit_source == SOURCE_BROWSED &&
769 (transition & ui::PAGE_TRANSITION_CHAIN_END)) {
770 RecordTopHostsMetrics(url);
771 }
772
748 // See if this URL is already in the DB. 773 // See if this URL is already in the DB.
749 URLRow url_info(url); 774 URLRow url_info(url);
750 URLID url_id = db_->GetRowForURL(url, &url_info); 775 URLID url_id = db_->GetRowForURL(url, &url_info);
751 if (url_id) { 776 if (url_id) {
752 // Update of an existing row. 777 // Update of an existing row.
753 if (ui::PageTransitionStripQualifier(transition) != 778 if (ui::PageTransitionStripQualifier(transition) !=
754 ui::PAGE_TRANSITION_RELOAD) 779 ui::PAGE_TRANSITION_RELOAD)
755 url_info.set_visit_count(url_info.visit_count() + 1); 780 url_info.set_visit_count(url_info.visit_count() + 1);
756 if (typed_increment) 781 if (typed_increment)
757 url_info.set_typed_count(url_info.typed_count() + typed_increment); 782 url_info.set_typed_count(url_info.typed_count() + typed_increment);
(...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after
2650 return true; 2675 return true;
2651 } 2676 }
2652 2677
2653 HistoryClient* HistoryBackend::GetHistoryClient() { 2678 HistoryClient* HistoryBackend::GetHistoryClient() {
2654 if (history_client_) 2679 if (history_client_)
2655 history_client_->BlockUntilBookmarksLoaded(); 2680 history_client_->BlockUntilBookmarksLoaded();
2656 return history_client_; 2681 return history_client_;
2657 } 2682 }
2658 2683
2659 } // namespace history 2684 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698