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

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: Fix unittest to be 1-based again. Created 5 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
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_client.h" 30 #include "components/history/core/browser/history_backend_client.h"
31 #include "components/history/core/browser/history_backend_observer.h" 31 #include "components/history/core/browser/history_backend_observer.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;
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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 ? end_ts - visit_row.visit_time 414 ? end_ts - visit_row.visit_time
412 : TimeDelta::FromMicroseconds(0); 415 : TimeDelta::FromMicroseconds(0);
413 db_->UpdateVisitRow(visit_row); 416 db_->UpdateVisitRow(visit_row);
414 } 417 }
415 } 418 }
416 419
417 TopHostsList HistoryBackend::TopHosts(int num_hosts) const { 420 TopHostsList HistoryBackend::TopHosts(int num_hosts) const {
418 if (!db_) 421 if (!db_)
419 return TopHostsList(); 422 return TopHostsList();
420 423
421 return db_->TopHosts(num_hosts); 424 auto top_hosts = db_->TopHosts(num_hosts);
425
426 host_ranks_.clear();
427 int i = 0;
428 for (const auto& host_count : top_hosts)
429 host_ranks_[host_count.first] = i++;
430 return top_hosts;
422 } 431 }
423 432
424 void HistoryBackend::AddPage(const HistoryAddPageArgs& request) { 433 void HistoryBackend::AddPage(const HistoryAddPageArgs& request) {
425 if (!db_) 434 if (!db_)
426 return; 435 return;
427 436
428 // 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.
429 std::pair<URLID, VisitID> last_ids( 438 std::pair<URLID, VisitID> last_ids(
430 0, tracker_.GetLastVisit(request.context_id, request.nav_entry_id, 439 0, tracker_.GetLastVisit(request.context_id, request.nav_entry_id,
431 request.referrer)); 440 request.referrer));
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 db_.reset(); 735 db_.reset();
727 // Forget the first recorded time since the database is closed. 736 // Forget the first recorded time since the database is closed.
728 first_recorded_time_ = base::Time(); 737 first_recorded_time_ = base::Time();
729 } 738 }
730 if (thumbnail_db_) { 739 if (thumbnail_db_) {
731 thumbnail_db_->CommitTransaction(); 740 thumbnail_db_->CommitTransaction();
732 thumbnail_db_.reset(); 741 thumbnail_db_.reset();
733 } 742 }
734 } 743 }
735 744
745 void HistoryBackend::RecordTopHostsMetrics(const GURL& url) {
746 auto it = host_ranks_.find(HostForTopHosts(url));
747 int host_rank = it != host_ranks_.end() ? it->second : kMaxTopHostsForMetrics;
748
749 // Convert index from 0-based to 1-based.
750 UMA_HISTOGRAM_ENUMERATION("History.TopHostsVisitsByRank", host_rank + 1,
751 kMaxTopHostsForMetrics + 2);
752 }
753
736 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( 754 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit(
737 const GURL& url, 755 const GURL& url,
738 Time time, 756 Time time,
739 VisitID referring_visit, 757 VisitID referring_visit,
740 ui::PageTransition transition, 758 ui::PageTransition transition,
741 VisitSource visit_source) { 759 VisitSource visit_source) {
742 // Top-level frame navigations are visible, everything else is hidden 760 // Top-level frame navigations are visible, everything else is hidden
743 bool new_hidden = !ui::PageTransitionIsMainFrame(transition); 761 bool new_hidden = !ui::PageTransitionIsMainFrame(transition);
744 762
745 // NOTE: This code must stay in sync with 763 // NOTE: This code must stay in sync with
746 // ExpireHistoryBackend::ExpireURLsForVisits(). 764 // ExpireHistoryBackend::ExpireURLsForVisits().
747 int typed_increment = 0; 765 int typed_increment = 0;
748 ui::PageTransition transition_type = 766 ui::PageTransition transition_type =
749 ui::PageTransitionStripQualifier(transition); 767 ui::PageTransitionStripQualifier(transition);
750 if (ui::PageTransitionIsNewNavigation(transition) && 768 if (ui::PageTransitionIsNewNavigation(transition) &&
751 ((transition_type == ui::PAGE_TRANSITION_TYPED && 769 ((transition_type == ui::PAGE_TRANSITION_TYPED &&
752 !ui::PageTransitionIsRedirect(transition)) || 770 !ui::PageTransitionIsRedirect(transition)) ||
753 transition_type == ui::PAGE_TRANSITION_KEYWORD_GENERATED)) 771 transition_type == ui::PAGE_TRANSITION_KEYWORD_GENERATED))
754 typed_increment = 1; 772 typed_increment = 1;
755 773
774 if (!host_ranks_.empty() && visit_source == SOURCE_BROWSED &&
775 (transition & ui::PAGE_TRANSITION_CHAIN_END)) {
776 RecordTopHostsMetrics(url);
777 }
778
756 // See if this URL is already in the DB. 779 // See if this URL is already in the DB.
757 URLRow url_info(url); 780 URLRow url_info(url);
758 URLID url_id = db_->GetRowForURL(url, &url_info); 781 URLID url_id = db_->GetRowForURL(url, &url_info);
759 if (url_id) { 782 if (url_id) {
760 // Update of an existing row. 783 // Update of an existing row.
761 if (ui::PageTransitionStripQualifier(transition) != 784 if (ui::PageTransitionStripQualifier(transition) !=
762 ui::PAGE_TRANSITION_RELOAD) 785 ui::PAGE_TRANSITION_RELOAD)
763 url_info.set_visit_count(url_info.visit_count() + 1); 786 url_info.set_visit_count(url_info.visit_count() + 1);
764 if (typed_increment) 787 if (typed_increment)
765 url_info.set_typed_count(url_info.typed_count() + typed_increment); 788 url_info.set_typed_count(url_info.typed_count() + typed_increment);
(...skipping 1900 matching lines...) Expand 10 before | Expand all | Expand 10 after
2666 // transaction is currently open. 2689 // transaction is currently open.
2667 db_->CommitTransaction(); 2690 db_->CommitTransaction();
2668 db_->Vacuum(); 2691 db_->Vacuum();
2669 db_->BeginTransaction(); 2692 db_->BeginTransaction();
2670 db_->GetStartDate(&first_recorded_time_); 2693 db_->GetStartDate(&first_recorded_time_);
2671 2694
2672 return true; 2695 return true;
2673 } 2696 }
2674 2697
2675 } // namespace history 2698 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/history_backend.h ('k') | components/history/core/browser/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698