blob: 4595f0ed5c65740614442f2a6f2d9500aa064a1f [file] [log] [blame]
[email protected]bb86d4c2014-04-17 12:17:151// 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
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]bb86d4c2014-04-17 12:17:1514#include "base/macros.h"
[email protected]ae5f7f82014-05-02 23:24:5215#include "base/memory/weak_ptr.h"
[email protected]ae5f7f82014-05-02 23:24:5216#include "base/process/process.h"
17#include "base/synchronization/lock.h"
[email protected]bb86d4c2014-04-17 12:17:1518#include "ipc/ipc_listener.h"
19
20namespace base {
21class WaitableEvent;
22} // namespace base
23
24namespace IPC {
25struct ChannelHandle;
26class Message;
27class SyncChannel;
28} // namespace IPC
29
30namespace nacl {
31
32class ManifestServiceChannel : public IPC::Listener {
33 public:
Justin TerAvestcffdd032014-09-10 19:21:5634 typedef base::Callback<void(base::File, uint64_t, uint64_t)>
35 OpenResourceCallback;
[email protected]ae5f7f82014-05-02 23:24:5236
[email protected]43fb4f82014-04-23 11:53:1337 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]ae5f7f82014-05-02 23:24:5244 // Called when irt_open_resource() is invoked in the NaCl plugin.
[email protected]bc4f9462014-06-23 18:24:4545 // Upon completion, callback is invoked with the file.
[email protected]ae5f7f82014-05-02 23:24:5246 virtual void OpenResource(
47 const std::string& key,
48 const OpenResourceCallback& callback) = 0;
[email protected]43fb4f82014-04-23 11:53:1349 };
50
[email protected]bb86d4c2014-04-17 12:17:1551 ManifestServiceChannel(
52 const IPC::ChannelHandle& handle,
53 const base::Callback<void(int32_t)>& connected_callback,
dcheng24f43a5e92016-04-22 18:29:0954 std::unique_ptr<Delegate> delegate,
[email protected]bb86d4c2014-04-17 12:17:1555 base::WaitableEvent* waitable_event);
dcheng00ea022b2014-10-21 11:24:5656 ~ManifestServiceChannel() override;
[email protected]bb86d4c2014-04-17 12:17:1557
[email protected]ae5f7f82014-05-02 23:24:5258 void Send(IPC::Message* message);
59
[email protected]bb86d4c2014-04-17 12:17:1560 // Listener implementation.
dcheng00ea022b2014-10-21 11:24:5661 bool OnMessageReceived(const IPC::Message& message) override;
avi26062922015-12-26 00:14:1862 void OnChannelConnected(int32_t peer_pid) override;
dcheng00ea022b2014-10-21 11:24:5663 void OnChannelError() override;
[email protected]bb86d4c2014-04-17 12:17:1564
65 private:
[email protected]43fb4f82014-04-23 11:53:1366 void OnStartupInitializationComplete();
[email protected]ae5f7f82014-05-02 23:24:5267 void OnOpenResource(const std::string& key, IPC::Message* reply);
Justin TerAvestcffdd032014-09-10 19:21:5668 void DidOpenResource(IPC::Message* reply,
69 base::File file,
70 uint64_t token_lo,
71 uint64_t token_hi);
[email protected]bb86d4c2014-04-17 12:17:1572 base::Callback<void(int32_t)> connected_callback_;
dcheng24f43a5e92016-04-22 18:29:0973 std::unique_ptr<Delegate> delegate_;
74 std::unique_ptr<IPC::SyncChannel> channel_;
[email protected]bb86d4c2014-04-17 12:17:1575
Justin TerAvestcffdd032014-09-10 19:21:5676 base::ProcessId peer_pid_;
77
[email protected]ae5f7f82014-05-02 23:24:5278 // 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 Roman5c341f6d2019-07-15 15:56:1080 base::WeakPtrFactory<ManifestServiceChannel> weak_ptr_factory_{this};
[email protected]ae5f7f82014-05-02 23:24:5281
[email protected]bb86d4c2014-04-17 12:17:1582 DISALLOW_COPY_AND_ASSIGN(ManifestServiceChannel);
83};
84
85} // namespace nacl
86
87#endif // COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_