Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame^] | 1 | // Copyright 2014 The Chromium Authors |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 2 | // 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 | |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
dcheng | 24f43a5e9 | 2016-04-22 18:29:09 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 12 | #include "base/callback.h" |
[email protected] | bc4f946 | 2014-06-23 18:24:45 | [diff] [blame] | 13 | #include "base/files/file.h" |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 14 | #include "base/memory/weak_ptr.h" |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 15 | #include "base/process/process.h" |
| 16 | #include "base/synchronization/lock.h" |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 17 | #include "ipc/ipc_listener.h" |
| 18 | |
| 19 | namespace base { |
| 20 | class WaitableEvent; |
| 21 | } // namespace base |
| 22 | |
| 23 | namespace IPC { |
| 24 | struct ChannelHandle; |
| 25 | class Message; |
| 26 | class SyncChannel; |
| 27 | } // namespace IPC |
| 28 | |
| 29 | namespace nacl { |
| 30 | |
| 31 | class ManifestServiceChannel : public IPC::Listener { |
| 32 | public: |
Shengfa Lin | 68f7cc6 | 2020-07-09 15:48:21 | [diff] [blame] | 33 | typedef base::OnceCallback<void(base::File, uint64_t, uint64_t)> |
Justin TerAvest | cffdd03 | 2014-09-10 19:21:56 | [diff] [blame] | 34 | OpenResourceCallback; |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 35 | |
[email protected] | 43fb4f8 | 2014-04-23 11:53:13 | [diff] [blame] | 36 | 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] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 43 | // Called when irt_open_resource() is invoked in the NaCl plugin. |
[email protected] | bc4f946 | 2014-06-23 18:24:45 | [diff] [blame] | 44 | // Upon completion, callback is invoked with the file. |
Shengfa Lin | 68f7cc6 | 2020-07-09 15:48:21 | [diff] [blame] | 45 | virtual void OpenResource(const std::string& key, |
| 46 | OpenResourceCallback callback) = 0; |
[email protected] | 43fb4f8 | 2014-04-23 11:53:13 | [diff] [blame] | 47 | }; |
| 48 | |
Shengfa Lin | 68f7cc6 | 2020-07-09 15:48:21 | [diff] [blame] | 49 | 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öm | 09c0182 | 2021-09-20 22:43:27 | [diff] [blame] | 53 | |
| 54 | ManifestServiceChannel(const ManifestServiceChannel&) = delete; |
| 55 | ManifestServiceChannel& operator=(const ManifestServiceChannel&) = delete; |
| 56 | |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 57 | ~ManifestServiceChannel() override; |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 58 | |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 59 | void Send(IPC::Message* message); |
| 60 | |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 61 | // Listener implementation. |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 62 | bool OnMessageReceived(const IPC::Message& message) override; |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 63 | void OnChannelConnected(int32_t peer_pid) override; |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 64 | void OnChannelError() override; |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 65 | |
| 66 | private: |
[email protected] | 43fb4f8 | 2014-04-23 11:53:13 | [diff] [blame] | 67 | void OnStartupInitializationComplete(); |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 68 | void OnOpenResource(const std::string& key, IPC::Message* reply); |
Justin TerAvest | cffdd03 | 2014-09-10 19:21:56 | [diff] [blame] | 69 | void DidOpenResource(IPC::Message* reply, |
| 70 | base::File file, |
| 71 | uint64_t token_lo, |
| 72 | uint64_t token_hi); |
Shengfa Lin | 68f7cc6 | 2020-07-09 15:48:21 | [diff] [blame] | 73 | base::OnceCallback<void(int32_t)> connected_callback_; |
dcheng | 24f43a5e9 | 2016-04-22 18:29:09 | [diff] [blame] | 74 | std::unique_ptr<Delegate> delegate_; |
| 75 | std::unique_ptr<IPC::SyncChannel> channel_; |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 76 | |
Justin TerAvest | cffdd03 | 2014-09-10 19:21:56 | [diff] [blame] | 77 | base::ProcessId peer_pid_; |
| 78 | |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 79 | // 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 Roman | 5c341f6d | 2019-07-15 15:56:10 | [diff] [blame] | 81 | base::WeakPtrFactory<ManifestServiceChannel> weak_ptr_factory_{this}; |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | } // namespace nacl |
| 85 | |
| 86 | #endif // COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_ |