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

Side by Side Diff: chrome/browser/prerender/prerender_link_manager.cc

Issue 10198040: New link rel=prerender api, using WebKit::WebPrerenderingPlatform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove the urls_to_id_map_, and follow consequences through. Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/prerender/prerender_link_manager.h"
6
7 #include <limits>
8 #include <queue>
9 #include <utility>
10
11 #include "chrome/browser/prerender/prerender_contents.h"
12 #include "chrome/browser/prerender/prerender_manager.h"
13 #include "chrome/browser/prerender/prerender_manager_factory.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/session_storage_namespace.h"
17 #include "content/public/common/referrer.h"
18 #include "googleurl/src/gurl.h"
19 #include "googleurl/src/url_canon.h"
20 #include "ui/gfx/size.h"
21
22 using content::RenderViewHost;
23 using content::SessionStorageNamespace;
24
25 namespace prerender {
26
27 PrerenderLinkManager::PrerenderLinkManager(PrerenderManager* manager)
28 : manager_(manager) {
29 }
30
31 PrerenderLinkManager::~PrerenderLinkManager() {
32 }
33
34 bool PrerenderLinkManager::OnAddPrerender(int child_id,
35 int prerender_id,
36 const GURL& orig_url,
37 const content::Referrer& referrer,
38 const gfx::Size& size,
39 int render_view_route_id) {
40 DVLOG(2) << "OnAddPrerender, child_id = " << child_id
41 << ", prerender_id = " << prerender_id
42 << ", url = " << orig_url.spec();
43 DVLOG(3) << "... render_view_route_id = " << render_view_route_id
44 << ", referrer url = " << referrer.url.spec();
45 // TODO(gavinp): Add tests to insure fragments work, then remove this fragment
dominich 2012/04/29 18:52:55 nit: ensure
gavinp 2012/04/30 11:43:16 Done.
46 // clearing code.
47 url_canon::Replacements<char> replacements;
48 replacements.ClearRef();
49 const GURL url = orig_url.ReplaceComponents(replacements);
50
51 // Unit tests pass in a child_id == -1.
52 RenderViewHost* source_render_view_host = NULL;
53 SessionStorageNamespace* session_storage_namespace = NULL;
54 if (child_id != -1) {
55 source_render_view_host =
56 RenderViewHost::FromID(child_id, render_view_route_id);
57 if (!source_render_view_host || !source_render_view_host->GetView())
58 return false;
59 session_storage_namespace =
60 source_render_view_host->GetSessionStorageNamespace();
61 }
62
63 if (!manager_->AddPrerenderFromLinkRelPrerender(
dominich 2012/04/29 18:52:55 possibly contentious comment: why not move this ma
gavinp 2012/04/30 11:43:16 We don't key on url/sessionstorage though. The ke
dominich 2012/04/30 15:52:05 I believe this will be necessary (or convenient) f
64 child_id, render_view_route_id, url, referrer,
65 size, session_storage_namespace))
66 return false;
67 const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_id);
68 DCHECK(!ids_to_url_map_.count(child_and_prerender_id));
69 ids_to_url_map_.insert(std::make_pair(child_and_prerender_id, url));
70 return true;
71 }
72
73 void PrerenderLinkManager::OnCancelPrerender(int prerender_id,
74 int child_id) {
75 DVLOG(2) << "OnCancelPrerender, child_id = " << child_id
76 << ", prerender_id = " << prerender_id;
77 const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_id);
78 IdPairToUrlMap::iterator id_url_iter =
79 ids_to_url_map_.find(child_and_prerender_id);
80 if (id_url_iter == ids_to_url_map_.end()) {
81 DVLOG(5) << "... canceling a prerender that doesn't exist.";
82 return;
83 }
84 const GURL url = id_url_iter->second;
85 ids_to_url_map_.erase(id_url_iter);
86 manager_->MaybeCancelPrerender(url);
87 }
88
89 void PrerenderLinkManager::OnAbandonPrerender(int prerender_id, int child_id) {
90 DVLOG(2) << "OnAbandonPrerender, child_id = " << child_id
91 << ", prerender_id = " << prerender_id;
92 // TODO(gavinp,cbentzel): Implement reasonable behaviour for
93 // navigation away from launcher.
94 const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_id);
95 if (ids_to_url_map_.count(child_and_prerender_id))
96 ids_to_url_map_.erase(child_and_prerender_id);
97 }
98
99 void PrerenderLinkManager::OnChannelClosing(int child_id) {
100 DVLOG(2) << "OnChannelClosing, child id = " << child_id;
101 const ChildAndPrerenderIdPair child_and_minimum_prerender_id(
102 child_id, std::numeric_limits<int>::min());
103 const ChildAndPrerenderIdPair child_and_maximum_prerender_id(
104 child_id, std::numeric_limits<int>::max());
105 std::queue<int> prerender_ids_to_abandon;
106 for (IdPairToUrlMap::iterator
107 i = ids_to_url_map_.lower_bound(child_and_minimum_prerender_id),
108 e = ids_to_url_map_.upper_bound(child_and_maximum_prerender_id);
109 i != e; ++i) {
110 prerender_ids_to_abandon.push(i->first.second);
111 }
112 while (!prerender_ids_to_abandon.empty()) {
113 DVLOG(4) << "---> abandon prerender_id = "
114 << prerender_ids_to_abandon.front();
115 OnAbandonPrerender(prerender_ids_to_abandon.front(), child_id);
116 prerender_ids_to_abandon.pop();
117 }
118 }
119
120 bool PrerenderLinkManager::IsEmpty() const {
121 return ids_to_url_map_.empty();
122 }
123
124 } // namespace prerender
125
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698