Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / sync_driver / revisit / sessions_page_revisit_observer.h
bloba00fbf0558f52d63a58392e47941916e01295dcd
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_
8 #include <vector>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "components/sync_driver/revisit/page_visit_observer.h"
13 #include "url/gurl.h"
15 namespace sessions {
16 struct SessionTab;
17 } // namespace sessions
19 namespace sync_driver {
21 struct SyncedSession;
23 class CurrentTabMatcher;
24 class OffsetTabMatcher;
26 // A simple interface to abstract away who is providing sessions.
27 class ForeignSessionsProvider {
28 public:
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> {
44 public:
45 explicit SessionsPageRevisitObserver(
46 scoped_ptr<ForeignSessionsProvider> provider);
47 ~SessionsPageRevisitObserver() override;
48 void OnPageVisit(const GURL& url, const TransitionType transition) override;
50 private:
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_