OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_VISIT_TRACKER_H__ | 5 #ifndef COMPONENTS_HISTORY_CORE_BROWSER_VISIT_TRACKER_H__ |
6 #define COMPONENTS_HISTORY_CORE_BROWSER_VISIT_TRACKER_H__ | 6 #define COMPONENTS_HISTORY_CORE_BROWSER_VISIT_TRACKER_H__ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "components/history/core/browser/history_types.h" | 12 #include "components/history/core/browser/history_types.h" |
13 | 13 |
14 namespace history { | 14 namespace history { |
15 | 15 |
16 // Tracks history transitions between pages. The history backend uses this to | 16 // Tracks history transitions between pages. The history backend uses this to |
17 // link up page transitions to form a chain of page visits, and to set the | 17 // link up page transitions to form a chain of page visits, and to set the |
18 // transition type properly. | 18 // transition type properly. |
19 // | 19 // |
20 // This class is not thread safe. | 20 // This class is not thread safe. |
21 class VisitTracker { | 21 class VisitTracker { |
22 public: | 22 public: |
23 VisitTracker(); | 23 VisitTracker(); |
24 ~VisitTracker(); | 24 ~VisitTracker(); |
25 | 25 |
26 // Notifications ------------------------------------------------------------- | 26 // Notifications ------------------------------------------------------------- |
27 | 27 |
28 void AddVisit(ContextID context_id, | 28 void AddVisit(ContextID context_id, |
29 int32 page_id, | 29 int nav_entry_id, |
30 const GURL& url, | 30 const GURL& url, |
31 VisitID visit_id); | 31 VisitID visit_id); |
32 | 32 |
33 // When a RenderProcessHost is destroyed, we want to clear out our saved | 33 // When a RenderProcessHost is destroyed, we want to clear out our saved |
34 // transitions/visit IDs for it. | 34 // transitions/visit IDs for it. |
35 void ClearCachedDataForContextID(ContextID context_id); | 35 void ClearCachedDataForContextID(ContextID context_id); |
36 | 36 |
37 // Querying ------------------------------------------------------------------ | 37 // Querying ------------------------------------------------------------------ |
38 | 38 |
39 // Returns the visit ID for the transition given information about the visit | 39 // Returns the visit ID for the transition given information about the visit |
40 // supplied by the renderer. We will return 0 if there is no appropriate | 40 // supplied by the renderer. We will return 0 if there is no appropriate |
41 // referring visit. | 41 // referring visit. |
42 VisitID GetLastVisit(ContextID context_id, int32 page_id, const GURL& url); | 42 VisitID GetLastVisit(ContextID context_id, |
| 43 int nav_entry_id, |
| 44 const GURL& url); |
43 | 45 |
44 private: | 46 private: |
45 struct Transition { | 47 struct Transition { |
46 GURL url; // URL that the event happened to. | 48 GURL url; // URL that the event happened to. |
47 int32 page_id; // ID generated by the render process host. | 49 int nav_entry_id; // ID of the navigation entry. |
48 VisitID visit_id; // Visit ID generated by history. | 50 VisitID visit_id; // Visit ID generated by history. |
49 }; | 51 }; |
50 typedef std::vector<Transition> TransitionList; | 52 typedef std::vector<Transition> TransitionList; |
51 typedef std::map<ContextID, TransitionList*> ContextList; | 53 typedef std::map<ContextID, TransitionList*> ContextList; |
52 | 54 |
53 // Expires oldish items in the given transition list. This keeps the list | 55 // Expires oldish items in the given transition list. This keeps the list |
54 // size small by removing items that are unlikely to be needed, which is | 56 // size small by removing items that are unlikely to be needed, which is |
55 // important for GetReferrer which does brute-force searches of this list. | 57 // important for GetReferrer which does brute-force searches of this list. |
56 void CleanupTransitionList(TransitionList* transitions); | 58 void CleanupTransitionList(TransitionList* transitions); |
57 | 59 |
58 // Maps render view hosts to lists of recent transitions. | 60 // Maps render view hosts to lists of recent transitions. |
59 ContextList contexts_; | 61 ContextList contexts_; |
60 | 62 |
61 DISALLOW_COPY_AND_ASSIGN(VisitTracker); | 63 DISALLOW_COPY_AND_ASSIGN(VisitTracker); |
62 }; | 64 }; |
63 | 65 |
64 } // namespace history | 66 } // namespace history |
65 | 67 |
66 #endif // COMPONENTS_HISTORY_CORE_BROWSER_VISIT_TRACKER_H__ | 68 #endif // COMPONENTS_HISTORY_CORE_BROWSER_VISIT_TRACKER_H__ |
OLD | NEW |