summaryrefslogtreecommitdiffstats
path: root/mojo/shell/public/cpp/shell_client.h
blob: aff1aac40ed5797f7c6b66462d47ccb49115eec6 (plain)
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
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_H_
#define MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_H_

#include <stdint.h>
#include <string>

#include "base/macros.h"
#include "mojo/shell/public/cpp/connection.h"
#include "mojo/shell/public/cpp/identity.h"

namespace mojo {

class Connector;

// An interface representing an instance "known to the Mojo Shell". The
// implementation receives lifecycle messages for the instance and gets the
// opportunity to handle inbound connections brokered by the Shell. Every client
// of ShellConnection must implement this interface, and instances of this
// interface must outlive the ShellConnection.
class ShellClient {
 public:
  ShellClient();
  virtual ~ShellClient();

  // Called once a bidirectional connection with the shell has been established.
  // |identity| is the identity of the instance.
  // |id| is a unique identifier the shell uses to identify this specific
  // instance of the application.
  // Called exactly once before any other method.
  virtual void Initialize(Connector* connector,
                          const Identity& identity,
                          uint32_t id);

  // Called when a connection to this client is brokered by the shell. Override
  // to expose services to the remote application. Return true if the connection
  // should succeed. Return false if the connection should be rejected and the
  // underlying pipe closed. The default implementation returns false.
  virtual bool AcceptConnection(Connection* connection);

  // Called when ShellConnection's ShellClient binding (i.e. the pipe the
  // Mojo Shell has to talk to us over) is closed. A shell client may use this
  // as a signal to terminate. Return true from this method to tell the
  // ShellConnection to run its connection lost closure if it has one, false to
  // prevent it from being run. The default implementation returns true.
  // When used in conjunction with ApplicationRunner, returning true here quits
  // the message loop created by ApplicationRunner, which results in the app
  // quitting.
  virtual bool ShellConnectionLost();

 private:
  DISALLOW_COPY_AND_ASSIGN(ShellClient);
};

}  // namespace mojo

#endif  // MOJO_SHELL_PUBLIC_CPP_SHELL_CLIENT_H_