Don't preload rarely seen large images
[chromium-blink-merge.git] / components / nacl / renderer / trusted_plugin_channel.cc
blob1ba39fe1efa48025d970c015fc87788197ec0ba5
1 // Copyright 2014 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.
5 #include "components/nacl/renderer/trusted_plugin_channel.h"
7 #include "base/callback_helpers.h"
8 #include "components/nacl/common/nacl_renderer_messages.h"
9 #include "components/nacl/renderer/histogram.h"
10 #include "components/nacl/renderer/nexe_load_manager.h"
11 #include "content/public/renderer/render_thread.h"
12 #include "ipc/ipc_sync_channel.h"
13 #include "ipc/ipc_message_macros.h"
14 #include "ppapi/c/pp_errors.h"
16 namespace nacl {
18 TrustedPluginChannel::TrustedPluginChannel(
19 NexeLoadManager* nexe_load_manager,
20 const IPC::ChannelHandle& handle,
21 base::WaitableEvent* shutdown_event,
22 bool is_helper_nexe)
23 : nexe_load_manager_(nexe_load_manager),
24 is_helper_nexe_(is_helper_nexe) {
25 channel_ = IPC::SyncChannel::Create(
26 handle,
27 IPC::Channel::MODE_CLIENT,
28 this,
29 content::RenderThread::Get()->GetIOMessageLoopProxy(),
30 true,
31 shutdown_event).Pass();
34 TrustedPluginChannel::~TrustedPluginChannel() {
37 bool TrustedPluginChannel::Send(IPC::Message* message) {
38 return channel_->Send(message);
41 bool TrustedPluginChannel::OnMessageReceived(const IPC::Message& msg) {
42 bool handled = true;
43 IPC_BEGIN_MESSAGE_MAP(TrustedPluginChannel, msg)
44 IPC_MESSAGE_HANDLER(NaClRendererMsg_ReportExitStatus, OnReportExitStatus);
45 IPC_MESSAGE_HANDLER(NaClRendererMsg_ReportLoadStatus, OnReportLoadStatus);
46 IPC_MESSAGE_UNHANDLED(handled = false);
47 IPC_END_MESSAGE_MAP()
48 return handled;
51 void TrustedPluginChannel::OnChannelError() {
52 if (!is_helper_nexe_)
53 nexe_load_manager_->NexeDidCrash();
56 void TrustedPluginChannel::OnReportExitStatus(int exit_status) {
57 if (!is_helper_nexe_)
58 nexe_load_manager_->set_exit_status(exit_status);
61 void TrustedPluginChannel::OnReportLoadStatus(NaClErrorCode load_status) {
62 if (load_status < 0 || load_status > NACL_ERROR_CODE_MAX) {
63 load_status = LOAD_STATUS_UNKNOWN;
65 // For now, we only report UMA for non-helper nexes
66 // (don't report for the PNaCl translators nexes).
67 if (!is_helper_nexe_) {
68 HistogramEnumerate("NaCl.LoadStatus.SelLdr", load_status,
69 NACL_ERROR_CODE_MAX);
70 // Gather data to see if being installed changes load outcomes.
71 const char* name = nexe_load_manager_->is_installed()
72 ? "NaCl.LoadStatus.SelLdr.InstalledApp"
73 : "NaCl.LoadStatus.SelLdr.NotInstalledApp";
74 HistogramEnumerate(name, load_status, NACL_ERROR_CODE_MAX);
76 if (load_status != LOAD_OK) {
77 nexe_load_manager_->ReportLoadError(PP_NACL_ERROR_SEL_LDR_START_STATUS,
78 NaClErrorString(load_status));
82 } // namespace nacl