blob: 3c50cbe29a7570fc7646629bbb25e53b01447a8a [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2014 The Chromium Authors
[email protected]bb86d4c2014-04-17 12:17:152// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_
6#define COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_
7
avi26062922015-12-26 00:14:188#include <stdint.h>
9
dcheng24f43a5e92016-04-22 18:29:0910#include <memory>
11
[email protected]bb86d4c2014-04-17 12:17:1512#include "base/callback.h"
[email protected]bc4f9462014-06-23 18:24:4513#include "base/files/file.h"
[email protected]ae5f7f82014-05-02 23:24:5214#include "base/memory/weak_ptr.h"
[email protected]ae5f7f82014-05-02 23:24:5215#include "base/process/process.h"
16#include "base/synchronization/lock.h"
[email protected]bb86d4c2014-04-17 12:17:1517#include "ipc/ipc_listener.h"
18
19namespace base {
20class WaitableEvent;
21} // namespace base
22
23namespace IPC {
24struct ChannelHandle;
25class Message;
26class SyncChannel;
27} // namespace IPC
28
29namespace nacl {
30
31class ManifestServiceChannel : public IPC::Listener {
32 public:
Shengfa Lin68f7cc62020-07-09 15:48:2133 typedef base::OnceCallback<void(base::File, uint64_t, uint64_t)>
Justin TerAvestcffdd032014-09-10 19:21:5634 OpenResourceCallback;
[email protected]ae5f7f82014-05-02 23:24:5235
[email protected]43fb4f82014-04-23 11:53:1336 class Delegate {
37 public:
38 virtual ~Delegate() {}
39
40 // Called when PPAPI initialization in the NaCl plugin is finished.
41 virtual void StartupInitializationComplete() = 0;
42
[email protected]ae5f7f82014-05-02 23:24:5243 // Called when irt_open_resource() is invoked in the NaCl plugin.
[email protected]bc4f9462014-06-23 18:24:4544 // Upon completion, callback is invoked with the file.
Shengfa Lin68f7cc62020-07-09 15:48:2145 virtual void OpenResource(const std::string& key,
46 OpenResourceCallback callback) = 0;
[email protected]43fb4f82014-04-23 11:53:1347 };
48
Shengfa Lin68f7cc62020-07-09 15:48:2149 ManifestServiceChannel(const IPC::ChannelHandle& handle,
50 base::OnceCallback<void(int32_t)> connected_callback,
51 std::unique_ptr<Delegate> delegate,
52 base::WaitableEvent* waitable_event);
Peter Boström09c01822021-09-20 22:43:2753
54 ManifestServiceChannel(const ManifestServiceChannel&) = delete;
55 ManifestServiceChannel& operator=(const ManifestServiceChannel&) = delete;
56
dcheng00ea022b2014-10-21 11:24:5657 ~ManifestServiceChannel() override;
[email protected]bb86d4c2014-04-17 12:17:1558
[email protected]ae5f7f82014-05-02 23:24:5259 void Send(IPC::Message* message);
60
[email protected]bb86d4c2014-04-17 12:17:1561 // Listener implementation.
dcheng00ea022b2014-10-21 11:24:5662 bool OnMessageReceived(const IPC::Message& message) override;
avi26062922015-12-26 00:14:1863 void OnChannelConnected(int32_t peer_pid) override;
dcheng00ea022b2014-10-21 11:24:5664 void OnChannelError() override;
[email protected]bb86d4c2014-04-17 12:17:1565
66 private:
[email protected]43fb4f82014-04-23 11:53:1367 void OnStartupInitializationComplete();
[email protected]ae5f7f82014-05-02 23:24:5268 void OnOpenResource(const std::string& key, IPC::Message* reply);
Justin TerAvestcffdd032014-09-10 19:21:5669 void DidOpenResource(IPC::Message* reply,
70 base::File file,
71 uint64_t token_lo,
72 uint64_t token_hi);
Shengfa Lin68f7cc62020-07-09 15:48:2173 base::OnceCallback<void(int32_t)> connected_callback_;
dcheng24f43a5e92016-04-22 18:29:0974 std::unique_ptr<Delegate> delegate_;
75 std::unique_ptr<IPC::SyncChannel> channel_;
[email protected]bb86d4c2014-04-17 12:17:1576
Justin TerAvestcffdd032014-09-10 19:21:5677 base::ProcessId peer_pid_;
78
[email protected]ae5f7f82014-05-02 23:24:5279 // Note: This should remain the last member so it'll be destroyed and
80 // invalidate the weak pointers before any other members are destroyed.
Jeremy Roman5c341f6d2019-07-15 15:56:1081 base::WeakPtrFactory<ManifestServiceChannel> weak_ptr_factory_{this};
[email protected]bb86d4c2014-04-17 12:17:1582};
83
84} // namespace nacl
85
86#endif // COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_