[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 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 |
| 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] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 16 | #include "base/process/process.h" |
| 17 | #include "base/synchronization/lock.h" |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 18 | #include "ipc/ipc_listener.h" |
| 19 | |
| 20 | namespace base { |
| 21 | class WaitableEvent; |
| 22 | } // namespace base |
| 23 | |
| 24 | namespace IPC { |
| 25 | struct ChannelHandle; |
| 26 | class Message; |
| 27 | class SyncChannel; |
| 28 | } // namespace IPC |
| 29 | |
| 30 | namespace nacl { |
| 31 | |
| 32 | class ManifestServiceChannel : public IPC::Listener { |
| 33 | public: |
Justin TerAvest | cffdd03 | 2014-09-10 19:21:56 | [diff] [blame] | 34 | typedef base::Callback<void(base::File, uint64_t, uint64_t)> |
| 35 | OpenResourceCallback; |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 36 | |
[email protected] | 43fb4f8 | 2014-04-23 11:53:13 | [diff] [blame] | 37 | class Delegate { |
| 38 | public: |
| 39 | virtual ~Delegate() {} |
| 40 | |
| 41 | // Called when PPAPI initialization in the NaCl plugin is finished. |
| 42 | virtual void StartupInitializationComplete() = 0; |
| 43 | |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 44 | // Called when irt_open_resource() is invoked in the NaCl plugin. |
[email protected] | bc4f946 | 2014-06-23 18:24:45 | [diff] [blame] | 45 | // Upon completion, callback is invoked with the file. |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 46 | virtual void OpenResource( |
| 47 | const std::string& key, |
| 48 | const OpenResourceCallback& callback) = 0; |
[email protected] | 43fb4f8 | 2014-04-23 11:53:13 | [diff] [blame] | 49 | }; |
| 50 | |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 51 | ManifestServiceChannel( |
| 52 | const IPC::ChannelHandle& handle, |
| 53 | const base::Callback<void(int32_t)>& connected_callback, |
dcheng | 24f43a5e9 | 2016-04-22 18:29:09 | [diff] [blame] | 54 | std::unique_ptr<Delegate> delegate, |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 55 | base::WaitableEvent* waitable_event); |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 56 | ~ManifestServiceChannel() override; |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 57 | |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 58 | void Send(IPC::Message* message); |
| 59 | |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 60 | // Listener implementation. |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 61 | bool OnMessageReceived(const IPC::Message& message) override; |
avi | 2606292 | 2015-12-26 00:14:18 | [diff] [blame] | 62 | void OnChannelConnected(int32_t peer_pid) override; |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 63 | void OnChannelError() override; |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 64 | |
| 65 | private: |
[email protected] | 43fb4f8 | 2014-04-23 11:53:13 | [diff] [blame] | 66 | void OnStartupInitializationComplete(); |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 67 | void OnOpenResource(const std::string& key, IPC::Message* reply); |
Justin TerAvest | cffdd03 | 2014-09-10 19:21:56 | [diff] [blame] | 68 | void DidOpenResource(IPC::Message* reply, |
| 69 | base::File file, |
| 70 | uint64_t token_lo, |
| 71 | uint64_t token_hi); |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 72 | base::Callback<void(int32_t)> connected_callback_; |
dcheng | 24f43a5e9 | 2016-04-22 18:29:09 | [diff] [blame] | 73 | std::unique_ptr<Delegate> delegate_; |
| 74 | std::unique_ptr<IPC::SyncChannel> channel_; |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 75 | |
Justin TerAvest | cffdd03 | 2014-09-10 19:21:56 | [diff] [blame] | 76 | base::ProcessId peer_pid_; |
| 77 | |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 78 | // Note: This should remain the last member so it'll be destroyed and |
| 79 | // invalidate the weak pointers before any other members are destroyed. |
Jeremy Roman | 5c341f6d | 2019-07-15 15:56:10 | [diff] [blame^] | 80 | base::WeakPtrFactory<ManifestServiceChannel> weak_ptr_factory_{this}; |
[email protected] | ae5f7f8 | 2014-05-02 23:24:52 | [diff] [blame] | 81 | |
[email protected] | bb86d4c | 2014-04-17 12:17:15 | [diff] [blame] | 82 | DISALLOW_COPY_AND_ASSIGN(ManifestServiceChannel); |
| 83 | }; |
| 84 | |
| 85 | } // namespace nacl |
| 86 | |
| 87 | #endif // COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_ |