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 #ifndef COMPONENTS_SYNC_DRIVER_REVISIT_SESSIONS_PAGE_REVISIT_OBSERVER_H_
6 #define COMPONENTS_SYNC_DRIVER_REVISIT_SESSIONS_PAGE_REVISIT_OBSERVER_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "components/sync_driver/revisit/page_visit_observer.h"
17 } // namespace sessions
19 namespace sync_driver
{
23 class CurrentTabMatcher
;
24 class OffsetTabMatcher
;
26 // A simple interface to abstract away who is providing sessions.
27 class ForeignSessionsProvider
{
29 // Fills the already instantiated passed vector with all foreign sessions.
30 // Returned boolean representes if there were foreign sessions and the vector
31 // should be examimed.
32 virtual bool GetAllForeignSessions(
33 std::vector
<const sync_driver::SyncedSession
*>* sessions
) = 0;
34 virtual ~ForeignSessionsProvider() {}
37 // An implementation of PageVisitObserver that checks the given page's url
38 // against in memory session information to detect if we've seen this page
39 // before, constituting a revisit. Then histogram information is emitted about
40 // this page navigation.
41 class SessionsPageRevisitObserver
42 : public PageVisitObserver
,
43 public base::SupportsWeakPtr
<SessionsPageRevisitObserver
> {
45 explicit SessionsPageRevisitObserver(
46 scoped_ptr
<ForeignSessionsProvider
> provider
);
47 ~SessionsPageRevisitObserver() override
;
48 void OnPageVisit(const GURL
& url
, const TransitionType transition
) override
;
51 friend class SessionsPageRevisitObserverTest
;
53 // Although the signature is identical to OnPageVisit(...), this method
54 // actually does all of the work. The assumption is that this method is the
55 // target of a PostTask call coming from OnPageVisit(...).
56 void CheckForRevisit(const GURL
& url
, const TransitionType transition
);
58 scoped_ptr
<ForeignSessionsProvider
> provider_
;
60 DISALLOW_COPY_AND_ASSIGN(SessionsPageRevisitObserver
);
63 } // namespace sync_driver
65 #endif // COMPONENTS_SYNC_DRIVER_REVISIT_SESSIONS_PAGE_REVISIT_OBSERVER_H_