Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / components / sync_driver / revisit / current_tab_matcher.cc
blob643a7b6a0fd51375fe57449a8142ec39c0328e2f
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/sync_driver/revisit/current_tab_matcher.h"
7 #include "base/metrics/histogram_macros.h"
8 #include "base/time/time.h"
9 #include "components/sessions/serialized_navigation_entry.h"
11 namespace sync_driver {
13 CurrentTabMatcher::CurrentTabMatcher(const PageEquality& page_equality)
14 : page_equality_(page_equality) {}
16 void CurrentTabMatcher::Check(const sessions::SessionTab* tab) {
17 if (tab->navigations.empty()) {
18 return;
20 const sessions::SerializedNavigationEntry& currentEntry =
21 tab->navigations[tab->normalized_navigation_index()];
22 // Cannot rely on SerializedNavigationEntry timestamps, they're
23 // not set for foreign sessions. Instead rely on tab timestamps.
24 if (page_equality_.IsSamePage(currentEntry.virtual_url()) &&
25 (most_recent_match_ == nullptr ||
26 tab->timestamp > most_recent_match_->timestamp)) {
27 most_recent_match_ = tab;
31 void CurrentTabMatcher::Emit(
32 const PageVisitObserver::TransitionType transition) {
33 if (most_recent_match_ == nullptr) {
34 UMA_HISTOGRAM_ENUMERATION("Sync.PageRevisitTabMissTransition", transition,
35 PageVisitObserver::kTransitionTypeLast);
36 } else {
37 base::TimeDelta age(base::Time::Now() - most_recent_match_->timestamp);
38 UMA_HISTOGRAM_CUSTOM_TIMES("Sync.PageRevisitTabMatchAge", age,
39 base::TimeDelta::FromSeconds(1),
40 base::TimeDelta::FromDays(14), 100);
41 UMA_HISTOGRAM_ENUMERATION("Sync.PageRevisitTabMatchTransition", transition,
42 PageVisitObserver::kTransitionTypeLast);
46 } // namespace sync_driver