Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: chrome/browser/history/visit_tracker.cc

Issue 823273003: Switch the history backend from using page ids to navigation entry unique ids. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: using Created 5 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/history/visit_tracker.h" 5 #include "chrome/browser/history/visit_tracker.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 8
9 namespace history { 9 namespace history {
10 10
(...skipping 11 matching lines...) Expand all
22 VisitTracker::~VisitTracker() { 22 VisitTracker::~VisitTracker() {
23 STLDeleteContainerPairSecondPointers(contexts_.begin(), contexts_.end()); 23 STLDeleteContainerPairSecondPointers(contexts_.begin(), contexts_.end());
24 } 24 }
25 25
26 // This function is potentially slow because it may do up to two brute-force 26 // This function is potentially slow because it may do up to two brute-force
27 // searches of the transitions list. This transitions list is kept to a 27 // searches of the transitions list. This transitions list is kept to a
28 // relatively small number by CleanupTransitionList so it shouldn't be a big 28 // relatively small number by CleanupTransitionList so it shouldn't be a big
29 // deal. However, if this ends up being noticable for performance, we may want 29 // deal. However, if this ends up being noticable for performance, we may want
30 // to optimize lookup. 30 // to optimize lookup.
31 VisitID VisitTracker::GetLastVisit(ContextID context_id, 31 VisitID VisitTracker::GetLastVisit(ContextID context_id,
32 int32 page_id, 32 int nav_entry_id,
33 const GURL& referrer) { 33 const GURL& referrer) {
34 if (referrer.is_empty() || !context_id) 34 if (referrer.is_empty() || !context_id)
35 return 0; 35 return 0;
36 36
37 ContextList::iterator i = contexts_.find(context_id); 37 ContextList::iterator i = contexts_.find(context_id);
38 if (i == contexts_.end()) 38 if (i == contexts_.end())
39 return 0; // We don't have any entries for this context. 39 return 0; // We don't have any entries for this context.
40 TransitionList& transitions = *i->second; 40 TransitionList& transitions = *i->second;
41 41
42 // Recall that a page ID is associated with a single session history entry. 42 // Recall that a navigation entry ID is associated with a single session
43 // In the case of automatically loaded iframes, many visits/URLs can have the 43 // history entry. In the case of automatically loaded iframes, many
44 // same page ID. 44 // visits/URLs can have the same navigation entry ID.
45 // 45 //
46 // We search backwards, starting at the current page ID, for the referring 46 // We search backwards, starting at the current navigation entry ID, for the
47 // URL. This won't always be correct. For example, if a render process has 47 // referring URL. This won't always be correct. For example, if a render
48 // the same page open in two different tabs, or even in two different frames, 48 // process has the same page open in two different tabs, or even in two
49 // we can get confused about which was which. We can have the renderer 49 // different frames, we can get confused about which was which. We can have
50 // report more precise referrer information in the future, but this is a 50 // the renderer report more precise referrer information in the future, but
51 // hard problem and doesn't affect much in terms of real-world issues. 51 // this is a hard problem and doesn't affect much in terms of real-world
52 // issues.
52 // 53 //
53 // We assume that the page IDs are increasing over time, so larger IDs than 54 // We assume that the navigation entry IDs are increasing over time, so larger
54 // the current input ID happened in the future (this will occur if the user 55 // IDs than the current input ID happened in the future (this will occur if
55 // goes back). We can ignore future transitions because if you navigate, go 56 // the user goes back). We can ignore future transitions because if you
56 // back, and navigate some more, we'd like to have one node with two out 57 // navigate, go back, and navigate some more, we'd like to have one node with
57 // edges in our visit graph. 58 // two out edges in our visit graph.
58 for (int i = static_cast<int>(transitions.size()) - 1; i >= 0; i--) { 59 for (int i = static_cast<int>(transitions.size()) - 1; i >= 0; i--) {
59 if (transitions[i].page_id <= page_id && transitions[i].url == referrer) { 60 if (transitions[i].nav_entry_id <= nav_entry_id &&
61 transitions[i].url == referrer) {
60 // Found it. 62 // Found it.
61 return transitions[i].visit_id; 63 return transitions[i].visit_id;
62 } 64 }
63 } 65 }
64 66
65 // We can't find the referrer. 67 // We can't find the referrer.
66 return 0; 68 return 0;
67 } 69 }
68 70
69 void VisitTracker::AddVisit(ContextID context_id, 71 void VisitTracker::AddVisit(ContextID context_id,
70 int32 page_id, 72 int nav_entry_id,
71 const GURL& url, 73 const GURL& url,
72 VisitID visit_id) { 74 VisitID visit_id) {
73 TransitionList* transitions = contexts_[context_id]; 75 TransitionList* transitions = contexts_[context_id];
74 if (!transitions) { 76 if (!transitions) {
75 transitions = new TransitionList; 77 transitions = new TransitionList;
76 contexts_[context_id] = transitions; 78 contexts_[context_id] = transitions;
77 } 79 }
78 80
79 Transition t; 81 Transition t;
80 t.url = url; 82 t.url = url;
81 t.page_id = page_id; 83 t.nav_entry_id = nav_entry_id;
82 t.visit_id = visit_id; 84 t.visit_id = visit_id;
83 transitions->push_back(t); 85 transitions->push_back(t);
84 86
85 CleanupTransitionList(transitions); 87 CleanupTransitionList(transitions);
86 } 88 }
87 89
88 void VisitTracker::ClearCachedDataForContextID(ContextID context_id) { 90 void VisitTracker::ClearCachedDataForContextID(ContextID context_id) {
89 ContextList::iterator i = contexts_.find(context_id); 91 ContextList::iterator i = contexts_.find(context_id);
90 if (i == contexts_.end()) 92 if (i == contexts_.end())
91 return; // We don't have any entries for this context. 93 return; // We don't have any entries for this context.
92 94
93 delete i->second; 95 delete i->second;
94 contexts_.erase(i); 96 contexts_.erase(i);
95 } 97 }
96 98
97 99
98 void VisitTracker::CleanupTransitionList(TransitionList* transitions) { 100 void VisitTracker::CleanupTransitionList(TransitionList* transitions) {
99 if (transitions->size() <= kMaxItemsInTransitionList) 101 if (transitions->size() <= kMaxItemsInTransitionList)
100 return; // Nothing to do. 102 return; // Nothing to do.
101 103
102 transitions->erase(transitions->begin(), 104 transitions->erase(transitions->begin(),
103 transitions->begin() + kResizeBigTransitionListTo); 105 transitions->begin() + kResizeBigTransitionListTo);
104 } 106 }
105 107
106 } // namespace history 108 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698