| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_ | 5 #ifndef COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_ | 
| 6 #define COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_ | 6 #define COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_ | 
| 7 | 7 | 
| 8 #include "base/callback.h" | 8 #include "base/callback.h" | 
|  | 9 #include "base/files/file.h" | 
| 9 #include "base/macros.h" | 10 #include "base/macros.h" | 
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" | 
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" | 
| 12 #include "base/platform_file.h" |  | 
| 13 #include "base/process/process.h" | 13 #include "base/process/process.h" | 
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" | 
| 15 #include "ipc/ipc_listener.h" | 15 #include "ipc/ipc_listener.h" | 
| 16 | 16 | 
| 17 namespace base { | 17 namespace base { | 
| 18 class WaitableEvent; | 18 class WaitableEvent; | 
| 19 }  // namespace base | 19 }  // namespace base | 
| 20 | 20 | 
| 21 namespace IPC { | 21 namespace IPC { | 
| 22 struct ChannelHandle; | 22 struct ChannelHandle; | 
| 23 class Message; | 23 class Message; | 
| 24 class SyncChannel; | 24 class SyncChannel; | 
| 25 }  // namespace IPC | 25 }  // namespace IPC | 
| 26 | 26 | 
| 27 namespace nacl { | 27 namespace nacl { | 
| 28 | 28 | 
| 29 class ManifestServiceChannel : public IPC::Listener { | 29 class ManifestServiceChannel : public IPC::Listener { | 
| 30  public: | 30  public: | 
| 31   typedef base::Callback<void(const base::PlatformFile&)> OpenResourceCallback; | 31   typedef base::Callback<void(base::File)> OpenResourceCallback; | 
| 32 | 32 | 
| 33   class Delegate { | 33   class Delegate { | 
| 34    public: | 34    public: | 
| 35     virtual ~Delegate() {} | 35     virtual ~Delegate() {} | 
| 36 | 36 | 
| 37     // Called when PPAPI initialization in the NaCl plugin is finished. | 37     // Called when PPAPI initialization in the NaCl plugin is finished. | 
| 38     virtual void StartupInitializationComplete() = 0; | 38     virtual void StartupInitializationComplete() = 0; | 
| 39 | 39 | 
| 40     // Called when irt_open_resource() is invoked in the NaCl plugin. | 40     // Called when irt_open_resource() is invoked in the NaCl plugin. | 
| 41     // Upon completion, callback is invoked with the platform file. | 41     // Upon completion, callback is invoked with the file. | 
| 42     virtual void OpenResource( | 42     virtual void OpenResource( | 
| 43         const std::string& key, | 43         const std::string& key, | 
| 44         const OpenResourceCallback& callback) = 0; | 44         const OpenResourceCallback& callback) = 0; | 
| 45   }; | 45   }; | 
| 46 | 46 | 
| 47   ManifestServiceChannel( | 47   ManifestServiceChannel( | 
| 48       const IPC::ChannelHandle& handle, | 48       const IPC::ChannelHandle& handle, | 
| 49       const base::Callback<void(int32_t)>& connected_callback, | 49       const base::Callback<void(int32_t)>& connected_callback, | 
| 50       scoped_ptr<Delegate> delegate, | 50       scoped_ptr<Delegate> delegate, | 
| 51       base::WaitableEvent* waitable_event); | 51       base::WaitableEvent* waitable_event); | 
| 52   virtual ~ManifestServiceChannel(); | 52   virtual ~ManifestServiceChannel(); | 
| 53 | 53 | 
| 54   void Send(IPC::Message* message); | 54   void Send(IPC::Message* message); | 
| 55 | 55 | 
| 56   // Listener implementation. | 56   // Listener implementation. | 
| 57   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 57   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 
| 58   virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 58   virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 
| 59   virtual void OnChannelError() OVERRIDE; | 59   virtual void OnChannelError() OVERRIDE; | 
| 60 | 60 | 
| 61  private: | 61  private: | 
| 62   void OnStartupInitializationComplete(); | 62   void OnStartupInitializationComplete(); | 
| 63   void OnOpenResource(const std::string& key, IPC::Message* reply); | 63   void OnOpenResource(const std::string& key, IPC::Message* reply); | 
| 64 #if !defined(OS_WIN) | 64 #if !defined(OS_WIN) | 
| 65   void DidOpenResource( | 65   void DidOpenResource(IPC::Message* reply, base::File file); | 
| 66       IPC::Message* reply, const base::PlatformFile& platform_file); |  | 
| 67 #endif | 66 #endif | 
| 68 | 67 | 
| 69   base::Callback<void(int32_t)> connected_callback_; | 68   base::Callback<void(int32_t)> connected_callback_; | 
| 70   scoped_ptr<Delegate> delegate_; | 69   scoped_ptr<Delegate> delegate_; | 
| 71   scoped_ptr<IPC::SyncChannel> channel_; | 70   scoped_ptr<IPC::SyncChannel> channel_; | 
| 72 | 71 | 
| 73   // Note: This should remain the last member so it'll be destroyed and | 72   // Note: This should remain the last member so it'll be destroyed and | 
| 74   // invalidate the weak pointers before any other members are destroyed. | 73   // invalidate the weak pointers before any other members are destroyed. | 
| 75   base::WeakPtrFactory<ManifestServiceChannel> weak_ptr_factory_; | 74   base::WeakPtrFactory<ManifestServiceChannel> weak_ptr_factory_; | 
| 76 | 75 | 
| 77   DISALLOW_COPY_AND_ASSIGN(ManifestServiceChannel); | 76   DISALLOW_COPY_AND_ASSIGN(ManifestServiceChannel); | 
| 78 }; | 77 }; | 
| 79 | 78 | 
| 80 }  // namespace nacl | 79 }  // namespace nacl | 
| 81 | 80 | 
| 82 #endif  // COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_ | 81 #endif  // COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_ | 
| OLD | NEW | 
|---|