File: manifest_service_channel.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (86 lines) | stat: -rw-r--r-- 2,726 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_
#define COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_

#include <stdint.h>

#include <memory>

#include "base/files/file.h"
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/process/process.h"
#include "base/synchronization/lock.h"
#include "ipc/ipc_listener.h"

namespace base {
class WaitableEvent;
}  // namespace base

namespace IPC {
struct ChannelHandle;
class Message;
class SyncChannel;
}  // namespace IPC

namespace nacl {

class ManifestServiceChannel : public IPC::Listener {
 public:
  typedef base::OnceCallback<void(base::File, uint64_t, uint64_t)>
      OpenResourceCallback;

  class Delegate {
   public:
    virtual ~Delegate() = default;

    // Called when PPAPI initialization in the NaCl plugin is finished.
    virtual void StartupInitializationComplete() = 0;

    // Called when irt_open_resource() is invoked in the NaCl plugin.
    // Upon completion, callback is invoked with the file.
    virtual void OpenResource(const std::string& key,
                              OpenResourceCallback callback) = 0;
  };

  ManifestServiceChannel(const IPC::ChannelHandle& handle,
                         base::OnceCallback<void(int32_t)> connected_callback,
                         std::unique_ptr<Delegate> delegate,
                         base::WaitableEvent* waitable_event);

  ManifestServiceChannel(const ManifestServiceChannel&) = delete;
  ManifestServiceChannel& operator=(const ManifestServiceChannel&) = delete;

  ~ManifestServiceChannel() override;

  void Send(IPC::Message* message);

  // Listener implementation.
  bool OnMessageReceived(const IPC::Message& message) override;
  void OnChannelConnected(int32_t peer_pid) override;
  void OnChannelError() override;

 private:
  void OnStartupInitializationComplete();
  void OnOpenResource(const std::string& key, IPC::Message* reply);
  void DidOpenResource(IPC::Message* reply,
                       base::File file,
                       uint64_t token_lo,
                       uint64_t token_hi);
  base::OnceCallback<void(int32_t)> connected_callback_;
  std::unique_ptr<Delegate> delegate_;
  std::unique_ptr<IPC::SyncChannel> channel_;

  base::ProcessId peer_pid_;

  // Note: This should remain the last member so it'll be destroyed and
  // invalidate the weak pointers before any other members are destroyed.
  base::WeakPtrFactory<ManifestServiceChannel> weak_ptr_factory_{this};
};

}  // namespace nacl

#endif  // COMPONENTS_NACL_RENDERER_MANIFEST_SERVICE_CHANNEL_H_