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

Side by Side Diff: chrome/renderer/prerender/prerender_dispatcher.cc

Issue 9623018: Prerendered pages are swapped in at browser::Navigate time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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/renderer/prerender/prerender_dispatcher.h"
6
7 #include "base/logging.h"
8 #include "chrome/common/prerender_messages.h"
9 #include "googleurl/src/gurl.h"
10
11 namespace prerender {
12
13 PrerenderDispatcher::PrerenderDispatcher() {
14 }
15
16 PrerenderDispatcher::~PrerenderDispatcher() {
17 }
18
19 bool PrerenderDispatcher::IsPrerenderURL(const GURL& url) const {
20 return prerender_urls_.find(url) != prerender_urls_.end();
21 }
22
23 bool PrerenderDispatcher::OnControlMessageReceived(
24 const IPC::Message& message) {
25 bool handled = true;
26 IPC_BEGIN_MESSAGE_MAP(PrerenderDispatcher, message)
27 IPC_MESSAGE_HANDLER(PrerenderMsg_AddPrerenderURL, OnAddPrerenderURL)
28 IPC_MESSAGE_HANDLER(PrerenderMsg_RemovePrerenderURL, OnRemovePrerenderURL)
29 IPC_MESSAGE_UNHANDLED(handled = false)
30 IPC_END_MESSAGE_MAP()
31
32 return handled;
33 }
34
35 void PrerenderDispatcher::OnAddPrerenderURL(const GURL& url) {
36 PrerenderMap::iterator it = prerender_urls_.find(url);
37 if (it != prerender_urls_.end()) {
38 DCHECK(it->second > 0);
39 it->second += 1;
40 } else {
41 prerender_urls_[url] = 1;
42 }
43 }
44
45 void PrerenderDispatcher::OnRemovePrerenderURL(const GURL& url) {
46 PrerenderMap::iterator it = prerender_urls_.find(url);
47 // This is possible with a spurious remove.
48 // TODO(cbentzel): We'd also want to send the map of active prerenders when
49 // creating a new render process, so the Add/Remove go relative to that.
50 // This may not be that big of a deal in practice, since the newly created tab
51 // is unlikely to go to the prerendered page.
52 if (it == prerender_urls_.end())
53 return;
54 DCHECK(it->second > 0);
55 it->second -= 1;
56 if (it->second == 0)
57 prerender_urls_.erase(it);
58 }
59
60 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698