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/renderer/histogram.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" |
| 11 #include "content/public/renderer/render_thread.h" |
| 12 #include "ipc/ipc_sync_channel.h" |
| 13 #include "ipc/ipc_message_macros.h" |
10 #include "ppapi/c/pp_errors.h" | 14 #include "ppapi/c/pp_errors.h" |
11 | 15 |
12 namespace nacl { | 16 namespace nacl { |
13 | 17 |
14 TrustedPluginChannel::TrustedPluginChannel( | 18 TrustedPluginChannel::TrustedPluginChannel( |
15 NexeLoadManager* nexe_load_manager, | 19 NexeLoadManager* nexe_load_manager, |
16 mojom::NaClRendererHostRequest request, | 20 const IPC::ChannelHandle& handle, |
| 21 base::WaitableEvent* shutdown_event, |
17 bool is_helper_nexe) | 22 bool is_helper_nexe) |
18 : nexe_load_manager_(nexe_load_manager), | 23 : nexe_load_manager_(nexe_load_manager), |
19 binding_(this, std::move(request)), | |
20 is_helper_nexe_(is_helper_nexe) { | 24 is_helper_nexe_(is_helper_nexe) { |
21 binding_.set_connection_error_handler(base::Bind( | 25 channel_ = IPC::SyncChannel::Create( |
22 &TrustedPluginChannel::OnChannelError, base::Unretained(this))); | 26 handle, IPC::Channel::MODE_CLIENT, this, |
| 27 content::RenderThread::Get()->GetIOTaskRunner(), true, shutdown_event); |
23 } | 28 } |
24 | 29 |
25 TrustedPluginChannel::~TrustedPluginChannel() { | 30 TrustedPluginChannel::~TrustedPluginChannel() { |
26 } | 31 } |
27 | 32 |
| 33 bool TrustedPluginChannel::Send(IPC::Message* message) { |
| 34 return channel_->Send(message); |
| 35 } |
| 36 |
| 37 bool TrustedPluginChannel::OnMessageReceived(const IPC::Message& msg) { |
| 38 bool handled = true; |
| 39 IPC_BEGIN_MESSAGE_MAP(TrustedPluginChannel, msg) |
| 40 IPC_MESSAGE_HANDLER(NaClRendererMsg_ReportExitStatus, OnReportExitStatus); |
| 41 IPC_MESSAGE_HANDLER(NaClRendererMsg_ReportLoadStatus, OnReportLoadStatus); |
| 42 IPC_MESSAGE_UNHANDLED(handled = false) |
| 43 IPC_END_MESSAGE_MAP() |
| 44 return handled; |
| 45 } |
| 46 |
28 void TrustedPluginChannel::OnChannelError() { | 47 void TrustedPluginChannel::OnChannelError() { |
29 if (!is_helper_nexe_) | 48 if (!is_helper_nexe_) |
30 nexe_load_manager_->NexeDidCrash(); | 49 nexe_load_manager_->NexeDidCrash(); |
31 } | 50 } |
32 | 51 |
33 void TrustedPluginChannel::ReportExitStatus( | 52 void TrustedPluginChannel::OnReportExitStatus(int exit_status) { |
34 int exit_status, | |
35 const ReportExitStatusCallback& callback) { | |
36 callback.Run(); | |
37 if (!is_helper_nexe_) | 53 if (!is_helper_nexe_) |
38 nexe_load_manager_->set_exit_status(exit_status); | 54 nexe_load_manager_->set_exit_status(exit_status); |
39 } | 55 } |
40 | 56 |
41 void TrustedPluginChannel::ReportLoadStatus( | 57 void TrustedPluginChannel::OnReportLoadStatus(NaClErrorCode load_status) { |
42 NaClErrorCode load_status, | |
43 const ReportLoadStatusCallback& callback) { | |
44 callback.Run(); | |
45 if (load_status < 0 || load_status > NACL_ERROR_CODE_MAX) { | 58 if (load_status < 0 || load_status > NACL_ERROR_CODE_MAX) { |
46 load_status = LOAD_STATUS_UNKNOWN; | 59 load_status = LOAD_STATUS_UNKNOWN; |
47 } | 60 } |
48 // For now, we only report UMA for non-helper nexes | 61 // For now, we only report UMA for non-helper nexes |
49 // (don't report for the PNaCl translators nexes). | 62 // (don't report for the PNaCl translators nexes). |
50 if (!is_helper_nexe_) { | 63 if (!is_helper_nexe_) { |
51 HistogramEnumerate("NaCl.LoadStatus.SelLdr", load_status, | 64 HistogramEnumerate("NaCl.LoadStatus.SelLdr", load_status, |
52 NACL_ERROR_CODE_MAX); | 65 NACL_ERROR_CODE_MAX); |
53 // Gather data to see if being installed changes load outcomes. | 66 // Gather data to see if being installed changes load outcomes. |
54 const char* name = nexe_load_manager_->is_installed() | 67 const char* name = nexe_load_manager_->is_installed() |
55 ? "NaCl.LoadStatus.SelLdr.InstalledApp" | 68 ? "NaCl.LoadStatus.SelLdr.InstalledApp" |
56 : "NaCl.LoadStatus.SelLdr.NotInstalledApp"; | 69 : "NaCl.LoadStatus.SelLdr.NotInstalledApp"; |
57 HistogramEnumerate(name, load_status, NACL_ERROR_CODE_MAX); | 70 HistogramEnumerate(name, load_status, NACL_ERROR_CODE_MAX); |
58 } | 71 } |
59 if (load_status != LOAD_OK) { | 72 if (load_status != LOAD_OK) { |
60 nexe_load_manager_->ReportLoadError(PP_NACL_ERROR_SEL_LDR_START_STATUS, | 73 nexe_load_manager_->ReportLoadError(PP_NACL_ERROR_SEL_LDR_START_STATUS, |
61 NaClErrorString(load_status)); | 74 NaClErrorString(load_status)); |
62 } | 75 } |
63 } | 76 } |
64 | 77 |
65 void TrustedPluginChannel::ProvideExitControl( | |
66 mojom::NaClExitControlPtr exit_control) { | |
67 exit_control_ = std::move(exit_control); | |
68 } | |
69 | |
70 } // namespace nacl | 78 } // namespace nacl |
OLD | NEW |