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

Side by Side Diff: chrome/renderer/prefetch_helper.cc

Issue 334483004: Enable resource prefetch from the browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make change in chrome rather than content Created 6 years, 6 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/prefetch_helper.h"
6
7 #include "chrome/common/prefetch_messages.h"
8 #include "content/public/renderer/render_frame.h"
9 #include "third_party/WebKit/public/platform/WebURLLoader.h"
10 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
11 #include "third_party/WebKit/public/web/WebFrame.h"
12 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h"
13
14 namespace prefetch {
15
16 class PrefetchHelper::PrefetchManager : public blink::WebURLLoaderClient {
17 public:
18 PrefetchManager() { }
jochen (gone - plz use gerrit) 2014/06/13 16:42:55 nit. no space between { } (did you clang-format?)
tburkard 2014/06/13 18:35:46 obsolete comment
19
20 virtual ~PrefetchManager() {
21 STLDeleteElements(&loader_set_);
jochen (gone - plz use gerrit) 2014/06/13 16:42:56 what happens if the manager is deleted while loads
tburkard 2014/06/13 18:35:46 will add a test for this later (will send out a ne
22 }
23
24 void AddPrefetch(blink::WebFrame* frame, const GURL& url) {
25 blink::WebURLRequest request(url);
26 request.setTargetType(blink::WebURLRequest::TargetIsPrefetch);
27 blink::WebURLLoaderOptions options;
28 options.allowCredentials = true;
29 options.crossOriginRequestPolicy =
30 blink::WebURLLoaderOptions::CrossOriginRequestPolicyAllow;
31 blink::WebURLLoader* loader = frame->createAssociatedURLLoader(options);
32 loader->loadAsynchronously(request, this);
33 loader_set_.insert(loader);
34 }
35
36 // blink::WebURLLoaderClient implementation.
37 virtual void didFinishLoading(blink::WebURLLoader* loader,
38 double finishTime,
39 int64_t totalEncodedDataLength) OVERRIDE {
40 loader_set_.erase(loader);
41 }
42 virtual void didFail(blink::WebURLLoader* loader,
43 const blink::WebURLError& error) OVERRIDE {
44 loader_set_.erase(loader);
45 }
46
47 private:
48 std::set<blink::WebURLLoader*> loader_set_;
49 };
jochen (gone - plz use gerrit) 2014/06/13 16:42:56 nit. disallow copy & assign
tburkard 2014/06/13 18:35:46 obsolete comment
50
51 PrefetchHelper::PrefetchHelper(content::RenderFrame* render_frame)
52 : content::RenderFrameObserver(render_frame),
53 prefetch_manager_(new PrefetchManager()) {
54 }
55
56 PrefetchHelper::~PrefetchHelper() {
57 }
58
59 bool PrefetchHelper::OnMessageReceived(
60 const IPC::Message& message) {
61 IPC_BEGIN_MESSAGE_MAP(PrefetchHelper, message)
62 IPC_MESSAGE_HANDLER(PrefetchMsg_Prefetch, OnPrefetch)
63 IPC_END_MESSAGE_MAP()
64 // Return false on ViewMsg_SetIsPrefetching so other observers can see the
65 // message.
jam 2014/06/13 16:44:37 i dont think you need this behavior for this ipc,
tburkard 2014/06/13 18:35:45 Done. Does this look ok?
66 return false;
67 }
68
69 void PrefetchHelper::OnPrefetch(const GURL& url) {
70 prefetch_manager_->AddPrefetch(render_frame()->GetWebFrame(), url);
jochen (gone - plz use gerrit) 2014/06/13 16:42:56 what's the reason you use a separate class here?
jkarlin 2014/06/13 16:53:46 Also, I'm adding a chrome/browser/prefetch/prefetc
tburkard 2014/06/13 18:35:46 Done.
tburkard 2014/06/13 18:35:46 Done.
71 }
72
73 } // namespace prefetch
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698