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.
5 #ifndef COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_
6 #define COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_
8 #include "base/callback.h"
9 #include "base/files/file.h"
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/process/process.h"
14 #include "base/synchronization/lock.h"
15 #include "ipc/ipc_listener.h"
29 class ManifestServiceChannel
: public IPC::Listener
{
31 typedef base::Callback
<void(base::File
)> OpenResourceCallback
;
35 virtual ~Delegate() {}
37 // Called when PPAPI initialization in the NaCl plugin is finished.
38 virtual void StartupInitializationComplete() = 0;
40 // Called when irt_open_resource() is invoked in the NaCl plugin.
41 // Upon completion, callback is invoked with the file.
42 virtual void OpenResource(
43 const std::string
& key
,
44 const OpenResourceCallback
& callback
) = 0;
47 ManifestServiceChannel(
48 const IPC::ChannelHandle
& handle
,
49 const base::Callback
<void(int32_t)>& connected_callback
,
50 scoped_ptr
<Delegate
> delegate
,
51 base::WaitableEvent
* waitable_event
);
52 virtual ~ManifestServiceChannel();
54 void Send(IPC::Message
* message
);
56 // Listener implementation.
57 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
58 virtual void OnChannelConnected(int32 peer_pid
) OVERRIDE
;
59 virtual void OnChannelError() OVERRIDE
;
62 void OnStartupInitializationComplete();
63 void OnOpenResource(const std::string
& key
, IPC::Message
* reply
);
65 void DidOpenResource(IPC::Message
* reply
, base::File file
);
68 base::Callback
<void(int32_t)> connected_callback_
;
69 scoped_ptr
<Delegate
> delegate_
;
70 scoped_ptr
<IPC::SyncChannel
> channel_
;
72 // Note: This should remain the last member so it'll be destroyed and
73 // invalidate the weak pointers before any other members are destroyed.
74 base::WeakPtrFactory
<ManifestServiceChannel
> weak_ptr_factory_
;
76 DISALLOW_COPY_AND_ASSIGN(ManifestServiceChannel
);
81 #endif // COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_