OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/prerender/prerender_link_manager.h" | 5 #include "chrome/browser/prerender/prerender_link_manager.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <queue> | 8 #include <queue> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 DVLOG(3) << "... referrer url = " << referrer.url.spec() | 43 DVLOG(3) << "... referrer url = " << referrer.url.spec() |
44 << ", size = (" << size.width() << ", " << size.height() << ")" | 44 << ", size = (" << size.width() << ", " << size.height() << ")" |
45 << ", render_view_route_id = " << render_view_route_id; | 45 << ", render_view_route_id = " << render_view_route_id; |
46 | 46 |
47 // TODO(gavinp): Add tests to ensure fragments work, then remove this fragment | 47 // TODO(gavinp): Add tests to ensure fragments work, then remove this fragment |
48 // clearing code. | 48 // clearing code. |
49 url_canon::Replacements<char> replacements; | 49 url_canon::Replacements<char> replacements; |
50 replacements.ClearRef(); | 50 replacements.ClearRef(); |
51 const GURL url = orig_url.ReplaceComponents(replacements); | 51 const GURL url = orig_url.ReplaceComponents(replacements); |
52 | 52 |
53 if (!manager_->AddPrerenderFromLinkRelPrerender( | 53 PrerenderHandle prerender = manager_->AddPrerenderFromLinkRelPrerender( |
dominich
2012/06/18 15:32:44
the addition of this doesn't seem to have changed
gavinp
2012/06/18 16:40:48
No. It's meant to prepare prerendermanager to have
| |
54 child_id, render_view_route_id, url, referrer, size)) { | 54 child_id, render_view_route_id, url, referrer, size); |
55 if (!prerender) | |
dominich
2012/06/18 15:32:44
i'm not comfortable with this implicit cast to boo
gavinp
2012/06/18 16:40:48
Already fixed.
| |
55 return false; | 56 return false; |
56 } | 57 DVLOG(4) << "... prerender initial ref count = " << prerender->ref_count_; |
58 | |
57 const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_id); | 59 const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_id); |
58 DCHECK_EQ(0U, ids_to_url_map_.count(child_and_prerender_id)); | 60 DCHECK_EQ(0U, ids_to_prerender_map_.count(child_and_prerender_id)); |
59 ids_to_url_map_.insert(std::make_pair(child_and_prerender_id, url)); | 61 ids_to_prerender_map_.insert( |
62 std::make_pair(child_and_prerender_id, prerender)); | |
63 DVLOG(4) << "... prerender onexit ref count = " << prerender->ref_count_; | |
60 return true; | 64 return true; |
61 } | 65 } |
62 | 66 |
63 // TODO(gavinp): Once an observer interface is provided down to the WebKit | 67 // TODO(gavinp): Once an observer interface is provided down to the WebKit |
64 // layer, we should add DCHECK_NE(0L, ids_to_url_map_.count(...)) to both | 68 // layer, we should add DCHECK_NE(0L, ids_to_prerender_map_.count(...)) to both |
65 // OnCancelPrerender and OnAbandonPrerender. We can't do this now, since | 69 // OnCancelPrerender and OnAbandonPrerender. We can't do this now, since |
66 // the WebKit layer isn't even aware if we didn't add the prerender to the map | 70 // the WebKit layer isn't even aware if we didn't add the prerender to the map |
67 // in OnAddPrerender above. | 71 // in OnAddPrerender above. |
68 void PrerenderLinkManager::OnCancelPrerender(int child_id, int prerender_id) { | 72 void PrerenderLinkManager::OnCancelPrerender(int child_id, int prerender_id) { |
69 DVLOG(2) << "OnCancelPrerender, child_id = " << child_id | 73 DVLOG(2) << "OnCancelPrerender, child_id = " << child_id |
70 << ", prerender_id = " << prerender_id; | 74 << ", prerender_id = " << prerender_id; |
75 DVLOG(4) << "... initial map size = " << ids_to_prerender_map_.size(); | |
71 const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_id); | 76 const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_id); |
72 IdPairToUrlMap::iterator id_url_iter = | 77 |
73 ids_to_url_map_.find(child_and_prerender_id); | 78 IdPairToPrerenderMap::iterator it = ids_to_prerender_map_.find(child_and_prere nder_id); |
74 if (id_url_iter == ids_to_url_map_.end()) { | 79 if (it != ids_to_prerender_map_.end()) { |
75 DVLOG(5) << "... canceling a prerender that doesn't exist."; | 80 DVLOG(5) << "ref count = " << it->second->ref_count_; |
76 return; | |
77 } | 81 } |
78 const GURL url = id_url_iter->second; | 82 |
79 ids_to_url_map_.erase(id_url_iter); | 83 ids_to_prerender_map_.erase(child_and_prerender_id); |
80 manager_->MaybeCancelPrerender(url); | 84 DVLOG(4) << "... final map size = " << ids_to_prerender_map_.size(); |
85 | |
81 } | 86 } |
82 | 87 |
83 void PrerenderLinkManager::OnAbandonPrerender(int child_id, int prerender_id) { | 88 void PrerenderLinkManager::OnAbandonPrerender(int child_id, int prerender_id) { |
84 DVLOG(2) << "OnAbandonPrerender, child_id = " << child_id | 89 DVLOG(2) << "OnAbandonPrerender, child_id = " << child_id |
85 << ", prerender_id = " << prerender_id; | 90 << ", prerender_id = " << prerender_id; |
86 // TODO(gavinp,cbentzel): Implement reasonable behaviour for | 91 // TODO(gavinp,cbentzel): Implement reasonable behaviour for |
87 // navigation away from launcher. | 92 // navigation away from launcher. |
88 const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_id); | 93 |
89 ids_to_url_map_.erase(child_and_prerender_id); | 94 // const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_i d); |
95 // XYZZY: WHOAH NELLY | |
96 //ids_to_prerender_map_.erase(child_and_prerender_id); | |
90 } | 97 } |
91 | 98 |
92 void PrerenderLinkManager::OnChannelClosing(int child_id) { | 99 void PrerenderLinkManager::OnChannelClosing(int child_id) { |
93 DVLOG(2) << "OnChannelClosing, child id = " << child_id; | 100 DVLOG(2) << "OnChannelClosing, child id = " << child_id; |
94 const ChildAndPrerenderIdPair child_and_minimum_prerender_id( | 101 const ChildAndPrerenderIdPair child_and_minimum_prerender_id( |
95 child_id, std::numeric_limits<int>::min()); | 102 child_id, std::numeric_limits<int>::min()); |
96 const ChildAndPrerenderIdPair child_and_maximum_prerender_id( | 103 const ChildAndPrerenderIdPair child_and_maximum_prerender_id( |
97 child_id, std::numeric_limits<int>::max()); | 104 child_id, std::numeric_limits<int>::max()); |
98 std::queue<int> prerender_ids_to_abandon; | 105 std::queue<int> prerender_ids_to_abandon; |
99 for (IdPairToUrlMap::iterator | 106 for (IdPairToPrerenderMap::iterator |
100 i = ids_to_url_map_.lower_bound(child_and_minimum_prerender_id), | 107 i = ids_to_prerender_map_.lower_bound(child_and_minimum_prerender_id) , |
101 e = ids_to_url_map_.upper_bound(child_and_maximum_prerender_id); | 108 e = ids_to_prerender_map_.upper_bound(child_and_maximum_prerender_id) ; |
102 i != e; ++i) { | 109 i != e; ++i) { |
103 prerender_ids_to_abandon.push(i->first.second); | 110 prerender_ids_to_abandon.push(i->first.second); |
104 } | 111 } |
105 while (!prerender_ids_to_abandon.empty()) { | 112 while (!prerender_ids_to_abandon.empty()) { |
106 DVLOG(4) << "---> abandon prerender_id = " | 113 DVLOG(4) << "---> abandon prerender_id = " |
107 << prerender_ids_to_abandon.front(); | 114 << prerender_ids_to_abandon.front(); |
108 OnAbandonPrerender(child_id, prerender_ids_to_abandon.front()); | 115 OnAbandonPrerender(child_id, prerender_ids_to_abandon.front()); |
109 prerender_ids_to_abandon.pop(); | 116 prerender_ids_to_abandon.pop(); |
110 } | 117 } |
111 } | 118 } |
112 | 119 |
113 bool PrerenderLinkManager::IsEmpty() const { | 120 bool PrerenderLinkManager::IsEmpty() const { |
114 return ids_to_url_map_.empty(); | 121 return ids_to_prerender_map_.empty(); |
115 } | 122 } |
116 | 123 |
117 } // namespace prerender | 124 } // namespace prerender |
118 | 125 |
OLD | NEW |