OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/nacl/renderer/trusted_plugin_channel.h" | 5 #include "components/nacl/renderer/trusted_plugin_channel.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "components/nacl/common/nacl_renderer_messages.h" | 8 #include "components/nacl/common/nacl_renderer_messages.h" |
| 9 #include "components/nacl/renderer/histogram.h" |
9 #include "components/nacl/renderer/nexe_load_manager.h" | 10 #include "components/nacl/renderer/nexe_load_manager.h" |
10 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
11 #include "ipc/ipc_sync_channel.h" | 12 #include "ipc/ipc_sync_channel.h" |
12 #include "ipc/ipc_message_macros.h" | 13 #include "ipc/ipc_message_macros.h" |
| 14 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" |
13 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
14 | 16 |
15 namespace nacl { | 17 namespace nacl { |
16 | 18 |
17 TrustedPluginChannel::TrustedPluginChannel( | 19 TrustedPluginChannel::TrustedPluginChannel( |
18 NexeLoadManager* nexe_load_manager, | 20 NexeLoadManager* nexe_load_manager, |
19 const IPC::ChannelHandle& handle, | 21 const IPC::ChannelHandle& handle, |
20 base::WaitableEvent* shutdown_event, | 22 base::WaitableEvent* shutdown_event, |
21 bool report_exit_status) | 23 bool is_helper_nexe) |
22 : nexe_load_manager_(nexe_load_manager), | 24 : nexe_load_manager_(nexe_load_manager), |
23 report_exit_status_(report_exit_status) { | 25 is_helper_nexe_(is_helper_nexe) { |
24 channel_ = IPC::SyncChannel::Create( | 26 channel_ = IPC::SyncChannel::Create( |
25 handle, | 27 handle, |
26 IPC::Channel::MODE_CLIENT, | 28 IPC::Channel::MODE_CLIENT, |
27 this, | 29 this, |
28 content::RenderThread::Get()->GetIOMessageLoopProxy(), | 30 content::RenderThread::Get()->GetIOMessageLoopProxy(), |
29 true, | 31 true, |
30 shutdown_event).Pass(); | 32 shutdown_event).Pass(); |
31 } | 33 } |
32 | 34 |
33 TrustedPluginChannel::~TrustedPluginChannel() { | 35 TrustedPluginChannel::~TrustedPluginChannel() { |
34 } | 36 } |
35 | 37 |
36 bool TrustedPluginChannel::Send(IPC::Message* message) { | 38 bool TrustedPluginChannel::Send(IPC::Message* message) { |
37 return channel_->Send(message); | 39 return channel_->Send(message); |
38 } | 40 } |
39 | 41 |
40 bool TrustedPluginChannel::OnMessageReceived(const IPC::Message& msg) { | 42 bool TrustedPluginChannel::OnMessageReceived(const IPC::Message& msg) { |
41 bool handled = true; | 43 bool handled = true; |
42 IPC_BEGIN_MESSAGE_MAP(TrustedPluginChannel, msg) | 44 IPC_BEGIN_MESSAGE_MAP(TrustedPluginChannel, msg) |
43 IPC_MESSAGE_HANDLER(NaClRendererMsg_ReportExitStatus, OnReportExitStatus); | 45 IPC_MESSAGE_HANDLER(NaClRendererMsg_ReportExitStatus, OnReportExitStatus); |
| 46 IPC_MESSAGE_HANDLER(NaClRendererMsg_ReportLoadStatus, OnReportLoadStatus); |
44 IPC_MESSAGE_UNHANDLED(handled = false); | 47 IPC_MESSAGE_UNHANDLED(handled = false); |
45 IPC_END_MESSAGE_MAP() | 48 IPC_END_MESSAGE_MAP() |
46 return handled; | 49 return handled; |
47 } | 50 } |
48 | 51 |
49 void TrustedPluginChannel::OnChannelError() { | 52 void TrustedPluginChannel::OnChannelError() { |
50 if (report_exit_status_) | 53 if (!is_helper_nexe_) |
51 nexe_load_manager_->NexeDidCrash(); | 54 nexe_load_manager_->NexeDidCrash(); |
52 } | 55 } |
53 | 56 |
54 void TrustedPluginChannel::OnReportExitStatus(int exit_status) { | 57 void TrustedPluginChannel::OnReportExitStatus(int exit_status) { |
55 if (report_exit_status_) | 58 if (!is_helper_nexe_) |
56 nexe_load_manager_->set_exit_status(exit_status); | 59 nexe_load_manager_->set_exit_status(exit_status); |
57 } | 60 } |
58 | 61 |
| 62 void TrustedPluginChannel::OnReportLoadStatus(int load_status) { |
| 63 if (load_status < 0 || load_status > NACL_ERROR_CODE_MAX) { |
| 64 load_status = LOAD_STATUS_UNKNOWN; |
| 65 } |
| 66 // For now, we only report UMA for non-helper nexes |
| 67 // (don't report for the PNaCl translators nexes). |
| 68 if (!is_helper_nexe_) { |
| 69 HistogramEnumerate("NaCl.LoadStatus.SelLdr", load_status, |
| 70 NACL_ERROR_CODE_MAX); |
| 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); |
| 75 } |
| 76 if (load_status != LOAD_OK) { |
| 77 nexe_load_manager_->ReportLoadError( |
| 78 PP_NACL_ERROR_SEL_LDR_START_STATUS, |
| 79 NaClErrorString(static_cast<NaClErrorCode>(load_status))); |
| 80 } |
| 81 } |
| 82 |
59 } // namespace nacl | 83 } // namespace nacl |
OLD | NEW |