Home | History | Annotate | Download | only in prerender
      1 // Copyright 2013 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_media_load_deferrer.h"
      6 
      7 #include "base/callback_helpers.h"
      8 #include "chrome/common/prerender_messages.h"
      9 
     10 namespace prerender {
     11 
     12 PrerenderMediaLoadDeferrer::PrerenderMediaLoadDeferrer(
     13     content::RenderFrame* render_frame,
     14     const base::Closure& closure)
     15     : RenderFrameObserver(render_frame),
     16       is_prerendering_(true),
     17       continue_loading_cb_(closure) {
     18   DCHECK(!continue_loading_cb_.is_null());
     19 }
     20 
     21 PrerenderMediaLoadDeferrer::~PrerenderMediaLoadDeferrer() {}
     22 
     23 bool PrerenderMediaLoadDeferrer::OnMessageReceived(
     24     const IPC::Message& message) {
     25   IPC_BEGIN_MESSAGE_MAP(PrerenderMediaLoadDeferrer, message)
     26     IPC_MESSAGE_HANDLER(PrerenderMsg_SetIsPrerendering, OnSetIsPrerendering)
     27   IPC_END_MESSAGE_MAP()
     28 
     29   return false;
     30 }
     31 
     32 void PrerenderMediaLoadDeferrer::OnSetIsPrerendering(bool is_prerendering) {
     33   // Prerendering can only be enabled prior to a RenderFrame's first
     34   // navigation, so no PrerenderMediaLoadDeferrer should see the notification
     35   // that enables prerendering.
     36   DCHECK(!is_prerendering);
     37   if (!is_prerendering_ || is_prerendering)
     38     return;
     39 
     40   is_prerendering_ = false;
     41   base::ResetAndReturn(&continue_loading_cb_).Run();
     42 }
     43 
     44 }  // namespace prerender
     45