Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / components / nacl / renderer / manifest_service_channel.h
blobdd77bc5b8763da0b9c0cf4080cfa95ca3de33297
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"
17 namespace base {
18 class WaitableEvent;
19 } // namespace base
21 namespace IPC {
22 struct ChannelHandle;
23 class Message;
24 class SyncChannel;
25 } // namespace IPC
27 namespace nacl {
29 class ManifestServiceChannel : public IPC::Listener {
30 public:
31 typedef base::Callback<void(base::File, uint64_t, uint64_t)>
32 OpenResourceCallback;
34 class Delegate {
35 public:
36 virtual ~Delegate() {}
38 // Called when PPAPI initialization in the NaCl plugin is finished.
39 virtual void StartupInitializationComplete() = 0;
41 // Called when irt_open_resource() is invoked in the NaCl plugin.
42 // Upon completion, callback is invoked with the file.
43 virtual void OpenResource(
44 const std::string& key,
45 const OpenResourceCallback& callback) = 0;
48 ManifestServiceChannel(
49 const IPC::ChannelHandle& handle,
50 const base::Callback<void(int32_t)>& connected_callback,
51 scoped_ptr<Delegate> delegate,
52 base::WaitableEvent* waitable_event);
53 ~ManifestServiceChannel() override;
55 void Send(IPC::Message* message);
57 // Listener implementation.
58 bool OnMessageReceived(const IPC::Message& message) override;
59 void OnChannelConnected(int32 peer_pid) override;
60 void OnChannelError() override;
62 private:
63 void OnStartupInitializationComplete();
64 void OnOpenResource(const std::string& key, IPC::Message* reply);
65 void DidOpenResource(IPC::Message* reply,
66 base::File file,
67 uint64_t token_lo,
68 uint64_t token_hi);
69 base::Callback<void(int32_t)> connected_callback_;
70 scoped_ptr<Delegate> delegate_;
71 scoped_ptr<IPC::SyncChannel> channel_;
73 base::ProcessId peer_pid_;
75 // Note: This should remain the last member so it'll be destroyed and
76 // invalidate the weak pointers before any other members are destroyed.
77 base::WeakPtrFactory<ManifestServiceChannel> weak_ptr_factory_;
79 DISALLOW_COPY_AND_ASSIGN(ManifestServiceChannel);
82 } // namespace nacl
84 #endif // COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_