Chromium Code Reviews| 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 "content/browser/loader/resource_scheduler_filter.h" | 5 #include "content/browser/loader/resource_scheduler_filter.h" |
| 6 | 6 |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include "base/macros.h" | |
| 10 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 11 #include "content/browser/loader/resource_scheduler.h" | 8 #include "content/browser/loader/resource_scheduler.h" |
| 12 #include "content/common/frame_messages.h" | 9 #include "content/common/frame_messages.h" |
| 13 #include "content/common/view_messages.h" | 10 #include "ipc/ipc_message_macros.h" |
| 14 #include "ui/base/page_transition_types.h" | 11 #include "ui/base/page_transition_types.h" |
| 15 | 12 |
| 16 namespace content { | 13 namespace content { |
| 17 namespace { | |
| 18 const uint32_t kFilteredMessageClasses[] = { | |
| 19 FrameMsgStart, ViewMsgStart, | |
| 20 }; | |
| 21 } // namespace | |
| 22 | 14 |
| 23 ResourceSchedulerFilter::ResourceSchedulerFilter(int child_id) | 15 ResourceSchedulerFilter::ResourceSchedulerFilter(int child_id) |
| 24 : BrowserMessageFilter( | 16 : BrowserMessageFilter(FrameMsgStart), child_id_(child_id) {} |
| 25 kFilteredMessageClasses, arraysize(kFilteredMessageClasses)), | |
| 26 child_id_(child_id) { | |
| 27 } | |
| 28 | 17 |
| 29 ResourceSchedulerFilter::~ResourceSchedulerFilter() { | 18 ResourceSchedulerFilter::~ResourceSchedulerFilter() {} |
| 30 } | |
| 31 | 19 |
| 32 bool ResourceSchedulerFilter::OnMessageReceived(const IPC::Message& message) { | 20 bool ResourceSchedulerFilter::OnMessageReceived(const IPC::Message& message) { |
| 33 ResourceScheduler* scheduler = | 21 ResourceScheduler* scheduler = ResourceDispatcherHostImpl::Get()->scheduler(); |
| 34 ResourceDispatcherHostImpl::Get()->scheduler(); | |
| 35 // scheduler can be NULL during shutdown, in which case it's ok to ignore the | |
| 36 // renderer's messages. | |
| 37 if (!scheduler) | 22 if (!scheduler) |
| 38 return false; | 23 return false; |
| 39 | 24 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(ResourceSchedulerFilter, message, scheduler) |
| 40 switch (message.type()) { | 25 IPC_MESSAGE_HANDLER(FrameHostMsg_DidCommitProvisionalLoad, |
| 41 case FrameHostMsg_DidCommitProvisionalLoad::ID: { | 26 OnDidCommitProvisionalLoad) |
| 42 base::PickleIterator iter(message); | 27 IPC_MESSAGE_HANDLER(FrameHostMsg_WillInsertBody, OnWillInsertBody) |
| 43 FrameHostMsg_DidCommitProvisionalLoad_Params params; | 28 IPC_END_MESSAGE_MAP() |
| 44 if (!IPC::ParamTraits<FrameHostMsg_DidCommitProvisionalLoad_Params>::Read( | |
| 45 &message, &iter, ¶ms)) { | |
| 46 break; | |
| 47 } | |
| 48 if (ui::PageTransitionIsMainFrame(params.transition) && | |
| 49 !params.was_within_same_page) { | |
| 50 // We need to track the RenderViewHost routing_id because of downstream | |
| 51 // dependencies (crbug.com/392171 DownloadRequestHandle, | |
| 52 // SaveFileManager, ResourceDispatcherHostImpl, MediaStreamUIProxy, | |
| 53 // SpeechRecognitionDispatcherHost and possibly others). They look up | |
| 54 // the view based on the ID stored in the resource requests. | |
| 55 // Once those dependencies are unwound or moved to RenderFrameHost | |
| 56 // (crbug.com/304341) we can move the client to be based on the | |
| 57 // routing_id of the RenderFrameHost. | |
| 58 scheduler->OnNavigate(child_id_, params.render_view_routing_id); | |
| 59 } | |
| 60 break; | |
| 61 } | |
| 62 | |
| 63 case ViewHostMsg_WillInsertBody::ID: | |
| 64 scheduler->OnWillInsertBody(child_id_, message.routing_id()); | |
| 65 break; | |
| 66 | |
| 67 default: | |
| 68 break; | |
| 69 } | |
| 70 | |
| 71 return false; | 29 return false; |
| 72 } | 30 } |
| 73 | 31 |
| 32 void ResourceSchedulerFilter::OnDidCommitProvisionalLoad( | |
| 33 ResourceScheduler* scheduler, | |
| 34 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { | |
| 35 // TODO(csharrison): This isn't quite right for OOPIF, as we *do* want to | |
| 36 // propogate OnNavigate to the client associated with the OOPIF's RVH. This | |
|
nasko
2017/01/31 15:50:34
nit: "propagate"?
Charlie Harrison
2017/01/31 20:19:31
Done.
| |
| 37 // should not result in show-stopping bugs, just poorer loading performance. | |
| 38 if (ui::PageTransitionIsMainFrame(params.transition) && | |
| 39 !params.was_within_same_page) { | |
| 40 scheduler->OnNavigate(child_id_, params.render_view_routing_id); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 void ResourceSchedulerFilter::OnWillInsertBody(ResourceScheduler* scheduler, | |
| 45 int render_view_routing_id) { | |
| 46 scheduler->OnWillInsertBody(child_id_, render_view_routing_id); | |
| 47 } | |
| 48 | |
| 74 } // namespace content | 49 } // namespace content |
| OLD | NEW |