| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/sync_driver/revisit/sessions_page_revisit_observer.h" | 5 #include "components/sync_sessions/revisit/sessions_page_revisit_observer.h" |
| 6 |
| 7 #include <utility> |
| 6 | 8 |
| 7 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "base/time/time.h" |
| 9 #include "components/sessions/core/session_types.h" | 12 #include "components/sessions/core/session_types.h" |
| 10 #include "components/sync_driver/glue/synced_session.h" | 13 #include "components/sync_driver/glue/synced_session.h" |
| 11 #include "components/sync_driver/revisit/current_tab_matcher.h" | 14 #include "components/sync_sessions/revisit/current_tab_matcher.h" |
| 12 #include "components/sync_driver/revisit/offset_tab_matcher.h" | 15 #include "components/sync_sessions/revisit/offset_tab_matcher.h" |
| 13 #include "components/sync_driver/revisit/page_equality.h" | 16 #include "components/sync_sessions/revisit/page_equality.h" |
| 14 | 17 |
| 15 namespace sync_driver { | 18 namespace sync_sessions { |
| 16 | 19 |
| 17 SessionsPageRevisitObserver::SessionsPageRevisitObserver( | 20 SessionsPageRevisitObserver::SessionsPageRevisitObserver( |
| 18 scoped_ptr<ForeignSessionsProvider> provider) | 21 scoped_ptr<ForeignSessionsProvider> provider) |
| 19 : provider_(provider.Pass()) {} | 22 : provider_(provider.Pass()) {} |
| 20 | 23 |
| 21 SessionsPageRevisitObserver::~SessionsPageRevisitObserver() {} | 24 SessionsPageRevisitObserver::~SessionsPageRevisitObserver() {} |
| 22 | 25 |
| 23 void SessionsPageRevisitObserver::OnPageVisit(const GURL& url, | 26 void SessionsPageRevisitObserver::OnPageVisit( |
| 24 const TransitionType transition) { | 27 const GURL& url, |
| 28 const PageVisitObserver::TransitionType transition) { |
| 25 // We need to be invoked and eventually execute on the thread which owns the | 29 // We need to be invoked and eventually execute on the thread which owns the |
| 26 // session objects the provider will give us. However, this work is not | 30 // session objects the provider will give us. However, this work is not |
| 27 // especially time sensitive, and so we post a task to perform this to get out | 31 // especially time sensitive, and so we post a task to perform this to get out |
| 28 // of the way of any currently executing logic. | 32 // of the way of any currently executing logic. |
| 29 | 33 |
| 30 // Bind this task to this->AsWeakPtr() so that if we're destructed this task | 34 // Bind this task to this->AsWeakPtr() so that if we're destructed this task |
| 31 // just vanish instead of breaking things. | 35 // just vanish instead of breaking things. |
| 32 base::ThreadTaskRunnerHandle::Get()->PostTask( | 36 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 33 FROM_HERE, base::Bind(&SessionsPageRevisitObserver::CheckForRevisit, | 37 FROM_HERE, base::Bind(&SessionsPageRevisitObserver::CheckForRevisit, |
| 34 this->AsWeakPtr(), url, transition)); | 38 this->AsWeakPtr(), url, transition)); |
| 35 } | 39 } |
| 36 | 40 |
| 37 void SessionsPageRevisitObserver::CheckForRevisit( | 41 void SessionsPageRevisitObserver::CheckForRevisit( |
| 38 const GURL& url, | 42 const GURL& url, |
| 39 const TransitionType transition) { | 43 const PageVisitObserver::TransitionType transition) { |
| 40 base::TimeTicks start(base::TimeTicks::Now()); | 44 base::TimeTicks start(base::TimeTicks::Now()); |
| 41 | 45 |
| 42 // We want to match tabs/navigation entries in two slightly different ways. We | 46 // We want to match tabs/navigation entries in two slightly different ways. We |
| 43 // value the current url/navigation entry of a tab more highly, and want to | 47 // value the current url/navigation entry of a tab more highly, and want to |
| 44 // actually seperate metrics from the backwards/forwards entries. And then | 48 // actually seperate metrics from the backwards/forwards entries. And then |
| 45 // to make things a little bit messier, we only have an accurate modified time | 49 // to make things a little bit messier, we only have an accurate modified time |
| 46 // for the tabs/current entries. So use index offset for forward/back entries. | 50 // for the tabs/current entries. So use index offset for forward/back entries. |
| 47 PageEquality page_equality(url); | 51 PageEquality page_equality(url); |
| 48 CurrentTabMatcher current_matcher(page_equality); | 52 CurrentTabMatcher current_matcher(page_equality); |
| 49 OffsetTabMatcher offset_matcher(page_equality); | 53 OffsetTabMatcher offset_matcher(page_equality); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 68 } | 72 } |
| 69 | 73 |
| 70 // emit even if there are no foreign sessions so that that counts all match. | 74 // emit even if there are no foreign sessions so that that counts all match. |
| 71 current_matcher.Emit(transition); | 75 current_matcher.Emit(transition); |
| 72 offset_matcher.Emit(transition); | 76 offset_matcher.Emit(transition); |
| 73 | 77 |
| 74 base::TimeDelta duration(base::TimeTicks::Now() - start); | 78 base::TimeDelta duration(base::TimeTicks::Now() - start); |
| 75 UMA_HISTOGRAM_TIMES("Sync.PageRevisitSessionDuration", duration); | 79 UMA_HISTOGRAM_TIMES("Sync.PageRevisitSessionDuration", duration); |
| 76 } | 80 } |
| 77 | 81 |
| 78 } // namespace sync_driver | 82 } // namespace sync_sessions |
| OLD | NEW |