xref: /aosp_15_r20/external/cronet/components/nacl/renderer/trusted_plugin_channel.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2014 The Chromium Authors
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 "components/nacl/renderer/trusted_plugin_channel.h"
6 
7 #include <utility>
8 
9 #include "base/functional/bind.h"
10 #include "base/functional/callback_helpers.h"
11 #include "components/nacl/renderer/histogram.h"
12 #include "components/nacl/renderer/nexe_load_manager.h"
13 #include "ppapi/c/pp_errors.h"
14 
15 namespace nacl {
16 
TrustedPluginChannel(NexeLoadManager * nexe_load_manager,mojo::PendingReceiver<mojom::NaClRendererHost> receiver,bool is_helper_nexe)17 TrustedPluginChannel::TrustedPluginChannel(
18     NexeLoadManager* nexe_load_manager,
19     mojo::PendingReceiver<mojom::NaClRendererHost> receiver,
20     bool is_helper_nexe)
21     : nexe_load_manager_(nexe_load_manager),
22       receiver_(this, std::move(receiver)),
23       is_helper_nexe_(is_helper_nexe) {
24   receiver_.set_disconnect_handler(base::BindOnce(
25       &TrustedPluginChannel::OnChannelError, base::Unretained(this)));
26 }
27 
~TrustedPluginChannel()28 TrustedPluginChannel::~TrustedPluginChannel() {
29 }
30 
OnChannelError()31 void TrustedPluginChannel::OnChannelError() {
32   if (!is_helper_nexe_)
33     nexe_load_manager_->NexeDidCrash();
34 }
35 
ReportExitStatus(int exit_status,ReportExitStatusCallback callback)36 void TrustedPluginChannel::ReportExitStatus(int exit_status,
37                                             ReportExitStatusCallback callback) {
38   std::move(callback).Run();
39   if (!is_helper_nexe_)
40     nexe_load_manager_->set_exit_status(exit_status);
41 }
42 
ReportLoadStatus(NaClErrorCode load_status,ReportLoadStatusCallback callback)43 void TrustedPluginChannel::ReportLoadStatus(NaClErrorCode load_status,
44                                             ReportLoadStatusCallback callback) {
45   std::move(callback).Run();
46   if (load_status < 0 || load_status > NACL_ERROR_CODE_MAX) {
47     load_status = LOAD_STATUS_UNKNOWN;
48   }
49   // For now, we only report UMA for non-helper nexes
50   // (don't report for the PNaCl translators nexes).
51   if (!is_helper_nexe_) {
52     HistogramEnumerate("NaCl.LoadStatus.SelLdr", load_status,
53                        NACL_ERROR_CODE_MAX);
54     // Gather data to see if being installed changes load outcomes.
55     const char* name = nexe_load_manager_->is_installed()
56                            ? "NaCl.LoadStatus.SelLdr.InstalledApp"
57                            : "NaCl.LoadStatus.SelLdr.NotInstalledApp";
58     HistogramEnumerate(name, load_status, NACL_ERROR_CODE_MAX);
59   }
60   if (load_status != LOAD_OK) {
61     nexe_load_manager_->ReportLoadError(PP_NACL_ERROR_SEL_LDR_START_STATUS,
62                                         NaClErrorString(load_status));
63   }
64 }
65 
ProvideExitControl(mojo::PendingRemote<mojom::NaClExitControl> exit_control)66 void TrustedPluginChannel::ProvideExitControl(
67     mojo::PendingRemote<mojom::NaClExitControl> exit_control) {
68   exit_control_.Bind(std::move(exit_control));
69 }
70 
71 }  // namespace nacl
72